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

dfu/boot: rework using newly introduced MCUBOOT_BOOTUTIL library #30370

Merged
merged 2 commits into from
Jan 14, 2021

Conversation

nvlsianpu
Copy link
Collaborator

@nvlsianpu nvlsianpu commented Dec 1, 2020

depends on mcu-tools/mcuboot#892

As some code are defined here and there it becomes problem when module is compiled within MCUboot.
It is possible to mitigate problem using #fdefry - but this is temporary hack.

aim to supersede #30060

fixes #29963

step needed for merge this PR

get the Zephyr's release-team member who can assist with merges sequence smoothly

  1. 1. PR approved,
  2. 2. merge zephyr: extracted bootutil_public library mcu-tools/mcuboot#892 (is approved, ready to be merged)
  3. 3. create upmereg PR to https://github.com/zephyrproject-rtos/mcuboot
  4. 4. merge the upmerge PR
  5. 5. update mcuboot SHA and merge this PR.

@nvlsianpu nvlsianpu requested a review from nashif as a code owner December 1, 2020 17:03
@github-actions github-actions bot added area: Modules manifest west manifest-mcuboot DNM This PR should not be merged (Do Not Merge) labels Dec 1, 2020
@github-actions
Copy link

github-actions bot commented Dec 1, 2020

The following projects have a revision update in this Pull Request:

Name Old Revision New Revision
mcuboot zephyrproject-rtos/mcuboot@c986a90 zephyrproject-rtos/mcuboot@6f48e0a (master)

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@github-actions github-actions bot added the area: API Changes to public APIs label Dec 7, 2020
@github-actions github-actions bot added the area: Tests Issues related to a particular existing or missing test label Dec 16, 2020
@nvlsianpu nvlsianpu force-pushed the zephyr/mcuboot_util branch 4 times, most recently from 7a5e7b3 to 4bccc6f Compare December 16, 2020 14:25
@nvlsianpu nvlsianpu changed the title [WIP] dfu/boot: rework using newly introduced MCUBOOT_BOOTUTIL library dfu/boot: rework using newly introduced MCUBOOT_BOOTUTIL library Dec 16, 2020
@nvlsianpu nvlsianpu requested a review from utzig December 18, 2020 11:20
modules/Kconfig.mcuboot_bootutil Outdated Show resolved Hide resolved
modules/Kconfig.mcuboot_bootutil Outdated Show resolved Hide resolved
include/dfu/mcuboot.h Outdated Show resolved Hide resolved
include/dfu/mcuboot.h Outdated Show resolved Hide resolved
tests/subsys/dfu/mcuboot/src/main.c Show resolved Hide resolved
* @return 0 on success, negative errno code on fail.
*/
int mcuboot_read_swap_state_by_id(int flash_area_id,
struct mcuboot_swap_state *state);
Copy link
Member

Choose a reason for hiding this comment

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

Is there a rationale for adding this function and struct mcuboot_swap_state instead of just using boot_read_swap_state_by_id and struct boot_swap_state?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

boot_read_swap_state_by_id() can't be made zephyr API. It can only be used by module which made a module shim (as it links with MCUBOOT_BOOTUTIL) (by convention). For the MCUBoot shell i can link it with the library as well, and left behind this API.
Do you think that this API will be rather not useful for other?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@utzig ^^?

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I think I understand, but shouldn't you also add the image_num field to struct mcuboot_swap_state since mcuboot_read_swap_state_by_id still calls boot_read_swap_state_by_id (including a proper pointer cast) and boot_read_swap_state tries to populate boot_num which you have not included in your definition of struct mcuboot_swap_state. Is it correct?

Copy link
Member

Choose a reason for hiding this comment

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

Adding image_num would be a short term fix. We should not blindly cast one structure to the other, because that is error prone. Somebody will change order of fields or add new information to struct boot_swap_state and we will be screwed once again.

So we should either:

  • add helper struct boot_swap_state variable and copy each structure field separately,
  • link MCUBOOT_BOOTUTIL to mcuboot shell or other modules that use mcuboot public API.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • link MCUBOOT_BOOTUTIL to mcuboot shell or other modules that use mcuboot public API.

Ok, I will go with that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@nvlsianpu nvlsianpu force-pushed the zephyr/mcuboot_util branch from 89b7130 to fdd19bc Compare January 8, 2021 16:26
@nvlsianpu
Copy link
Collaborator Author

Currently this PR breaks git bisectability: all commits (except the last one that touches tests) are needed in order to build successfully.

I will squash patches once PR changes will be accepted.

@zephyrbot zephyrbot added the area: DFU Device Firmware Upgrade label Jan 8, 2021
Copy link
Collaborator

@de-nordic de-nordic left a comment

Choose a reason for hiding this comment

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

Looks OK.

Comment on lines 12 to 13
#hiden option for disabling module-own log configuration
#while building MCUboot bootloader
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing space between # and first word.

