Magic byte ERROR

BARS2022
Posts: 6
Joined: Mon Nov 14, 2022 1:04 pm

Magic byte ERROR

Postby BARS2022 » Sun Sep 15, 2024 12:29 pm

Hi. I want to make the custom bootloader for esp32 WROOM. I made the custom partition table:
  1. # Name,   Type, SubType, Offset,  Size, Flags
  2. boot,     data, 0xFE,    0x17000, 0x1000,
  3. meta,     data, 0xFF,    0x18000, 0x2000,
  4. nvs,      data, nvs,     0x1A000, 0x6000,
  5. phy_init, data, phy,     0x20000, 0x1000,
  6. storage,  data, ,        0x21000, 0x5F000,
  7. app0,     app,  factory, 0x100000, 1M,
  8. app1,     app,  factory, 0x200000, 1M,

And I wrote small bootloader, that start my app from app0/app1 partition by function:
  1. 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;
	}
}
But when I try to load image from partition app1 I get the invalid magic byte
  1. >>) D (1682) boot: Trying partition index -1 offs 0x200000 size 0x100000
  2. (>>) D (1682) esp_image: reading image header @ 0x200000
  3. (>>) D (1685) bootloader_flash: mmu set block paddr=0x00200000 (was 0xffffffff)
  4. (>>) D (1692) esp_image: image header: 0x00 0x05 0x02 0x02 4008189c
  5. (>>) E (1697) esp_image: image at 0x200000 has invalid magic byte (nothing flashed here?)
  6. (>>) E (1705) boot: Factory app partition is not bootable
  7. (>>) D (1709) boot: Can't boot from zero-length partition
  8. (>>) E (1714) boot: No bootable app partitions in the partition table
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?

boarchuz
Posts: 606
Joined: Tue Aug 21, 2018 5:28 am

Re: Magic byte ERROR

Postby boarchuz » Sun Sep 15, 2024 1:43 pm

BARS2022 wrote:
Sun Sep 15, 2024 12:29 pm
When I read the first 4 bytes from app2 partition, I see 0xE9 0x05 0x02 0x22.
How are you doing this? esptool.py? I trust the bootloader when it says there's actually 00 05 02 02 there.

Have you erased that region of flash beforehand? Not doing this is likely to be your problem based on those sequences of bytes.

Also I doubt ESP-IDF ever expects to see multiple factory partitions so be conscious of that if you ever encounter weirdness with building, partitions, bootloader, OTA, etc.

BARS2022
Posts: 6
Joined: Mon Nov 14, 2022 1:04 pm

Re: Magic byte ERROR

Postby BARS2022 » Sun Sep 15, 2024 2:08 pm

I used the function esp_rom_spiflash_write() in bootloader and this function broke all. Need to use bootloader_flash_write()!!!!!

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 197 guests