Skip to content
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

option to insert SHA256 hash does not zero check the correct range #560

Closed
sinope-db opened this issue Sep 17, 2020 · 1 comment
Closed

Comments

@sinope-db
Copy link

sinope-db commented Sep 17, 2020

  • Operating system: Windows
  • Python version: 2.7.11

Full esptool.py command line as run:

esptool.py --chip esp32 elf2image --flash_mode qio --flash_freq 40m --flash_size 4MB --secure-pad --elf-sha256-offset 0xb0 -o image.bin Build\Debug\project.elf

Full output from esptool.py

esptool.py v2.8
A fatal error occurred: Contents of segment at SHA256 digest offset 0xb0 are not all zero. Refusing to overwrite.

What is the expected behaviour?

Image is generated successfully and SHA digest is inserted

Do you have any other information from investigating this?

in function maybe_patch_segment_data(), I think patch_offset -= self.SEG_HEADER_LEN should be done before performing the zero check.

Is there any other information you can think of which will help us reproduce this problem?

I'm trying to generate an image for ESP32 using ESP-IDF v3.3.3 with a modified esp_app_desc.
If I fully initialize esp_app_desc except member app_elf_sha256 with non-zero values, the zero check fails.

const __attribute__((section(".rodata_desc"), weak)) esp_app_desc_t esp_app_desc = {    //  D.B. allow our app to override to insert our application data
    .magic_word = 0xFFFFFFFF,
    .version = "1234567890123456789A123456789B1",
    .project_name = "1234567890123456789A123456789B1",
    .idf_ver = "1234567890123456789A123456789B1",
    .secure_version = 0x11111111,
    .reserv1 = {0xBAADBEEF, 0xBAADF00D},
    .time = "123456789012345",
    .date = "123456789012345",
    .reserv2 = {0x55AA55AA, 0x55AA55AA, 0x55AA55AA, 0x55AA55AA, 0x55AA55AA, 0x55AA55AA, 0x55AA55AA, 0x55AA55AA, 0x55AA55AA, 0x55AA55AA,
                0x55AA55AA, 0x55AA55AA, 0x55AA55AA, 0x55AA55AA, 0x55AA55AA, 0x55AA55AA, 0x55AA55AA, 0x55AA55AA, 0x55AA55AA, 0x55AA55AA}
};

First 256 bytes of the first segment data generated:

    ffffffff11111111 efbeadba0df0adba | ................
    3132333435363738 3930313233343536 | 1234567890123456
    3738394131323334 3536373839423100 | 789A123456789B1.
    3132333435363738 3930313233343536 | 1234567890123456
    3738394131323334 3536373839423100 | 789A123456789B1.
    3132333435363738 3930313233343500 | 123456789012345.
    3132333435363738 3930313233343500 | 123456789012345.
    3132333435363738 3930313233343536 | 1234567890123456
    3738394131323334 3536373839423100 | 789A123456789B1.
    0000000000000000 0000000000000000 | ................
    0000000000000000 0000000000000000 | ................
    aa55aa55aa55aa55 aa55aa55aa55aa55 | .U.U.U.U.U.U.U.U
    aa55aa55aa55aa55 aa55aa55aa55aa55 | .U.U.U.U.U.U.U.U
    aa55aa55aa55aa55 aa55aa55aa55aa55 | .U.U.U.U.U.U.U.U
    aa55aa55aa55aa55 aa55aa55aa55aa55 | .U.U.U.U.U.U.U.U
    aa55aa55aa55aa55 aa55aa55aa55aa55 | .U.U.U.U.U.U.U.U

.bin file generated without --elf-sha256-offset 0xb0

00000000  E9 09 00 20 5C 11 08 40 EE 00 00 00 00 00 00 00  é.. \..@î.......
00000010  00 00 00 00 00 00 00 01 20 00 40 3F 7C 7A 06 00  ........ .@?|z..
00000020  FF FF FF FF 11 11 11 11 EF BE AD BA 0D F0 AD BA  ÿÿÿÿ....ï¾.º.ð.º
00000030  31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36  1234567890123456
00000040  37 38 39 41 31 32 33 34 35 36 37 38 39 42 31 00  789A123456789B1.
00000050  31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36  1234567890123456
00000060  37 38 39 41 31 32 33 34 35 36 37 38 39 42 31 00  789A123456789B1.
00000070  31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 00  123456789012345.
00000080  31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 00  123456789012345.
00000090  31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36  1234567890123456
000000A0  37 38 39 41 31 32 33 34 35 36 37 38 39 42 31 00  789A123456789B1.
000000B0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000C0  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000000D0  AA 55 AA 55 AA 55 AA 55 AA 55 AA 55 AA 55 AA 55  ªUªUªUªUªUªUªUªU
000000E0  AA 55 AA 55 AA 55 AA 55 AA 55 AA 55 AA 55 AA 55  ªUªUªUªUªUªUªUªU
000000F0  AA 55 AA 55 AA 55 AA 55 AA 55 AA 55 AA 55 AA 55  ªUªUªUªUªUªUªUªU
00000100  AA 55 AA 55 AA 55 AA 55 AA 55 AA 55 AA 55 AA 55  ªUªUªUªUªUªUªUªU
00000110  AA 55 AA 55 AA 55 AA 55 AA 55 AA 55 AA 55 AA 55  ªUªUªUªUªUªUªUªU
``
@sinope-db sinope-db added the bug label Sep 17, 2020
@dobairoland
Copy link
Collaborator

Hi @sinope-db. Thank you for submitting this issue and sorry for the delay with the response.

You are absolutely right about this. We will submit a fix in a couple of days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants