Using mcuboot_status_change() to control GPIO and I2C during MCUboot execution

Hi! I’m currently implementing a hook using mcuboot_status_change() inside MCUboot. I’m following the path defined by CONFIG_MCUBOOT_ACTION_HOOKS, and I’ve confirmed that my function is properly compiled into the mcuboot image.

I want to confirm if this setup is correct, and at what point it is safe to perform low-level operations like turning on a GPIO or initiating I2C communication. I’m targeting an nRF54L15 with sysbuild enabled.

What I’ve done so far:

  • I enabled CONFIG_MCUBOOT_ACTION_HOOKS=y in the prj.conf for MCUboot.

  • I implemented mcuboot_status_change(mcuboot_status_type_t status) inside the MCUboot image (not in the application).

  • I’m able to print the status 

What I’d like to do:

  • Use the MCUBOOT_STATUS_STARTUP status to activate a GPIO or send a short I2C command to a peripheral (e.g., a power controller).

  • I’m wondering:

    1. Is it safe to initialize and use I2C from this hook?

    2. What configs or steps do I need in MCUboot’s prj.conf to enable DEVICE_DT_GET() or i2c_write() in this context?

    3. Is there any official example or limitation for this kind of use?

Parents
  • Hello, The I2C action that you want to perform, do you want to do this every time in MCUBOOT, or do you want to do it based on some check that you are doing during bootup (such as swapping the application for a new one, and you want to send some signal to the power controller)?

    Depending on that:

    If this is something you want to do every time you can either create a driver that you include in your MCUBOOT bootloader. The reason why this is neat is that you can enable the driver from Kconfig files in your main application, and thus, you don't need to do any changes to the MCUBOOT project.

    If you only want to do it occationally, you do need to adjust the MCUBOOT project, and this requires you to maintain these changes whenever you go to a new version of NCS, and you want to update your bootloader.

    Is it safe to initialize and use I2C from this hook?

    Yes, but you need to maintain it every time you update the bootloader. This doesn't need to be everytime your application updates NCS version, but every time your bootloader changes NCS version.

    What configs or steps do I need in MCUboot’s prj.conf to enable DEVICE_DT_GET() or i2c_write() in this context?

    Something like CONFIG_I2C=y, but you would also need to enable the I2C instance that you want to use in the bootloader's devicetree files (.dts/.dtsi files, but don't change these directly. You should use .overlay files for this, to keep the board files pristine).

    Is there any official example or limitation for this kind of use?

    Not for the bootloader, that I am aware of. But there are samples doing this from the application. I suggest that you look into implementing this in the application first, and then port it to the bootloader when it is all working.

    For some introduction to I2C, and how to enable it, please have a look at our DevAcademy, nRF Connect SDK Fundamentals, Lesson 6 - Serial Communication (I2C).

    Best regards,

    Edvin

Reply
  • Hello, The I2C action that you want to perform, do you want to do this every time in MCUBOOT, or do you want to do it based on some check that you are doing during bootup (such as swapping the application for a new one, and you want to send some signal to the power controller)?

    Depending on that:

    If this is something you want to do every time you can either create a driver that you include in your MCUBOOT bootloader. The reason why this is neat is that you can enable the driver from Kconfig files in your main application, and thus, you don't need to do any changes to the MCUBOOT project.

    If you only want to do it occationally, you do need to adjust the MCUBOOT project, and this requires you to maintain these changes whenever you go to a new version of NCS, and you want to update your bootloader.

    Is it safe to initialize and use I2C from this hook?

    Yes, but you need to maintain it every time you update the bootloader. This doesn't need to be everytime your application updates NCS version, but every time your bootloader changes NCS version.

    What configs or steps do I need in MCUboot’s prj.conf to enable DEVICE_DT_GET() or i2c_write() in this context?

    Something like CONFIG_I2C=y, but you would also need to enable the I2C instance that you want to use in the bootloader's devicetree files (.dts/.dtsi files, but don't change these directly. You should use .overlay files for this, to keep the board files pristine).

    Is there any official example or limitation for this kind of use?

    Not for the bootloader, that I am aware of. But there are samples doing this from the application. I suggest that you look into implementing this in the application first, and then port it to the bootloader when it is all working.

    For some introduction to I2C, and how to enable it, please have a look at our DevAcademy, nRF Connect SDK Fundamentals, Lesson 6 - Serial Communication (I2C).

    Best regards,

    Edvin

Children
No Data
Related