Welcome! Log In Create A New Profile

Advanced

Conditional boot with DLINK DNS325 original U-boot

Posted by davidedg 
Conditional boot with DLINK DNS325 original U-boot
January 26, 2014 12:33PM
Hello.

I am trying to do conditional booting (USB -> HDD -> NAND) using *only* original U-boot.
I tried this:

setenv uImageAddr 0xa00000;
setenv uInitramfsAddr '0xf00000'
# from USB
setenv usb_root 'LABEL=rootusb'
setenv usb_opts 'usb-storage.delay_use=0 rootdelay=10'
setenv usb_load_uImage 'ext2load usb 0:1 ${uImageAddr} /boot/uImage'
setenv usb_load_uInitramfs 'ext2load usb 0:1 ${uInitramfsAddr} /boot/uInitramfs'
setenv usb_setbootargs 'setenv bootargs console=ttyS0,115200 root=${usb_root} ${usb_opts} ${mtdparts} ${bootargs_end} ${bootopts}'
setenv boot_from_usb 'usb reset; run usb_load_uImage; run usb_load_uInitramfs; run usb_setbootargs; bootm ${uImageAddr} ${uInitramfsAddr}'
# from HDD
setenv hdd_root 'LABEL=roothdd'
setenv hdd_opts ''
setenv hdd_load_uImage 'ext2load ide 0:1 ${uImageAddr} /uImage'
setenv hdd_load_uInitramfs 'ext2load ide 0:1 ${uInitramfsAddr} /uInitramfs'
setenv hdd_setbootargs 'setenv bootargs console=ttyS0,115200 root=${hdd_root} ${hdd_opts} ${mtdparts} ${bootargs_end} ${bootopts}'
setenv boot_from_hdd 'ide reset; run hdd_load_uImage; run hdd_load_uInitramfs; run hdd_setbootargs; bootm ${uImageAddr} ${uInitramfsAddr}'
# NAND
setenv nand_setbootargs 'setenv bootargs root=/dev/ram console=ttyS0,115200 :::DB88FXX81:egiga0:none'
setenv boot_from_nand 'run nand_setbootargs; nand read.e 0xa00000 0x100000 0x300000;nand read.e 0xf00000 0x600000 0x300000;bootm 0xa00000 0xf00000'

# BOOTCMD
setenv bootcmd 'run boot_from_usb; run boot_from_hdd; run boot_from_nand'

Single commands (boot_from_usb or boot_from_hdd or boot_from_nand) just work.
Problem is that if it cannot find the 1st device (eg USB), it does not go to the following, instead it is trying some sort of "builtin" bootcmd, which I cannot understand where is coming from.


This is serial output, without 1st device (usb) attached
it gives bad partition (expected), but then it reads from nand ... why? shouldn't it try to execute next command?

Hit any key to stop autoboot:  0
(Re)start USB...
USB:   scanning bus for devices... 1 USB Device(s) found
       scanning bus for storage devices... 0 Storage Device(s) found
** Bad partition 1 **
** Bad partition 1 **
## Booting image at 00a00000 ...
Bad Magic Number

NAND read: device 0 offset 0x7100800, size 0x500000
load addr ....  =a00000

 5242880 bytes read: OK
## Booting image at 00a00000 ...
   Image Name:   Linux-2.6.22.18
   Created:      2011-05-25   7:23:15 UTC
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    2214860 Bytes =  2.1 MB
   Load Address: 00008000
   Entry Point:  00008000
   Verifying Checksum ... OK
OK
## Loading Ramdisk Image at 00d00000 ...
   Image Name:   Ramdisk
   Created:      2011-07-11   5:47:12 UTC
   Image Type:   ARM Linux RAMDisk Image (gzip compressed)
   Data Size:    1566183 Bytes =  1.5 MB
   Load Address: 00e00000
   Entry Point:  00e00000
   Verifying Checksum ... OK


Any help is appreciated ^_^
Thx!

--
DavideDG
My NAS userspace configs
My Zyxel NSA325 mod
My D-Link DNS325 mod
My Lacie NS2MAX mod
Re: Conditional boot with DLINK DNS325 original U-boot
January 26, 2014 02:25PM
The reason is the bootm was executed at the end of this command:
setenv boot_from_usb 'usb reset; run usb_load_uImage; run usb_load_uInitramfs; run usb_setbootargs; bootm ${uImageAddr} ${uInitramfsAddr}'

So take out the bootm and commonize it, something like this:
setenv bootm_cmd 'bootm ${uImageAddr} ${uInitramfsAddr}'
setenv bootcmd 'run boot_from_usb; run boot_from_hdd; run boot_from_nand; run bootm_cmd'

It probably wont work as exactly above:) but the idea is to commonize the bootm!

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)



