mcu-tools / mcuboot

Secure boot for 32-bit Microcontrollers!
Apache License 2.0
1.31k stars 666 forks source link

Higher consumption on nRF52832 when boot from mcuboot. #958

Closed vbelloir closed 3 years ago

vbelloir commented 3 years ago

Hi everybody, This issue may be linked with #529 but I'm not sure.

I'm trying to improve consumption of PineTime watch, using:

Infinitime is based on FreeRTOS.

Consumption is higher when Infinitime is booted by mcuboot than when it is stand-alone. Difference is about 500µA.

As a example, I disabled watchdog in bootloader, and add a simple __WFE loop in main function of Infinitime. Booting from mcuboot gives a consumption of 574µA, while booting in stand-alone configuration gives 170µA.

Resources may be used in mcuboot/mynewt and not de-initialized in mcuboot, nor in Infinitime.

Do you have any idea for me? How can I identify which resource is consuming power?

d3zd3z commented 3 years ago

One suggestion, that may help before #529 is fixed, would be to disable the UART and logging from within MCUboot. At least see if that helps with the consumption.

vbelloir commented 3 years ago

Hello @d3zd3z and thanks for your answer. If I well understand I have to add

CONFIG_SERIAL=n
CONFIG_LOG=n

in repos/mcuboot/boot/zephyr/prj.conf

But If I do that, exactly the same mynewt.elf.hex file is generated. I must miss something.

d3zd3z commented 3 years ago

It might need to be

# CONFIG_SERIAL is not set
# CONFIG_LOG is not set

I'm not exactly sure when one is required over the explicit 'n'. You can always run a menuconfig build, and see what it writes in the zephyr/.config file in the build output directory.

utzig commented 3 years ago

Mynewt does not use config files, this would be for Zephyr. Please gist the output of newt target brief <your-target> somewhere so I can take a look.

vbelloir commented 3 years ago

@utzig Here is the result of newt target config brief targets/nrf52_boot

I hope this is what you ask for. https://pastebin.com/3ZAuhVeQ

@d3zd3z I really don't know how to use menuconfig. I will ask to my friend DuckDuckGo and come back to you.

utzig commented 3 years ago

@utzig Here is the result of newt target config brief targets/nrf52_boot

I hope this is what you ask for. https://pastebin.com/3ZAuhVeQ

Ok, I'll take a look later. I would also recommend to update to a version that at least includes this commit: https://github.com/mcu-tools/mcuboot/commit/1d0467e8339f91b0dac9cb0bcedb131cdf7ac63d

@d3zd3z I really don't know how to use menuconfig. I will ask to my friend DuckDuckGo and come back to you.

This is only for Zephyr, you are on Mynewt so you don't need to do this.

vbelloir commented 3 years ago

I would say that my newt version is new enough :

19:33 $ newt version
Apache Newt 1.9.0-dev / 5da6e2f / 2021-02-21_22:34
utzig commented 3 years ago

I would say that my newt version is new enough :

19:33 $ newt version
Apache Newt 1.9.0-dev / 5da6e2f / 2021-02-21_22:34

The newt tool version is irrelevant here, what you need is a recent MCUboot. If you are using 0-dev you can just new upgrade and get more recent releases; use newt info to print the sha's of your current repositories.

vbelloir commented 3 years ago

ok, sorry for that, I'm really new to mynewt, and may say lot of wrong thing.

Here is the project.yml file:

repository.apache-mynewt-core:
    type: github
    vers: 1.8.0
    user: apache
    repo: mynewt-core

repository.mcuboot:
    type: github
    vers: 1.5.0
    user: JuulLabs-OSS
    repo: mcuboot

and here is the sha1: mcuboot: 310af87f61779f0f1930921055f2b19921a1ef45, 1.5.0,

so yes, the commit you are pointed seems to be introduced in 1.7.0, so I have to update.

EDIT: I updated yaml file specifying 1.7.0 for mcuboot, but I got:


$ newt upgrade
Error: Repository conflicts:
    Installation of repo "mcuboot" is blocked:
                       project.yml requires mcuboot/1.7.0
          apache-mynewt-core/1.8.0 requires mcuboot/1.5.0
vbelloir commented 3 years ago

OK, I put 0-dev for both mcuboot and mynewt, and upgrade process succeed. Now, I will try to build it and check if it still works.

Apache Newt 1.9.0-dev / 5da6e2f / 2021-02-21_22:34
Repository info:
    * apache-mynewt-core: 89b70143d1e199cdd545ff032b68032c055be028, 0.0.1
    * apache-mynewt-mcumgr: e289eaddc9b8e238b5683359a6b3207c70c2c0e7, 0.0.0
    * apache-mynewt-nimble: 741651b8a57998b2f937ab68665966d248633b98, 0.0.0
    * mcuboot: 26edaf3d125e5c0725a2076202945af4c89eb98f, 0.0.0
    * my_project (project): 2e1a66e10310f94d3af6e090b736ba84b7dbc177 

It builds and it still works as expected, but there is no improvements in consumption.

I will double check tomorrow.

vbelloir commented 3 years ago

Hi @utzig sorry for the delay. So, I can confirm that even with 0-dev, consumption is still higher with bootloader than without. Did you have time to see my pastebined conf?

vbelloir commented 3 years ago

Hi @utzig can I ask you a little bit more help, checking the pastebin?

utzig commented 3 years ago

Hi @utzig can I ask you a little bit more help, checking the pastebin?

It looks pretty standard, I believe you can disable TIMER_0 because it is only used by BOOT_SERIAL. Have you tried to compare with the config of your app?

vbelloir commented 3 years ago

Thanks for your answer.
How should I do that? modifying a syscfg.yml somewhere, or with the newt target config command?

I found this post on Nordic forum. https://devzone.nordicsemi.com/f/nordic-q-a/42145/spim-easydma-to-increase-power-consumption/163946#163946 Maybe I have to check that also.

nvlsianpu commented 3 years ago

@vbelloir You might try config CONFIG_MCUBOOT_NRF_CLEANUP_PERIPHERAL implemented in NCS mcuboot fork https://github.com/nrfconnect/sdk-mcuboot/blob/78fc1d62edc9d639059fa5fdf7b39ef8a9e3f1a3/boot/zephyr/Kconfig#L189

vbelloir commented 3 years ago

It's really interested, and seems closed to my issue. How can I do that? I should change mcuboot repo in project.yml to point to nrfconnect one?

EDIT : this is a Zephyr config. but the project is not using zephyr, but mynewt, is it CONFIG_MCUBOOT_NRF_CLEANUP_PERIPHERAL is still relevant?

nvlsianpu commented 3 years ago

^^ You are using NRF, you can port the code enabled by this configuration.

github-actions[bot] commented 3 years ago

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.