Adding mcuboot to tfm provisioning sample

I'm working on a project where its desired to use an initial provisioning image with capability to update firmware after the completion of the provisioning step.  For this purpose I am adding secure boot and mcuboot to the cpuapp.  My builds are successful with original project and with CONFIG_SECURE_BOOT=y, but when I add CONFIG_BOOTLOADER_MCUBOOT=y I get an error:

A domain may only have a single child image.Current domain image is:
empty_net_core, `empty_net_core` is a domain parent image, so you may add
`cpunet` as a child inside `empty_net_core`

How do I workaround this error? 

Is the tfm provisioning sample app built without hci in the cpunet? 

If I want to utilize ble during provisioning, how should I modify the configuration?

Also I have noticed this worrisome message at the end of the cmake generation step:

Dropping partition 'hw_unique_key_partition' since its size is 0.

Is this expected or does it indicate something is missing from the configuration? 

  • Hi,

    How do I workaround this error? 

    Depending on what you want to do, it could be that you should start with another sample. The TF-M provisioning sample is intended to be used for provisioning keys only, so first program this sample in production and do the provisioning (which writes data to the UICR / KMU), and then flash whatever application, bootloader(s) etc that should be subsequently used. For the intended use case for this sample, I do not think a bootloader makes much sense.

    Is the tfm provisioning sample app built without hci in the cpunet? 

    Yes, the provisioning sample is supposes to just do key provisioning. There is no need for a Bluetooth stack for this.

    If I want to utilize ble during provisioning, how should I modify the configuration?

    If that is the case I suspect you want to do something very differently from what the provisioning sample was intended to do. Perhaps you can elaborate on what that is (starting from a high level)?

  • This is for a security focused project.   The debug ports must be locked before generating unique identifiers which must never leave the device.    Since the debug ports must be locked to protect these secrets, a bootloader is necessary to allow transition from the provisioning image to the production image.  The production image will utilize TF-M to access the KMU where the data will be  stored.  The unique keys will never leave the secure TF-M zone.

    And yes, I'm aware that the keys can still be accessed in a lab setting by physically attacking the device, however that is unlikely and can also be mitigated with additional physical protections.

    In addition, in order to streamline the manufacturing procedure,  it is desired for this provisioning image to perform manufacturing validation of all functions of the design.  Since Bluetooth is a critical feature, it is necessary for this provisioning image to include the HCI for BLE function in the cpunet.

    From my read of your response, you would recommend starting with a sample that supports bootloader updates and adding the steps to protect the debug ports and provisioning capability.

    What sample would you recommend in this case? 

    What do I find the  steps to add debug port protection to cpuapp/cpunet in nrf5340?

  • Hi,

    I see. What you describe makes sense and is certainly possible, but not supported by our samples. I would start with a sample that includes most of what you need, and if you are making a Bluetooth product, that means starting with a bluetooth sample. If you are prototyping on a DK first, that means you should use nrf5340dk_nrf5340_cpuapp_ns, where the "_ns" part is for "non-secure". Then the app will be non-secure, and TF-M will be included in the build. Moreover, when building a Bluetooth sample for the app core, hci_rpmsg will be automatically included as a child image for the net core.

    Then there are two separate features that needs to be added: DFU support and provisioning support.

    For DFU, you can refer to the Bootloaders and Device Firmware Updates, as well as nRF53 specifics here.

    For provisioning the app core, you can refer to the provisioning sample implementation, but you will need to do things a bit differently. That is because the sample is designed to run in secure mode, and your app needs to run in non-secure (if not, TF-M is irrelevant). So your application cannot do provision directly, but you will need to make a custom secure service in TF-M that can do it for you. That is discussed in this thread. (Alternatively, it should work to have a secure application first and then DFU in a non-secure application and TF-M after provisioning if that fits better). For provisioning the net core you don't have this complication, as there is no secure/non-secure split there.

  • Thanks for confirming this new approach.  I have some additional questions:

    1) Is the code to disable the debug port enabled by:

          a) a kconfig variable

          b) code in sample source

         c) both

    2) The provisioning sample says it used the empty cpunet to disable the debug port.  Do I need to do this for both cores, the cpunet core only or either?

    3) Any thoughts on the dropping hw unique key partition?  Is this dropped because the nrf5340 stores the keys in the KMU which uses the UICR instead of a dedicated flash partition?

    4) its understandable that the samples don't fulfill all end-user requirements, is there any checklist or guidelines for building production ready apps?   Stuff like setting up pre-generated signing keys, disabling debug ports, validating maximum size DFU of all updatable components..

    Thanks for all your help!


  • Regarding locking the debug port...

    It appears the code to lock the debug port on the cpunet image is in sub-provisioning_image/cpunet_image/src/main.c

    bool is_writable = nrfx_nvmc_word_writable_check((uint32_t)&NRF_UICR->APPROTECT,

    if (!is_writable) {
    printk("Cannot write to the UICR->APPROTECT register, exiting...!\n");

    nrfx_nvmc_word_write((uint32_t)&NRF_UICR->APPROTECT, UICR_APPROTECT_PALL_Protected);
    printk("The UICR->APPROTECT register is now configured to deny debugging access for the "
    "network core!\n");

    Is there any way to add this code into the hci_rpmsg cpunet image.  Maybe something like a module that just runs some code at startup?

    alternatively, is it possible to perform this code from the cpuapp image instead of from the cpunet image?