-
Notifications
You must be signed in to change notification settings - Fork 842
zephyr: refactor zephyr port #1411
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
zephyr: refactor zephyr port #1411
Conversation
932aa0e to
70cc399
Compare
|
Note: zephyrproject-rtos/zephyr#47638 is related to how this is solved. |
70cc399 to
e18513d
Compare
|
The workflow showed which Zephyr samples need to pass for the PR to be accepted. Some of this revealed further changes needed in this PR. Fundamentally, though, it revealed that the current configurations of The consequence: this PR will not pass the Zephyr build until the |
e18513d to
0fc1c9f
Compare
It turns out the MULTITHREADING default 'n' should only be applied when building in the mcuboot application. This PR has been updated with the change and should not depend on the Zephyr change anymore. |
0fc1c9f to
a1cf15b
Compare
a1cf15b to
d802988
Compare
@nvlsianpu That sounds appropriate. My membership in mcuboot is in process. Unfortunately I will be unable to attend the Aug 9 meeting, so here is the summary of what is done here and why it is this way: Situation: For context, here are some User Needs revealing the situation above:
Background: Assessment: Proposal:
See the commit comments for the easiest tracking of the refactoring changes. |
|
Another User Need that leads to this refactoring: The simplest way to achieve this in Zephyr is have all logic in a subsystem, resulting in an empty The proposed refactoring has not been extended for automated verification of the remaining source file (keys.c - lacking logic), but doing so is directly following the same pattern. The proposed refactoring needs guidance on location for The proposed refactoring naturally should relocate the remaining contents of |
989c115 to
054faa6
Compare
Extend this repository to be a Zephyr application manifest-module to better support development as a downstream Zephyr module when using `west`. Verified by using `west init -m $repo --mr $branch $workspace` to initialize a west workspace, followed by a west update and a successful build of `$mcuboot/boot/zephyr` for mimxrt1064_evk. Further verified that the following testcases still pass with mcuboot options on twister: mcuboot/boot/zephyr zephyr/tests/subsys/dfu zephyr/samples/subsys/mgmt/mcumgr/smp_svr Signed-off-by: Gregory SHUE <[email protected]>
Separate `boot/zephyr/Kconfig` into the portion to be
picked up through `zephyr/module.yml` (variable declarations)
and the portion appropriate for a top-level Kconfig
(main menu, sourcing Kconfig.zephyr). Relocate all the
module-specific Kconfig content beneath `$mcuboot/zephyr/`
and extend `$mcuboot/zephyr/module.yml` to reference it.
Fix up mcuboot-specific internal files to get the existing
builds to pass.
Verified by:
1. building with `-t guiconfig` and manually verifying the
relocation of mcuboot Kconfig content within the Modules:mcuboot
section.
2. building a full image and verifying the .map file did not change
in flash or ram size.
3. Further verified that the following testcases still pass with
mcuboot options on twister:
mcuboot/boot/zephyr
zephyr/tests/subsys/dfu
zephyr/samples/subsys/mgmt/mcumgr/smp_svr
Signed-off-by: Gregory SHUE <[email protected]>
The Zephyr build system exposes to module CMakeLists.txt files
the following variables:
ZEPHYR_${MODULE_NAME}_MODULE_DIR
ZEPHYR_${MODULE_NAME}_CMAKE_DIR
where MODULE_NAME is the uppercase version of the current module.
This variable is set based on the `name:` field in `module.yml`.
If the `name:` field is not present, then it picks up the name
from the manifest file if present, and follows other defaulting
logic if not. In order to enable other modules to reference
overlays in this module the module name must be fixed by setting
it in `module.yml`.
Verified by:
1. setting the name to the value "mcuboot2" and verifying
the build artifacts produced `$build/modules/mcuboot2`.
2. setting the name to the value "mcuboot" and verifying
the build artifacts produced `$buildmodules/mcuboot`
3. Further verified that the following testcases still pass with
mcuboot options on twister:
mcuboot/boot/zephyr
zephyr/tests/subsys/dfu
zephyr/samples/subsys/mgmt/mcumgr/smp_svr
Signed-off-by: Gregory SHUE <[email protected]>
In the Zephyr directory structure the module-level include is
located as a subdirectory of the module-level CMakeLists.txt.
For a general pattern suitable for extending existing repositories
the Zephyr directory structure must exist within the `zephyr/`
directory along with `module.yml`. This is necessary to avoid
conflicts with existing repository directory structures and
build files.
Verified by:
1. Building `boot/zephyr` for mimxrt1064_evk and verifying
that the zephyr image did not change in sizes.
2. Further verified that the following testcases still pass with
mcuboot options on twister:
mcuboot/boot/zephyr
zephyr/tests/subsys/dfu
zephyr/samples/subsys/mgmt/mcumgr/smp_svr
Signed-off-by: Gregory SHUE <[email protected]>
Refactor `boot/zephyr/CMakeLists.txt` and
`boot/bootutil/zephyr/CMakeLists.txt` into
more standard subsystems beneath `$mcuboot/zephyr/`.
This required changing which CMake file was
pointed to by `module.yml`.
Verified by:
1. building `$mcuboot/boot/zephyr` for mimxrt1064_evk and
verifying the map file reported the same output and
the same functions exist. (Since they are linked in
a different order the sizes may be different by a few
padding bytes.
2. Further verified that the following testcases still pass with
mcuboot options on twister:
mcuboot/boot/zephyr
zephyr/tests/subsys/dfu
zephyr/samples/subsys/mgmt/mcumgr/smp_svr
Signed-off-by: Gregory SHUE <[email protected]>
Relocate `$mcuboot/boot/zephyr/*.c` files to
`$mcuboot/zephyr/subsys/mcuboot_svc/` to become a
reusable subsystem.
NOTE: keys.c was not put into `mcuboot_svc` as this
will need to be project-specific and may need to be kept
in a different module.
Verified by:
1. Building `$mcuboot/boot/zephyr` and verifying the
zephyr.map files showed the same functions and
that the flash an ram usage was the same.
2. Further verified that the following testcases still pass with
mcuboot options on twister:
mcuboot/boot/zephyr
zephyr/tests/subsys/dfu
zephyr/samples/subsys/mgmt/mcumgr/smp_svr
Resolve mcu-tools#1410
Signed-off-by: Gregory SHUE <[email protected]>
054faa6 to
ac37fb2
Compare
nvlsianpu
left a comment
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.
I'm just on review beginning.
I don't fully understand what this PR is doing with current port nor what is improved.
Brief explanation is welcome ( saw lot of cases described).
| @@ -0,0 +1,32 @@ | |||
| # Copyright (c) 2022 Legrand North America, LLC. | |||
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.
Why it is done?
In zephyr project the MCUboot is just one of submodule. So zephyr-rtos manifest points given MCUboot version.
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.
This PR is to resolve MCUBoot issue #1410.
The problem is the Zephyr port of MCUBoot does not allow me to configure and build an MCUBoot image from my proprietary workspace application module. This is different behavior from most(?) other Zephyr (sub)modules and prevents me from keeping all of my project configurations and builds in one repository. This refactoring aligns the Zephyr port with the Zephyr configuration and build system modularity and enables standard Zephyr module behavior.
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.
This PR is to resolve MCUBoot issue #1410.
The problem is the Zephyr port of MCUBoot does not allow me to configure and build an MCUBoot image from my proprietary workspace application module. This is different behavior from most(?) other Zephyr (sub)modules and prevents me from keeping all of my project configurations and builds in one repository.
I believe this is solved by zephyrproject-rtos/zephyr#51166
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.
@tejlmand I tried your suggestion but it does not solve my scenario. It missed picking up boards/ configs within APPLICATION_CONFIG_DIR.
| zephyr_interface_library_named(MCUBOOT_BOOTUTIL) | ||
|
|
||
| target_include_directories(MCUBOOT_BOOTUTIL INTERFACE | ||
| zephyr_include_directories(MCUBOOT_BOOTUTIL INTERFACE |
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.
why this change?
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.
Because the repartitioned build system couldn't see this otherwise, and this is a zephyr-specific build file.
| samples: | ||
| - boot/zephyr | ||
| build: | ||
| kconfig: zephyr/Kconfig |
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.
Why can't refer to ../boot/zephyr/Kconfig ?
Was this move neccessery?
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.
In the original implementation the boot/zephyr/Kconfig file mixed two layers into one file. First, the top-level (executable-specific) build Kconfig declarations, which is optional and usually does little more than sources "Kconfig.zephyr". Second, the module-level Kconfig declarations, which declare controls for configuring subsystems. Combining them caused problems when configuring and building my MCUBoot executable from outside of the MCUBoot repository.
|
cc @tejlmand |
|
Much of this refactoring was to separate the Zephyr-specific MCUBoot application (subsystem/service) away from the executable configuration to become aligned with the composability inherent in Zephyr. I chose to refactor the glue into the top-level
|
|
Haven't looked at all those changes, but based on the description:
and #1410:
I believe this is solved by zephyrproject-rtos/zephyr#51166 and I don't see the need for this PR. Also note, Zephyr, and thus MCUboot supports the use of Further remember, MCUboot is not the only sample that might need such reconfiguration, so could OpenAMP and RPMsg which are samples often used in multi core SoCs. |
tejlmand
left a comment
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.
So far not convinced, see #1411 (comment)
But if @nvlsianpu thinks this change is considered important I can lift the -1 and do a proper in detailed review.
I am not building this as an extras image, and I expect to build and configure this in exactly the same way as other images. Having the option to use sysbuild is fine. Not being able to configure & build this in exactly the same way is a problem.
APPLICATION_CONFIG_DIR does support referencing configuration files from multiple other directories, so it doesn't address the full scope of the problem. I also don't know if it expands ZEPHYR_${MODULE_NAME_UPPER}_MODULE_DIR, needed for reliably referencing directories in other modules. This PR solves multiple problems. Only one was entered as a top-level issue. See items 1-6 above. Sysbuild cannot address all of these (e.g., #4, #5). Perhaps I need to enter the other items as issues and reference fixing them also in this PR? |
|
@tejlmand I discovered that APPLICATION_CONFIG_DIR does not solve the problem when board overlay files are also needed. It seems the build generates an incorrect configuration when APPLICATION_CONFIG_DIR is used and CONF_FILE is set before find_package(Zephyr). When I tried |
|
This PR is superseded by #1489. Reviews and discussions should continue there. |
I am not yet able to verify these changes on actual hardware, so the verification has been done by inspection of the .map files.
This refactoring could go farther. I am submitting it as is to get feedback on how much farther to take it. One goal is to fully demonstrate a pattern for extending an existing repository for full integration with the Zephyr build system while minimizing the impact on existing code.