Edited 1 time(s). Last edit at 01/26/2014 02:49PM by bodhi.
Re: Conditional boot with DLINK DNS325 original U-boot
January 26, 2014 04:39PM
But I need to change bootargs, too, depending on which device I'm booting from.
But being unable to use "if" or "test" commands, if I just execute them in order, the last one will win
Since nand is always available, I may reverse order:
load nand uImage; load hdd uImage; load usb uImage

So if present, the last one will overwrite the previous one.
But how can I do with bootargs? I may end up running from NAND, but using USB bootargs.

Or am I missing something?
Ty!

--
DavideDG
My NAS userspace configs
My Zyxel NSA325 mod
My D-Link DNS325 mod
My Lacie NS2MAX mod



Edited 1 time(s). Last edit at 01/26/2014 04:59PM by davidedg.
Re: Conditional boot with DLINK DNS325 original U-boot
January 27, 2014 03:54AM
davidedg,

> But how can I do with bootargs? I may end up
> running from NAND, but using USB bootargs.
>
> Or am I missing something?
> Ty!

No, you did not miss any thing. It's a limitation of stock uBoot where you can't use "if else" syntax (contrary to the newer uBoot that I've built recently for other plugs).

With stock uBoot, the envs for booting USB-HDD is easier to code, but the problem with booting using 2 or 3 different rootfs still remains. Unless you have a very simple boot args, it's quite difficult to factor out the common part. The only way that I can think of that will possibly allow booting USB-HDD-NAND is to use rootfs label (therefore the rootfs should be in NAND as ubifs/jffs2).

Now the good news :) the DNS325 is supported in the latest uBoot, so I might be able to built it. But you should check if the DNS325 has UART booting, see davygrady thread: http://forum.doozan.com/read.php?3,7852,7852. If it does, then updating DNS525 uBoot is doable with minimal risk.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Conditional boot with DLINK DNS325 original U-boot
January 27, 2014 05:16AM
Maybe you could work around the bootarg problem by using kernels that you compiled yourself. This way you could tell the kernel to use hardcoded bootargs instead of the ones provided by uBoot. This can be done pretty easily in the kernel configuration.
Re: Conditional boot with DLINK DNS325 original U-boot
January 27, 2014 11:55AM
bodhi Wrote:
-------------------------------------------------------
> Now the good news :) the DNS325 is supported in
> the latest uBoot, so I might be able to built it.

bodhi, thank you for taking time to check.
Actually I already rebuilt U-boot 2014.01 and there multiboot works flawlessly (with if statements ofc)
I wanted to try to use just stock u-boot mainly as an exercise, and to find a "less-risky" way of modifying the nas (again, as an exercise, because i'm on 5th rewrite of u-boot region... God bless kwartboot :D).

ingmar_k Wrote:
-------------------------------------------------------
> Maybe you could work around the bootarg problem by
> using kernels that you compiled yourself. This way
> you could tell the kernel to use hardcoded
> bootargs instead of the ones provided by uBoot.
> This can be done pretty easily in the kernel
> configuration.

Ouch! This actually could work :D
Gonna try it and report.
Thank you!

--
DavideDG
My NAS userspace configs
My Zyxel NSA325 mod
My D-Link DNS325 mod
My Lacie NS2MAX mod
Re: Conditional boot with DLINK DNS325 original U-boot
January 27, 2014 03:05PM
Ingmar,

it worked like a charm!

Kernel Config:
CONFIG_CMDLINE="console=ttyS0,115200 root=LABEL=rootusb usb-storage.delay_use=0 rootdelay=10 mtdparts=nand_mtd:0xc0000@0(uboot)ro,0x7f00000@0x100000(root) :::DB88FXX81:egiga0:none"
CONFIG_CMDLINE_FORCE=y

U-Boot Env:
setenv uImageAddr '0xa00000'
setenv uInitramfsAddr '0xf00000'

setenv prepboot_from_nand 'echo LOADING FROM NAND; nand read.e $uImageAddr 0x100000 0x300000;nand read.e $uInitramfsAddr 0x600000 0x300000'
setenv prepboot_from_hdd 'echo TRY OVERRIDE FROM HDD; ide reset; run hdd_load_uImage; run hdd_load_uInitramfs'
setenv prepboot_from_usb 'echo TRY OVERRIDE FROM USB; usb reset; run usb_load_uImage; run usb_load_uInitramfs'

setenv bootcmd 'run prepboot_from_nand; run prepboot_from_hdd; run prepboot_from_usb; bootm ${uImageAddr} ${uInitramfsAddr}'


Thank you all!

--
DavideDG
My NAS userspace configs
My Zyxel NSA325 mod
My D-Link DNS325 mod
My Lacie NS2MAX mod
Re: Conditional boot with DLINK DNS325 original U-boot
January 27, 2014 03:06PM
Great to hear that my little theory worked out like expected.
Re: Conditional boot with DLINK DNS325 original U-boot
January 28, 2014 11:39AM
ingmar_k Wrote:
-------------------------------------------------------
> Great to hear that my little theory worked out
> like expected.

Nice solution!

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
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: