Downloading a Block of Code from PunyForth

In a previous post, I was talking about how you can edit blocks of flash code directly on the ESP2866 punyforth system, if you want to do so. That raises the question of how you could get that code off the chip and saved onto your PC (say for version control) without having to do some painful copying and pasting. The answer is that you can use esptool.py to download the block of code that you want.

Let's say I have been editing a block:

First of all, DON'T FORGET to run the flush command to save recent edits to flash.

Next, you need to get the blocknumber, which I have saved as a constant:

Multiply that by 4096 to get that actual starting byte number, in this case 606208.

Then use esptool.py to read 4096 bytes from that starting address into a file:

If your module uses more than one block, just multiply 4096 in the above line by the number of blocks.

You can see my program is not using much of that block yet.

The data in the outputted binary file contains the padding spaces as well, so I should be able to do this process in reverse also, using write_flash. I have not gotten around to trying that yet.

As I have mentioned previously, editing programs in this way does waste some flash space, since we inevitably have some unnecessary padding in a block. But, on these ESP systems at least, we have a LOT of flash to work with, at least compared to the amount of RAM available. Anyway, there are easy things that you could do later to turn your space-padded code into a compressed format, if you needed to do so.

Proxied content from gemini://gem.librehacker.com/gemlog/tech/20211021-0.gmi

Gemini request details:

Original URL
gemini://gem.librehacker.com/gemlog/tech/20211021-0.gmi
Status code
Success
Meta
text/gemini
Proxied by
kineto

Be advised that no attempt was made to verify the remote SSL certificate.