ivo@system76-pc:~/src/nrf91-1.5.0/ncs/nrf/samples/nrf9160/fmfu_smp_svr$ python3 update_modem.py mfw_nrf9160_1.2.3.zip /dev/ttyACM0 1000000
# modem firmware upgrade over serial port example started.
[Debug   ] [HighLevel ] dll_open
[Info    ] [HighLevel ] default_jlink_path parameter is NULL, latest JLINKARM DLL will be looked for and used.
[Debug   ] [HighLevel ] is_dll_open
[Debug   ] [HighLevel ] mcuboot_dfu_init
[Info    ] [HighLevel ] Creating new probe
[Info    ] [HighLevel ] initializing DFU
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] ModemUARTDFUProbe_initialize
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Dll directory is /home/ivo/.local/lib/python3.8/site-packages/pynrfjprog/lib_x64.
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Find and connect to dfu dll
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Using DFU dll at /home/ivo/.local/lib/python3.8/site-packages/pynrfjprog/lib_x64/libnrfdfu.so.
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Load library at /home/ivo/.local/lib/python3.8/site-packages/pynrfjprog/lib_x64/libnrfdfu.so.
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Library loaded, loading member functions.
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Member functions succesfully loaded.
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] Timeout set to 30000ms
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Initialize new probe.
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] initialize
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Successfully opened port: /dev/ttyACM0@1000000,flow_control:none,parity:none.
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] TX pkt with header: op:0 flags:0 len:14, group:2, seq:0, id: 0, total size: 36
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] UART TX(39)
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] Waiting with timeout 400ms
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] UART RX(7): 0x06 0x09 0x41 0x44 0x30 0x42 0x41
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] UART RX(52): 0x41 0x41 0x31 0x41 0x41 0x49 0x41 0x41 0x4c 0x39 0x69 0x63 0x6d 0x4d 0x41 0x5a 0x47 0x35 0x68 0x62 0x57 0x56 0x6e 0x63 0x32 0x31 0x77 0x58 0x32 0x4e 0x76 0x62 0x57 0x5a 0x6d 0x61 0x57 0x56 0x73 0x5a 0x48 0x4f 0x2f 0x61 0x57 0x5a 0x79 0x59 0x57 0x31 0x6c 0x58
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] Got uart flags: DATA true, CORRUPT false
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] Waiting with timeout 200ms
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] UART RX(32): 0x32 0x31 0x68 0x65 0x42 0x6b 0x43 0x41 0x47 0x68 0x77 0x59 0x57 0x4e 0x72 0x58 0x32 0x31 0x68 0x65 0x42 0x6b 0x42 0x2b 0x50 0x2f 0x2f 0x4c 0x34 0x30 0x3d 0x0a
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] Frame type after decode: START
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] Waiting with timeout 200ms
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] Attempting to decode frames vector with 1 frames
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] Found max frame length  512 and max package length 504
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] Obtained connection parameters. Max frame size: 512, mtu: 504
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] Have image upload chunk size of 276 (1st packet) and 328 (proceeding)
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] Using MTU 504 and frame size 512.
{
    "duration": 406, 
    "error_code": "Ok", 
    "operation": "open_uart", 
    "outcome": "success", 
    "progress_percentage": 100
}
[Info    ] [HighLevel ] Probe initialization complete!
[Debug   ] [HighLevel ] program
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] program
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] program_package
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Check if provided file exists
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Check if provided file can be read
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Unzipping package mfw_nrf9160_1.2.3.zip.
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Extracting 13416, bytes from 72B3D7C.ipc_dfu.signed_1.1.0.ihex.
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Extracting 456, bytes from firmware.update.image.digest.txt.
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Extracting 6510, bytes from firmware.update.image.segments.0.hex.
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Extracting 5622317, bytes from firmware.update.image.segments.1.hex.
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Extracting 68782, bytes from mfw_nrf9160_1.2.3_release_notes.txt.
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Extracting 15722, bytes from mfw_nrf9160_license-agreement.txt.
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Extracting 219106, bytes from mfw_nrf9160_update_from_1.2.1_to_1.2.3.bin.
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Extracting 35214, bytes from mfw_nrf9160_update_from_1.2.2_to_1.2.3.bin.
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Extracting 14166, bytes from mfw_nrf9160_update_from_1.2.3-FOTA-TEST_to_1.2.3.bin.
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Extracting 14166, bytes from mfw_nrf9160_update_from_1.2.3_to_1.2.3-FOTA-TEST.bin.
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Extracting 726, bytes from README.txt.
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] program files
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Programming bootloader
Programming modem bootloader.
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Found bootloader file /tmp/filej45Tc1nrfjprog/72B3D7C.ipc_dfu.signed_1.1.0.ihex.
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] program_file
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Evaluating file /tmp/filej45Tc1nrfjprog/72B3D7C.ipc_dfu.signed_1.1.0.ihex.
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Check if provided file exists
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Check if provided file can be read
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Open provided file
{
    "duration": 0, 
    "message": "Calculating image size", 
    "operation": "upload_image", 
    "progress_percentage": 5
}
{
    "duration": 0, 
    "message": "Uploading image to device", 
    "operation": "upload_image", 
    "progress_percentage": 10
}
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] Uploading chunk offset: 0, len: 276, out of total len 4752, target addr: 536870924
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] TX pkt with header: op:2 flags:0 len:345, group:65, seq:1, id: 1, total size: 476
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] UART TX(479)
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] Waiting with timeout 30000ms
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] UART RX(27): 0x06 0x09 0x41 0x41 0x34 0x44 0x41 0x41 0x41 0x47 0x41 0x45 0x45 0x42 0x41 0x62 0x39 0x69 0x63 0x6d 0x4d 0x47 0x2f 0x34 0x32 0x66 0x0a
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] Frame type after decode: START
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] Attempting to decode frames vector with 1 frames
[Error   ] [ModemUARTDFU-Probe-/dev/ttyACM0] CBOR response contains non-zero return code, 6
{
    "duration": 11, 
    "error_code": "BadState", 
    "message": "Image upload failed. Bad response from device", 
    "operation": "upload_image", 
    "outcome": "fail", 
    "progress_percentage": 100
}
[Error   ] [ModemUARTDFU-Probe-/dev/ttyACM0] Error during image file upload. Upload returned an error.
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Failed to program bootloader file
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Programming bootloader failed!
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Failed while programming files to target.
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Failed to program DFU package
[Info    ] [HighLevel ] Failed programming the device.
b'An error was reported by NRFJPROG DLL: -2 INVALID_OPERATION.'
[Debug   ] [HighLevel ] is_dll_open
[Debug   ] [HighLevel ] probe_uninit
[Info    ] [HighLevel ] Deleting probe at location 0x138f900
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] readDeviceInfo
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Uninitializing ModemUARTDFU probe at serial port /dev/ttyACM0.
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] uninitialize
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Sending device reset request
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Sending reset request to device.
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] UART TX(23)
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] Closing connection to mcuboot device
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] serial port read on port /dev/ttyACM0 aborted
[Debug   ] [ModemUARTDFU-Probe-/dev/ttyACM0] serial io_context executed 6 handlers.
[Info    ] [ModemUARTDFU-Probe-/dev/ttyACM0] serial port /dev/ttyACM0 closed.
{
    "duration": 1, 
    "error_code": "Ok", 
    "operation": "close_uart", 
    "outcome": "success", 
    "progress_percentage": 100
}
[Info    ] [HighLevel ] Done.
[Debug   ] [HighLevel ] dll_close
[Info    ] [HighLevel ] closing and freeing sub dlls.
Traceback (most recent call last):
  File "update_modem.py", line 43, in <module>
    run(args.uart, args.firmware, args.baudrate)
  File "update_modem.py", line 26, in run
    modem_dfu_probe.program(modem_firmware_zip)
  File "/home/ivo/.local/lib/python3.8/site-packages/pynrfjprog/HighLevel.py", line 350, in program
    raise APIError(result, log=self._logger.error)
pynrfjprog.APIError.APIError: An error was reported by NRFJPROG DLL: -2 INVALID_OPERATION.
ivo@system76-pc:~/src/nrf91-1.5.0/ncs/nrf/samples/nrf9160/fmfu_smp_svr$ 
