Skip to content

# Using external drives in U Boot

ValCher1961 edited this page Mar 6, 2018 · 4 revisions

Using external drives in U-Boot

As it turned out, U-Boot WRT3200ACM can directly work with external disks connected to USB 2.0/eSATA ports. U-Boot supports FAT, EXT2 and EXT4 file systems. FAT and EXT2 support read only, EXT4 - read/write. Data exchange between the router and the external storage makes it possible to organize the debugging of new software more flexibly and to partially refuse to use the TFTP-server.

Using USB-Flash drive

For clarity of use, take a USB-Flash drive and create on it three sections with the file system FAT32, EXT2 and EXT4.

Install USB-Flash drive in the USB/SATA port we give the command -

Marvell>> usb reset
(Re)start USB...
USB0:   Port (usbActive) : 0    Interface (usbType = 2) : USB EHCI 1.00
scanning bus 0 for devices... 2 USB Device(s) found
       scanning usb for storage devices... 1 Storage Device(s) found
       scanning usb for ethernet devices... 0 Ethernet Device(s) found

We look at information about the Hub and the connected device -

Marvell>> usb info
1: Hub,  USB Revision 2.0
 - u-boot EHCI Host Controller
 - Class: Hub
 - PacketSize: 64  Configurations: 1
 - Vendor: 0x0000  Product 0x0000 Version 1.0
   Configuration: 1
   - Interfaces: 1 Self Powered 0mA
     Interface: 0
     - Alternate Setting 0, Endpoints: 1
     - Class Hub
     - Endpoint 1 In Interrupt MaxPacket 8 Interval 255ms

2: Mass Storage,  USB Revision 2.10
 - Jetflash Mass Storage Device F6413224200006BA
 - Class: (from Interface) Mass Storage
 - PacketSize: 64  Configurations: 1
 - Vendor: 0x8564  Product 0x1000 Version 1.0
   Configuration: 1
   - Interfaces: 1 Bus Powered 200mA
     Interface: 0
     - Alternate Setting 0, Endpoints: 2
     - Class Mass Storage, Transp. SCSI, Bulk only
     - Endpoint 2 Out Bulk MaxPacket 512
     - Endpoint 1 In Bulk MaxPacket 512

You can see the partitions of the mapped drive and the types of file systems -

Marvell>> usb part

Partition Map for USB device 0  --   Partition Type: DOS

Part    Start Sector    Num Sectors     UUID            Type
  1     2048            10485760        00000000-01     0b
  2     10487808        10485760        00000000-02     83
  3     20973568        11384832        00000000-03     83

Here you can see the contents of the volumes -

Marvell>> fatls usb 0:1
   995328   uboot-v004-wrt3200.bin
   995868   uboot-v100-wrt3200.bin

2 file(s), 0 dir(s)

Marvell>> ext2ls usb 0:2
<DIR>       4096 .
<DIR>       4096 ..
<DIR>      16384 lost+found
            8283 armada-385-linksys-venom.dts
<DIR>       4096 WRT32X_gpl
         5056103 my-kernel-rango.img

Marvell>> ext4ls usb 0:3
<DIR>       4096 .
<DIR>       4096 ..
<DIR>      16384 lost+found

Now we can copy the files we need from USB-Flash drive to the router memory, for example from the first partition -

Marvell>> fatload usb 0:1 0x1000000 uboot-v100-wrt3200.bin
reading uboot-v100-wrt3200.bin
995868 bytes read in 52 ms (18.3 MiB/s)

or from the second partition -

Marvell>> ext2load usb 0:2 0x2000000 my-kernel-rango.img
5056103 bytes read in 239 ms (20.2 MiB/s)

Then we can transfer the information to the desired NAND partition from the router's memory, for example, write the kernel. Preview he names of the partitions and their absolute addresses -

Marvell>> mtdparts

device nand0 <armada-nand>, # parts = 11
 #: name                size            offset          mask_flags
 0: uboot               0x000000200000          0x000000000000          1
 1: u_env               0x000000020000          0x000000200000          0
 2: s_env               0x000000040000          0x000000220000          0
 3: devinfo             0x000000040000          0x0000007e0000          0
 4: sysdiag             0x0000001e0000          0x000000820000          0
 5: ubifs               0x00000a000000          0x000000a00000          0
 6: kernel              0x000005000000          0x000000a00000          0
 7: rootfs              0x000004a00000          0x000001000000          0
 8: alt_kernel          0x000005000000          0x000005a00000          0
 9: alt_rootfs          0x000004a00000          0x000006000000          0
10: syscfg              0x000005600000          0x00000aa00000          0

Select the NAND device number, in our case - 0 and clean the kernel and alt_kernel partitions -

Marvell>> nand device 0
Marvell>> nand erase.part kernel; nand erase.part alt_kernel 

NAND erase.part: device 0 offset 0xa00000, size 0x5000000
Erasing at 0x59e0000 -- 100% complete.
OK

NAND erase.part: device 0 offset 0x5a00000, size 0x5000000
Erasing at 0xa9e0000 -- 100% complete.
OK

Write from memory to NAND kernel partitions.

Marvell>> nand write 0x2000000 0x0a00000 0x4D2667

NAND write: device 0 offset 0xa00000, size 0x4d2667
 5056103 bytes written: OK
Marvell>> nand write 0x2000000 0x5a00000 0x4D2667

NAND write: device 0 offset 0x5a00000, size 0x4d2667
 5056103 bytes written: OK

