Welcome! Log In Create A New Profile

Advanced

What is the purpose of "usb_scan" ?

Posted by ElectronikHeart 
What is the purpose of "usb_scan" ?
June 17, 2012 07:25AM
I'm learning how uBoot works and I don't know what to think of the usb_scan environment variable.

Is it for finding the good drive to boot from ? Can we modify it to detect if a s-ata drive is on /dev/sda and then using /dev/sdb1 automatically instead of /dev/sda1 ?

If the goflex net is detecting usb as /dev/sda even if a s-ata drive is inserted, can we use the proper Goflex Home arcNumber (3338) to trigger the workaround only for goflex home ?

I find this s-ata hijacking the boot process very annoying, I'm trying to find a way to make this transparent (instead of the "label the boot partition and edit the uboot variables method")

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
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
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_init=run usb_scan
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=02:50:43:66:fb:a8
rescue_installed=1
arcNumber=3338
serverip=192.168.0.8
ipaddr=192.168.0.5
if_netconsole=ping $serverip
start_netconsole=setenv ncip $serverip; setenv bootdelay 10; setenv stdin nc; setenv stdout nc; setenv stderr nc; version;
preboot=run if_netconsole start_netconsole
Re: What is the purpose of "usb_scan" ?
June 17, 2012 08:18AM
Quote

Is it for finding the good drive to boot from ?

Yes. The name is self explanatory really (Thanks Jeff!).

Quote

Can we modify it to detect if a s-ata drive is on /dev/sda and then using /dev/sdb1 automatically instead of /dev/sda1 ?

No. usb_scan scans the USB (thus the name) ports and boots from the drive at usb_device, and the partition set in usb_root. It does not do anything to allow booting from SATA drives.

Uboot utilizes "subsystems" for devices types to enable modularity and portability. If you want to boot from SATA then you need to use the IDE subystem (bad naming, it is the SATA subsystem for most devices). Your existing Uboot environment does not initialize the IDE subystem or scan for any SATA drives. So you cannot currently boot from them. That is your problem. You need a Uboot environment that implements SATA.

Do you have the latest uboot installed from here? Davy's latest GoFlex Uboot probably has a default environment that implements SATA boot. I personally do not know if it does, because I overwrote the default with my config. But I would assume that it does.

You need something like this in your environment:

ide_init=ide reset
ide_rootfstype=ext2
bootcmd_ide=run ide_init; run ide_load_uimage; run set_bootargs_ide; run ide_boot;
ide_root=/dev/sda5
bootcmd=run bootcmd_ide; run bootcmd_usb; usb stop; run bootcmd_pogo; reset
ide_device=0:3
ide_load_uimage=mw 0x800000 0 1;ext2load ide 0:3 0x800000 /uImage
ide_boot=if ext2load ide 0:3 0x1100000 /uInitrd; then bootm 0x800000 0x1100000;else bootm 0x800000;fi;

That is from my environment and initializes the IDE subystem and if it detects a SATA drive it boots from it first.

Update your Uboot. Then search the forum for the above environment variables. That will solve your problem.
Re: What is the purpose of "usb_scan" ?
June 17, 2012 08:45AM
No the current default environment (I have done a reset of my environment this morning to check if it implements a sata boot feature)

I think p-ata and s-ata are two different kind of IDE. (I'm possibly wrong here)

My problem is not booting from s-ata, it's booting from USB when I have a s-ata drive plugged in. When a s-ata drive is plugged in the goflex Home, it take the place of sda, and usb_scan is setting the usb drive to sda, because it is the first usb drive. But sda is not the first usb drive sda, it's sdb.

the problem is there:

usb_scan_1=usb=0:1 dev=sda1

As you can see, the environment is making the assumption that usb 0:1 is automatically sda. On the goflex home it's only true when you don't have any s-ata drive plugged in.

So the idea is to replace the usb_scan with a "boot_device_scan" that can handle theses kinds of problems.

PS: I think we should learn from all theses weird things the goflex net and home can do and make a new default environment. And make the uboot flashing script ask something to setup a netconsole when you install uboot. Some over good features can be, sata booting and proper devices scan. (I don't even know how it's possible)



Edited 1 time(s). Last edit at 06/17/2012 08:54AM by ElectronikHeart.
Re: What is the purpose of "usb_scan" ?
June 17, 2012 01:23PM
Quote

I think p-ata and s-ata are two different kind of IDE. (I'm possibly wrong here)
You are correct. That is why it is called the IDE subystem. But our devices only have SATA.

Quote

My problem is not booting from s-ata, it's booting from USB when I have a s-ata drive plugged in. When a s-ata drive is plugged in the goflex Home, it take the place of sda, and usb_scan is setting the usb drive to sda, because it is the first usb drive. But sda is not the first usb drive sda, it's sdb.

usb_scan can't boot from sata. The IDE subystem is responsible for that. In the environment code you posted above there are no IDE subystem commands like the one I posted above. If the device will boot from SATA then you are not posting the complete environment. That is a problem. It is not easy to comment on an issue without seeing the full environment.

It is certainly possible, however, that the SATA drive is getting detected even without any IDE settings in the environment, and that is causing the drives to get renumbered. But the drive renumbering is not the problem. It is your config.

Jeff's Uboot environment does a good job at detecting drives and then booting from them. But it is not magic. It can't compensate for things like drive renumbering. It just boots from the first available drive. If you don't want to boot from that drive using Jeff's code then it should not have a kernel on it. As an example my systems kernel is at /dev/sda3, and the rootfs is sda5. That type of setup has to be set manually in the Uboot environment. You should be thankful that Jeff implemented the HUSH shell with all the fancy drive detection code. No other Uboot setups have that. You can only get that here. The code can certainly be improved. But there is only a small space for the environment, and if it is changed a new Uboot would need to be released by Jeff or somebody. If you want to assist in that everyone here would be thankful. But first you need to completely understand what Jeff's environment code does.

To get your setup working correctly we really need to know exactly what Uboot version you are using and what the FULL environment contains. But to get your setup to boot you only need to set the device manually. You are correct that usb_scan is the problem. It automatically sets the device to boot from the first detected USB drive. If you have a SATA drive installed it should have tried to boot from that first. To get your device to boot do what everyone else does. Just disable usb_scan by deleting "run usb_init;" from usb_bootcmd and change usb_device and usb_root to the correct drive and partition. As an added bonus the device will boot much faster then since it does not need to scan all USB devices.
Hope that helps.
Re: What is the purpose of "usb_scan" ?
October 31, 2012 09:53AM
Quote

gnexus Wrote:
-------------------------------------------------------
you need to completely understand what Jeff's environment code does.

It sounds like a good idea. May be someone can help? For example, do we need the 1-to-4 USB scan for GoFlex Home or GoFlex Net that have a single USB port, or this portion of the code is redundant? Will it work for external USB Hubs?

What's the right way in Uboot to test USB and/or SATA drive presence, whether bootable or not?

I wonder if Help command shows working commands list? I.e., usb2ls usb 0:1 / doesn't seem to work

Any manual for Hush Shell implemented by Jeff? I mean correct syntax for its commands. Any suggestions for a quick Uboot manual relevant to ARM?



Edited 9 time(s). Last edit at 10/31/2012 02:13PM by sambul14.
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: