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 application description for ESP-IDF image format #3124

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

bjoernQ
Copy link
Contributor

@bjoernQ bjoernQ commented Feb 10, 2025

Thank you for your contribution!

We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:

Submission Checklist 📝

  • I have updated existing examples or added new ones (if applicable).
  • I have used cargo xtask fmt-packages command to ensure that all changed code is formatted correctly.
  • My changes were added to the CHANGELOG.md in the proper section.
  • I have added necessary changes to user code to the Migration Guide.
  • My changes are in accordance to the esp-rs API guidelines

Extra:

Pull Request Details 📖

Description

This adds the esp_app_desc macro which defines the app descriptor from information which either gathered from Cargo or is hardcoded for now.

Since we get e.g. the package name and version we cannot just put this macro in esp_hal::init but the user needs to use it in the binary crate.

While the macro is quite straight forward placing the app-descriptor where the bootloader expects it required some changed to the linker scripts. I tested a couple of scenarios and hopefully nothing broke

Closes #3058

Testing

I tested with a custom made esp-idf bootloader. In theory you could just enable some security features which require the app-desc but for me that always resulted in a bootloader which is too big. In the end I just changed the bootloader code to load and parse the app-descriptor.

Alternatively, bootloaders from later esp-idf versions always get the app-descriptor (so just update esp-idf and try a recent bootloader)

@@ -180,6 +180,26 @@ fn main() -> Result<(), Box<dyn Error>> {
copy_dir_all(&config_symbols, "ld/sections", &out)?;
copy_dir_all(&config_symbols, format!("ld/{device_name}"), &out)?;

// supply build time and date
// see https://reproducible-builds.org/docs/source-date-epoch/
let ts = match std::env::var("SOURCE_DATE_EPOCH") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is obviously not the time when some source files got touched for the last time but when the build script was run

I guess that is fine since production builds are usually clean builds

@bugadani
Copy link
Contributor

Since we get e.g. the package name and version we cannot just put this macro in esp_hal::init but the user needs to use it in the binary crate.

The app name/version doesn't have to be the real value. We could use esp-config to let the user configure these values independent of their Cargo.toml (which isn't ideal, but they would have the option to set it without the macro), or we could provide an esp-config switch to allow the user to call the macro themselves with data from their Cargo.toml.

My point is, we could default to a "something exists that we partially fake".

@bjoernQ
Copy link
Contributor Author

bjoernQ commented Feb 10, 2025

I'm not even sure this should be a macro (it's more or less just the macro from esp-idf-hal)

We could do it all in the build.rs - which would work if we only honor config-values

We can also consider to get all the fields (including build time) via the config. (And we could change the esp-generate generated build.rs to set the fields automatically by default - in a follow up step) 🤔

@bjoernQ bjoernQ marked this pull request as ready for review February 10, 2025 15:36
@bjoernQ
Copy link
Contributor Author

bjoernQ commented Feb 10, 2025

Lets discuss how to proceed here - as said I'm not in favor of a macro at all

esp-hal/src/macros.rs Show resolved Hide resolved
@@ -202,6 +202,14 @@ pub use procmacros::load_lp_code;
#[cfg_attr(not(feature = "unstable"), allow(unused))]
pub use procmacros::{handler, ram};

// used by a macro
#[doc(hidden)]
pub const BUILD_TIME: &str = env!("BUILD_TIME");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put these inside the __macro_implementation module?


/// Macro to define the application descriptor.
#[macro_export]
macro_rules! esp_app_desc {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does feel a bit odd living here in the HAL, but I'm not sure where else it should go either 🤔. I suppose we should also mark it as unstable for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t.b.h. I am not sure I like to have this as a macro at all

My other idea would be to generate the app-desc in build.rs and let the linker include it - but then we would need to get the app-name and app-version from a config option instead (or play some dirty tricks to get the binary's manifest)

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 this pull request may close these issues.

Implement application description for ESP-IDF image format
3 participants