Setting Extra CMake Arguments only applies to initial build

When I apply an Extra CMake build argument when creating a build configuration, it only takes effect on the first build, but none after that.

For example, I have added this code to my CMakeLists.txt file:

# Set JLINK_FLASH_BUILD to TRUE in order to build an image that will boot
# from the initial flash (this will automatically confirm the applications in
# the merged.hex file)
#
# When building images for DFU updates, this should be set to FALSE
set(JLINK_FLASH_BUILD FALSE CACHE INTERNAL "Automatically confirm application for initial flash images")
if(JLINK_FLASH_BUILD)
  list(APPEND IMGTOOL_ARGS "--confirm")
endif(JLINK_FLASH_BUILD)

If I define JLINK_FLASH_BUILD in the Extra CMake Arguments part of the "Create Build Configuration", I can see that the image is built with the --confirm flag as expected. However, in an MCUboot based image with two partitions, the secondary image is NOT confirmed. The build log shows that the --confirm option is not set for the secondary image.

In addition, if I run a build from the command line, the same issue shows up. The secondary image is NOT confirmed, when it is expected to be so.

The overall issue is that in VS code, if I re-run a build where I expect the primary boot image to be confirmed with the --confirm flag, even the primary image is not confirmed.

This is easily reproduced by simply adding the above code to your CMakeLists.txt file, creating a build configuration and adding the extra CMake argument of "-DJLINK_FLASH_BUI
LD=TRUE". The initial image generated will be confirmed and boot properly. Subsequent builds of the same configuration will not be bootable.

This is using NCS v2.5.1.

Parents
  • Hi jrhaws,

    The nRF Connect Extension for VS Code issue with using build configuration, extra CMake arguments, and multi-image build is unfortunately a known issue that our team hasn't been able to resolve due to some complications in the build system.

    Our apologies for the inconvenience.

    In addition, if I run a build from the command line, the same issue shows up. The secondary image is NOT confirmed, when it is expected to be so.

    Regarding this point, however. Is this from the first time building with the command line? Or from the second time? Could you please give me some detailed steps to reproduce this observation?

    Hieu

  • In our CI system we run a build with this command:

    nrfutil toolchain-manager launch -- west build -b pru_001697 --build-dir _bld . -DJLINK_FLASH_BUILD=TRUE

    This causes the primary image to be confirmed, but the secondary to not be. I would expect that if I set the JLINK_FLASH_BUILD flag to true, it will apply to BOTH images.

    If I set JLINK_FLASH_BUILD to true inside the CMakeLists.txt file, then both images ARE confirmed properly.

  • I understand now. I will have to investigate this and come back later.

Reply Children
  • Hi jrhaws,

    I wonder if the JLINK_FLASH_BUILD trick you are using is working in the first place, rather than that it doesn't work only on the second image.

    I tested by adding some print() in imgtool.py files as followed:

    // imgtool main.py
    
    def sign(key, public_key_format, align, version, pad_sig, header_size,
             pad_header, slot_size, pad, confirm, max_sectors, overwrite_only,
             endian, encrypt_keylen, encrypt, infile, outfile, dependencies,
             load_addr, hex_addr, erased_val, save_enctlv, security_counter,
             boot_record, custom_tlv, rom_fixed, max_align, clear, fix_sig,
             fix_sig_pubkey, sig_out, vector_to_sign):
    
        
        print("hieu imgtool main.py test point 1")
        if confirm:
            # Confirmed but non-padded images don't make much sense, because
            # otherwise there's no trailer area for writing the confirmed status.
            print("hieu imgtool main.py test point 2")
            pad = True

    // image.py, just to be sure I am tweaking the correct imgtool copy
                    if hasattr(key, 'sign'):
                        print(os.path.basename(__file__) + ": sign the payload hivo2")
                        sig = key.sign(bytes(self.payload))

    And here is the log I got. It seems the confirm flag was not set for any of the images.

    [28/33] Generating ../../zephyr/app_signed.hex
    hieu imgtool main.py test point 1
    image.py: sign the payload hieu2
    [29/33] Generating ../../zephyr/app_update.bin
    hieu imgtool main.py test point 1
    image.py: sign the payload hieu2
    [31/33] Generating ../../zephyr/app_test_update.hex
    hieu imgtool main.py test point 1
    image.py: sign the payload hieu2
    [33/33] Generating zephyr/merged.hex

    I wonder if the IMGTOOL_ARGS line in your CMakeLists.txt works at all. Perhaps the primary slot image is just confirmed by default, not thanks to your change.

    Did you find somewhere the reference that arguments can be added to this IMGTOOL_ARGS list?

Related