Skip to content

install --uboot-file crashes: NameError 'cached' is not defined (RAM-burn session) #123

Description

@widgetii

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions