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

Add strip support to esp-lp-hal #2121

Closed
Szybet opened this issue Sep 9, 2024 · 7 comments
Closed

Add strip support to esp-lp-hal #2121

Szybet opened this issue Sep 9, 2024 · 7 comments

Comments

@Szybet
Copy link
Contributor

Szybet commented Sep 9, 2024

When trying to:

[profile.release]
strip = true 

The program that tries to load the binary complains that it's not a ULP program. That's because strip removes the __ULP_MAGIC_ symbol. I was not able to keep it via linker script magic. The work around I was able to do is removing argument support:

main...Szybet:esp-hal:esp-lp-hal-strip

I don't know if it's possible to remain the symbol with strip, but it's worth it. For a simple blinky program it saves 1-2 Kb. Also everything seems to work fine, I just need to:

let pin: Output<3> = Output {};

I don't know the perfect solution for this, maybe a feature but I have no idea if they would work with those macros.

Any thoughts?

@MabezDev
Copy link
Member

MabezDev commented Sep 9, 2024

For a simple blinky program it saves 1-2 Kb

How did you measure this?

iirc strip does nothing on embedded programs. strip is only useful for reducing the size of an elf by stripping the debug symbols etc. For an embedded system, only the loadable sections of an ELF are actually flashed to the board.

@Szybet
Copy link
Contributor Author

Szybet commented Sep 9, 2024

Huh, stat -c %s
So how do I measure the size then? How do I get a binary of the lp program that could be loaded from esp-idf? (Because I think it would be an awesome way to start using rust in esp-idf projects who want to use the lp core)

@MabezDev
Copy link
Member

MabezDev commented Sep 9, 2024

stat -c %s

On which file are you running this command, on the ELF, i.e esp-lp-hal/target/riscv32imc-unknown-none-elf/release/examples/blinky or something else?

How do I get a binary of the lp program that could be loaded from esp-idf? (Because I think it would be an awesome way to start using rust in esp-idf projects who want to use the lp core)

I'm not sure I follow this bit, but maybe @bjoernQ knows what you mean?

@bjoernQ
Copy link
Contributor

bjoernQ commented Sep 9, 2024

If you want to see the size of code/data in memory you could use something like riscv32-esp-elf-size esp-lp-hal\target\riscv32imc-unknown-none-elf\release\examples\blinky

This outputs e.g.

   text    data     bss     dec     hex filename
   1392       4       0    1396     574 esp-lp-hal\target\riscv32imc-unknown-none-elf\release\examples\blinky

i.e. 1396 bytes

ESP-IDF uses its own mechanism to build and include LP-core code - see https://github.com/espressif/esp-idf/blob/59e18382702b6986be3d3f55e9ac7763c1397cf7/components/ulp/cmake/IDFULPProject.cmake#L194-L198 - TL;DR it's using objcpy

@Szybet
Copy link
Contributor Author

Szybet commented Sep 9, 2024

I'm running it on target/riscv32imac-unknown-none-elf/release/yatchy-lp-program so it's good, and this binary gets smaller by applying strip

I got confused at this point, how do I get the bare memory which will be putted to rtc memory and executed? I think it's the file I wrote the path above?

@bjoernQ
Copy link
Contributor

bjoernQ commented Sep 9, 2024

I got confused at this point, how do I get the bare memory which will be putted to rtc memory and executed? I think it's the file I wrote the path above?

No - that's the elf - running size on it will show text and data size (i.e. what gets into LP/RTC memory)

@Szybet
Copy link
Contributor Author

Szybet commented Sep 9, 2024

Oh... Yea, now strip doesn't do anything... Nevermind

cargo objcopy --release -- -O binary out/yatchy-lp-program-new.bin and I have the pure binary

Thanks for clearing out my confusion 😄

@Szybet Szybet closed this as completed Sep 9, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in esp-rs Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

3 participants