For quite a long time I was trying to get the USB flash disk based environment
for development of drivers and applications for Asus WL500gP v2.
My main goal was to avoid reflashing after each recompilation of the kernel.
I also wanted to have the root filesystem on a media big enough to
put e.g. full Python and other development tools on it.
Just yesterday I've managed to obtain the working environment, and today I have
polished it sufficiently to give you quite short description.
In my approach the system works with the kernel loaded from the USB drive, so when
you change the kernel, you only have to change the contents of the USB drive.
The flashed in system is just the "kexec based bootloader" (I think,
that it could be nice to add possibility to block booting from the USB drive,
e.g. when one of buttons is pressed. Then you could modify the contents
of the USB drive from the "bootloader", as it is also fully functional OpenWRT system.
I'll try to add this functionality later).
Of course this result was possible only due to hard work of all OpenWRT developers,
so many thanks to them all for bringing the trunk version to the state,
where the above was possible.
1. Preparation of the flashed in, kexec enabled system
I start from the fresh OpenWRT downloaded with the below commands:
svn co svn://svn.openwrt.org/openwrt/trunk/
cd trunk
./scripts/feeds update
make V=99 defconfig
make V=99 package/symlinks
Then I execute the "make menuconfig" and select the following options:
a) In "Kernel modules/Filesystems" I select: nfs, e2fs, e3fs, vfat
and code-pages: cp437, iso8859-1, utf-8
b) In "Kernel modules/Device drivers/USB" i select: usb-core, usb-storage, usb-ohci, usb2
In the "Utilities" I select "kexec-tools" package.
All the above selections have to be done as "*", not as "M".
As the type of the image I select "squashfs".
Then I run the "make kernel_menuconfig" and in "Kernel type" I select "kexec system call".
Finally I run "make V=99 world".
After compilation I have entered the
trunk/build_dir/linux-brcm47xx/linux-2.6.32.9/arch/mips/kernel
directory and modified the file machine_kexec.c
the 55th line I have changed from: kexec_start_address = image->start;
into: kexec_start_address = (unsigned long) phys_to_virt(image->start);
Then I have ran "make V=99" in the trunk directory and get the ready to flash image
in trunk/bin...
After flashing and rebooting i waited until the jffs2 system is populated
after first reboot. (In the serial console the following messages appeared:
jffs2_scan_eraseblock(): End of filesystem marker found at 0x10000
jffs2_build_filesystem(): unlocking the mtd device... done.
jffs2_build_filesystem(): erasing all blocks after the end marker... done.
switching to jffs2
mini_fo: using base directory: /
mini_fo: using storage directory: /jffs
- config restore - )
Then I had to modify the system, so it can automatically boot the files from the USB disk.
I have added that functionality to the /etc/rc.local script.
After modification it looks as follows
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
mkdir /new
until [ -e /dev/sda1 ]; do
sleep 2
done
mount /dev/sda1 /new
if [ -f /new/linux.elf ]; then
kexec -l /new/linux.elf
kexec -e
fi
exit 0
2. Preparation of the USB bootable system
I start from the fresh OpenWRT downloaded with the below commands:
svn co svn://svn.openwrt.org/openwrt/trunk/
cd trunk
./scripts/feeds update
make V=99 defconfig
make V=99 package/symlinks
Then I execute the "make menuconfig" and select the following options:
a) As the image type I select "ramfs"
b) In "Kernel modules/Filesystems" I select: e2fs, e3fs
c) In "Kernel modules/Device drivers/USB" i select: usb-core, usb-storage, usb-ohci, usb2
Then I run the "make V=99 world" command.
After compilation is finished I modify the trunk/package/base-files/files/etc/preinit, adding
the line:
'rootfs=/dev/sda1'
right after line '. /etc/diag.sh'
You can also modify the file trunk/target/linux/generic-2.6/base-files/init
line 47: from: 'mount $rootfs /mnt' to: 'mount $rootfs /mnt -o noatime',
to make sure, that the access time of the read files is not stored on the USB drive
(however the standard "relatime" option also reasonably limits wear of the USB flash disk).
After that I run "make V=99"
Finally I get file trunk/bin/brcm47xx/openwrt-brcm47xx-vmlinux.elf , which I copy
as linux.elf to the root directory of the USB disk
and directory trunk/build_dir/target-mipsel_uClibc-0.9.30.1/root-brcm47xx, which I copy
(with "cp -a") to the USB disk.
3. Results
The environment prepared in that way works quite reliably, however sometimes
I get strange problems. One of these is presented below.
When the kernel is booted from USB, sometimes right after unused kernel memory is freed,
the error occurs:
Freeing unused kernel memory: 2596k freed
Instruction bus error, epc == 80004d2c, ra == 80000018
Oops[#1]:
Cpu 0
$ 0 : 00000000 10008800 80000000 00000000
$ 4 : 7f8549ec 80cc5e00 0000002d 80cb7e50
$ 8 : 40646461 646f6d2f 2f656c75 67616964
$12 : 54434100 0000004d 0000004d 3d4e4f49
$16 : 0000004d 0000004d 00000a00 0000004d
$20 : 00000000 80cb7d60 80cc4cc0 80cb7e50
$24 : 0000000d 80cc5e00
$28 : 80cb6000 80cb7cb0 7f8549ec 80000018
Hi : 00000000
Lo : 9abbd100
epc : 80004d2c 0x80004d2c
Not tainted
ra : 80000018 0x80000018
Status: 10008803 KERNEL EXL IE
Cause : 00804018
PrId : 00029029 (Broadcom BCM3302)
Modules linked in: diag(+)
Process hotplug2 (pid: 157, threadinfo=80cb6000, task=81c5a9d8, tls=00000000)
Stack : 00000a00 8019d094 00000000 80cb7d60 81804560 00418280 80cc4cc0 80c9d400
00000a00 80cb7e58 00000000 80cb7d60 81804560 0000004d 7f8549ec 801c2dd8
00000000 80001444 007fffff 00000000 ffffffff 80063b34 000200da 000200da
00000000 fffffffe 001fe154 80cb87f8 80c9f000 80cb7da0 80cb7e74 00000a00
7f8549ec 00000000 7f8548b8 00410000 00418280 801903d0 fffffffc 00410000
...
Call Trace:[<8019d094>] 0x8019d094
[<801c2dd8>] 0x801c2dd8
[<80001444>] 0x80001444
[<80063b34>] 0x80063b34
[<801903d0>] 0x801903d0
[<8007906c>] 0x8007906c
[<8001aca8>] 0x8001aca8
[<80079104>] 0x80079104
[<8003d814>] 0x8003d814
[<8007b45c>] 0x8007b45c
[<80190674>] 0x80190674
[<800325a0>] 0x800325a0
[<80032668>] 0x80032668
[<8000aefc>] 0x8000aefc
[<801906ec>] 0x801906ec
[<80003230>] 0x80003230
Code: 24c6ffe0 8cac0010 8caf0014 <ac880000> ac890004 8ca80018 8ca9001c 24a
Disabling lock debugging due to kernel taint
diag: Detected 'ASUS WL-500g Premium V2'
Instruction bus error, epc == 80005050, ra == 80000018
Oops[#2]:
Cpu 0
$ 0 : 00000000 10008800 fffffff2 00000000
$ 4 : 0047e5ef 00000000 00000a11 0047e5ef
$ 8 : ffffffff 800050fc 00000a11 00000001
$12 : 80cacc60 80279e24 80524bc8 00010000
$16 : 0047e5ef 80cabf00 00000000 0047fb50
$20 : 80c91980 80cffe48 0047e5ef 0047fb50
$24 : 80516880 00000001
$28 : 80cfe000 80cffc28 00000008 80000018
Hi : 00000000
Lo : a4bf4b00
epc : 80005050 0x80005050
Tainted: G D
ra : 80000018 0x80000018
Status: 10008803 KERNEL EXL IE
Cause : 00804018
PrId : 00029029 (Broadcom BCM3302)
Modules linked in: diag
Process hotplug.failsaf (pid: 166, threadinfo=80cfe000, task=80cc69f8, tls=0000)
Stack : 80cabf00 800d4cf4 00000000 00000000 80c91980 00000080 00006012 00000000
00000000 00000001 ffffffff 81d938c0 00000000 00000000 00000000 00000000
80cc69f8 0047e5ef 0047e000 0046daa0 00400000 80cc69f8 80c91880 80ca4280
00000001 00000000 00400000 81c30da0 00000000 00002021 8027aac0 fffffff8
80c91980 8027a750 00000002 00010000 80516880 00000000 fffffff8 8009898c
...
Call Trace:[<800d4cf4>] 0x800d4cf4
[<8009898c>] 0x8009898c
[<800d3fa4>] 0x800d3fa4
[<8007b720>] 0x8007b720
[<8007b720>] 0x8007b720
[<80098484>] 0x80098484
[<80098678>] 0x80098678
[<8009898c>] 0x8009898c
[<80099e2c>] 0x80099e2c
[<8009d3fc>] 0x8009d3fc
[<80012c30>] 0x80012c30
[<80003230>] 0x80003230
[<80044a6c>] 0x80044a6c
[<80037f44>] 0x80037f44
[<80012858>] 0x80012858
[<8000f7b4>] 0x8000f7b4
[<80037e28>] 0x80037e28
[<8000f7a4>] 0x8000f7a4
Code: 30880003 11000004 2508fffc <b8850000> 00882023 00c83021 34c9003f 392
Instruction bus error, epc == 2ab5e080, ra == 80000018
Instruction bus error, epc == 80027a8c, ra == 80000018
Oops[#3]:
Cpu 0
$ 0 : 00000000 10008801 00000000 80000000
$ 4 : 7fb752a0 00000000 00000000 0000000a
$ 8 : 00000000 00000000 00000000 00000000
$12 : 81c18d60 80281b14 81c13968 00000001
$16 : 000000a5 80cc6570 00000000 00000000
$20 : 81c13938 81c15ee8 20000000 81c15f00
$24 : 00000008 800189a4
$28 : 81c14000 81c15e60 fffffff6 80000018
Hi : 00000000
Lo : ae85bc00
epc : 80027a8c 0x80027a8c
Tainted: G D
ra : 80000018 0x80000018
Status: 10008803 KERNEL EXL IE
Cause : 00804018
PrId : 00029029 (Broadcom BCM3302)
Modules linked in: diag
Process init (pid: 1, threadinfo=81c14000, task=81c13938, tls=00000000)
Stack : 80cacc60 8000aefc 80cacde0 80017bbc 00000000 00000000 80cc6570 00000000
81c13a48 81c15ee8 81c13938 ffffffff 20000000 81c15f00 fffffff6 80028410
00000012 00000000 00000000 80cc6570 00000000 00000000 7fb752a0 00000000
00000002 00000000 0000002d 00480008 ffffffff 8002860c 00000000 000081ed
00000001 00000000 00000003 00000004 00000000 00000000 7fb752a0 00000000
...
Call Trace:[<8000aefc>] 0x8000aefc
[<80017bbc>] 0x80017bbc
[<80028410>] 0x80028410
[<8002860c>] 0x8002860c
[<80026424>] 0x80026424
[<80003230>] 0x80003230
Code: 00431024 1440021c 00000000 <ac870000> 14a0003f 8ea4000c 1080003e 248
Kernel panic - not syncing: Attempted to kill init!
Anyway, the presented environment works sufficiently reliable to be useful.
I'll appreciate any corrections and improvements
(Last edited by wzab on 14 Mar 2010, 18:55)