How do you burn a .ubp file to an ESP32 motherboard and run it using the burn firmware method?

Issue #549 resolved
xixicarry created an issue

Hi,John

I'm planning to implement a microblocks firmware and project burn-in for ESP32 devices in the scratch platform. The project I'm currently using is https://espressif.github.io/esptool-js/
I see these configurations in the microblocks code

I burned the firmware using 0x1000 and it would burn but not work, switching to 0x0 allowed me to burn and use it normally.
Then I have another ubp project that I want to correspond to burn into mbcode, I used 0x1e8000 as the Flash Address, it can be burned but can't be used, please tell me what I should do to achieve the same function as the microblocks platform to burn the program.

Comments (12)

  1. John Maloney repo owner

    There are two ways that ESP32 firmware can be installed:

    1. Installing four files (bootloader, boot_app, partitions file, and the actual firmware file, each at their own address)
    2. Installing an "all-in-one" .bin file at address 0x0. I'm not sure how to build such a file but it is possible.

    The address are:

    1. bootloader (e.g. bootloader_dio_40m.bin): 0x1000 for ESP32 and ESP32-S2, 0x0 for ESP32-S3 and ESP32-C3
    2. boot_app0.bin: 0xe000
    3. MicroBlocks partitions file: 0x8000
    4. actual application firmware: 0x10000

    Note: Different ESP32 boards use different bootloader files. Make sure you use the right one for your board.

    You can find all the necessary files in the smallvm/esp32 folder.

    You can find these details in smallvm/ide/ESPTool.gp

  2. xixicarry reporter

    How can a .ubp program file be burned into the motherboard and booted up in the same way as a firmware burn?

  3. John Maloney repo owner

    So can .ubp program files be burned directly into it as well?

    Yes, it can be done, with some effort.

    How many boards do you need to produce?

    For a small number of boards, you can do install the .ubp file manually. Have the .ubp file loaded into the IDE, connect each board, wait for the project to load (i.e. the circular load progress indicator to disappear), then disconnect. I've done this for workshops. For a few dozen boards, the process does not take too long.

    However, to produce hundreds of boards, you'll can automate that process.

    First, use the MicroBlocks IDE to install the .upb file on one board and test it to make sure everything works.

    Then, use esptool to read. 0x28000 bytes from 0x1e8000 into a file. (As you guessed, the mbcode partition is where MicroBlocks stores the compiled code for the .ubp file.) To install that code on other boards, you would simply write that file on the the board at 0x1e8000. Of course, you also need to install the four files I mentioned earlier.

    I haven't actually tried this, but it should work. Let me know if it does.

    It sounds as though this is for a commercial product. How many do you hope to sell? When the product launches, please send us a link to it. Good luck!

  4. Dariusz Dorożalski

    A "bulk" copy of the already MB programmed flash, with the read_flash, write_flash does not work for you? Does it take too long for the whole memory?

    For 4MB version

    esptool.py -p PORT read_flash 0 0x400000 flash_dump.bin

    esptool.py -p PORT write_flash 0 flash_dump.bin

  5. John Maloney repo owner

    Thanks for the suggestion, Dariusz. That's much simpler than doing five separate writes!

  6. xixicarry reporter

    Hi all, according to your suggestions, using the following method you can successfully merge the program to the firmware and achieve boot enable.

    1. first burn the required program into the motherboard
    2. Read the file and save it as (.bin) file Method: esptool.py --chip ESP32 read_flash 0x1e8000 0x28000 output_file.bin
    3. merge into a single firmware Method: esptool.py --chip ESP32 merge_bin -o merged-flash.bin --flash_mode dio --flash_size 4MB 0x1000 esp32/bootloader_dio_40m.bin 0x8000 esp32/partitionsMicroBlocks.bin 0xe000 esp32/boot_app0.bin 0x10000
      .pio/build/longan-core/firmware.bin 0x1e8000 output_file.bin (note that you need to adjust the directory where firmware.bin is stored)
    4. Burn the firmware for testing Method: esptool.py write_flash 0x0 merged-flash.bin

  7. Log in to comment