Skip to content

MCUboot-compatible builds in Zephyr #5756

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

Closed
carlescufi opened this issue Jan 19, 2018 · 12 comments
Closed

MCUboot-compatible builds in Zephyr #5756

carlescufi opened this issue Jan 19, 2018 · 12 comments
Assignees
Labels
area: Flash Feature A planned feature with a milestone
Milestone

Comments

@carlescufi
Copy link
Member

carlescufi commented Jan 19, 2018

The goal is to be able to generate .hex and .bin files from the Zephyr build system that are compatible with MCUboot, either as a "slot0" or as a "slot1" image.

Here's a rough outline of how I see this working:

$ cmake -DBOARD=<board> -DMCUBOOT_SLOT0 -DWITH_MCUBOOT ..
$ cmake -DBOARD=<board> -DMCUBOOT_SLOT1 ..

The first line would generate a .hex or .bin that contains both the MCUboot and the Slot0 images together, with Slot0 signed as necessary by imgtool.py.
The second line would generate a .hex or a .bin with the Slot1 image signed as necessary.

@carlescufi
Copy link
Member Author

Comments welcome, this is just an idea for now

@carlescufi carlescufi added Feature A planned feature with a milestone area: Flash labels Jan 19, 2018
@pfalcon
Copy link
Collaborator

pfalcon commented Jan 19, 2018

image signed as necessary.

IMHO, stuffing signing into Zephyr build system is too much.

Also, we seem to move towards splitting of e.g. emulation to a separate tool instead of "make run" (well, I heard talks about...). Here, instead, more adhoc tools get integrated into Cmake system. No consistent direction of motion...

@carlescufi
Copy link
Member Author

IMHO, stuffing signing into Zephyr build system is too much.

That's where we really need to take a decision. We either go for an external tool that does all of this sort of stuff, or we integrate it into CMake. I think we need quorum to take that decision, so I will ressucitate the old issue and add people there.

@mbolivar
Copy link
Contributor

I think I agree with @pfalcon that putting explicit mcuboot support into Zephyr feels strange.

We have DT partitions that let us build images in an mcuboot compatible way. I think perhaps a more flexible and general approach would be to allow combining multiple DT overlay files we can specify at CMake generation or build convenient time, rather than just having DTC_OVERLAY_FILE and falling back to DTC_OVERLAY_DIR/board.overlay).

This would allow building for mcuboot as a single, perhaps SoC-specific overlay file, but also allow application-specific overlay files too.

@mbolivar
Copy link
Contributor

mbolivar commented Jan 20, 2018

re: Image signing, I also think it's a strange thing to add directly to Zephyr's CMake build system.

In a non-toy environment, the location of the manufacturer or device specific signing keys probably need to be passed at runtime to the tooling that does the signing (which is, in sufficiently paranoid places, not the same environment as the one that does the building). CMake-generated build systems are not a good fit for this since they require manipulating the environment to pass runtime arguments, and the issue of separate environments pushes me towards separate (but still convenient) tools than the Zephyr build system.

@carlescufi
Copy link
Member Author

carlescufi commented Jan 24, 2018

An option suggested by @mbolivar would be to have CMake or an external tool drop .conf and .dts files in APPLICATION_BINARY_DIR before actually running Kconfig or dtc.
For this to work we would need to have something similar to what we have here in dts.cmake

@carlescufi
Copy link
Member Author

Current tweaks required to have a Zephyr application boot with MCUboot:

  • Set CONFIG_TEXT_SECTION_OFFSET in the app's prj.conf
  • If Cortex-M0 with no VTOR, set IRQ_SOFT_RELAY in the app's prj.conf
  • Modify the app CMakeLists.txt so that it includes a dts overlay
  • Have a dts.overlay file in the app

@SebastianBoe
Copy link
Collaborator

IMHO, stuffing signing into Zephyr build system is too much.

I disagree.

It fits nicely into Zephyr's build system because signing from a build system perspective is just files depending on other files with a command or two to implement the dependency rule.

Also, we seem to move towards splitting of e.g. emulation to a separate tool instead of "make run" (well, I heard talks about...). Here, instead, more adhoc tools get integrated into Cmake system. No consistent direction of motion...

I'd say we are consistently moving in the direction of Zephyr using the build system to integrate tools needed by the user. Examples; DTC, Kconfig, gdb, pyocd, gen_syscalls, merge_config, git (for downloading OpenThread), etc.

If this separate tool had existed and been responsible for certain workflows not covered today I would agree we were inconsistent, but today at least things are consistent.

@SebastianBoe
Copy link
Collaborator

SebastianBoe commented Jan 26, 2018

We have DT partitions that let us build images in an mcuboot compatible way. I think perhaps a more flexible and general approach would be to allow combining multiple DT overlay files we can specify at CMake generation or build convenient time, rather than just having DTC_OVERLAY_FILE and falling back to DTC_OVERLAY_DIR/board.overlay).

This would allow building for mcuboot as a single, perhaps SoC-specific overlay file, but also allow application-specific overlay files too.

Sounds good. No matter how we end up integrating with MCUBoot we probably would want this at some point down the road anyway.

@SebastianBoe
Copy link
Collaborator

In a non-toy environment, the location of the manufacturer or device specific signing keys probably need to be passed at runtime to the tooling that does the signing (which is, in sufficiently paranoid places, not the same environment as the one that does the building). CMake-generated build systems are not a good fit for this since they require manipulating the environment to pass runtime arguments, and the issue of separate environments pushes me towards separate (but still convenient) tools than the Zephyr build system.

Toy environments are useful though, for early prototyping work. So I figure why not support both use-cases, especially when supporting signing in the build system appears to be straightforward to implement.

@pfalcon
Copy link
Collaborator

pfalcon commented Jan 26, 2018

So I figure why not support both use-cases

@SebastianBoe, I appreciate your comments, and definitely don't try to argue with you. Instead, just try to pinpoint arguments which may conflict with the desired goal. In this regard, answer to "why" in "why not support both use-cases" would be "because unless 2 ways are well aligned and overlap, that might mean doing double-work (one-time, minor factor) and then double-work in maintenance and support (recurring, major factor)". Surely, if there're no bigger problems in the build system maintenance (e.g. #5605, #5723, #5153, #4917 are resolved/no longer apply), then why not?

@carlescufi carlescufi added this to the v1.11.0 milestone Feb 12, 2018
@carlescufi
Copy link
Member Author

Closing this for now since we now have CONFIG_BOOTLOADER_MCUBOOT which essentially does everything required to create an MCUboot-compatible binary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Flash Feature A planned feature with a milestone
Projects
None yet
Development

No branches or pull requests

7 participants