Note: In general, all records can be shortened if you use variables.

  • The length of the recorded file in RAM is automatically written to the variable - $filesize,
  • The starting address of the file location in RAM 0x2000000 is recorded in the variable - $defaultLoadAddr,
  • Also listed in the address variables of NAND - $priKernAddr, $altKernAddr.

Example of write command -

nand write $defaultLoadAddr $priKernAddr $filesize

Also we can write the contents of NAND partition in USB-Flash drive, for example we will do it with U-boot -

Marvell>> nand device 0
Marvell>> nand read 0x2000000 0 0x200000

NAND read: device 0 offset 0x0, size 0x200000
 2097152 bytes read: OK

Marvell>> ext4write usb 0:3 /mtd0.bin 0x2000000 0x200000
File System is consistent
update journal finished

Let's check that the file is written on USB-Flash drive -

Marvell>> ext4ls usb 0:3
<DIR>       4096 .
<DIR>       4096 ..
<DIR>      16384 lost+found
         2097152 mtd0.bin

Practical application

You can also implement to start the router with USB-Flash drive without using NAND. To do this, for example, in the root of the McDebian file system, place the kernel image file my-kernel-rango.img. In order to start the router looking for a kernel image on USB-Flash drive, you need to change the environment variables nandboot and altnandboot -

Marvell>> setenv nandboot 'usb reset;ext2load usb 0:1 $defaultLoadAddr my-kernel-rango.img;bootm $defaultLoadAddr'
Marvell>> setenv altnandboot 'usb reset;ext2load usb 0:1 $defaultLoadAddr my-kernel-rango.img;bootm $defaultLoadAddr'
Marvell>> saveenv
Saving Environment to NAND...
U-ENV offset == 0x200000
Erasing Nand...
Writing to Nand... U-ENV offset == 0x200000
U-ENV offset == 0x200000
done
Marvell>> reset
.
.
.
auto_recovery_check changes bootcmd: run altnandboot
Hit any key to stop autoboot:  0
(Re)start USB...
USB0:   Port (usbActive) : 0    Interface (usbType = 2) : USB EHCI 1.00
scanning bus 0 for devices... 2 USB Device(s) found
       scanning usb for storage devices... 1 Storage Device(s) found
       scanning usb for ethernet devices... 0 Ethernet Device(s) found
5056103 bytes read in 239 ms (20.2 MiB/s)
## Booting kernel from Legacy Image at 02000000 ...
   Image Name:   kernel
   Created:      2018-02-26   0:40:57 UTC
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    5056039 Bytes = 4.8 MiB
   Load Address: 00008000
   Entry Point:  00008000
   Verifying Checksum ... OK
   Loading Kernel Image ... OK
OK

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 4.14.22 (root@wrt3200acm) (gcc version 5.4.1 20160919 (15:5.4.1+svn241155-1)) #1 SMP Mon Feb 26 03:39:22 MSK 2

Now your router will not use NAND. To return the router to its original factory state, it is enough in U-boot to execute the command -

Marvell>> resetenv
Erasing 0x200000 - 0x220000:[Done]
Warning: Default Environment Variables will take effect Only after RESET

Using HDD/SSD

Connect the HDD/SSD to the eSATA port of the router and go to the U-Boot. To initialize the disk, execute the command -

Marvell>> scsi init
AHCI init for unit0
SATA link 0 timeout.
Target spinup took 0 ms.

Error: SCSI Controller(s) 1B4B:9215 1B4B:9235 not found
scanning bus for devices...
  Device 0: (1:0) Vendor: ATA Prod.: Hitachi HTS54251 Rev: BBCO
            Type: Hard Disk
            Capacity: 152627.8 MB = 149.0 GB (312581808 x 512)
Found 1 device(s).

The mapped drive is found and now see its structure -

Marvell>> scsi part

Partition Map for SCSI device 0  --   Partition Type: DOS

Part    Start Sector    Num Sectors     UUID            Type
  1     2048            51355648        a7802e7f-01     83 Boot
  2     51357696        2121728         a7802e7f-02     82
  3     53479424        259102383       a7802e7f-03     83

Can see its contents -

Marvell>> ext4ls scsi 0:1
<DIR>       4096 .
<DIR>       4096 ..
<DIR>      16384 lost+found
<DIR>       4096 var
<DIR>       4096 lib
<DIR>       4096 usr
<DIR>       4096 etc
<DIR>       4096 bin
<DIR>       4096 boot
<DIR>       4096 dev
<DIR>       4096 home
<DIR>       4096 proc
<DIR>       4096 root
<DIR>       4096 run
<DIR>       4096 sbin
<DIR>       4096 sys
<DIR>       4096 tmp
<DIR>       4096 mnt
<DIR>       4096 srv
<DIR>       4096 opt
<DIR>       4096 media
         5056103 my-kernel-rango.img

The use of HDD/SSD is almost no different from the use of USB-Flash drive, you can also read and write information. Here is an example of HDD/SSD usage in the router loading. To do this, change the environment variables nandkernel and altnandkernel -

Marvell>> setenv nandboot 'scsi init;ext4load scsi 0:1 $defaultLoadAddr my-kernel-rango.img;bootm $defaultLoadAddr'
Marvell>> setenv altnandboot 'scsi init;ext4load scsi 0:1 $defaultLoadAddr my-kernel-rango.img;bootm $defaultLoadAddr'
Marvell>> saveenv
Saving Environment to NAND...
U-ENV offset == 0x200000
Erasing Nand...
Writing to Nand... U-ENV offset == 0x200000
U-ENV offset == 0x200000
done
Clone this wiki locally