diff --git a/install_bl.py b/install_bl.py index dd7b255..96a544b 100644 --- a/install_bl.py +++ b/install_bl.py @@ -26,15 +26,16 @@ fn_remote = '/tmp/bootloader.bin' fn_local = None if bl_name == 'breed': - if dn != 'R3G' and dn != 'R3P' and dn != 'RM2100' and dn != 'RA71' and dn != 'CR6006' and dn != 'CR6008' and dn != 'CR6009' and dn != 'TR609' and dn !='TR608': + supported_devices = ['R3G', 'R3P', 'RM2100', 'RA71', 'CR6606', 'CR6608', 'CR6609', 'TR609', 'TR608'] + if dn not in supported_devices: die("Breed bootloader cannot be installed on this device!") - if dn in ['CR6006', 'CR6008', 'CR6009', 'TR609', 'TR608']: + if dn in ['CR6606', 'CR6608', 'CR6609', 'TR609', 'TR608']: fn_local = fn_dir + 'pb-boot-cr660x.img' else: fn_local = fn_dir + 'breed_r3g_eng.bin' if bl_name == 'uboot': - fn_local = fn_dir + 'uboot_{}.bin'.format(gw.device_name) + fn_local = fn_dir + 'uboot_{}.bin'.format(dn) if not fn_local: die('Incorrect bootloader name!') @@ -54,6 +55,10 @@ if dev.bl.spi_rom: die("Not support SPI Flash ROM! (now supported only NAND)") addr = None +name = None +size = None + +# Find bootloader partition (typically at address 0, but skip large "ALL" partitions) for p, part in enumerate(dev.partlist): if part['addr'] == 0 and part['size'] > 0x00800000: # 8MiB continue # skip "ALL" part @@ -62,12 +67,29 @@ for p, part in enumerate(dev.partlist): fname = ''.join(e for e in name if e.isalnum()) addr = part['addr'] size = part['size'] + break # Take the first valid partition found if addr is None: die("No matching partition found!") -gw.upload(fn_local, fn_remote) -print ('Writing data to partition "{}" (addr: {}) ...'.format(name, "0x%08X" % addr)) -gw.run_cmd('mtd write {bin} "{name}"'.format(bin=fn_remote, name=name)) +# Validate that we have a proper partition name before proceeding +if not name: + die("Invalid partition name found!") + +print('Selected partition: "{}" at address 0x{:08X} (size: 0x{:08X})'.format(name, addr, size)) + +# Upload bootloader file to device +try: + gw.upload(fn_local, fn_remote) +except Exception as e: + die('Failed to upload bootloader file: {}'.format(str(e))) + +print('Writing data to partition "{}" (addr: {}) ...'.format(name, "0x%08X" % addr)) + +# Write bootloader to partition with error handling +try: + gw.run_cmd('mtd write {bin} "{name}"'.format(bin=fn_remote, name=name)) +except Exception as e: + die('Failed to write bootloader to partition: {}'.format(str(e))) print('Ready! Bootloader "{}" installation is complete.'.format(bl_name))