This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SDK 15 and Mesh 2.0 Generate a DFU file with nrfutil - ValueError

We used nRF5_SDK_15.0.0_a53641a and nrf5_SDK_for_Mesh_v2.0.0_src.

We are following DFU quick start guide http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.meshsdk.v0.10.0%2Findex.html

For nRF52:

mesh-sdk$ nrfutil dfu genpkg --application bin/blinky/blinky_nrf52832_xxAA_s132_5.0.0.hex \
--company-id 0x00000089 \
--application-id 1 \
--application-version 2 \
--key-file private_key.txt \
--sd-req 0x009D \
--mesh dfu_test.zip
We used "--company-id 0x00000089 \" to match Step 2 public key:
{
"bootloader_config": {
"bootloader_id": 1,
"bootloader_version": 1,
"company_id": 89,
"application_id": 1,
"application_version": 1,
"public_key": "ed09a58df6db5cd15b8637304f31d31f4042492ed7c7e4839fbe903f260a2ba1a855e92b72885825481ad56282bcf549ad7455ec46f000f0f62d97eeec883ba6"
}
}
The hex we used is C:\Nordic\nRF5_SDK_15.0.0_a53641a\mesh_sdk\bin\blinky\blinky_nrf52832_xxAA_s132_5.0.0.hexblinky_nrf52832_xxAA_s132_5.0.0.hex
We got ValueError, please see attached screen shot. 
Please advise.  Thanks
Parents
  • We started command prompt on an administrator.  I have make sure all the steps before and after step 8 using s132 softdevice version 6.0.  We tried to flash the program via both SES and nrfjprog (like shown in step 8).  We also used difference Bud rate 115200, 57600, 38400, 19200, 14400 and 9600.

    Attached are the cmd script file

    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
    
    C:\Users\ALaw>cd C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfutil keys --gen-key private_key.txt
    Generated key at: private_key.txt
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfutil keys --show-vk hex private_key.tx
    t
    Verification key Qx: d78ea2728b31c63b185402f4209803b478d0828b02a0f44da9f5d782b04
    7fe45
    Verification key Qy: b60bf4db2e572b4b6053c0c7e9371b309c93ee53c300906afc6c7f2d99c
    e11cd
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfutil dfu genpkg --application bin/blin
    ky/blinky_nrf52832_xxAA_s132_6.0.0.hex --company-id 0x00000059 --application-id
    1 --application-version 2 --key-file private_key.txt --sd-req 0x009D --mesh dfu_
    test.zip
    Key file was given, setting DFU version to 0.8
    Zip created at dfu_test.zip
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>cd tools/dfu
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src\tools\dfu>python device_page_generator.py
     -d nrf52832_xxAA -sd "s132_6.0.0"
    Wrote device page for nrf52832_xxAA with the s132_6.0.0 SoftDevice to bin/device
    _page_nrf52832_xxAA_s132_6.0.0.hex.
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src\tools\dfu>cd ..
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src\tools>cd ..
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfjprog --eraseall
    Erasing user available code and UICR flash areas.
    Applying system reset.
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfjprog --program bin/softdevice/s132_nr
    f52_6.0.0_softdevice.hex --chiperase
    Parsing hex file.
    Erasing user available code and UICR flash areas.
    Applying system reset.
    Checking that the area to write is not protected.
    Programming device.
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfjprog --program bin/bootloader/armcc/m
    esh_bootloader_serial_armcc__nrf52832_xxAA.hex
    Parsing hex file.
    ERROR: The file specified could not be found.
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfjprog --program bin/bootloader/armcc/m
    esh_bootloader_serial_armcc_nrf52832_xxAA.hex
    Parsing hex file.
    Reading flash area to program to guarantee it is erased.
    Checking that the area to write is not protected.
    Programming device.
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfjprog --program examples\dfu\build\dfu
    _nrf52832_xxAA_s132_6.0.0_Debug\dfu_nrf52832_xxAA_s132_6.0.0.hex
    Parsing hex file.
    Reading flash area to program to guarantee it is erased.
    Checking that the area to write is not protected.
    Programming device.
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfjprog --program tools/dfu/bin/device_p
    age_nrf52832_xxAA_s132_6.0.0.hex
    Parsing hex file.
    Reading flash area to program to guarantee it is erased.
    Checking that the area to write is not protected.
    Programming device.
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfjprog --reset
    Applying system reset.
    Run.
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfutil dfu serial -pkg dfu_test.zip -p C
    OM46 -b 115200 -fc --mesh
    Upgrading target on COM46 with DFU package C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_sr
    c\dfu_test.zip. Flow control is enabled.
      [------------------------------------]    0%
    
    Failed to upgrade target. Error is: Failed to establish connection
    
    Possible causes:
    - bootloader, SoftDevice or application on target does not match the requirement
    s in the DFU package.
    - baud rate or flow control is not the same as in the target bootloader.
    - target is not in DFU mode. If using the SDK examples, press Button 4 and RESET
     and release both to enter DFU mode.
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfutil --verbose dfu serial -pkg dfu_tes
    t.zip -p COM46 -b 115200 -fc --mesh
    Upgrading target on COM46 with DFU package C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_sr
    c\dfu_test.zip. Flow control is enabled.
      [------------------------------------]    0%Flushing com-port...
    Opened com-port
    Starting DFU upgrade of type 4, SoftDevice size: 0, bootloader size: 0, applicat
    ion size: 1912
    Sending DFU start packet, afterwards we wait for the flash on target to be initi
    alized before continuing.
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    
    
    Failed to upgrade target. Error is: Failed to establish connection
    
    Possible causes:
    - bootloader, SoftDevice or application on target does not match the requirement
    s in the DFU package.
    - baud rate or flow control is not the same as in the target bootloader.
    - target is not in DFU mode. If using the SDK examples, press Button 4 and RESET
     and release both to enter DFU mode.
    Closing serial port...
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfutil dfu serial -pkg dfu_test.zip -p C
    OM46 -b 57600 -fc --mesh
    Upgrading target on COM46 with DFU package C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_sr
    c\dfu_test.zip. Flow control is enabled.
      [------------------------------------]    0%
    
    Failed to upgrade target. Error is: Failed to establish connection
    
    Possible causes:
    - bootloader, SoftDevice or application on target does not match the requirement
    s in the DFU package.
    - baud rate or flow control is not the same as in the target bootloader.
    - target is not in DFU mode. If using the SDK examples, press Button 4 and RESET
     and release both to enter DFU mode.
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfutil --verbose dfu serial -pkg dfu_tes
    t.zip -p COM46 -b 38400 -fc --mesh
    Upgrading target on COM46 with DFU package C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_sr
    c\dfu_test.zip. Flow control is enabled.
      [------------------------------------]    0%Flushing com-port...
    Opened com-port
    Starting DFU upgrade of type 4, SoftDevice size: 0, bootloader size: 0, applicat
    ion size: 1912
    Sending DFU start packet, afterwards we wait for the flash on target to be initi
    alized before continuing.
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    
    
    Failed to upgrade target. Error is: Failed to establish connection
    
    Possible causes:
    - bootloader, SoftDevice or application on target does not match the requirement
    s in the DFU package.
    - baud rate or flow control is not the same as in the target bootloader.
    - target is not in DFU mode. If using the SDK examples, press Button 4 and RESET
     and release both to enter DFU mode.
    Closing serial port...
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfutil --verbose dfu serial -pkg dfu_tes
    t.zip -p COM46 -b 19200 -fc --mesh
    Upgrading target on COM46 with DFU package C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_sr
    c\dfu_test.zip. Flow control is enabled.
      [------------------------------------]    0%Flushing com-port...
    Opened com-port
    Starting DFU upgrade of type 4, SoftDevice size: 0, bootloader size: 0, applicat
    ion size: 1912
    Sending DFU start packet, afterwards we wait for the flash on target to be initi
    alized before continuing.
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    
    
    Failed to upgrade target. Error is: Failed to establish connection
    
    Possible causes:
    - bootloader, SoftDevice or application on target does not match the requirement
    s in the DFU package.
    - baud rate or flow control is not the same as in the target bootloader.
    - target is not in DFU mode. If using the SDK examples, press Button 4 and RESET
     and release both to enter DFU mode.
    Closing serial port...
    target -> PC: e8
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfutil --verbose dfu serial -pkg dfu_tes
    t.zip -p COM46 -b 14400 -fc --mesh
    Upgrading target on COM46 with DFU package C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_sr
    c\dfu_test.zip. Flow control is enabled.
      [------------------------------------]    0%Flushing com-port...
    Opened com-port
    Starting DFU upgrade of type 4, SoftDevice size: 0, bootloader size: 0, applicat
    ion size: 1912
    Sending DFU start packet, afterwards we wait for the flash on target to be initi
    alized before continuing.
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    
    
    Failed to upgrade target. Error is: Failed to establish connection
    
    Possible causes:
    - bootloader, SoftDevice or application on target does not match the requirement
    s in the DFU package.
    - baud rate or flow control is not the same as in the target bootloader.
    - target is not in DFU mode. If using the SDK examples, press Button 4 and RESET
     and release both to enter DFU mode.
    Closing serial port...
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfutil --verbose dfu serial -pkg dfu_tes
    t.zip -p COM46 -b 9600 -fc --mesh
    Upgrading target on COM46 with DFU package C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_sr
    c\dfu_test.zip. Flow control is enabled.
      [------------------------------------]    0%Flushing com-port...
    Opened com-port
    Starting DFU upgrade of type 4, SoftDevice size: 0, bootloader size: 0, applicat
    ion size: 1912
    Sending DFU start packet, afterwards we wait for the flash on target to be initi
    alized before continuing.
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    
    
    Failed to upgrade target. Error is: Failed to establish connection
    
    Possible causes:
    - bootloader, SoftDevice or application on target does not match the requirement
    s in the DFU package.
    - baud rate or flow control is not the same as in the target bootloader.
    - target is not in DFU mode. If using the SDK examples, press Button 4 and RESET
     and release both to enter DFU mode.
    Closing serial port...
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>
    
    
    
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>

    Step 1: private_key.txt 

    -----BEGIN EC PRIVATE KEY-----
    MHcCAQEEIHPeFxystPEoiZd7uOpCqfRxyO69QavgEeIowj7u+fp2oAoGCCqGSM49
    AwEHoUQDQgAE146icosxxjsYVAL0IJgDtHjQgosCoPRNqfXXgrBH/kW2C/TbLlcr
    S2BTwMfpNxswnJPuU8MAkGr8bH8tmc4RzQ==
    -----END EC PRIVATE KEY-----
    

    Step 2: bootloader_config_default.json 

    {
        "bootloader_config": {
            "bootloader_id": 1,
            "bootloader_version": 1,
            "company_id": 89,
            "application_id": 1,
            "application_version": 1,
    		"public_key": 
    	"d78ea2728b31c63b185402f4209803b478d0828b02a0f44da9f5d782b047fe45b60bf4db2e572b4b6053c0c7e9371b309c93ee53c300906afc6c7f2d99ce11cd"	
    	
        }
    }
    

    Step 3: dfu_test.zip dfu_test.zip

    Step 4: Modified  dfu_nrf52832_xxAA_s132_6.0.0.py from 5.0.0 to 6.0.0 

    # Copyright (c) 2010 - 2018, Nordic Semiconductor ASA
    # All rights reserved.
    #
    # Redistribution and use in source and binary forms, with or without
    # modification, are permitted provided that the following conditions are met:
    #
    # 1. Redistributions of source code must retain the above copyright notice, this
    #    list of conditions and the following disclaimer.
    #
    # 2. Redistributions in binary form must reproduce the above copyright
    #    notice, this list of conditions and the following disclaimer in the
    #    documentation and/or other materials provided with the distribution.
    #
    # 3. Neither the name of Nordic Semiconductor ASA nor the names of its
    #    contributors may be used to endorse or promote products derived from this
    #    software without specific prior written permission.
    #
    # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    # IMPLIED WARRANTIES OF MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE
    # ARE DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
    # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    # POSSIBILITY OF SUCH DAMAGE.
    
    import argparse
    import enum
    import struct
    import intelhex
    import sys
    import json
    import os
    
    PACKAGE_PARENT = '..'
    SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
    sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
    
    from deviceutil.deviceutil import \
        get_application_limits, \
        make_bootloader_for_platforms, \
        set_softdevices_for_platforms, \
        load_softdevies, \
        load_platforms
    
    WORD_SIZE = 4
    
    
    class BLInfoType(enum.IntEnum):
        INVALID = 0x00
        ECDSA_PUBLIC_KEY = 0x01
        VERSION = 0x02
        JOURNAL = 0x03
        FLAGS = 0x04
        SEGMENT_SD = 0x10
        SEGMENT_BL = 0x11
        SEGMENT_APP = 0x12
        LAST = 0x7FFF
    
    
    class DevicePageEntry(object):
        def __init__(self, bl_info_type, data):
            #print("Type: ", type(data).__name__)
            if not (isinstance(bl_info_type, BLInfoType) and
                    (isinstance(data, bytearray) or isinstance(data, str))):
                raise TypeError("Invalid type %r" % (type(data)))
    
            self.bl_info_type = bl_info_type
            if (isinstance(data, str)):
               data = bytearray.fromhex(data)
            self.data = self.pad(data)
    
        @property
        def word_count(self):
            return (len(self.data) + WORD_SIZE) // WORD_SIZE
    
        def pad(self, data):
            pad_byte_count = (WORD_SIZE - len(data) % WORD_SIZE) % WORD_SIZE
            if pad_byte_count > 0:
                data += bytearray([0xFF] * pad_byte_count)
            return data
    
        def serialize(self):
            return (bytearray(struct.pack('<HH', self.word_count, self.bl_info_type)
                              + self.data))
    
    
    class DevicePage(object):
        def __init__(self, platform, softdevice, bootloader_config):
            self.entries = []
            self.generate_entries(platform, softdevice, bootloader_config)
            self.platform = platform
            self.softdevice = softdevice
    
        def generate_entries(self, platform, softdevice, bootloader_config):
            public_key = bytearray.fromhex(bootloader_config["public_key"]) \
                         if "public_key" in bootloader_config else None
            if public_key:
                self.entries.append(
                    DevicePageEntry(BLInfoType.ECDSA_PUBLIC_KEY, public_key))
    
            app_limits = get_application_limits(platform, softdevice)
            app_segment = bytearray(struct.pack("<II",
                                                app_limits["flash_start"],
                                                app_limits["flash_size"]))
            sd_segment = bytearray(struct.pack("<II",
                                               softdevice["flash_start"],
                                               softdevice["flash_size"]))
            bl_segment = bytearray(struct.pack("<II",
                                               platform["bootloader"]["flash_start"],
                                               platform["bootloader"]["flash_size"]))
    
            self.entries.append(
                DevicePageEntry(BLInfoType.SEGMENT_APP, app_segment))
            self.entries.append(
                DevicePageEntry(BLInfoType.SEGMENT_SD, sd_segment))
            self.entries.append(
                DevicePageEntry(BLInfoType.SEGMENT_BL, bl_segment))
    
            version_data = bytearray(struct.pack("<HBBIHI",
                                                 int(softdevice["version"], 16),
                                                 bootloader_config["bootloader_id"],
                                                 bootloader_config["bootloader_version"],
                                                 bootloader_config["company_id"],
                                                 bootloader_config["application_id"],
                                                 bootloader_config["application_version"]))
    
            #print(version_data)
            self.entries.append(DevicePageEntry(BLInfoType.VERSION,
                                                version_data))
    
            self.entries.append(DevicePageEntry(BLInfoType.FLAGS,
                                                bytearray(struct.pack('I', 0xFFFFFFFF))))
    
        def write_hex(self, hexfile):
            # Info page metadata
            raw_data = bytearray(struct.pack("<BBBB", 4, 1, 8, 8))
            raw_data += bytearray().join(map(DevicePageEntry.serialize, self.entries))
            raw_data += bytearray(struct.pack("<HH", 0xFFFF, BLInfoType.LAST))
            hex_output = intelhex.IntelHex()
            hex_output.frombytes(raw_data,
                                 self.platform["flash_size"] - self.platform["page_size"])
            hex_output.tofile(hexfile, "hex")
    
    
    def write_specific_page(platforms, softdevices, args):
        platform = next((p for p in platforms if args.device == p["name"]), None)
        if not platform:
            print("Unknown device: \"%s\" in list %r" % (args.device, [p["name"] for p in platforms]))
            sys.exit(1)
    
        softdevice = next((s for s in softdevices if args.softdevice == s["name"]), None)
        if not softdevice:
            print("Unknown SoftDevice: \"%s\"" % (args.softdevice))
            sys.exit(1)
    
        if args.softdevice not in platform["softdevices"]:
            print("Unknown SoftDevice \"%s\" for platform \"%s\"" %
                  (args.softdevice, args.device))
            sys.exit(1)
    
        # Filter out the others...
        platforms = [p for p in platforms
                     if args.device.lower() in p["name"].lower()]
    
        make_bootloader_for_platforms(platforms)
        set_softdevices_for_platforms(platforms, softdevices)
    
        # Dict is updated by reference
        # platform = platforms[args.device]
        # softdevice = softdevices[args.softdevice]
    
        with open(args.bootloader_config, "r") as f:
            bootloader_config = json.load(f)["bootloader_config"]
        device_page = DevicePage(platform, softdevice, bootloader_config)
        if not args.output_file:
            args.output_file = "_".join(["device_page",
                                         self.platform["name"],
                                         self.softdevice["name"]]) + ".hex"
    
        device_page.write_hex(args.output_file)
    
    
    def write_all(platforms, softdevices, args):
        make_bootloader_for_platforms(platforms)
        set_softdevices_for_platforms(platforms, softdevices)
    
        with open(args.bootloader_config, "r") as f:
            bootloader_config = json.load(f)["bootloader_config"]
    
        for platform in platforms:
            for softdevice in platform["softdevices"]:
                device_page = DevicePage(platform, softdevice, bootloader_config)
                device_page.write_hex(args.output_file)
    
    
    def main():
        softdevices = load_softdevies("../configuration/softdevices.json")
        platforms = load_platforms("../configuration/platforms.json")
        sd_str = ''
        for sd in softdevices:
            sd_str += ''.join(sd["name"]) + "\n"
        plt_str = ''
        for plt in platforms:
            plt_str += ''.join(plt["name"]) + '\n'
    
        SOFTDEVICE = "s132_6.0.0"
        DEVICE = "nrf52832_xxAA"
        parser = argparse.ArgumentParser(description="Device Page Generator")
        parser.add_argument("-d", "--device", help="Select device: " + ''.join(plt_str),
                            default=DEVICE)
        parser.add_argument("-sd", "--softdevice", help="Select SoftDevice: "  + ''.join(sd_str),
                            default=SOFTDEVICE)
        parser.add_argument("-c", "--bootloader-config",
                            default="bootloader_config_default.json",
                            help="Bootloader configuration file")
        parser.add_argument("-o", "--output-file", help="Output hex file",
                            default="bin/device_page_%s_%s.hex" % (DEVICE, SOFTDEVICE))
        parser.add_argument("--all", default=False, action="store_true",
                            help=("Writes all known device page combinations to "
                                  + "\'bin/\'"))
        args = parser.parse_args()
    
        dirname = os.path.dirname(args.output_file)
        if not os.path.exists(dirname):
            os.mkdir(dirname)
    
        if args.all:
            write_all(platforms, softdevices, args)
            print("Wrote for device pages for all devices.")
        elif args.softdevice and args.device:
            write_specific_page(platforms, softdevices, args)
            print("Wrote device page for %s with the %s SoftDevice to %s." %
                  (args.device, args.softdevice, args.output_file))
    
    
    if __name__ == "__main__":
        main()
    

    to generate 

     device_page_nrf52832_xxAA_s132_6.0.0.hex device_page_nrf52832_xxAA_s132_6.0.0.hex

    Step 6: s132_nrf52_6.0.0_softdevice.hex s132_nrf52_6.0.0_softdevice.hex

    Step 7: s132_nrf52_6.0.0_softdevice.hex mesh_bootloader_serial_armcc_nrf52832_xxAA.hex

    Step 8: Program device using nrfjprog  to download dfu_nrf52832_xxAA_s132_6.0.0.hex dfu_nrf52832_xxAA_s132_6.0.0.hexdfu_nrf52832_xxAA_s132_6.0.0.map

     

    Step 9: Program device_page_nrf52832_xxAA_s132_6.0.0.hex device_page_nrf52832_xxAA_s132_6.0.0.hex 

    Step 10: We tried difference Baud Rates, press Button 4 and RESET and release both to enter DFU mode and use s132 and version 6.0.0, still got

    "Error is: Failed to establish connection"

     

    Please advise.  Thanks.

  • I got a few tips from a Mesh developer here at Nordic:

    "The original issue seems to be an error in the json file. Looks like there is an extra "}" at the end, maybe.

    Next, is the customer sure that the com port used is the correct com port?

    The SEGGER DFU build had a known issue with the flash_placement.xml file. I would advise the customer to use some of the pre-compiled binaries to test the DFU first."

    But I believe you have fixed the first issue, correct? I also believe you are using the correct com port & I believe you have used the pre-compiled binaries & not your own built hex files.

    I am not sure these tips will help all too much, but it's worth giving it a shot!

  • Have you tried using the bootloader_verify.py file from mesh sdk v2.0.1? Do you still receive the same error then? Did you make sure to run an nrfjprog --reset running the python script? This may help.

    Regarding ninja, I believe you can run the command: pip install Ninja or pip install ninja

    As far as I am aware though, for your use case, you will not need to use cmake unless you want a different segger project for a different device.

  • I successfully built file using cmake.  Thank you very much.

    Yes, I used the bootloader_verify.py file from mesh sdk v2.0.1, please see attached directory folder of bootloader_verify.py 

    # Copyright (c) 2010 - 2018, Nordic Semiconductor ASA
    # All rights reserved.
    #
    # Redistribution and use in source and binary forms, with or without
    # modification, are permitted provided that the following conditions are met:
    #
    # 1. Redistributions of source code must retain the above copyright notice, this
    #    list of conditions and the following disclaimer.
    #
    # 2. Redistributions in binary form must reproduce the above copyright
    #    notice, this list of conditions and the following disclaimer in the
    #    documentation and/or other materials provided with the distribution.
    #
    # 3. Neither the name of Nordic Semiconductor ASA nor the names of its
    #    contributors may be used to endorse or promote products derived from this
    #    software without specific prior written permission.
    #
    # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    # IMPLIED WARRANTIES OF MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE
    # ARE DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
    # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    # POSSIBILITY OF SUCH DAMAGE.
    
    import binascii
    import subprocess
    import shlex
    import sys
    import serial
    import time
    
    def get_device_family(serial_number):
        family = {
            '480': 'NRF51',
            '680': 'NRF51',
            '681': 'NRF51',
            '682': 'NRF52',
        }
        if not serial_number[:3] in family:
            return 'NRF51' # fallback to 51.
        else:
            return family[serial_number[:3]]
    
    def read_serial_event(s):
        evt = ""
        while True:
            length = s.read()
            if ord(length) > 0:
                evt = s.read(ord(length))
                return evt
    
    
    
    def print_usage():
        print("")
        print("Usage:\tbootloader_verify.py <Segger serial-number> <COM-port>")
    
    def nrfjprog(args):
        process = subprocess.Popen(shlex.split("nrfjprog " + args), stdout=subprocess.PIPE)
        out, err = process.communicate()
        if process != None and process.returncode == 2:
            print("Couldn't find nrfjprog, exiting.")
            exit(2)
        if process == None or process.returncode != 0:
            print("Error calling nrfjprog with arguments " + args + ".")
            print(out)
            exit(2)
        return out
    
    def read_uicr(serial_number):
        family = get_device_family(serial_number)
        sys.stdout.write("Device family:\t\t\t" + family + "\n")
        sys.stdout.write("Reading UICR..\t\t\t")
        read = nrfjprog("-s " + serial_number + " --memrd 0x10001014 --n 4 --w 32 --family " + family).strip()
        bootloader_addr = str(read).split()[1]
        if bootloader_addr == "FFFFFFFF":
            print("ERROR: UICR NOT SET.")
            print("Checkpoints:")
            print("\tHave you flashed the bootloader with nrfjprog?")
            print("\tDid you flash the Softdevice BEFORE the bootloader?")
            exit(1)
    
        read = nrfjprog("-s " + serial_number + " --memrd 0x" + bootloader_addr + " --n 4 --w 32 --family " + family).strip()
        bootloader_vector_pointer = str(read).split()[1]
        if bootloader_vector_pointer < "20000000":
            print("ERROR: Bootloader vector pointer invalid.")
            print("Checkpoints:")
            print("\tHave you flashed the bootloader with nrfjprog?")
            print("\tDid you flash the Softdevice BEFORE the bootloader?")
            print("\tDid you erase the device before programming all the hex-files?")
            exit(1)
        if bootloader_vector_pointer == "FFFFFFFF":
            print("ERROR: Bootloader not present.")
            print("Checkpoints:")
            print("\tHave you flashed the bootloader with nrfjprog?")
            print("\tDid you flash the Softdevice BEFORE the bootloader?")
            print("\tDid you erase the device before programming all the hex-files?")
            exit(1)
        print("OK.")
        return bootloader_addr
    
    def read_device_page(serial_number):
        family = get_device_family(serial_number)
        # need to know the flash size to get the device page. Can read this from the FICR:
        ficr = str(nrfjprog("-s " + serial_number + " --memrd 0x10000010 --n 8 --w 32 --family " + family).strip()).split()[1:]
        code_page_size = int(ficr[0], 16)
        code_page_count = int(ficr[1], 16)
        device_page_location = code_page_size * (code_page_count - 1)
    
        sys.stdout.write("Reading Device page..\t\t")
        device_page = nrfjprog("-s " + serial_number + " --memrd " + hex(device_page_location) + " --n 4 --w 32 --family " + family).strip()
        device_page_header = str(device_page).split()[1]
        if device_page_header == "FFFFFFFF":
            print("ERROR: DEVICE PAGE NOT PRESENT.")
            print("Checkpoints:")
            print("\tHave you flashed the device page?")
            exit(1)
        if device_page_header != "08080104":
            print("ERROR: DEVICE PAGE INVALID.")
            print("Checkpoints:")
            print("\tDid you erase the device before programming all the hex-files?")
            exit(1)
        print("OK.")
        return device_page_header
    
    def reset_device(serial_number, port):
        sys.stdout.write("Resetting device..\t\t")
        try:
            s = serial.Serial(port, 115200, rtscts = True)
        except:
            print("ERROR: Could not open COM port " + port)
            exit(1)
        family = get_device_family(serial_number)
        nrfjprog("-s " + serial_number + " --reset --family " + family)
        time.sleep(0.2)
        response = read_serial_event(s)
    
        if b"\x81\x02\x00" == response[:3]:
            print("OK (In application)")
        elif not b"\x81\x01\x00" in response:
            print("ERROR: Invalid start sequence from bootloader: " + binascii.hexlify(response))
            print("Checkpoints:")
            print("\tHave you flashed the bootloader with nrfjprog?")
            print("\tDoes your bootloader have serial communication enabled?")
            s.close()
            exit(1)
        else:
            print("OK.")
        time.sleep(0.1)
        s.close()
    
    def echo(port):
        sys.stdout.write("Checking serial connection..\t")
        try:
            s = serial.Serial(port, 115200, rtscts = True)
        except:
            print("ERROR: Could not open COM port " + port)
            exit(1)
        s.write(b"\x03\x02\xaa\xbb")
        time.sleep(0.1)
        if not s.read(4).startswith(b"\x03\x82\xaa\xbb"):
            print("ERROR: Invalid response!")
            print("Checkpoints:")
            s.close()
            exit(1)
        s.close()
        print("OK.")
    
    if __name__ == "__main__":
        if len(sys.argv) < 2:
            print("Please provide the serial number of your device")
            print_usage()
            exit(1)
        if len(sys.argv) < 3:
            print("Please provide the COM port of your device")
            print_usage()
            exit(1)
        try:
            int(sys.argv[1])
        except:
            print("Invalid serial number " + sys.argv[1])
            print_usage()
            exit(1)
    
        bootloader_addr = read_uicr(sys.argv[1])
        read_device_page(sys.argv[1])
        reset_device(sys.argv[1], sys.argv[2])
        echo(sys.argv[2])
    
        print("\nBootloader verification OK.")
    

    When I ran python bootloader_verify.py 682630616 COM3, it was get stuck in

    Resetting device..

    and didn't go anywhere.  The Command Prompt won't accept any command, please see attached screen shoot.  

    Please advise.  Thanks.

  • I have two tips: add some prints (i.e. sys.stdout.write("...")) in the bootloader_verify.py script to see where the error is occurring and/or try the whole dfu getting started process again. Most likely there is some small mistake you are making somewhere that is leading to this issue (e.g. running mesh_bootloader_gccarmemb instead of mesh_bootloader_serial_gccarmemb). I have tested this example again with three nrf52832 dev kits & the blinky dfu worked.

    I have had one issue with the COM port, so it might also be worthwhile to try a different usb port or try running the python bootloader_verify.py script on another one of your devices.

  • Hello,

    Thank you for the help here.

    I tried all the steps mentioned in the post, including the change to flash_placement.xml before flashing to the target board, I still see the issue (Failed to establish connection, after sending the DFU start packet).

    I’m following the quick start guide for this, using following setup: one target board – nrf52840 dev kit, softdevice – s140_6.0.0 (I verified in the nRF Go studio that this corresponds to ID 0x00A9), bootloader: mesh_bootloader_serial_gccarmemb_nrf52840_xxAA.hex. I built my dfu application using ninja/cmake, having set the device and softdevice to nrf52840/s140 respectively.

    Do I need to flash the host board as well, with the same first application? I assumed that since it is just a carrier, as long as it is recognized as a JLINK device, I should be able to run nrfutil on the serial port connected to the host board.

    Please advise,

    Thanks and regards,

    Shubhangi

  • It worked in my other computer now.

    I tried both

    C:\Nordic_SES\nrf5_SDK_for_Mesh_v2.0.1_src\bin\bootloader\gccarmemb\ mesh_bootloader_serial_gccarmemb_nrf52832_xxAA.hex

    And

    C:\Nordic_SES\nrf5_SDK_for_Mesh_v2.0.1_src\bin\bootloader\armcc\ mesh_bootloader_serial_armcc_nrf52832_xxAA.hex

    What is the difference between gccarmemb and armcc?

    Now it works using serial port, but my goal is updating firmware on mesh devices without using any cable connection as stated in the DFU quick start guide.

    I tried to use -s <serial number> on another module, but nothing happened.  Please specify which steps I should add -s <serial number>.  

    Please advise.  Thanks.

Reply
  • It worked in my other computer now.

    I tried both

    C:\Nordic_SES\nrf5_SDK_for_Mesh_v2.0.1_src\bin\bootloader\gccarmemb\ mesh_bootloader_serial_gccarmemb_nrf52832_xxAA.hex

    And

    C:\Nordic_SES\nrf5_SDK_for_Mesh_v2.0.1_src\bin\bootloader\armcc\ mesh_bootloader_serial_armcc_nrf52832_xxAA.hex

    What is the difference between gccarmemb and armcc?

    Now it works using serial port, but my goal is updating firmware on mesh devices without using any cable connection as stated in the DFU quick start guide.

    I tried to use -s <serial number> on another module, but nothing happened.  Please specify which steps I should add -s <serial number>.  

    Please advise.  Thanks.

Children
Related