Summary
defib install --uboot-file <file> crashes with NameError: name 'cached' is not defined before it can burn U-Boot. The --uboot-file code path never assigns cached, but the RecoverySession for the RAM-burn is constructed with firmware_path=str(cached).
Environment
- defib
a39e0e2 (master), pyproject.toml version 0.1.0
- Target:
hi3516ev300 (128 MiB SPI-NAND, board Rostelecom IPC8232SWC-WE)
- Host: Linux
Repro
defib install -c hi3516ev300 \
--firmware openipc.hi3516ev300-nand-ultimate.tgz \
--nand -p /dev/ttyUSB4 \
--uboot-file u-boot-hi3516ev300-nand.bin \
--nic eth0 --host-ip ... --device-ip ...
Root cause
In src/defib/cli/app.py, Step 2 "Get U-Boot":
# --- Step 2: Get U-Boot ---
if uboot_file: # L2349
ub_path = _Path(uboot_file)
...
uboot_raw = ub_path.read_bytes() # cached is NEVER set here
uboot_label = ub_path.name
else:
...
cached = get_cached_path(chip) # L2368 — only set in the else branch
...
Then later:
session = RecoverySession(
chip=chip, firmware_path=str(cached), # L2439 — NameError when --uboot-file was used
...
)
cached is only bound in the else (no --uboot-file) branch, so any --uboot-file invocation raises NameError at L2439 (and the rack-fastboot path at L2480 has the same cached.read_bytes() reference).
Expected
--uboot-file should work. The apparent intent is: RAM-burn uses the cached universal U-Boot (defib knows its SPL boundary), while --uboot-file overrides only the image flashed to the boot partition (uboot_raw). So cached should be resolved unconditionally.
Suggested fix
Resolve cached (the universal U-Boot for the RAM-burn) before the if uboot_file: block, and let --uboot-file override only uboot_raw/uboot_label:
cached = get_cached_path(chip) or (download_firmware(chip) if has_firmware(chip) else None)
if uboot_file:
ub_path = _Path(uboot_file); uboot_raw = ub_path.read_bytes(); uboot_label = ub_path.name
else:
...
uboot_raw = cached.read_bytes(); uboot_label = cached.name
(For V500 chips with no universal U-Boot, cached may legitimately be None; the session should then RAM-burn uboot_file itself.)
Workaround
Omit --uboot-file; defib then uses the cached universal U-Boot for both RAM-burn and the flashed boot partition, which boots fine on hi3516ev300 NAND.
Summary
defib install --uboot-file <file>crashes withNameError: name 'cached' is not definedbefore it can burn U-Boot. The--uboot-filecode path never assignscached, but theRecoverySessionfor the RAM-burn is constructed withfirmware_path=str(cached).Environment
a39e0e2(master),pyproject.tomlversion 0.1.0hi3516ev300(128 MiB SPI-NAND, board Rostelecom IPC8232SWC-WE)Repro
Root cause
In
src/defib/cli/app.py, Step 2 "Get U-Boot":Then later:
cachedis only bound in theelse(no--uboot-file) branch, so any--uboot-fileinvocation raisesNameErrorat L2439 (and the rack-fastboot path at L2480 has the samecached.read_bytes()reference).Expected
--uboot-fileshould work. The apparent intent is: RAM-burn uses the cached universal U-Boot (defib knows its SPL boundary), while--uboot-fileoverrides only the image flashed to the boot partition (uboot_raw). Socachedshould be resolved unconditionally.Suggested fix
Resolve
cached(the universal U-Boot for the RAM-burn) before theif uboot_file:block, and let--uboot-fileoverride onlyuboot_raw/uboot_label:(For V500 chips with no universal U-Boot,
cachedmay legitimately beNone; the session should then RAM-burnuboot_fileitself.)Workaround
Omit
--uboot-file; defib then uses the cached universal U-Boot for both RAM-burn and the flashed boot partition, which boots fine on hi3516ev300 NAND.