-
Notifications
You must be signed in to change notification settings - Fork 841
bootutil: Add manifest-based loader for Direct XIP #2511
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
Open
tomchy
wants to merge
4
commits into
mcu-tools:main
Choose a base branch
from
tomchy:feature/mcuboot/NCSDK-NONE_Transaction_manifest_xip_upstream
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| /* | ||
| * Copyright (c) 2025 Nordic Semiconductor ASA | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #ifndef __MCUBOOT_MANIFEST_H__ | ||
| #define __MCUBOOT_MANIFEST_H__ | ||
|
|
||
| /** | ||
| * @file mcuboot_manifest.h | ||
| * | ||
| * @note This file is only used when MCUBOOT_MANIFEST_UPDATES is enabled. | ||
| */ | ||
|
|
||
| #include <stdint.h> | ||
| #include "bootutil/bootutil.h" | ||
| #include "bootutil/crypto/sha.h" | ||
|
|
||
| #ifndef __packed | ||
| #define __packed __attribute__((__packed__)) | ||
| #endif | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /** Manifest structure for image updates. */ | ||
| struct mcuboot_manifest { | ||
| uint32_t format; | ||
| uint32_t image_count; | ||
| /* Skip a digest of the MCUBOOT_MANIFEST_IMAGE_NUMBER image. */ | ||
| uint8_t image_hash[MCUBOOT_IMAGE_NUMBER - 1][IMAGE_HASH_SIZE]; | ||
| } __packed; | ||
|
|
||
| /** | ||
| * @brief Check if the specified manifest has the correct format. | ||
| * | ||
| * @param[in] manifest The reference to the manifest structure. | ||
| * | ||
| * @return true on success. | ||
| */ | ||
| static inline bool bootutil_verify_manifest(const struct mcuboot_manifest *manifest) | ||
| { | ||
| if (manifest == NULL) { | ||
| return false; | ||
| } | ||
|
|
||
| /* Currently only the simplest manifest format is supported */ | ||
| if (manifest->format != 0x1) { | ||
| return false; | ||
| } | ||
|
|
||
| if (manifest->image_count != MCUBOOT_IMAGE_NUMBER - 1) { | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Get the image hash from the manifest. | ||
| * | ||
| * @param[in] manifest The reference to the manifest structure. | ||
| * @param[in] image_index The index of the image to get the hash for. | ||
| * Must be in range <0, MCUBOOT_IMAGE_NUMBER - 1>, but | ||
| * must not be equal to MCUBOOT_MANIFEST_IMAGE_NUMBER. | ||
| * | ||
| * @return true if hash matches with the manifest, false otherwise. | ||
| */ | ||
| static inline bool bootutil_verify_manifest_image_hash(const struct mcuboot_manifest *manifest, | ||
| const uint8_t *exp_hash, uint32_t image_index) | ||
| { | ||
| if (!bootutil_verify_manifest(manifest)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (image_index >= MCUBOOT_IMAGE_NUMBER) { | ||
| return false; | ||
| } | ||
|
|
||
| if (image_index < MCUBOOT_MANIFEST_IMAGE_NUMBER) { | ||
| if (memcmp(exp_hash, manifest->image_hash[image_index], IMAGE_HASH_SIZE) == 0) { | ||
| return true; | ||
| } | ||
| } else if (image_index > MCUBOOT_MANIFEST_IMAGE_NUMBER) { | ||
| if (memcmp(exp_hash, manifest->image_hash[image_index - 1], IMAGE_HASH_SIZE) == 0) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* __MCUBOOT_MANIFEST_H__ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move that into the
mcuboot_manifest? We can have different structs for TLV and internal usage.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That'd need a struct within a struct, as the
struct mcuboot_manifestis directly loaded from the TLV and themanifest_validis not part of the incoming data, but an internal flag, indicating that the structure was loaded.If you find the "valid" sate flag to be non-universal, I may move everything inside (including
manifest_validas well asmatching_manifest), but I am hesitant to do so as those are not variables that holds information from the manifest, but a state variables for a loader logic and are not needed outside of the bootloader scope.