WRTNode(MT7620) 通过USB启动OpenWRT过程记录(下)

16 篇文章 0 订阅
7 篇文章 0 订阅

现在的核心问题:解决USB rootfs问题。

找到这篇文章:http://macbruins.com/2011/09/01/easy-live-usb-for-x86-openwrt/

里面说到:

Why Booting from USB Fails

A desktop Linux system typically boots up in these steps:

  1. A bootloader, usually Grub, loads Linux kernel and initial rootfs image into memory and starts kernel execution.
  2. From initial rootfs Kernel starts an initialization program, usually “/init”, to set up essential system components, including root file system.
    • If the necessary drivers are not built in the kernel, they are loaded from kernel modules.
    • These modules are included in the initial rootfs because it is custom built for each system (by “dracut” or “mkinitrd” usually).
  3. Finally, the control is transferred to the “real” initialization program on the root file system.

The official x86 OpenWRT distribution differs from  this flow.  It skips the second step.  The OpenWRT kernel itself initializes the root file system and transfer controls to it.  This isn’t a problem when the root file system resides in an ext2 partition of a IDE or SATA hard disk.  The ext2 and ATA drivers are already in the kernel.  The USB drivers however are not, and this turns booting from USB into a Catch-22:  The kernel can’t access the root file system without the USB modules, but the USB modules aren’t available because they are on the root file system.

决定将USB Storage编译进内核。

查阅相关资料后,发现:内核如果要支持USB Storage,必须要先将SCSI支持先打开。

进入kernel_menuconfig,配置好相关信息,编译运行,控制台的信息确实发生了变化,但是很可惜,还是没有能mount到usb

rt3xxx-usbphy ubsphy.3: loaded
ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
rt3xxx-usbphy ubsphy.3: remote usb device wakeup disabled
rt3xxx-usbphy ubsphy.3: UTMI 16bit 30MHz
ohci-platform 101c1000.ohci: Generic Platform OHCI Controller
ohci-platform 101c1000.ohci: new USB bus registered, assigned bus number 1
ohci-platform 101c1000.ohci: irq 26, io mem 0x101c1000
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 1 port detected
usbcore: registered new interface driver usb-storage
usbcore: registered new interface driver ums-alauda
usbcore: registered new interface driver ums-cypress
usbcore: registered new interface driver ums-datafab
usbcore: registered new interface driver ums_eneub6250
usbcore: registered new interface driver ums-freecom
usbcore: registered new interface driver ums-isd200
usbcore: registered new interface driver ums-jumpshot
usbcore: registered new interface driver ums-karma
usbcore: registered new interface driver ums-onetouch
usbcore: registered new interface driver ums-realtek
usbcore: registered new interface driver ums-sddr09
usbcore: registered new interface driver ums-sddr55
usbcore: registered new interface driver ums-usbat
rt2880_wdt 10000120.watchdog: Initialized
usbcore: registered new interface driver ushc
TCP: cubic registered
NET: Registered protocol family 17
8021q: 802.1Q VLAN Support v1.8
Key type dns_resolver registered
VFS: Cannot open root device "sda2" or unknown-block(0,0): error -6

正常的加载日志如下:

...    ...
 0.190000] usbcore: registered new interface driver usbfs
 0.200000] usbcore: registered new interface driver hub
 0.210000] usbcore: registered new device driver usb
...    ...
 0.740000] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
 0.750000] ehci-platform: EHCI generic platform driver
 0.760000] ehci-platform 101c0000.ehci: EHCI Host Controller
 0.770000] ehci-platform 101c0000.ehci: new USB bus registered, assigned bus number 1
 0.790000] ehci-platform 101c0000.ehci: irq 26, io mem 0x101c0000
 0.820000] ehci-platform 101c0000.ehci: USB 2.0 started, EHCI 1.00
 0.830000] hub 1-0:1.0: USB hub found
 0.840000] hub 1-0:1.0: 1 port detected
...    ...
 1.180000] usb 1-1: new high-speed USB device number 2 using ehci-platform
 4.640000] SCSI subsystem initialized
 4.690000] usb-storage 1-1:1.0: USB Mass Storage device detected
 4.700000] scsi0 : usb-storage 1-1:1.0
 4.710000] usbcore: registered new interface driver usb-storage