bool boot_is_img_confirmed(void)
{
return boot_image_ok_read(FLASH_AREA_IMAGE_PRIMARY) == BOOT_FLAG_SET;
return flag_val == BOOT_FLAG_SET;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have noticed that it is not distinguished between failure to access the flag and the flag not being set.
This is not issue to this PR but maybe we need return some other type than bool to distinguish between failures and actual flag check.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reworking this would be an API change - so, yes not in this PR.

@nvlsianpu nvlsianpu force-pushed the zephyr/mcuboot_util branch 2 times, most recently from ade92ac to 357993d Compare January 11, 2021 12:41
@nvlsianpu
Copy link
Collaborator Author

Currently this PR breaks git bisectability: all commits (except the last one that touches tests) are needed in order to build successfully.

@mniestroj Squashed

include/dfu/mcuboot.h Show resolved Hide resolved
include/dfu/mcuboot.h Show resolved Hide resolved
include/dfu/mcuboot.h Show resolved Hide resolved
@nvlsianpu nvlsianpu force-pushed the zephyr/mcuboot_util branch 2 times, most recently from ffa9038 to 29e876f Compare January 13, 2021 11:17
@nvlsianpu
Copy link
Collaborator Author

@mniestroj Regard next step for eliminate copied definitions (so linking test, mcumgr, img_utill to MCUBOOT_BOOTUTIL library)- I will do that in the next PR which will open immediately after this will be merge. I think this PR is heavy enough - I prefer smaller chunks of patches.

@nvlsianpu nvlsianpu force-pushed the zephyr/mcuboot_util branch from 29e876f to c30de78 Compare January 13, 2021 17:39
@nvlsianpu
Copy link
Collaborator Author

mcuboot counterpart PR zephyrproject-rtos/mcuboot#42

Some parts of subsys/dfu/boot code are re-implementations of
what is implemented in the MCUBoot repository.

Mcuboot's repository already provide implementation of function
required for application for interact with the MCUboot.

This patch introduces new MCUBOOT_BOOTUTIL module which covers
common code which is used in the bootloader and the chainnloaded
application.

dfu/boot: use MCUBoot's source code

Module was reworked so it start using MCUBoot's
bootutil_public API instead of copied code.

Reworked boot_is_img_confirmed() used MCUBoot's API
for determine image_ok flag.

mcuboot_shell switchd to use MCUboot's boot_read_swap_state_by_id()
This is MCUBoot function, use it for avoid linking conflict.

test/subsys/mcuboot: fix `test_write_confirm`

dfu/boot library was reworked so it uses MCUboot's bootutil_public
library whenever it can.
The library required that image was marked as copy-done before it
can be pending.
This patch adds such mark which fixes the test.

Signed-off-by: Andrzej Puzdrowski <[email protected]>
MCUboot support flash write-bock-size up to BOOT_MAX_ALIGN.
This patch takes this into account.

Signed-off-by: Andrzej Puzdrowski <[email protected]>
@nvlsianpu nvlsianpu force-pushed the zephyr/mcuboot_util branch from c30de78 to ae6404d Compare January 14, 2021 16:04
@github-actions github-actions bot removed the DNM This PR should not be merged (Do Not Merge) label Jan 14, 2021
@carlescufi carlescufi merged commit d9c308c into zephyrproject-rtos:master Jan 14, 2021
nvlsianpu added a commit to nvlsianpu/zephyr that referenced this pull request Jan 26, 2021
Mcumgr-cli application doesn't accept log on the communication
channel. Since zephyrproject-rtos#30370 was merged log messages are generated from
MCUBOOT_UTIL by default. That made `mcumgr image upload` failing.

Patch disables logging via shell which cure the issue.
It is not necessary if another application on the host intercepts
log messages (like picocom can).

Signed-off-by: Andrzej Puzdrowski <[email protected]>
nashif pushed a commit that referenced this pull request Jan 27, 2021
Mcumgr-cli application doesn't accept log on the communication
channel. Since #30370 was merged log messages are generated from
MCUBOOT_UTIL by default. That made `mcumgr image upload` failing.

Patch disables logging via shell which cure the issue.
It is not necessary if another application on the host intercepts
log messages (like picocom can).

Signed-off-by: Andrzej Puzdrowski <[email protected]>
lmaciejonczyk pushed a commit to lmaciejonczyk/zephyr that referenced this pull request Feb 4, 2021
Mcumgr-cli application doesn't accept log on the communication
channel. Since zephyrproject-rtos#30370 was merged log messages are generated from
MCUBOOT_UTIL by default. That made `mcumgr image upload` failing.

Patch disables logging via shell which cure the issue.
It is not necessary if another application on the host intercepts
log messages (like picocom can).

Signed-off-by: Andrzej Puzdrowski <[email protected]>
(cherry picked from commit cb6e2a6)
Signed-off-by: Johann Fischer <[email protected]>
(cherry picked from commit 895f9ed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: API Changes to public APIs area: DFU Device Firmware Upgrade area: Modules area: Tests Issues related to a particular existing or missing test manifest manifest-mcuboot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: dfu/boot/mcuboot: consider usage of boootloader/mcuboot code
7 participants