Magic byte ERROR
Posted: Sun Sep 15, 2024 12:29 pm
Hi. I want to make the custom bootloader for esp32 WROOM. I made the custom partition table:
And I wrote small bootloader, that start my app from app0/app1 partition by function:
I made wi-fi TCP connection and write the image in to partition app1:
But when I try to load image from partition app1 I get the invalid magic byte
When I read the first 4 bytes from app2 partition, I see 0xE9 0x05 0x02 0x22. I read data from app0 and compare it with data from app1 by memcmp() function. The data is the same! But app0 recorded by JTAG and app2 recorded by my code. Why the image from app1 doesn't work?
- # Name, Type, SubType, Offset, Size, Flags
- boot, data, 0xFE, 0x17000, 0x1000,
- meta, data, 0xFF, 0x18000, 0x2000,
- nvs, data, nvs, 0x1A000, 0x6000,
- phy_init, data, phy, 0x20000, 0x1000,
- storage, data, , 0x21000, 0x5F000,
- app0, app, factory, 0x100000, 1M,
- app1, app, factory, 0x200000, 1M,
And I wrote small bootloader, that start my app from app0/app1 partition by function:
- bootloader_utility_load_boot_image(&bootloader_state, FACTORY_INDEX);
I made wi-fi TCP connection and write the image in to partition app1:
Code: Select all
if (esp_partition_write(app_partition, up_data.header.addr, &up_data.data, up_data.header.len) == ESP_OK)
{
esp_partition_read(app_partition, up_data.header.addr, &tmp_verify_buffer, up_data.header.len);
if (memcmp(up_data.data, tmp_verify_buffer, up_data.header.len) == 0)
answer_data.ack = _OK;
else
answer_data.ack = _DATA_ERR;
}
else
{
answer_data.ack = _DATA_ERR;
}
}
- >>) D (1682) boot: Trying partition index -1 offs 0x200000 size 0x100000
- (>>) D (1682) esp_image: reading image header @ 0x200000
- (>>) D (1685) bootloader_flash: mmu set block paddr=0x00200000 (was 0xffffffff)
- (>>) D (1692) esp_image: image header: 0x00 0x05 0x02 0x02 4008189c
- (>>) E (1697) esp_image: image at 0x200000 has invalid magic byte (nothing flashed here?)
- (>>) E (1705) boot: Factory app partition is not bootable
- (>>) D (1709) boot: Can't boot from zero-length partition
- (>>) E (1714) boot: No bootable app partitions in the partition table