Welcome! Log In Create A New Profile

Advanced

U-Boot - Booting process in multiple drives configuration

Posted by bodhi 
U-Boot - Booting process in multiple drives configuration
January 05, 2015 12:24AM
I've released 2 new u-boot envs image (for Kirkwood and Oxnas) that will automate the booting process in a multiple-partition multiple-drive configuration. There is no need to set it up manually if you've installed new u-boot and flashed this default env image.

Kirkwood U-Boot default environment image
Oxnas U-Boot default environment image

The discussion below are kept here for reference purpose. And in case someone has a need to set it up manually.

=======================================================================

Discussion

I'm starting this thread specifically about the booting process so that we can have a home for questions/answer about booting process. This post starts with a summary, and later we can expand the description, as needed.

Summary:

The booting process has 2 phases:

1. Boot loader:

- Power up, bootROM is running, u-boot image is loaded and run.
- u-boot uses the envs to find uImage and uInitrd.
- u-boot loads uImage and uInitrd from partition that has /boot folder, and start kernel. If multiple drives exist, only one drive and partition should have /boot.

2. Kernel

- Kernel starts using bootargs.
- Kernel search for rootfs to mount. This is when root device with label or UUID is used. If none specified, drive letter is used (e.g. /dev/sda1). If multiple drives exist, rootfs label or UUID will pinpoint to the exact rootfs partition.


How to:

A. Scanning for uImage and UInitrd in multi-drive configuration

If the /boot folder is on a partition among multiple drives, a scanning logic is needed to detect that partition. Usually, if a single partition is used to house rootfs, then /boot is on the same partition. However, it could be located in a different partition, which could cause problem for u-boot to find /boot. Therefore, the /boot folder should be on the 1st partition of a drive. Note that this is a convention only, 1st partition requirement is not absolute (u-boot env could be scripted so that a different partition can be used).

A.1. Jeff's u-boot envs to scan up to 4 USB devices looking for uImage in 1st partition

usb_boot=mw 0x800000 0 1; ext2load usb $usb_device 0x800000 /boot/uImage; if ext2load usb $usb_device 0x1100000 /boot/uInitrd; then bootm 0x800000 0x1100000; else bootm 0x800000; fi
usb_bootcmd=run usb_init; run usb_set_bootargs; run usb_boot
usb_device=0:1
usb_init=run usb_scan
usb_root=/dev/sda1
usb_scan=usb_scan_done=0;for scan in $usb_scan_list; do run usb_scan_$scan; if test $usb_scan_done -eq 0 && ext2load usb $usb 0x800000 /boot/uImage 1; then usb_scan_done=1; echo "Found bootable drive on usb $usb"; setenv usb_device $usb; setenv usb_root /dev/$dev; fi; done
usb_scan_1=usb=0:1 dev=sda1
usb_scan_2=usb=1:1 dev=sdb1
usb_scan_3=usb=2:1 dev=sdc1
usb_scan_4=usb=3:1 dev=sdd1
usb_scan_list=1 2 3 4

A.2. New scanning script to scan all types of device looking for uImage in 1st partition :

With the new u-boot 2014.07-tld-2, it is possible to implement a more complex scanning logic for all drives. This might work even with the old u-boot.

Set default values. This could be modied to include any number of disks that are attached during boot, and specify what type of devices are available.
fw_setenv devices 'usb ide mmc'
fw_setenv device '0:1'
fw_setenv disks '0 1 2 3'
fw_setenv bootdev usb

The scanning script. After this is run, device will contain the correct disk number and partition number that a uImage was found. For example, 1:1 indicates that uImage was found in disk 1 and partition 1 (disk 1 was a specific USB, IDE, MMC drive assigment by u-boot). Also bootdev will contain the disk type (one of the devices list).
fw_setenv scan_disk 'scan_done=0; setenv scan_usb "usb start";  setenv scan_ide "ide reset";  setenv scan_mmc "mmc rescan"; for dev in $devices; do if test $scan_done -eq 0; then echo Scan device $dev; run scan_$dev; for disknum in $disks; do if test $scan_done -eq 0; then echo device $dev $disknum:1; if ext2load $dev $disknum:1 0x800000 /boot/uImage 1; then scan_done=1; echo Found bootable drive on $dev $disknum; setenv device $disknum:1; setenv bootdev $dev; fi; fi; done; fi; done'