...    ...
 5.710000] scsi 0:0:0:0: Direct-Access     HP       USB 2.0 Flash    5.00 PQ: 0 ANSI: 2
 5.730000] sd 0:0:0:0: [sda] 2063360 512-byte logical blocks: (1.05 GB/1007 MiB)
 5.740000] sd 0:0:0:0: [sda] Write Protect is off
 5.750000] sd 0:0:0:0: [sda] No Caching mode page found
 5.760000] sd 0:0:0:0: [sda] Assuming drive cache: write through
 5.780000] sd 0:0:0:0: [sda] No Caching mode page found
 5.790000] sd 0:0:0:0: [sda] Assuming drive cache: write through
 5.800000]  sda: sda1 sda2
 5.810000] sd 0:0:0:0: [sda] No Caching mode page found
 5.820000] sd 0:0:0:0: [sda] Assuming drive cache: write through
 5.840000] sd 0:0:0:0: [sda] Attached SCSI removable disk

对照正常的内核日志,发现里面有个细节一直没有注意,正常的日志多出了一条信息:

SCSI subsystem initialized

然后才是注册usb-storage驱动的信息。

此时才开始probe usb storage设备!

并且,正常的日志显示的是EHCI的驱动,而有问题的显示的OHCI驱动!难道……又是USB驱动配置的问题?

取消OHCI的驱动,编译,果然EHCI的驱动加载成功,然而,再一次!又一次!还是!没能在mount之前加载到usb storage。

于是乎,我想到了:会不会是USB storage probe的时间有点慢,没有赶得上mount的脚步?

学学NFS mount的代码,加上一些延迟试试呢:)代码位于init/do_mounts.c

retry:
    for (p = fs_names; *p; p += strlen(p)+1) {
        // manfeel ,debug output
        pr_info("do_mount_root ,name=%s,p=%s\n",name,p);
        int err = do_mount_root(name, p, flags, root_mount_data);
        switch (err) {
            case 0:
                goto out;
            case -EACCES:
                flags |= MS_RDONLY;
                goto retry;
            case -EINVAL:
                continue;
            // manfeel , add to delay mount usb storage
            case -ENXIO : // -6
	    case -ENODEV: // -19
                ssleep(5);
                if(++try < 5)
                    goto retry;
        }

哈哈,控制台终于看到一些有用的东西了!

下面分别是/dev/mtdblock4和/dev/sda2的输出:

[    1.170000] --> name_to_dev_t : /dev/mtdblock4
[    1.170000] do_mount_root ,name=/dev/root,p=ext3
[    1.190000] do_mount_root ,name=/dev/root,p=ext2
[    1.200000] do_mount_root ,name=/dev/root,p=ext4
[    1.210000] do_mount_root ,name=/dev/root,p=squashfs
[    1.230000] VFS: Mounted root (squashfs filesystem) readonly on device 31:4.
[    1.250000] Freeing unused kernel memory: 208K (804bc000 - 804f0000)
[    1.260000] usb 1-1: new high-speed USB device number 2 using ehci-platform
[    1.460000] usb 1-1: New USB device found, idVendor=0204, idProduct=6025
[    1.470000] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    1.490000] usb 1-1: Product: USB 2.0 Flash
[    1.500000] usb 1-1: Manufacturer: HP
[    1.500000] usb 1-1: SerialNumber: 00CCCBB99999
[    1.590000] ------> storage probe <-------- 
[    1.600000] usb-storage 1-1:1.0: USB Mass Storage device detected
[    1.640000] scsi0 : usb-storage 1-1:1.0
[    2.640000]  12 00 00 00 24 00
[    2.650000] scsi 0:0:0:0: Direct-Access     HP       USB 2.0 Flash    5.00 PQ: 0 ANSI: 2
[    2.700000]  00 00 00 00 00 00
[    2.700000]  25 00 00 00 00 00 00 00 00 00
[    2.710000] sd 0:0:0:0: Attached scsi generic sg0 type 0
[    2.730000] sd 0:0:0:0: [sda] 2063360 512-byte logical blocks: (1.05 GB/1007 MiB)
[    2.750000]  1a 00 3f 00 c0 00
[    2.760000] sd 0:0:0:0: [sda] Write Protect is off
[    2.760000]  1a 00 3f 00 c0 00
[    2.780000] sd 0:0:0:0: [sda] No Caching mode page found
[    2.790000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[    2.830000]  00 00 00 00 00 00
[    2.830000]  1e 00 00 00 01 00
[    2.840000]  00 00 00 00 00 00
[    2.870000]  25 00 00 00 00 00 00 00 00 00
[    2.890000]  1a 00 3f 00 c0 00
[    2.920000]  1a 00 3f 00 c0 00
[    2.950000] sd 0:0:0:0: [sda] No Caching mode page found
[    2.960000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[    2.970000]  28 00 00 00 00 00 00 00 08 00
[    3.000000]  sda: sda1 sda2
[    3.000000]  1e 00 00 00 00 00
[    3.030000]  00 00 00 00 00 00
[    3.040000]  00 00 00 00 00 00
[    3.080000]  25 00 00 00 00 00 00 00 00 00
[    3.090000]  1a 00 3f 00 c0 00
[    3.100000]  1a 00 3f 00 c0 00
[    3.120000] sd 0:0:0:0: [sda] No Caching mode page found
[    3.130000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[    3.140000] sd 0:0:0:0: [sda] Attached SCSI removable disk
[    1.170000] --> name_to_dev_t : /dev/sda2
[    1.170000] do_mount_root ,name=/dev/root,p=ext4
[    1.240000] usb 1-1: new high-speed USB device number 2 using ehci-platform
[    1.400000] usb 1-1: New USB device found, idVendor=0204, idProduct=6025
[    1.410000] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    1.420000] usb 1-1: Product: USB 2.0 Flash
[    1.430000] usb 1-1: Manufacturer: HP
[    1.440000] usb 1-1: SerialNumber: 00CCCBB99999
[    1.450000] ------> storage probe <-------- 
[    1.460000] usb-storage 1-1:1.0: USB Mass Storage device detected
[    1.470000] scsi0 : usb-storage 1-1:1.0
[    2.480000]  12 00 00 00 24 00
[    2.480000] scsi 0:0:0:0: Direct-Access     HP       USB 2.0 Flash    5.00 PQ: 0 ANSI: 2
[    2.500000]  00 00 00 00 00 00
[    2.510000] sd 0:0:0:0: Attached scsi generic sg0 type 0
[    2.520000]  25 00 00 00 00 00 00 00 00 00
[    2.530000] sd 0:0:0:0: [sda] 2063360 512-byte logical blocks: (1.05 GB/1007 MiB)
[    2.540000]  1a 00 3f 00 c0 00
[    2.550000] sd 0:0:0:0: [sda] Write Protect is off
[    2.560000]  1a 00 3f 00 c0 00
[    2.570000] sd 0:0:0:0: [sda] No Caching mode page found
[    2.580000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[    2.590000]  00 00 00 00 00 00
[    2.600000]  1e 00 00 00 01 00
[    2.600000]  00 00 00 00 00 00
[    2.610000]  25 00 00 00 00 00 00 00 00 00
[    2.620000]  1a 00 3f 00 c0 00
[    2.630000]  1a 00 3f 00 c0 00
[    2.630000] sd 0:0:0:0: [sda] No Caching mode page found
[    2.640000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[    2.660000]  28 00 00 00 00 00 00 00 08 00
[    2.660000]  sda: sda1 sda2
[    2.670000]  1e 00 00 00 00 00
[    2.680000]  00 00 00 00 00 00
[    2.690000]  00 00 00 00 00 00
[    2.690000]  25 00 00 00 00 00 00 00 00 00
[    2.700000]  1a 00 3f 00 c0 00
[    2.710000]  1a 00 3f 00 c0 00
[    2.710000] sd 0:0:0:0: [sda] No Caching mode page found
[    2.730000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[    2.740000] sd 0:0:0:0: [sda] Attached SCSI removable disk
[    6.190000] do_mount_root ,name=/dev/root,p=ext4
[   11.200000] do_mount_root ,name=/dev/root,p=ext4
[   16.210000] do_mount_root ,name=/dev/root,p=ext4
[   21.220000] do_mount_root ,name=/dev/root,p=ext4
[   26.230000] VFS: Cannot open root device "sda2" or unknown-block(0,0): error -6
[   26.240000] Please append a correct "root=" boot option; here are the available partitions:
[   26.260000] 1f00             192 mtdblock0  (driver?)
[   26.270000] 1f01              64 mtdblock1  (driver?)
[   26.280000] 1f02              64 mtdblock2  (driver?)
[   26.290000] 1f03           16064 mtdblock3  (driver?)
[   26.300000] 1f04           14565 mtdblock4  (driver?)
[   26.310000] 1f05            7104 mtdblock5  (driver?)
[   26.320000] 0800         1031680 sda  driver: sd
[   26.330000]   0801          257008 sda1 f93e1ba1-01
[   26.340000]   0802          771120 sda2 f93e1ba1-02
[   26.350000] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

为何还是不能mount到sda2呢?为什么设备都变成了/dev/root呢?太多的疑问萦绕心中……

静下心来,再次翻看init/do_mounts.c中的代码:

dev_t name_to_dev_t(char *name)
{
    char s[32];
    char *p;
    dev_t res = 0;
    int part;
 
    // manfeel , add debug output
    pr_info("--> name_to_dev_t : %s\n",name);
 
#ifdef CONFIG_BLOCK
    if (strncmp(name, "PARTUUID=", 9) == 0) {
        name += 9;
        res = devt_from_partuuid(name);
        if (!res)
            goto fail;
        goto done;
    }
#endif
 
    if (strncmp(name, "/dev/", 5) != 0) {
        unsigned maj, min;
 
        if (sscanf(name, "%u:%u", &maj, &min) == 2) {
            res = MKDEV(maj, min);
            if (maj != MAJOR(res) || min != MINOR(res))
                goto fail;
        } else {
            res = new_decode_dev(simple_strtoul(name, &p, 16));
            if (*p)
                goto fail;
        }
        goto done;
    }
 
    name += 5;
    res = Root_NFS;
    if (strcmp(name, "nfs") == 0)
        goto done;
    res = Root_RAM0;
    if (strcmp(name, "ram") == 0)
        goto done;
 
    if (strlen(name) > 31)
        goto fail;
    strcpy(s, name);
    for (p = s; *p; p++)
        if (*p == '/')
            *p = '!';
    res = blk_lookup_devt(s, 0);
    if (res)
        goto done;
 
    /*
     * try non-existent, but valid partition, which may only exist
     * after revalidating the disk, like partitioned md devices
     */
    while (p > s && isdigit(p[-1]))
        p--;
    if (p == s || !*p || *p == '0')
        goto fail;
 
    /* try disk name without <part number> */
    part = simple_strtoul(p, NULL, 10);
    *p = '\0';
    res = blk_lookup_devt(s, part);
    if (res)
        goto done;
 
    /* try disk name without p<part number> */
    if (p < s + 2 || !isdigit(p[-2]) || p[-1] != 'p')
        goto fail;
    p[-1] = '\0';
    res = blk_lookup_devt(s, part);
    if (res)
        goto done;
 
fail:
    return 0;
done:
    return res;
}

真是不看不知道,一看又被吓了一跳!

如果root设备使用的是/dev/开头的形式,代码只处理了/dev/nfs和/dev/ram的设备!!!心中千万只草泥马奔腾而过啊!

好在系统给了另外一种设备的表达方式,那就是major:minor数字方式的设备。

马上修改bootargs为:root=8:2 rootfstype=ext4 console=ttyS0,57600

再次启动,成功!我想,这个过程可以载入屎册了,哈哈。

mount似乎还有那么一点点小问题,这个需要后期修正一下了

root@OpenWrt:/etc# mount
rootfs on / type rootfs (rw)
/dev/root on /rom type ext4 (ro,relatime,data=ordered)
proc on /proc type proc (rw,noatime)
sysfs on /sys type sysfs (rw,noatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime)
/dev/mtdblock5 on /overlay type jffs2 (rw,noatime)
overlayfs:/overlay on / type overlayfs (rw,noatime,lowerdir=/,upperdir=/overlay)
tmpfs on /dev type tmpfs (rw,relatime,size=512k,mode=755)
devpts on /dev/pts type devpts (rw,relatime,mode=600)
debugfs on /sys/kernel/debug type debugfs (rw,noatime)
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值