Flashing multi-core application over terminal

Hello,
I 'm trying to flash my multi-core application to the NRF5340DK using a terminal but having issues. 
The application uses both network and application CPUs. After building the application I end up with multiple .hex files inside `./build/zephyr` and `./build/hci_rpmsg` folders.
So far I m using NRF Connect SDK v2.2.0 and I have tried to flash the hex files using a batch script from terminal using the following commands:
For network CPU:

set hex_file=".\bin\cpu_net\zephyr.hex"
echo Unlock and erase network cpu...
nrfjprog.exe -f nrf53 --coprocessor CP_NETWORK --recover
nrfjprog.exe -f nrf53 --coprocessor CP_NETWORK --eraseall
nrfjprog.exe -f nrf53 --coprocessor CP_APPLICATION --eraseall
nrfjprog.exe -f nrf53 --coprocessor CP_NETWORK --recover
nrfjprog.exe -f nrf53 --coprocessor CP_NETWORK --program %hex_file% --sectorerase --verify
echo Network cpu flash finished.


For application CPU:

set hex_file=".\bin\cpu_app\zephyr.hex"
echo Unlock and erase cpu
nrfjprog.exe -f nrf53 --coprocessor CP_NETWORK --recover
nrfjprog.exe -f nrf53 --coprocessor CP_APPLICATION --eraseall
echo Flash application cpu...
nrfjprog.exe -f nrf53 --coprocessor CP_APPLICATION --program %hex_file% --sectorerase --verify
echo Application cpu flash finished.


I have tried to replace the `zephyr.hex` files with `merged_CPUNET.hex` for network CPU and `merged.hex` for application CPU buth that did not work either.
The output I m getting is something like this: 
...
[00:00:01.870,513] <err> bt_hci_driver: Endpoint binding failed with -11
[00:00:01.870,544] <err> bt_hci_core: HCI driver open failed (-11)
...

The application code seems to run fine if we exclude the BLE functionality.

If I try to flash the board using the vs code plugin then all runs smoothly and I notice that it splits the `merged_domains`.hex file into `GENERATED_CP_APPLICATION_merged_domains.hex` and `GENERATED_CP_NETWORK_merged_domains.hex` files and flash those to the board.
Question is how can I generate those files from the command line?
What files should I flash to network and application CPUs?
I would like to avoid the `west flash` command and make use of nrfjprog utility if possible.

Best regards,
Alex

Parents
  • For anyone else trying to figure out how to split the "merged_domains.hex" into "app.hex" and "net.hex" ones, here is a python script I did and then integrated it into my flashing scripts:

    import os
    from pathlib import Path
    import getopt, sys
    from intelhex import IntelHex
    
    
    def hex_refers_region(hex, region_start, region_end):
        for segment_start, _ in hex.segments():
            if region_start <= segment_start <= region_end:
                return True
        return False
    
    def split_hex(hexPath):
        try:
            file_path = Path(hexPath)
            hex_dir, hex_name = file_path.parent, file_path.name
            hex_orig = os.fspath(hex_dir / hex_name)
            hex = IntelHex(hex_orig)
    
            net_flash_start = 0x01000000
            net_flash_end = 0x0103FFFF
            net_hex, app_hex = IntelHex(), IntelHex()
    
            if not hex_refers_region(hex, net_flash_start, net_flash_end):
                return -1
            elif (
                hex.minaddr() < net_flash_start
                or hex.maxaddr() > net_flash_end
            ):
                net_hex, app_hex = IntelHex(), IntelHex()
                for start, end in hex.segments():
                    if net_flash_start <= start <= net_flash_end:
                        net_hex.merge(hex[start:end])
                    else:
                        app_hex.merge(hex[start:end])
    
                hex_path = Path(hexPath)
                hex_dir, hex_name = hex_path.parent, hex_path.name
                net_hex_file = os.fspath(hex_dir / f"net.hex")
                app_hex_file = os.fspath(hex_dir / f"app.hex")
                #net_hex_file = os.fspath(hex_dir / f"CP_NETWORK_{hex_name}")
                #app_hex_file = os.fspath(hex_dir / f"CP_APPLICATION_{hex_name}")
                print(
                    f"hex targets both nRF53 coprocessors;\n"
                    f"splitting it into:\n{net_hex_file}\n{app_hex_file}"
                )
                net_hex.write_hex_file(net_hex_file)
                app_hex.write_hex_file(app_hex_file)
                return 0
            else:
                return 0
        except Exception as inst:
            print(type(inst))    # the exception type
            print(inst.args)     # arguments stored in .args
            print(inst)          # __str__ allows args to be printed directly,
                                 # but may be overridden in exception subclasses
    
    # Remove 1st argument from the
    # list of command line arguments
    argumentList = sys.argv[1:]
    
    # Options
    options = "f:"
    
    # Long options
    long_options = ["file"]
    
    try:
        # Parsing argument
        arguments, values = getopt.getopt(argumentList, options, long_options)
    
        # checking each argument
        for currentArgument, currentValue in arguments:
    
            if currentArgument in ("-f", "--file"):
                split_hex(currentValue)
            else:
                print("Error: argument to hex file not found, re-run the script using -f / --file <file_path_to_hex>")
    
    except getopt.error as err:
        # output error, and return with an error code
        print(str(err))


    you will need to "pip install intelhex" package.

    To run it just call the script from a terminal window, passing to it the path to your "merged_domains.hex" file:
    python hexSplitter -f <path_to_merged_domains.hex>


    Cheers,
    Alex

Reply
  • For anyone else trying to figure out how to split the "merged_domains.hex" into "app.hex" and "net.hex" ones, here is a python script I did and then integrated it into my flashing scripts:

    import os
    from pathlib import Path
    import getopt, sys
    from intelhex import IntelHex
    
    
    def hex_refers_region(hex, region_start, region_end):
        for segment_start, _ in hex.segments():
            if region_start <= segment_start <= region_end:
                return True
        return False
    
    def split_hex(hexPath):
        try:
            file_path = Path(hexPath)
            hex_dir, hex_name = file_path.parent, file_path.name
            hex_orig = os.fspath(hex_dir / hex_name)
            hex = IntelHex(hex_orig)
    
            net_flash_start = 0x01000000
            net_flash_end = 0x0103FFFF
            net_hex, app_hex = IntelHex(), IntelHex()
    
            if not hex_refers_region(hex, net_flash_start, net_flash_end):
                return -1
            elif (
                hex.minaddr() < net_flash_start
                or hex.maxaddr() > net_flash_end
            ):
                net_hex, app_hex = IntelHex(), IntelHex()
                for start, end in hex.segments():
                    if net_flash_start <= start <= net_flash_end:
                        net_hex.merge(hex[start:end])
                    else:
                        app_hex.merge(hex[start:end])
    
                hex_path = Path(hexPath)
                hex_dir, hex_name = hex_path.parent, hex_path.name
                net_hex_file = os.fspath(hex_dir / f"net.hex")
                app_hex_file = os.fspath(hex_dir / f"app.hex")
                #net_hex_file = os.fspath(hex_dir / f"CP_NETWORK_{hex_name}")
                #app_hex_file = os.fspath(hex_dir / f"CP_APPLICATION_{hex_name}")
                print(
                    f"hex targets both nRF53 coprocessors;\n"
                    f"splitting it into:\n{net_hex_file}\n{app_hex_file}"
                )
                net_hex.write_hex_file(net_hex_file)
                app_hex.write_hex_file(app_hex_file)
                return 0
            else:
                return 0
        except Exception as inst:
            print(type(inst))    # the exception type
            print(inst.args)     # arguments stored in .args
            print(inst)          # __str__ allows args to be printed directly,
                                 # but may be overridden in exception subclasses
    
    # Remove 1st argument from the
    # list of command line arguments
    argumentList = sys.argv[1:]
    
    # Options
    options = "f:"
    
    # Long options
    long_options = ["file"]
    
    try:
        # Parsing argument
        arguments, values = getopt.getopt(argumentList, options, long_options)
    
        # checking each argument
        for currentArgument, currentValue in arguments:
    
            if currentArgument in ("-f", "--file"):
                split_hex(currentValue)
            else:
                print("Error: argument to hex file not found, re-run the script using -f / --file <file_path_to_hex>")
    
    except getopt.error as err:
        # output error, and return with an error code
        print(str(err))


    you will need to "pip install intelhex" package.

    To run it just call the script from a terminal window, passing to it the path to your "merged_domains.hex" file:
    python hexSplitter -f <path_to_merged_domains.hex>


    Cheers,
    Alex

Children
Related