Use scan disk in bootcmd (xxx should be replaced by whatever the names of your envs are):
fw_setenv bootcmd 'run scan_disk; run set_bootargs_xxx; run bootcmd_xxx, reset'

or specically for u-boot 2014.07-tld-2:
fw_setenv bootcmd 'run bootcmd_uenv; sleep 2; run scan_disk; run set_bootargs_xxx; run bootcmd_xxx, reset'

Note: between the bootcmd_uenv and the scan_disk there should be some idle period: to allow a slowly responding SATA disk to settle down before it can be reset again.


B. Mounting rootfs in multi-drive configuration.

The approach was to tell U-Boot to find the rootfs on the USB drive that was labeled as "rootfs", or whatever you want it to be. The setup for SATA or MMC rootfs is similar.

1. Set the label of the USB drive to "rootfs":

In Linux, set the rootfs label for the drive (assuming the drive is assigned sda1, if it's assigned different drive letter then use it)
tune2fs -L rootfs /dev/sda1

2. set the booting environment variable (note that usb_root variable is part of the bootargs):

Set the usb_root label separately:
fw_setenv usb_root 'LABEL=rootfs'

Or if in your set up, the usb_init env is used to start USB then the usb_init is set to:
fw_setenv usb_init "usb start; setenv usb_root LABEL=rootfs"


...
more TBD

-bodhi
===========================
Wiki
latest Kirkwood kernel builds and rootfs
latest u-boot-kirkwood builds
latest Oxnas kernel builds and rootfs
latest u-boot-oxnas builds
latest MVEBU Armada kernel builds and rootfs
U-Boot & Kernel Booting process
bodhi's u-boot GitHub
bodhi's corner



Edited 16 time(s). Last edit at 10/25/2015 06:21PM by bodhi.
Re: U-Boot - Booting process with partition label in multiple drives configuration
January 05, 2015 07:34PM
Happy New Year to all!

@Bodhi,
Thanks for the new topic which brings more clarity about the booting process. I am using GFN for a number of years. Had some issues but now I thought it's time to go for RAID1 and get mdadm installed in. I am booting from USB memory (dev/sda1) and use two 1TB hdds attached to GFN's two sata ports. For the moment the hdds are NTFS. Reading the forum (Thanks @Don_Charisma!) I understood that RAID1 on debian will not work with NTFS but ext3/4 so partition them accordingly but there is a small surprise.

It seems "get-apt install mdadm" re-built "/boot/initrd.img-3.10.4-kirkwood-tld-1" as the time stamp is "Jan 3 16:04"! and suddenly my GFN is not booting correctly anymore, not with the NTFS hdds connected in at the boot sequence. GFN boots successfully only with the USB memory in and no hdds, so GFN gets an IP address and I can ssh in still.

I would like to give you a trace of what's happening at booting but I have no netconsole uboot environment values setup. It must be somewhere in the forum but I can't find it just now. How I can setup all envs. to try a netconsole values set in uboot environment from the CLI?

What may go wrong after installation of mdadm on a GFN debian wheezy?

Thanks in anticipation of your responses,
Re: U-Boot - Booting process with partition label in multiple drives configuration
January 06, 2015 03:20AM
enki ,

> It seems "get-apt install mdadm" re-built
> "/boot/initrd.img-3.10.4-kirkwood-tld-1" as the
> time stamp is "Jan 3 16:04"! and suddenly my GFN
> is not booting correctly anymore, not with the
> NTFS hdds connected in at the boot sequence. GFN
> boots successfully only with the USB memory in and
> no hdds, so GFN gets an IP address and I can ssh
> in still.
>

The problem is pretty typical. That's why I've been trying to emphasize. With rootfs partition label, you can avoid this problem for sure. Loading uImage and uInitrd on the USB is taken care of by usb_scanning logic mentioned above. The rootfs label will force the kernel to skip the HDD and find it on USB.

> I would like to give you a trace of what's
> happening at booting but I have no netconsole
> uboot environment values setup. It must be
> somewhere in the forum but I can't find it just
> now. How I can setup all envs. to try a netconsole
> values set in uboot environment from the CLI?
>

Jeff's instruction for Netconsole:
http://forum.doozan.com/read.php?3,14

For the 2 commands to set up netconsole:
nc -l -u -p 6666 &
nc -u 192.168.1.100 6666
You can combine them into one:
nc -lup 6666 192.168.1.100 6666

-bodhi
===========================
Wiki
latest Kirkwood kernel builds and rootfs
latest u-boot-kirkwood builds
latest Oxnas kernel builds and rootfs
latest u-boot-oxnas builds
latest MVEBU Armada kernel builds and rootfs
U-Boot & Kernel Booting process
bodhi's u-boot GitHub
bodhi's corner



Edited 1 time(s). Last edit at 01/06/2015 03:38AM by bodhi.
Re: U-Boot - Booting process with partition label in multiple drives configuration
January 06, 2015 08:06AM
Hi Bodhi,

Thanks for fast reply. You said we can have two approaches A (with green color in the code below - scanning logic) or B (with red color in the code below - pinpointing to 'rootfs' label). I have set the env values as described in B. and here is my fw_printenv values, and as we can see I have 'scanning logic' included in ... before setting up usb_root LABEL=rootfs

root@debian:~# fw_printenv
ethact=egiga0
bootdelay=3
baudrate=115200
mainlineLinux=yes
console=ttyS0,115200
led_init=green blinking
led_exit=green off
led_error=orange blinking
mtdparts=mtdparts=orion_nand:1M(u-boot),4M(uImage),32M(rootfs),-(data)
mtdids=nand0=orion_nand
partition=nand0,2
stdin=serial
stdout=serial
stderr=serial
rescue_set_bootargs=setenv bootargs console=$console ubi.mtd=2 root=ubi0:rootfs ro rootfstype=ubifs $mtdparts $rescue_custom_params
pogo_bootcmd=if fsload uboot-original-mtd0.kwb; then go 0x800200; fi
force_rescue=0
force_rescue_bootcmd=if test $force_rescue -eq 1 || ext2load usb 0:1 0x1700000 /rescueme 1 || fatload usb 0:1 0x1700000 /rescueme.txt 1; then run rescue_bootcmd; fi
ubifs_mtd=3
ubifs_set_bootargs=setenv bootargs console=$console ubi.mtd=$ubifs_mtd root=ubi0:rootfs rootfstype=ubifs $mtdparts $ubifs_custom_params
ubifs_bootcmd=run ubifs_set_bootargs; if ubi part data && ubifsmount rootfs && ubifsload 0x800000 /boot/uImage && ubifsload 0x1100000 /boot/uInitrd; then bootm 0x800000 0x1100000; fi
usb_scan=usb_scan_done=0;for scan in $usb_scan_list; do run usb_scan_$scan; if test $usb_scan_done -eq 0 && ext2load usb $usb 0x800000 /boot/uImage 1; then usb_scan_done=1; echo "Found bootable drive on usb $usb"; setenv usb_device $usb; setenv usb_root /dev/$dev; fi; done
usb_scan_list=1 2 3 4
usb_scan_1=usb=0:1 dev=sda1
usb_scan_2=usb=1:1 dev=sdb1
usb_scan_3=usb=2:1 dev=sdc1
usb_scan_4=usb=3:1 dev=sdd1
usb_device=0:1
usb_root=/dev/sda1
usb_rootfstype=ext2
usb_rootdelay=10
usb_set_bootargs=setenv bootargs console=$console root=$usb_root rootdelay=$usb_rootdelay rootfstype=$usb_rootfstype $mtdparts $usb_custom_params
usb_bootcmd=run usb_init; run usb_set_bootargs; run usb_boot
usb_boot=mw 0x800000 0 1; ext2load usb $usb_device 0x800000 /boot/uImage; if ext2load usb $usb_device 0x1100000 /boot/uInitrd; then bootm 0x800000 0x1100000; else bootm 0x800000; fi
bootcmd=usb start; run force_rescue_bootcmd; run ubifs_bootcmd; run usb_bootcmd; usb stop; run rescue_bootcmd; run pogo_bootcmd; reset
ethaddr=00:10:75:26:39:3A
arcNumber=3089
rescue_installed=1
rescue_bootcmd=if test $rescue_installed -eq 1; then run rescue_set_bootargs; nand read.e 0x500000 0x100000 0x400000; bootm 0x500000; else run pogo_bootcmd; fi
setenv=usb_root LABEL=rootfs
usb_init=usb start; setenv usb_root LABEL=rootfs

Is this correct? Does the order of env values matter? Do I need to remove 'scanning logic' env values?

Rgds,
Re: U-Boot - Booting process with partition label in multiple drives configuration
January 06, 2015 12:24PM
enki,

You should use both, if you are booting with multiple drives. The USB scanning is for u-boot to find uImage on USB drive(s), the rootfs label is for the kernel to find rootfs in any drive. They are 2 separate steps.

-bodhi
===========================
Wiki
latest Kirkwood kernel builds and rootfs
latest u-boot-kirkwood builds
latest Oxnas kernel builds and rootfs
latest u-boot-oxnas builds
latest MVEBU Armada kernel builds and rootfs
U-Boot & Kernel Booting process
bodhi's u-boot GitHub
bodhi's corner
Re: U-Boot - Booting process with partition label in multiple drives configuration
January 06, 2015 02:46PM
@Bodhi,

Everything works like magic. Thanks. I feel you should a little bit clearer about the booting process and add whenever you'll have a chance the details in the top post? I think a picture on 'architecture' will help a lot 'one picture can say 1000 words' ;)

Rgds.,
Re: U-Boot - Booting process with partition label in multiple drives configuration
January 07, 2015 12:26AM
Re: U-Boot - Booting process with partition label in multiple drives configuration
January 31, 2015 04:30PM
2. set the booting environment variable (note that usb_root variable is part of the bootargs):
fw_setenv setenv usb_root 'LABEL=rootfs'


Is this command correct?

Should it be? :

fw_setenv usb_root 'LABEL=rootfs'

Also will this work with Pogoplug v2?



Edited 1 time(s). Last edit at 01/31/2015 05:46PM by hachigo.
Re: U-Boot - Booting process with partition label in multiple drives configuration
February 01, 2015 02:19AM
hachigo Wrote:
-------------------------------------------------------
> 2. set the booting environment variable (note that
> usb_root variable is part of the bootargs):
>
> fw_setenv setenv usb_root 'LABEL=rootfs'
>
>
>
> Is this command correct?
>
> Should it be? :
>
>
> fw_setenv usb_root 'LABEL=rootfs'
>
>
> Also will this work with Pogoplug v2?

Thanks! It was typo. Yes it should work with the Pogo V2

-bodhi
===========================
Wiki
latest Kirkwood kernel builds and rootfs
latest u-boot-kirkwood builds
latest Oxnas kernel builds and rootfs
latest u-boot-oxnas builds
latest MVEBU Armada kernel builds and rootfs
U-Boot & Kernel Booting process
bodhi's u-boot GitHub
bodhi's corner
Re: U-Boot - Booting process with partition label in multiple drives configuration
February 07, 2015 08:26PM
Hi Bodhi. I wasn't able to make the booting multiple drives to work with just Bodhi's instructions alone. But after messing with it and pulling out my hair I finally got it to work. I read from archlinux forums that you can use ramdisk to help the pogoplug search for the correct boot USB device. I don't fully understand this but it appears to work.

I will leave how I did it here for others trying to boot multiple drives with Pogoplug E02 (I don't know if these instructions will work for other devices other than PogoPlug E02)



I followed bodhi's instructions with some modifications:

=== PART 1 ===

1. Set the label of the USB drive to "ROOTFS" :

In Linux, set the ROOTFS label for the drive (assuming the drive is assigned sda1, if it's assigned different drive letter then use it)
tune2fs -L ROOTFS /dev/sda1


2. set the booting environment variable (note that usb_root variable is part of the bootargs):

Set the usb_root label separately (I am not sure if you have to set usb_root to "LABEL=ROOTFS", it appears to work with or without it, mine is set to usb_root=/dev/sda1):
fw_setenv usb_root 'LABEL=ROOTFS'


Or if in your set up, the usb_init env is used to start USB then the usb_init is set to (I changed "usb start" to "run usb_scan"):
fw_setenv usb_init "run usb_scan; setenv usb_root LABEL=ROOTFS"

I also added this setting to uboot env, so that my pogo labels my usb_root as LABEL=ROOTFS before it runs usb_init. (I don't really understand this either, but it worked)
fw_setenv usb_bootcmd 'setenv usb_root LABEL=ROOTFS; run usb_init; run usb_set_bootargs; run usb_boot'


=== PART 2 ===

I then followed a guide from here http://archlinuxarm.org/forum/viewtopic.php?f=18&t=5329.

Specifically this:

#create the required initial ramdisk

1. Need to download this package for the commands in the next steps to work.
pacman -Sy uboot-mkimage


2.
mkinitcpio -v -g /boot/kernel.img


3.
mkimage -A arm -O linux -T ramdisk -C gzip -a 0x00000000 -e 0x00000000 -n initramfs -d /boot/kernel.img /boot/uInitrd


I hope this will help those trying to figure out how to boot multiple drives on their Pogoplugs.
This is also my fw_printenv output:

arcNumber=3542
baudrate=115200
bootcmd=usb start; run force_rescue_bootcmd; run ubifs_bootcmd; run usb_bootcmd; usb stop; run rescue_bootcmd; run pogo_bootcmd; reset
bootdelay=4
console=ttyS0,115200
ethact=egiga0
ethaddr=00:11:22:33:44:55
force_rescue_bootcmd=if test $force_rescue -eq 1 || ext2load usb 0:1 0x1700000 /rescueme 1 || fatload usb 0:1 0x1700000 /rescueme.txt 1; then run rescue_bootcmd; fi
if_netconsole=ping $serverip
led_error=orange blinking
led_exit=green off
led_init=green blinking
machid=dd6
mainlineLinux=yes
mtdids=nand0=orion_nand
mtdparts=mtdparts=orion_nand:1M(u-boot),4M(uImage),32M(rootfs),-(data)
partition=nand0,2
pogo_bootcmd=if fsload uboot-original-mtd0.kwb; then go 0x800200; fi
preboot=run if_netconsole start_netconsole
rescue_bootcmd=if test $rescue_installed -eq 1; then run rescue_set_bootargs; nand read.e 0x800000 0x100000 0x400000; bootm 0x800000; else run pogo_bootcmd; fi
rescue_set_bootargs=setenv bootargs console=$console ubi.mtd=2 root=ubi0:rootfs ro rootfstype=ubifs $mtdparts $rescue_custom_params
start_netconsole=setenv ncip $serverip; setenv bootdelay 10; setenv stdin nc; setenv stdout nc; setenv stderr nc; version;
stderr=serial
stdin=serial
stdout=serial
ubifs_bootcmd=run ubifs_set_bootargs; if ubi part data && ubifsmount rootfs && ubifsload 0x800000 /boot/uImage && ubifsload 0x1100000 /boot/uInitrd; then bootm 0x800000 0x1100000; fi
ubifs_mtd=3
ubifs_set_bootargs=setenv bootargs console=$console ubi.mtd=$ubifs_mtd root=ubi0:rootfs rootfstype=ubifs $mtdparts $ubifs_custom_params
usb_boot=mw 0x800000 0 1; ext2load usb $usb_device 0x800000 /boot/uImage; if ext2load usb $usb_device 0x1100000 /boot/uInitrd; then bootm 0x800000 0x1100000; else bootm 0x800000; fi
usb_rootdelay=10
usb_rootfstype=ext3
usb_scan=usb_scan_done=0;for scan in $usb_scan_list; do run usb_scan_$scan; if test $usb_scan_done -eq 0 && ext2load usb $usb 0x800000 /boot/uImage 1; then usb_scan_done=1; echo "Found bootable drive on usb $usb"; setenv usb_device $usb; setenv usb_root /dev/$dev; fi; done
usb_scan_1=usb=0:1 dev=sda1
usb_scan_2=usb=1:1 dev=sdb1
usb_scan_3=usb=2:1 dev=sdc1
usb_scan_4=usb=3:1 dev=sdd1
usb_scan_list=1 2 3 4
usb_set_bootargs=setenv bootargs console=$console root=$usb_root rootdelay=$usb_rootdelay rootfstype=$usb_rootfstype $mtdparts $usb_custom_params
rescue_installed=1
bootcmd_rescue=run set_bootargs_rescue; nand read.e 0x800000 0x100000 0x400000; bootm 0x800000
bootcmd_pogo=run bootcmd_rescue
force_rescue=0
ipaddr=192.168.0.176
serverip=192.168.0.159
usb_device=0:1
usb_root=/dev/sda1
usb_bootcmd=setenv usb_root LABEL=ROOTFS; run usb_init; run usb_set_bootargs; run usb_boot
usb_init=run usb_scan; setenv usb_root LABEL=ROOTFS

Update
Thanks Bodhi for clearing up that you only need to do the steps above for ArchLinux to build uInitrd file for the multiple drive boot to work.



Edited 6 time(s). Last edit at 02/08/2015 10:30AM by hachigo.
Re: U-Boot - Booting process with partition label in multiple drives configuration
February 08, 2015 03:30AM
@hachigo,

To use the label rootfs for booting, you always need to use initrd. It is a standard kernel file for Debian, so there was really no need for me to mention.

For Arch, you need to build initrd yourself, that's why you were struggling with it!

-bodhi
===========================
Wiki
latest Kirkwood kernel builds and rootfs
latest u-boot-kirkwood builds
latest Oxnas kernel builds and rootfs
latest u-boot-oxnas builds
latest MVEBU Armada kernel builds and rootfs
U-Boot & Kernel Booting process
bodhi's u-boot GitHub
bodhi's corner
Re: U-Boot - Booting process in multiple drives configuration
March 15, 2015 03:43PM
I've updated the 1st post to include new scanning script. With the new script, we can scan all types of drives in a multi-drive configuration to find the boot partition.

In the near future, I will post another set of default u-boot envs to simplify the booting envs substantially (generalize all device types in booting using the same approach in this script).

Please see section A.2 for the new script.

-bodhi
===========================
Wiki
latest Kirkwood kernel builds and rootfs
latest u-boot-kirkwood builds
latest Oxnas kernel builds and rootfs
latest u-boot-oxnas builds
latest MVEBU Armada kernel builds and rootfs
U-Boot & Kernel Booting process
bodhi's u-boot GitHub
bodhi's corner
Re: U-Boot - Booting process in multiple drives configuration
March 22, 2015 05:53PM
FYI,

I am seeing a problem with the "ide reset" that seems to occur only on the NSA325 (2 SATAs). The GoFlex Net does not seem to have this problem, though. The second "ide reset" performs on the scan_disk part seems to fail because "ide reset" already done on bootcmd_uenv.
setenv bootcmd 'run bootcmd_uenv; run scan_disk; run set_bootargs_xxx; run bootcmd_xxx, reset'

Also note that explicitly run "ide reset" twice works without problem. Ony when the scan_disk in the above command is executed that I saw the failure. So most likely, the scan_disk does not have problem. Only the 2nd "ide reset" right after the bootcmd_uenv was causing problem.

UPDATE:

Ok. I found the problem. Inserting a sleep period in between seem to solve it:

setenv bootcmd 'run bootcmd_uenv; sleep 2; run scan_disk; run set_bootargs_xxx; run bootcmd_xxx, reset'

So it was the SATA disk that needs sometime to settle down before it can be "ide reset"

-bodhi
===========================
Wiki
latest Kirkwood kernel builds and rootfs
latest u-boot-kirkwood builds
latest Oxnas kernel builds and rootfs
latest u-boot-oxnas builds
latest MVEBU Armada kernel builds and rootfs
U-Boot & Kernel Booting process
bodhi's u-boot GitHub
bodhi's corner



Edited 5 time(s). Last edit at 03/22/2015 07:09PM by bodhi.
Re: U-Boot - Booting process in multiple drives configuration
April 25, 2015 04:49AM
Guys, help me please to boot from SATA (USB works fine)

Here is my env:
mtdparts=mtdparts=orion_nand:1M(u-boot),4M(uImage),32M(rootfs),-(data)
baudrate=115200
bootcmd_sata=run sata_init; run set_bootargs_sata; run sata_boot;
bootcmd_usb=run usb_init; run set_bootargs_usb; run usb_boot;
bootdelay=10
console=ttyS0,115200
device=0:1
ethact=egiga0
if_netconsole=ping $serverip
led_error=orange blinking
led_exit=green off
led_init=green blinking
mainlineLinux=yes
mtdids=nand0=orion_nand
partition=nand0,2
preboot_nc=run if_netconsole start_netconsole
rootdelay=10
rootfstype=ext3
sata_init=ide reset
set_bootargs_sata=setenv bootargs console=$console root=$sata_root rootdelay=$rootdelay rootfstype=$rootfstype $mtdparts
set_bootargs_usb=setenv bootargs console=$console root=$usb_root rootdelay=$rootdelay rootfstype=$rootfstype $mtdparts
start_netconsole=setenv ncip $serverip; setenv bootdelay 10; setenv stdin nc; setenv stdout nc; setenv stderr nc; version;
stderr=serial
stdin=serial
stdout=serial
usb_init=usb start
bootcmd_uenv=run uenv_load; if test $uenv_loaded -eq 1; then run uenv_import; fi
uenv_import=echo importing envs ...; env import -t 0x810000
uenv_load=usb start; mmc rescan; ide reset; setenv uenv_loaded 0; for devtype in usb mmc ide; do for disknum in 0; do run uenv_read_disk; done; done
uenv_read=echo loading envs from $devtype $disknum ...; if load $devtype $disknum:1 0x810000 /boot/uEnv.txt; then setenv uenv_loaded 1; fi
uenv_read_disk=if test $devtype -eq mmc; then if $devtype part; then run uenv_read;  fi; else if $devtype part $disknum; then run uenv_read; fi;  fi
arcNumber=4495
ethaddr=5C:F4:AB:2F:F9:95
ipaddr=192.168.0.3
preboot=run preboot_nc
load_dtb=ext2load usb 0:1 0x1c00000 /boot/dts/kirkwood-nsa325.dtb
load_initrd=ext2load usb 0:1 0x1100000 /boot/uInitrd
load_uimage=ext2load usb 0:1 0x800000 /boot/uImage
usb_boot=run load_dtb; run load_uimage; if run load_initrd; then bootm 0x800000 0x1100000 0x1c00000; else bootm 0x800000 - 0x1c00000; fi
serverip=192.168.0.10
usb_root=LABEL=rootfs
sata_boot=run load_dtb_sata; run load_uimage_sata; if run load_initrd_sata; then bootm 0x800000 0x1100000 0x1c00000; else bootm 0x800000 - 0x1c00000; fi
load_dtb_sata=ext2load ide 0:2 0x1c00000 /boot/dts/kirkwood-nsa325.dtb
load_initrd_sata=ext2load ide 0:2 0x1100000 /boot/uInitrd
load_uimage_sata=ext2load ide 0:2 0x800000 /boot/uImage
bootcmd=run bootcmd_uenv; run bootcmd_usb; run bootcmd_sata; reset
sata_root=LABEL=rootfs

When I have USB and SATA insreted:

root@debian:~# fdisk -l

Disk /dev/sda: 931,5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x0004983a

Device     Boot      Start        End    Sectors   Size Id Type
/dev/sda1               63 1890613247 1890613185 901,5G 83 Linux
/dev/sda2  *    1890613248 1949331455   58718208    28G 83 Linux
/dev/sda3       1949331456 1953523711    4192256     2G 82 Linux swap / Solaris

Partition 2 does not start on physical sector boundary.


Disk /dev/sdb: 14,9 GiB, 15955132416 bytes, 31162368 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00009485

Device     Boot Start      End  Sectors  Size Id Type
/dev/sdb1  *     2048 31162367 31160320 14,9G 83 Linux

I want to load from /dev/sda2.
It looks like it load kernel (because its not reboot system). But uBoot cant find rootfs.
Ive tried to set LABEL and UUID as sata_root variable, no luck.
Unfortunately I dont have UART and netcat, so I cant check where is the problem.
Any Ideas?



Edited 1 time(s). Last edit at 04/25/2015 04:50AM by andsol.
Re: U-Boot - Booting process in multiple drives configuration
April 25, 2015 04:59AM
andsol,

You need to add the setup in section

A.2. New scanning script to scan all types of device looking for uImage in 1st partition.


Rootfs was taken care off by the label. But since you have both the USB ad HDD installed, u-boot must be able to find which disk has the kernel uImage. If there is no "scan" funciton, u-boot will pick the wrong disk

And I would advise against using partition 2 for /boot. If you want to separate /boot from the rootfs, then /boot should be on partition 1, rootfs should be on partition 2. This will make it easier.

And without netconsole or serial console, please do not attempt to change u-boot envs.

-bodhi
===========================
Wiki
latest Kirkwood kernel builds and rootfs
latest u-boot-kirkwood builds
latest Oxnas kernel builds and rootfs
latest u-boot-oxnas builds
latest MVEBU Armada kernel builds and rootfs
U-Boot & Kernel Booting process
bodhi's u-boot GitHub
bodhi's corner



Edited 2 time(s). Last edit at 04/25/2015 05:02AM by bodhi.
Re: U-Boot - Booting process in multiple drives configuration
January 07, 2016 01:56AM
Sticky please. A lot of good info here.
Re: U-Boot - Booting process in multiple drives configuration
January 07, 2016 02:07AM
Re: U-Boot - Booting process in multiple drives configuration
May 11, 2017 11:28AM
The drive enumeration had me tearing my hair out when I upgraded from Jeff's davygravy-2012-02-20.kwb uboot to Bodhi's 2016.05 uboot.

(Google search brings up Jeff's instruction page, and the script there says the davygravy is "current". I guess Jeff & Davy have abandoned it, but it sure would be nice if somebody could update that page and the supplied scripts to get a more current uboot.)

Here's the deal. The drive enumeration in U-boot and the drive enumeration in the Wheezy/Jessie Linux kernel are different and distinct from one another. By coincidence, the 2012 uboot enumeration came out the same way as the kernel's (at least for PinkPogo E02), so you could use disknames like "/dev/sda1" in the uboot disk scan. "usb 0:1" in uboot always was the same as "/dev/sda1" in the kernel, so it could give /dev/sda1 in the kernel cmdline.

But the 2016.05 enumeration comes out different that the kernel's. So the drive "usb 0:1" in uboot could be /dev/sdb1 or /dev/sdc1 or /dev/sda1 to the kernel, totally at random. In fact, the ordering of the usb devices seems to be totally random. If you have several USB drives plugged in, the same drive can come us as usb 0 or usb 1 or usb 2 each time it does usb start/reset.

Hence, the only reliable way for uboot is to give give the kernel the correct rootfs was by LABEL= or UUID=. And the current environment code hardcodes "root=LABEL=rootfs".

But there is a better way. Instead of hardcoding it, take the concept of the old 2012-02 environment and make it a variable: "root=$usb_root" and initialize it as "usb_root=LABEL=rootfs".

Thusly:
fw_setenv set_bootargs 'setenv bootargs console=ttyS0,115200 root=$usb_root rootdelay=10 $mtdparts $custom_params'
fw_setenv usb_root 'LABEL=rootfs'

Now you can customise it via a /boot/uEnv.txt file, just put in a line "usb_root=LABEL=whatever_you_want"

--------------------------------
There is another issue related to the randomness of the order that usb devices are enumerated. The current 2016 environment code load every /boot/uEnv.txt it finds, but imports only the last one it finds. So in a multiple drive situation with different /boot/uEnv.txt files on several drives, it is unpredictable which one will be imported.

I modified the code so that in imports _every_ /boot/uEnv.txt that it finds. It imports it right after it is loaded.
I guess that if you wanted to be very strict, you would only import a /boot/uEnv.txt that is on the same drive as uImage, which is $bootdev.
Re: U-Boot - Booting process in multiple drives configuration
May 11, 2017 11:47AM
rayvt,

Glad you have read and understood my reason for the definition for bootargs root=LABEL=rootfs! So now just follow this convention and you're golden:) There should be One and Only One partition labeled as rootfs. That is not too hard to do, isn't it?

-bodhi
===========================
Wiki
latest Kirkwood kernel builds and rootfs
latest u-boot-kirkwood builds
latest Oxnas kernel builds and rootfs
latest u-boot-oxnas builds
latest MVEBU Armada kernel builds and rootfs
U-Boot & Kernel Booting process
bodhi's u-boot GitHub
bodhi's corner
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: