Hi,
is there a way to clean the flash of a micropython board with one command. I don't want to reflash the whole flash.
So basically a equivalent to "rm -r /" but remotely on the board.
Why?
Because i want to write some kind of continuous deployment for a showcase. So when a new version of the program is there in want to programmatically take that firmware and transfer it to the micropython board. And to make sure no leftovers stay there i want to wipe everything beforehand.
What i tried already
I tried probably every existing command line program (ampy, mpytool, mpremote, mpr) that isn't interactive (rshell, mpsync, mpfshell). But they all need a concrete filename or directory name.
My first approach was to build upon mpytool since it can be directly imported but the "put" command feels unfinished compared to the rest.
Is there really no way to omit first reading the content, parsing the filelist, walk through the directory tree and delete every file seperately?
I would be really thankful for a hint.
Wipe Board with one command
Re: Wipe Board with one command
You can do this by formatting the block device with the filesystem. Unfortunately right now the exact sequence of commands is different on different ports.
See instructions here for formatting a device as FAT or LittleFS. https://docs.micropython.org/en/latest/ ... ilesystems
I have this in my mpremote config, and it will re-format the device as LittleFS. You could adapt this for FAT based on the docs.
Code: Select all
commands = {
"littlefs_stm": [
"exec",
"--no-follow",
"import os, pyb, machine; os.umount('/flash'); os.VfsLfs2.mkfs(pyb.Flash(start=0)); os.mount(pyb.Flash(start=0), '/flash'); os.chdir('/flash'); machine.reset()",
],
"littlefs_rp2": [
"exec",
"--no-follow",
"import os, machine, rp2; os.umount('/'); bdev = rp2.Flash(); os.VfsLfs2.mkfs(bdev, progsize=256); vfs = os.VfsLfs2(bdev, progsize=256); os.mount(vfs, '/'); machine.reset()",
],
"littlefs_esp": [
"exec",
"--no-follow",
"import os; os.umount('/'); os.VfsLfs2.mkfs(bdev); os.mount(bdev, '/'); machine.reset()",
]
}
Re: Wipe Board with one command
Hi,
thanks for the answer. I haven't really though about reformating the device.
When trying it in repl it worked but i have some problems with mpremote.
My understanding from the docs is that "mpremote connect u0" should connect to the board but not start a repl shell. But that is what is always does for me.
Therefore using exec on the command line won't work since i'm, stuck in repl when i execute the commands programatically.
Do you have any idea why that isn't working?
thanks for the answer. I haven't really though about reformating the device.
When trying it in repl it worked but i have some problems with mpremote.
My understanding from the docs is that "mpremote connect u0" should connect to the board but not start a repl shell. But that is what is always does for me.
Therefore using exec on the command line won't work since i'm, stuck in repl when i execute the commands programatically.
Do you have any idea why that isn't working?
Re: Wipe Board with one command
mpremote takes a series of commands to execute one after the other, but it has no state across multiple invocations.lhoff wrote: ↑Sun Jul 10, 2022 7:38 pmMy understanding from the docs is that "mpremote connect u0" should connect to the board but not start a repl shell. But that is what is always does for me.
Therefore using exec on the command line won't work since i'm, stuck in repl when i execute the commands programatically.
The rule is basically that if you don't do a specific control command (e.g. exec, run, fs, etc) then "repl" is added by default.
So "mpremote connect u0" is the same as "mpremote connect u0 repl".
You can also do (for example) "mpremote connect u0 exec "print(1 + 1)" repl".
I think we need to improve the docs for mpremote because the current docs are not very clear on this and it's a bit of an FAQ now
Re: Wipe Board with one command
Not quite sure what you mean here though... if you use
Code: Select all
mpremote connect u0 exec 'python code'
Re: Wipe Board with one command
Oh OK got it, thanks.jimmo wrote: ↑Mon Jul 11, 2022 12:27 am
mpremote takes a series of commands to execute one after the other, but it has no state across multiple invocations.
The rule is basically that if you don't do a specific control command (e.g. exec, run, fs, etc) then "repl" is added by default.
So "mpremote connect u0" is the same as "mpremote connect u0 repl".
You can also do (for example) "mpremote connect u0 exec "print(1 + 1)" repl".
A quick fix would be to add the example from your post to the examples in the docs because there is no other example with connect and a command in it. I was reading the first three examples as "three possible ways to connect"
If I find some time tomorrow I'll create a PR for the Docs so I would understand it