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

Related