-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Writing >= 16MB addresses not working (ESF-106) #92
Comments
Hello @higaski , we do not know of any limitation that would cause flashing some memory regions to fail. Can you please provide either a log with |
How should Also none of your examples writes larger binaries at higher adresses. Could you maybe add one? |
I apologize, I have assumed you have implemented debug tracing in the same way as it is implemented in other ports. In that case either copy over the tracing from other ports to your port and enable it, or provide a logic analyzer trace.
Thanks for the suggestion, we will explore the idea! |
Oh I'm sorry now I got it. I thought the macro enables I'll provide logs tomorrow. |
Unification of logging/tracing is something we are looking into for the future, but it requires quite extensive changes. |
I've added the logging. Here is a log of me trying to write the --- WRITE ---
c0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 c0
--- READ ---
45 53 50 2d 52 4f 4d 3a 65 73 70 33 32 73 33 2d 32 30 32 31 30 33 32 37 0d 0a 42 75 69 6c 64 3a 4d 61 72 20 32 37 20 32 30 32 31 0d 0a 72 73 74 3a 30 78 31 20 28 50 4f 57 45 52 4f 4e 29 2c 62 6f 6f 74 3a 30 78 31 30 20 28 44 4f 57 4e 4c 4f 41 44 28 55 53 42 2f 55 41 52 54 30 29 29 0d 0a 77 61 69 74 69 6e 67 20 66 6f 72 20 64 6f 77 6e 6c 6f 61 64 0d 0a
--- WRITE ---
c0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 c0
--- READ ---
c0 01 08 04 00 07 07 12 20 00 00 00 00 c0 c0 01 08 04 00 07 07 12 20 00 00 00 00 c0 c0 01 08 04 00 07 07 12 20 00 00 00 00 c0 c0 01 08 04 00 07 07 12 20 00 00 00 00 c0 c0 01 08 04 00 07 07 12 20 00 00 00 00 c0 c0 01 08 04 00 07 07 12 20 00 00 00 00 c0 c0 01 08 04 00 07 07 12 20 00 00 00 00 c0 c0 01 08 04 00 07 07 12 20 00 00 00 00 c0
--- WRITE ---
c0 00 0a 04 00 00 00 00 00 00 10 00 40 c0
--- READ ---
c0 01 0a 04 00 09 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 0a 04 00 00 00 00 00 48 70 00 60 c0
--- READ ---
c0 01 0a 04 00 12 f4 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 0a 04 00 00 00 00 00 4c 70 00 60 c0
--- READ ---
c0 01 0a 04 00 00 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 0d 08 00 00 00 00 00 00 00 00 00 00 00 00 00 c0
--- READ ---
c0 01 0d 04 00 00 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 0a 04 00 00 00 00 00 18 20 00 60 c0
--- READ ---
c0 01 0a 04 00 00 00 00 80 00 00 00 00 c0
--- WRITE ---
c0 00 0a 04 00 00 00 00 00 20 20 00 60 c0
--- READ ---
c0 01 0a 04 00 00 00 00 70 00 00 00 00 c0
--- WRITE ---
c0 00 09 10 00 00 00 00 00 28 20 00 60 17 00 00 00 ff ff ff ff 00 00 00 00 c0
--- READ ---
c0 01 09 04 00 00 00 00 70 00 00 00 00 c0
--- WRITE ---
c0 00 09 10 00 00 00 00 00 18 20 00 60 00 00 00 90 ff ff ff ff 00 00 00 00 c0
--- READ ---
c0 01 09 04 00 00 00 00 70 00 00 00 00 c0
--- WRITE ---
c0 00 09 10 00 00 00 00 00 20 20 00 60 9f 00 00 70 ff ff ff ff 00 00 00 00 c0
--- READ ---
c0 01 09 04 00 00 00 00 70 00 00 00 00 c0
--- WRITE ---
c0 00 09 10 00 00 00 00 00 58 20 00 60 00 00 00 00 ff ff ff ff 00 00 00 00 c0
--- READ ---
c0 01 09 04 00 00 00 00 70 00 00 00 00 c0
--- WRITE ---
c0 00 09 10 00 00 00 00 00 00 20 00 60 00 00 04 00 ff ff ff ff 00 00 00 00 c0
--- READ ---
c0 01 09 04 00 00 00 00 70 00 00 00 00 c0
--- WRITE ---
c0 00 0a 04 00 00 00 00 00 00 20 00 60 c0
--- READ ---
c0 01 0a 04 00 00 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 0a 04 00 00 00 00 00 58 20 00 60 c0
--- READ ---
c0 01 0a 04 00 c2 80 39 00 00 00 00 00 c0
--- WRITE ---
c0 00 09 10 00 00 00 00 00 18 20 00 60 00 00 00 80 ff ff ff ff 00 00 00 00 c0
--- READ ---
c0 01 09 04 00 c2 80 39 00 00 00 00 00 c0
--- WRITE ---
c0 00 09 10 00 00 00 00 00 20 20 00 60 00 00 00 70 ff ff ff ff 00 00 00 00 c0
--- READ ---
c0 01 09 04 00 c2 80 39 00 00 00 00 00 c0
--- WRITE ---
c0 00 02 14 00 00 00 00 00 00 00 ff 00 db dc 3f 00 00 00 04 00 00 00 00 01 01 00 00 00 00 c0
--- READ ---
c0 01 02 04 00 c2 80 39 00 01 06 00 00 c0 I'm getting shut down in line 121 of check_response esp-serial-flasher/src/protocol_uart.c Lines 97 to 121 in 105279c
Here is the call stack at this point libflasher.so!check_response(command_t cmd, uint32_t * reg_value, void * resp, uint32_t resp_size)
libflasher.so!send_cmd(const void * cmd_data, uint32_t size, uint32_t * reg_value)
libflasher.so!loader_flash_begin_cmd(uint32_t offset, uint32_t erase_size, uint32_t block_size, uint32_t blocks_to_write, _Bool encryption)
libflasher.so!esp_loader_flash_start(uint32_t offset, uint32_t image_size, uint32_t block_size) |
Thanks for the data, after looking into this in the ROM, I don't see any reason it would fail, however it is possible that the default hardcoded params used by Can you compare the parameters of the flash chip used on your board to these? |
I'm using a ESP32-S3-WROOM-2-N32R8V module. Do they come with different flash chips? I don't think that this is the issue though. Flashing generally seems to work. I can write the hello_world example just fine. I assume that this also wouldn't work if the flash parameters would be wrong? /edit |
Good spot, it seems that is the reason |
I've manually set the flash size to 32MB, but this doesn't cut it. I can now flash the project, but it's giving me an "invalid header" error after reboot. Is there anything else beside flash size I might need to set? |
Did you successfully manage to flash the same exact binaries with |
Flashing with the idf.py frontend works yes. |
Have you enabled the MD5 checks? Also, can you read back the contents of the flash flashed with |
I haven't gotten MD5 to work yet. Even on examples which work it keeps telling me that my MD5 checks fail. Haven't looked into this further. For the esptool, yes, I'll try that tomorrow. |
Out of curiosity I've started flashing the hello_world example at various addresses. I've used the following partition table and gradually increased the location of the app binary.
This works up to I'll read out the written binaries later that day to see where exactly it fails. |
Thanks for the data, I will investigate this further. |
Hello @higaski , it appears the flasher stub used by |
Does this mean that the |
Any updates on this? Can you please give me a time frame for when this will be addressed? |
Hello @higaski , thank you for the interest however we don't have an ETA for this yet. |
Just for reference and other people coming here: It doesn't. |
Sorry for the late confirmation, but yes it doesn't and as far as I know can't. So we need to add stub support before going forward with this. If you can't wait, and want to contribute to help with this we are welcome to help you through the process. |
I've peeked at the esptool source for a little while and this seems like a daunting task now... I assume the following steps would be necessary:
|
Can you elaborate on Yes, for stub use, it is uploaded to RAM, then jumped to and then there are differences in behavior that have to be accounted for in flashing code. |
I think this could be done even without a flasher stub. In the case of esptool, the reason for being not supported is because flasher stub is used by default so adding support without flasher stub wasn't a priority (and not because it wasn't possible). |
I'm sorry my bad. Yes, flash detection works now, my 32MB flash is recognized correctly. |
What would have to be done to finally support >16MB? Are there any necessary changes to the ESP32 bootloader? /edit |
@higaski Continuing the discussion at espressif/esp-idf#8365 (comment), here are some pointers about the flasher stub. The stub source code is available in https://github.com/espressif/esptool/tree/master/flasher_stub. I think you probably don't need to build the stub from source in this particular case, and it is simpler to get the compiled stubs from https://github.com/espressif/esptool/tree/master/esptool/targets/stub_flasher. Each of the JSON files contains base64-encoded .text and .data segments, as well as their load addresses. There is also the entry point address. The flasher tool needs to upload the .text and .data segments to the correct addresses, then instruct the ROM loader to jump to the entry point. I think what might help you is to run Another implementation of uploading the stub can be found in esptool-js project, in case it helps: https://github.com/espressif/esptool-js/blob/7ed57e18642088675bec01b8e34ba196d5e135af/src/esploader.ts#L1142-L1188. |
@higaski Keep in mind that the behavior of the stub is not identical to the behavior of the ROM, this is why it is going to take a bit of work for us to add the stub support. For all differences you can check the esptool source code. |
Are you already working on it? Because I've just forked the current master... 😃 |
Not at the moment, no. We will not add it until Q3 at least due to other feature work in |
Do I have to worry about the *beta versions of the stub too or is that something internal to Espressif? Currently esp-serial-flasher has an enumeration for supported targets typedef enum {
ESP8266_CHIP = 0,
ESP32_CHIP = 1,
ESP32S2_CHIP = 2,
ESP32C3_CHIP = 3,
ESP32S3_CHIP = 4,
ESP32C2_CHIP = 5,
ESP32_RESERVED0_CHIP = 6, // Reserved for future use
ESP32H2_CHIP = 7,
ESP32C6_CHIP = 8,
ESP_MAX_CHIP = 9,
ESP_UNKNOWN_CHIP = 9
} target_chip_t; And that enum does not contain any "*beta" versions. |
If you only need to support the chips which are mass-produced, then you don't have to worry about the |
Why does the code send a FLASH_BEGIN command with all 0's for the ESP8266? esp-serial-flasher/src/esp_loader.c Lines 91 to 93 in 2851591
Is this for the "erase size bug" mentioned in the docs? And... more questions. I think I can now successfully upload the stub loader but I get shut down right after when the loader tries to read the SPI config. esp-serial-flasher/src/esp_loader.c Lines 94 to 96 in 2851591
Here's the log at this point --- WRITE ---
c0 00 06 08 00 00 00 00 00 00 00 00 00 50 8a 37 40 c0 # Done with stub, jump to addr
--- READ ---
c0 01 06 04 00 09 00 00 00 00 00 00 00 c0 # Done with stub response?
--- WRITE ---
c0 00 0a 04 00 00 00 00 00 48 70 00 60 c0
--- READ ---
c0 4f 48 41 49 c0 c0 01 0a 02 00 12 f4 00 00 00 00 c0
--- WRITE ---
c0 00 0a 04 00 00 00 00 00 18 20 00 60 c0
--- READ ---
c0 01 0a 02 00 00 00 00 80 00 00 c0
--- WRITE ---
c0 00 0a 04 00 00 00 00 00 20 20 00 60 c0
--- READ ---
c0 01 0a 02 00 00 00 00 70 00 00 c0
--- WRITE ---
c0 00 09 10 00 00 00 00 00 28 20 00 60 17 00 00 00 ff ff ff ff 00 00 00 00 c0
--- READ ---
c0 01 09 02 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 09 10 00 00 00 00 00 18 20 00 60 00 00 00 90 ff ff ff ff 00 00 00 00 c0
--- READ ---
c0 01 09 02 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 09 10 00 00 00 00 00 20 20 00 60 9f 00 00 70 ff ff ff ff 00 00 00 00 c0
--- READ ---
c0 01 09 02 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 09 10 00 00 00 00 00 58 20 00 60 00 00 00 00 ff ff ff ff 00 00 00 00 c0
--- READ ---
c0 01 09 02 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 09 10 00 00 00 00 00 00 20 00 60 00 00 04 00 ff ff ff ff 00 00 00 00 c0
--- READ ---
c0 01 09 02 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 0a 04 00 00 00 00 00 00 20 00 60 c0
--- READ ---
c0 01 0a 02 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 0a 04 00 00 00 00 00 58 20 00 60 c0
--- READ ---
c0 01 0a 02 00 c2 80 39 00 00 00 c0
--- WRITE ---
c0 00 09 10 00 00 00 00 00 18 20 00 60 00 00 00 80 ff ff ff ff 00 00 00 00 c0
--- READ ---
c0 01 09 02 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 09 10 00 00 00 00 00 20 20 00 60 00 00 00 70 ff ff ff ff 00 00 00 00 c0
--- READ ---
c0 01 09 02 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 0b 18 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 01 00 00 10 00 00 00 01 00 00 ff ff 00 00 c0
--- READ ---
c0 01 0b 02 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 02 14 00 00 00 00 00 10 54 00 00 16 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 c0
--- READ ---
c0 01 02 02 00 00 00 00 00 01 00 c0 # Error here? Does the last response contain an error? And if so, which one? |
Ok, one step further. I've simply forgotten to read the "OHAI" sequence from the stub loader... It's still not working though. The log also looks the same apart from the OHAI sequence? --- READ ---
c0 01 07 04 00 09 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 06 08 00 00 00 00 00 00 00 00 00 50 8a 37 40 c0
--- READ ---
c0 01 06 04 00 09 00 00 00 00 00 00 00 c0 c0 4f 48 41 49 c0 # OHAI
--- WRITE ---
c0 00 0a 04 00 00 00 00 00 48 70 00 60 c0
--- READ ---
c0 01 0a 02 00 12 f4 00 00 00 00 c0
--- WRITE ---
c0 00 0a 04 00 00 00 00 00 4c 70 00 60 c0
--- READ ---
c0 01 0a 02 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 0d 08 00 00 00 00 00 00 00 00 00 00 00 00 00 c0
--- READ ---
c0 01 0d 02 00 00 00 00 00 01 00 c0
--- WRITE ---
c0 00 0a 04 00 00 00 00 00 18 20 00 60 c0
--- READ ---
c0 01 0a 02 00 00 00 00 80 00 00 c0
--- WRITE ---
c0 00 0a 04 00 00 00 00 00 20 20 00 60 c0
--- READ ---
c0 01 0a 02 00 00 00 00 70 00 00 c0
--- WRITE ---
c0 00 09 10 00 00 00 00 00 28 20 00 60 17 00 00 00 ff ff ff ff 00 00 00 00 c0
--- READ ---
c0 01 09 02 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 09 10 00 00 00 00 00 18 20 00 60 00 00 00 90 ff ff ff ff 00 00 00 00 c0
--- READ ---
c0 01 09 02 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 09 10 00 00 00 00 00 20 20 00 60 9f 00 00 70 ff ff ff ff 00 00 00 00 c0
--- READ ---
c0 01 09 02 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 09 10 00 00 00 00 00 58 20 00 60 00 00 00 00 ff ff ff ff 00 00 00 00 c0
--- READ ---
c0 01 09 02 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 09 10 00 00 00 00 00 00 20 00 60 00 00 04 00 ff ff ff ff 00 00 00 00 c0
--- READ ---
c0 01 09 02 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 0a 04 00 00 00 00 00 00 20 00 60 c0
--- READ ---
c0 01 0a 02 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 0a 04 00 00 00 00 00 58 20 00 60 c0
--- READ ---
c0 01 0a 02 00 c2 80 39 00 00 00 c0
--- WRITE ---
c0 00 09 10 00 00 00 00 00 18 20 00 60 00 00 00 80 ff ff ff ff 00 00 00 00 c0
--- READ ---
c0 01 09 02 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 09 10 00 00 00 00 00 20 20 00 60 00 00 00 70 ff ff ff ff 00 00 00 00 c0
--- READ ---
c0 01 09 02 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 0b 18 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 01 00 00 10 00 00 00 01 00 00 ff ff 00 00 c0
--- READ ---
c0 01 0b 02 00 00 00 00 00 00 00 c0
--- WRITE ---
c0 00 02 14 00 00 00 00 00 10 54 00 00 16 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 c0
--- READ ---
c0 01 02 02 00 00 00 00 00 01 00 c0 |
And again... one step further. I just noticed that the documentation says that the SPI_ATTACH sends 4 additional bytes for the ROM bootloader... so I also accounted for that. esp_loader_error_t loader_spi_attach_cmd(uint32_t config)
{
spi_attach_command_t attach_cmd = {
.common = {
.direction = WRITE_DIRECTION,
.command = SPI_ATTACH,
.size = CMD_SIZE(attach_cmd),
.checksum = 0
},
.configuration = config,
.zero = 0
};
#if STUB_ENABLED
uint32_t const attach_cmd_size = esp_no_stub ? sizeof(attach_cmd) : sizeof(attach_cmd) - sizeof(attach_cmd.zero);
#else
uint32_t const attach_cmd_size = sizeof(attach_cmd);
#endif
return send_cmd(&attach_cmd, attach_cmd_size, NULL);
} The response of this command still tells me that it fails... static esp_loader_error_t check_response(command_t cmd, uint32_t *reg_value, void *resp, uint32_t resp_size)
{
esp_loader_error_t err;
common_response_t *response = (common_response_t *)resp;
do {
err = SLIP_receive_packet(resp, resp_size);
if (err != ESP_LOADER_SUCCESS) {
return err;
}
} while ((response->direction != READ_DIRECTION) || (response->command != cmd));
response_status_t *status = (response_status_t *)((uint8_t *)resp + resp_size - sizeof(response_status_t));
if (status->failed) {
log_loader_internal_error(status->error); // FAILS HERE
return ESP_LOADER_ERROR_INVALID_RESPONSE;
}
if (reg_value != NULL) {
*reg_value = response->value;
}
return ESP_LOADER_SUCCESS;
} If I ignore the SPI_ATTACH for now (something the docs says is optional) and continue with esp_loader_flash_start I also receive an error, this time from loader_flash_begin_cmd. Again check_response fails when checking the status bytes. I'm starting to believe that the check_reponse function needs to be adapted to the stub loader, but I can't figure out how. Some help would be appreciated... |
Hello @higaski , nice to hear that you are progressing, for more info you can take a look at esptool/loader.py and do a search for |
Yes that's how I've found the difference between the original ROM SPI_ATTACH and the stub version in the first place. There does not seem to be any difference in reading the response between ROM and stub loader. Problem is the stub flasher does not send any meaningful error codes, all I get is the status member being set to 1... no further details. I have an S3 DevKitC here. Should the SPI_ATTACH command with value 0 (=Default SPI flash interface) work out of the box? I don't understand why it keeps failing. Here is what gets send
/edit
/edit loader_flash_begin_cmd(offset, erase_size, block_size, blocks_to_write, encryption_in_cmd); Once I change that the stub works on my S3... 🥳 |
I am using ESP32-S3_WROOM-2 with 32MB. My project needs to activate secure bootloader flash encryption, this requires --no-stub option when flashing with esptool (v4.7.0) and I have exactly the same problem where flash content gets corrupted whenever flashing beyond 16MB address. Can I check if we have any workaround to flash beyond 16MB with flash encryption enable? |
Hello @vtthanh83 , for |
Linking esp-rs/esp-flasher-stub#56 which will add support here. |
@dobairoland ... ESP32-S3-SK , 32MB GD Qflash ( 32MB OctalPSRAM ) |
@DNedic /edit |
Hi @higaski , 32MB chips is supported when using |
Port
USER_DEFINED
Target chip
ESP32-S3
Hardware Configuration
Custom ESP32-S3 board connected via USB CDC
Log output
More Information
I've written a small native CLI/GUI application much like the Espressif Flash Download Tool to make downloading multiple binaries easier. So far I've tested this app with the hello_world example on various Espressif demo boards. Uploading the example (consisting of bootloader, app and partition table) works flawlessly.
Thinking that my app works I've moved on to trying to flash my current project on a custom ESP32-S3 board. The projects flash files are
As you can probably guess some of those binaries are bigger than the hello_world example
Uploading those bigger binaries does not work. I'm getting the following output from the library (see full log above)
I assume that for some reason the library can't handle certain memory region or binary sizes (yet)?
This might also be related to #23?
Any suggestions? Is this a known issue?
The text was updated successfully, but these errors were encountered: