This script performs a safe A/B rootfs update for the LAN9662 SoC:
- Running SSH Dropbear server on the target device
- Root user with password authentication enabled
- The script prog.sh handles it all. Either it is already available on the target, or it has to be copied to the target
For direct console access without network setup:
- Prepare data partition:
- if the programming script isn't already available, then copy from host (Windows) to target (LAN9662) with:
scp -O prog.sh root@169.254.45.100:/sbin- in the target console ensure execution rights with
chmod 744 /sbin/prog.sh- and execute script with
/sbin/prog.sh- The script will format
/dev/mmcblk0p7and mount it to/data. - Transfer
brsdk_standalone_arm.ext4.gzto/data/using these method: scp -O brsdk_standalone_arm.ext4.gz root@169.254.45.100:/data/- Press ENTER in the script to continue with the update process
- The script will extract and install the image automatically
For network-based remote update:
-
Copy script to target system:
ssh-keygen -R 169.254.45.100 scp -O prog.sh root@169.254.45.100:/sbin/ ssh root@169.254.45.100 "chmod 744 /sbin/prog.sh" -
Prepare image: Have
brsdk_standalone_arm.ext4.gzready on your host computer. -
Run the script:
ssh root@169.254.45.100 "/sbin/prog.sh" -
Follow instructions: The script will guide you through the SCP upload process and perform the update automatically.
Important: Root privileges required, active network connection to target device necessary.
The prog.sh script is a comprehensive rootfs update utility designed for the LAN9662 System-on-Chip (SoC). It implements a safe A/B partition update mechanism that allows for reliable firmware updates without the risk of bricking the device.
- Redundant Boot System: Uses A/B partitioning (mmcblk0p5/p6) for safe updates
- Automatic Slot Detection: Intelligently determines active and inactive boot slots
- Data Partition Management: Automatically prepares
/dev/mmcblk0p7for image storage - Network Transfer Support: Provides SCP commands for easy image transfer
- U-Boot Environment Control: Automatically configures boot parameters in SPI flash
- Error Handling: Comprehensive error checking and validation throughout the process
- SoC: LAN9662 (Microchip)
- Storage: eMMC/MMC with specific partition layout:
/dev/mmcblk0p5: Root partition A/dev/mmcblk0p6: Root partition B/dev/mmcblk0p7: Data partition
- Flash: SPI flash for U-Boot environment storage
- Network: Ethernet interface (eth0) for file transfer
- Linux: Embedded Linux with U-Boot bootloader
- Tools Required:
fw_setenv/fw_printenv(U-Boot environment tools)mkfs.ext4(filesystem utilities)dd,gunzip,mount/umountscp(for file transfer)
-
Copy script to target system:
scp -O prog.sh root@<TARGET_IP>:/sbin/
-
Make executable:
chmod 744 /sbin/prog.sh
-
Run the script:
/sbin/prog.sh
- Root Access: Script must be run with root privileges
- Image File: Prepare
brsdk_standalone_arm.ext4.gzon host computer - Network Connectivity: Ensure target board is accessible via SSH/SCP
- Formats
/dev/mmcblk0p7as ext4 - Creates mount point
/dataif not exists - Mounts the data partition for image storage
- Detects target IP address automatically
- Provides SCP command for host computer:
scp -O brsdk_standalone_arm.ext4.gz root@<TARGET_IP>:/data/
- Includes troubleshooting for SSH key conflicts
- Decompresses
.gzfile usinggunzip - Validates extracted image file
- Analyzes
/proc/cmdlineto determine current root partition - Identifies active slot (5 or 6)
- Selects inactive slot for update
- Unmounts target partition if mounted
- Writes image to inactive slot using
ddwith optimized parameters - Uses
bs=1M conv=fsyncfor reliable writing
Creates /etc/fw_env.config with SPI flash parameters:
/dev/mtd0 0x00180000 0x00040000 0x00001000
/dev/mtd0 0x001C0000 0x00040000 0x00001000
- Sets
mmc_curto new boot slot - Sets
mmc_bakto current slot (for fallback) - Updates U-Boot environment in SPI flash
- Primary Environment: Offset 0x180000 (1.5MB)
- Redundant Environment: Offset 0x1C0000 (1.75MB)
- Size: 256KB each (0x40000)
- Sector Size: 4KB (0x1000)
- mmc_cur: Current active boot slot (5 or 6)
- mmc_bak: Backup slot for fallback mechanism
- A/B Updates: Never overwrites currently running system
- Fallback Mechanism: U-Boot can revert to previous slot on boot failure
- Dual Environment: Redundant U-Boot environments prevent corruption
- Root Privilege Check: Prevents accidental execution
- Partition Validation: Verifies expected partition layout
- Mount State Checking: Safely handles mounted partitions
- File Existence Validation: Confirms image files before processing
If you see "REMOTE HOST IDENTIFICATION HAS CHANGED":
ssh-keygen -R <TARGET_IP>Ensure script runs as root:
sudo /sbin/prog.shVerify partition layout:
fdisk -l /dev/mmcblk0Check environment access:
fw_printenvIf automatic configuration fails, manually set in U-Boot:
For slot 5:
U-Boot> setenv mmc_cur 5
U-Boot> setenv mmc_bak 6
U-Boot> saveenv
U-Boot> boot
For slot 6:
U-Boot> setenv mmc_cur 6
U-Boot> setenv mmc_bak 5
U-Boot> saveenv
U-Boot> boot
/dev/mmcblk0p5 # Root partition A
/dev/mmcblk0p6 # Root partition B
/dev/mmcblk0p7 # Data partition (/data)
/dev/mtd0 # SPI flash (U-Boot environment)
/etc/fw_env.config # U-Boot tools configuration
The LAN9662 system uses a carefully designed eMMC partition layout to support redundant booting and reliable firmware updates:
+-------------------+----------------+--------------------+---------------------------------------------+
| Device | Start Sector | Start Address (hex)| Purpose |
+-------------------+----------------+--------------------+---------------------------------------------+
| /dev/mmcblk0 | 0 | 0x00000000 | Complete eMMC device |
| /dev/mmcblk0p1 | 64 | 0x00008000 | Firmware Image Package, Bootloader Code |
| /dev/mmcblk0p2 | 262208 | 0x08008000 | Backup FIP Partition |
| /dev/mmcblk0p3 | 524352 | 0x10008000 | U-Boot Environment |
| /dev/mmcblk0p4 | 528448 | 0x10208000 | Backup Environment |
| /dev/mmcblk0p5 | 532544 | 0x10408000 | Boot Slot A (Kernel+Rootfs Image) |
| /dev/mmcblk0p6 | 2629696 | 0xA0408000 | Boot Slot B (Kernel+Rootfs Image, current) |
| /dev/mmcblk0p7 | 4726848 | 0x120408000 | Data/Persistence Partition |
+-------------------+----------------+--------------------+---------------------------------------------+
Key Partitions:
- p1/p2: Redundant bootloader storage (FIP - Firmware Image Package)
- p3/p4: Redundant U-Boot environments (also mirrored in SPI flash)
- p5/p6: A/B root filesystem slots for safe updates
- p7: User data partition, used by update script for temporary storage
The SPI flash contains critical boot components and configuration:
+-------------------+-----------+----------+---------------------------------------------+
| Device | Size | GPT Name | Purpose |
+-------------------+-----------+----------+---------------------------------------------+
| /dev/mtd0 | 2.0 MB | spi1 | Complete SPI Flash |
| /dev/mtd0_fip | 1.5 MB | fip | Firmware Image Package, Bootloader Code |
| /dev/mtd0_env | 256 kB | Env | U-Boot Environment (primary copy) |
| /dev/mtd0_envbk | 256 kB | Env.bak | Backup Environment (redundant copy) |
+-------------------+-----------+----------+---------------------------------------------+
Address (hex) Size Region Content / Purpose
──────────────────────────────────────────────────────────────────────────────
0x00000000
│
│ 0x00180000 (1,536 KiB)
│
├─────────────────────────────── FIP (Firmware Image Package)
│ - U-Boot SPL / TF-A / additional FW
│ - Boot code that starts the CPU
0x00180000
│
│ 0x00040000 (256 KiB)
│
├─────────────────────────────── Env (Primary Environment)
│ - U-Boot variables as Key=Value pairs:
│ e.g., mmc_cur, mmc_bak, bootcmd,
│ bootargs, mtdparts, offsets etc.
│ - CRC / Management data
0x001C0000
│
│ 0x00040000 (256 KiB)
│
├─────────────────────────────── Env.bak (Backup Environment)
│ - Redundant copy of environment
│ - Used if primary Env is corrupted
0x00200000 (End, 2 MiB)
Important Notes:
- Redundancy: Both eMMC and SPI flash contain U-Boot environments for maximum reliability
- Boot Order: System boots from SPI flash (FIP), then loads kernel/rootfs from eMMC
- Update Safety: A/B partitioning (p5/p6) ensures system never becomes unbootable
- Environment Access: Script uses
/etc/fw_env.configto access SPI flash environments
- Access U-Boot: Interrupt boot process (spacebar)
- Check Environment:
printenv - Switch Slots: Manually set
mmc_curandmmc_bak - Save and Boot:
saveenvthenboot
If both slots are corrupted:
- Boot from external media (SD card, USB)
- Re-flash both partitions manually
- Restore U-Boot environment
- Modify partition paths in variables section
- Adjust SPI flash offsets if hardware differs
- Customize network interface detection
- Format: ext4 filesystem image
- Compression: gzip (.gz)
- Naming:
brsdk_standalone_arm.ext4.gz
- Root Access: Script requires and validates root privileges
- Network Security: Uses SCP with authentication
- Flash Protection: Redundant environments prevent brick scenarios
- Validation: Multiple checkpoints prevent partial updates
- Initial Version: Basic A/B update functionality
- Current: Enhanced error handling, automatic U-Boot configuration
For issues specific to LAN9662 hardware or U-Boot configuration, consult:
- LAN9662 Hardware Reference Manual
- Microchip U-Boot Documentation
- Embedded Linux Build System Documentation
Note: This script is specifically designed for LAN9662 SoC systems with the described partition layout. Modification may be required for different hardware configurations.