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

elf2image: Use map file instead of xtensa-lx106-elf-nm #24

Closed
nekromant opened this issue Apr 1, 2015 · 7 comments
Closed

elf2image: Use map file instead of xtensa-lx106-elf-nm #24

nekromant opened this issue Apr 1, 2015 · 7 comments

Comments

@nekromant
Copy link

The current elf2image implementation uses xtensa-lx106-elf-nm. However if we compile the binary with -ffunction-sections/-fdata-sections and do -gc-sections to strip unused functions from the resulting binary we'll end up with this error message:

  [ESPTOOL]   images/antares.rom
xtensa-lx106-elf-nm: images/antares.elf: no symbols
Traceback (most recent call last):
  File "/home/necromant/bin/esptool.py", line 471, in <module>
    image.entrypoint = e.get_symbol_addr("call_user_start")
  File "/home/necromant/bin/esptool.py", line 283, in get_symbol_addr
    return self.symbols[sym]
KeyError: 'call_user_start'
make: *** [images/antares.rom] Error 1

Proposed solution: Link with -Wl,-Map=$(IMAGENAME).map
and pass either the whole mapfile or the just the call_user_start address to esptool.

@nekromant nekromant changed the title elf2image: Use map file instead of xtensa-lx106-elf- elf2image: Use map file instead of xtensa-lx106-elf-nm Apr 1, 2015
@nekromant
Copy link
Author

@pfalcon If I'm not mistaken, you are the one who implemented the magic required to generate rom images?

@pfalcon
Copy link
Contributor

pfalcon commented Apr 1, 2015

Well, if you look at that code, call_user_start is a special, magic function, the real start address (aka entry point) to which the vendor bootloader jumps to start the app. So, it's not recommended to get rid of the standard implementation of that function (you may need to pull it in explicitly using appropriate linker switch). And if you did get rid of it, and are sure you're right with that, that I suggest to just call you own entrypoint (or its wrap) such to avoid confusion. (I myself would love to get rid of all that vendor mess and have just normal "main", but as you know, there's rather long way to that, so if we can't do it right, let's stick to vendor's stuff, and not invent something 3rd yet).

@nekromant
Copy link
Author

@pfalcon I know that and I did NOT get rid of call_user_start, it's there. The problem is that after stripping the elf file is missing symbol information. e.g. call_user_start is there, but you can't find it by symbol name.
As of an even better option I've just noticed - it looks like ELF entry point IS the address of call_user_start, so using elf entry point would be an even cleaner approach, rather than generating a map file and reading an address from it.
-gc-sections comes very handy in terms of reducing code size.

@pfalcon
Copy link
Contributor

pfalcon commented Apr 2, 2015

Ah, I see. I'd still wonder why --gc-sections removes symbols information - symbols are not in a section, it is separate structure in ELF file, right? But if you say it does, then well, something needs to be done for sure.

I'd suggest starting with ability to override entry point address - "make_image" already takes --entrypoint, there it's required param, "elf2image" can take it optional, as override. Then look if it's possible to have sed one-liner to extract it from a map file, if not, add optional ability to parse map file to esptool indeed. My 2 cents ;-).

@nekromant
Copy link
Author

If what I remember about ELF format, symbols are stored in .symtab/.dynsym sections. Since they are not referenced by any code in the actual firmware (why should they?) they get ditched by -gc-sections, which looks kind of sane and expected.
Using ELF entry point instead of embedding sed onliners into python code looks like the best solution so far. I think I'll throw up a patch as soon as I get a spare minute.

@pfalcon
Copy link
Contributor

pfalcon commented Jun 15, 2015

See #24 which touches this somehow.

@projectgus
Copy link
Contributor

I think this is fixed since a0c18ea, now that the entry point is read from the ELF. I'm able to compile esp-open-rtos images with -ffunction-sections/-gc-sections, and also different entry point names, and it all seems happy.

So I'm closing this for now, please reopen if you think there's still an issue here.

Jason2866 referenced this issue in Jason2866/esptool Nov 29, 2023
* Update version to v4.6

* Update version to v4.7-dev

* fix(ESP32-S3): Correct RTC WDT registers to fix resets during flashing

* Update version to v4.6.1

* Update version to v4.7-dev

* docs: add explanation for flash_id example to avoid confusion

* docs(boot-log): fix list formatting

* docs: add c2, c6 and h2 as build targets

* fix(compressed upload): Accept short data blocks with only Adler-32 bytes

---------

Co-authored-by: radim.karnis <radim.karnis@espressif.com>
Co-authored-by: Peter Dragun <peter.dragun@espressif.com>
Jason2866 referenced this issue in Jason2866/esptool Nov 30, 2023
* Tasmota changes

* v4.5.3

* Release of Tasmota esptool v4.6.1 (#23)

* Update version to v4.6

* Update version to v4.7-dev

* fix(ESP32-S3): Correct RTC WDT registers to fix resets during flashing

* Update version to v4.6.1

---------

Co-authored-by: radim.karnis <radim.karnis@espressif.com>

* v4.6.1

* Upstream updates (#24)

* Update version to v4.6

* Update version to v4.7-dev

* fix(ESP32-S3): Correct RTC WDT registers to fix resets during flashing

* Update version to v4.6.1

* Update version to v4.7-dev

* docs: add explanation for flash_id example to avoid confusion

* docs(boot-log): fix list formatting

* docs: add c2, c6 and h2 as build targets

* fix(compressed upload): Accept short data blocks with only Adler-32 bytes

---------

Co-authored-by: radim.karnis <radim.karnis@espressif.com>
Co-authored-by: Peter Dragun <peter.dragun@espressif.com>

* pyinstaller==5.13.2

* Update package.json

* Latest PyInstaller

* Update package.json

* Reset s3 out of flash mode

* fix(testloadram): Windows assertion error

* docs(advanced-topics): Fixed strapping pin for Automatic Bootloader section

* s3 CDC reboot Fix / rm intelhex

* Merge upstream (#32)

* fix(testloadram): Windows assertion error

* docs(advanced-topics): Fixed strapping pin for Automatic Bootloader section

---------

Co-authored-by: Jakub Kocka <jakub.kocka@espressif.com>

* Update test_esptool.py

---------

Co-authored-by: radim.karnis <radim.karnis@espressif.com>
Co-authored-by: Peter Dragun <peter.dragun@espressif.com>
Co-authored-by: Jakub Kocka <jakub.kocka@espressif.com>
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

Successfully merging a pull request may close this issue.

3 participants