http://www.openplug.org/plugwiki/index.php/SD_Card_As_Root_File_SystemSD Card As Root File SystemFrom PlugWiki
How to use an SD card as the root file systemThis is the procedure I followed in order to use an SD card, rather than the internal NAND flash, as the root file system. My reasons to do this are in order to have a bigger root FS (I'm using 8GB), in order to avoid hammering the internal flash and wearing it out, and to make it easy to make duplicate plugs, by simply by duplicating the SD card. It also seems to run quite a bit faster, though I haven't measured anything. I did this with a very early sheevaPlug, running u-boot 1.1.4, and the built-in debian/ubuntu. How to test the read and write speed of your SD cardType in the following command to write a file to the SD card that is 1GB big. >dd bs=1024 count=1M if=/dev/zero of=/path/to/sdcard/speedtest.txt if you want a smaller file like 50MB to be written then just change it to >dd bs=1024 count=50K if=/dev/zero of=/path/to/sdcard/speedtest.txt count determines the size of the file you are going to write. After the command is finished it should print out the write speed like this (mine is very slow by the way) >892108+0 records in >892108+0 records out >104857600 bytes (105 MB) copied, 48.0403 s, 2.2 MB/s To test the read speed run this command on the file you just created >dd if=/mnt/sdcard/speedtest.txt of=/dev/null It should give you a print out like this >204800+0 records in >204800+0 records out >104857600 bytes (105 MB) copied, 0.857745 s, 122 MB/s Now you will know if your SD card is fast enough to run a file system from.
Create a bootable file system on the SD cardThe first step is to make a bootable file system on the SD card. Insert the card into the slot of a running plug. Enter the following commands: >fdisk /dev/mmcblk0 press "o" / create a new partition table press "n" / create a new partition press "p" / it's a primary partition press "1" / partition #1 press enter / default first cylinder press enter / default last cylinder press "a" / set the boot flag press "1" / ... for partition #1 press "w" / save changes >mkfs -t ext2 (or ext3, if you wish) /dev/mmcblk0p1 >mkdir /mnt/sdcard >mount /dev/mmcblk0p1 /mnt/sdcard >df You've now got an empty file system mounted on /mnt/sdcard. The df that you just typed should show you something like the following. Note the last line, which is the new SD file system. This one is an 8GB card, and because it's an ext3 journaling file system, a bunch of it is already set aside for directories, journals and such. Filesystem 1K-blocks Used Available Use% Mounted on rootfs 519168 185612 333556 36% / tmpfs 257816 0 257816 0% /lib/init/rw varrun 257816 260 257556 1% /var/run varlock 257816 0 257816 0% /var/lock udev 257816 12 257804 1% /dev tmpfs 257816 0 257816 0% /dev/shm tmpfs 257816 21824 235992 9% /var/cache/apt /dev/mmcblk0p1 7707056 148400 7167156 3% /mnt/sdcard Now copy your existing nand file system onto the sd card. The second cp of /dev is required because the first cp doesn't populate the new /dev directory. The first cp takes 10–15 minutes, so relax for a bit. >cp -ax / /mnt/sdcard # takes 13 minutes >cp -a /dev /mnt/sdcard The SD card should now mirror your internal nand flash, which you can confirm with ls, etc. On my system, df now shows: Filesystem 1K-blocks Used Available Use% Mounted on rootfs 519168 185612 333556 36% / tmpfs 257816 0 257816 0% /lib/init/rw varrun 257816 260 257556 1% /var/run varlock 257816 0 257816 0% /var/lock udev 257816 12 257804 1% /dev tmpfs 257816 0 257816 0% /dev/shm tmpfs 257816 21824 235992 9% /var/cache/apt /dev/mmcblk0p1 7707056 516216 6799340 8% /mnt/sdcard Congrats, your SD card now has a bootable system. The next step is to boot it. Booting from the SD CardYou need to interact with u-boot now. You must do this from a program talking to the usb-serial port, not from an ssh shell (duh). I use minicom, from an ubuntu system. >shutdown -r now When u-boot appears, stop it by typing ENTER a few times, to stop it from booting automatically. Marvell>> printenv bootargs bootargs=console=ttyS0,115200 mtdparts=nand_mtd:0x400...@0x100000(uImage),0x1fb00...@0x500000(rootfs) rw root=/dev/mtdblock1 rw ip=10.4.50.4:10.4.50.5:10.4.50.5:255.255.255.0:DB88FXX81:eth0:none This is the line that you'll need to change. Copy everything after the first "=", and paste it into a text editor. Edit the line to change "root=/dev/mtdblock1" to "root=/dev/mmcblk0p1". Optionally, you can also get rid of the mtdparts stuff. So, the new line (at least on my plug) is console=ttyS0,115200 root=/dev/mmcblk0p1 rw ip=10.4.50.4:10.4.50.5:10.4.50.5:255.255.255.0:DB88FXX81:eth0:none Add, at the beginning of the line "setenv bootargs". The line is now: setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p1 rw ip=10.4.50.4:10.4.50.5:10.4.50.5:255.255.255.0:DB88FXX81:eth0:none Copy it. Paste that line into u-boot as a command, then proceed as follows: Marvell>> setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p1 rw ip=10.4.50.4:10.4.50.5:10.4.50.5:255.255.255.0:DB88FXX81:eth0:none Marvell>> printenv bootargs (if you like, just to confirm that you did it right) Marvell>> boot With any luck, the system will now boot. If you watch the boot text scrolling by, you should see something like this. If you formatted with ext2 instead of ext3, it will be different of course. EXT3 FS on mmcblk0p1, internal journal EXT3-fs: mounted filesystem with ordered data mode. VFS: Mounted root (ext3 filesystem). When the system comes up, log in and type "df". You should see something like this, with a much bigger root fs than you had before. > df Filesystem 1K-blocks Used Available Use% Mounted on rootfs 7707056 516388 6799168 8% / tmpfs 257816 0 257816 0% /lib/init/rw varrun 257816 260 257556 1% /var/run varlock 257816 0 257816 0% /var/lock udev 257816 12 257804 1% /dev tmpfs 257816 0 257816 0% /dev/shm tmpfs 257816 0 257816 0% /var/cache/apt /dev/mtdblock2 521216 202120 319096 39% /mnt/nand Note that on this display, the rootfs is the new SD file system, and is much bigger. The last line is the internal nand flash. You won't see that unless you mount it, as follows. The -r on the mount command mounts the nand read-only. Leave it off, if you like. mkdir /mnt/nand mount -r /dev/mtdblock2 /mnt/nand -t jffs2 # takes 1–2 minutes
Write u-boot environment to flash if desired.The changes you made to the boot environment (setenv) don't persist across a reboot. You'll need to do that every time, unless you explicitly write your changes to internal flash. You do so by inserting "saveenv" after the setenv. Marvell>> setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p1 rw ip=10.4.50.4:10.4.50.5:10.4.50.5:255.255.255.0:DB88FXX81:eth0:none Marvell>> printenv bootargs (if you like, just to confirm that you did it right) Marvell>> saveenv Marvell>> boot I DON'T suggest you do this the first time. Try it first and, if it works, reboot with the saveenv. Once you've done this, it will automatically boot from the SD card after a power-up, reboot, or reset. Changes for Alpha6 BetaThis tutorial doesn't quite work out of the box for the Alpha6 system. Namely, the printenv bootargs will not work, and will say variable not found. Instead you can see: printenv bootargs_root bootargs_root=ubi.mtd=1 root=ubi0:rootfs rootfstype=ubifs it seems to work for me if you change this bootargs_root variable to be the following: setenv bootargs_root root=b301 This seems to work- for more information see the thread at: http://plugcomputer.org/plugforum/index.php?topic=591.0 Ensure that you power cycle (at the wall) to ensure that the configuration works. Should you end up with a message like this: VFS: Cannot open root device "b301" or unknown-block(179,1) Please append a correct "root=" boot option; here are the available partitions: 1f00 4096 mtdblock0 (driver?) 1f01 519168 mtdblock1 (driver?) Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(179,1) [<c00309c0>] (unwind_backtrace+0x0/0xe0) from [<c003db20>] (panic+0x50/0x120) [<c003db20>] (panic+0x50/0x120) from [<c0008ec4>] (mount_block_root+0x1d4/0x214) [<c0008ec4>] (mount_block_root+0x1d4/0x214) from [<c000916c>] (prepare_namespace+0x16c/0x1c4) [<c000916c>] (prepare_namespace+0x16c/0x1c4) from [<c0008734>] (kernel_init+0xc0/0xec) [<c0008734>] (kernel_init+0xc0/0xec) from [<c0040b18>] (do_exit+0x0/0x6ac) Then setting the following may work around the problem: setenv bootcmd 'mmcinit; setenv bootargs $(bootargs_console) $(mtdpartitions) $(bootargs_root); nand read.e 0x00800000 0x00100000 0x00400000; bootm 0x00800000' MysteryIf you just type "printenv" into u-boot, you'll see lots of environment variables, including: bootargs_root=root=/dev/mtdblock2 ro Changing this seems to have no effect. I'm not sure what it's there for, but if anybody gets any weird results this might be worth investigating.
Where Credit is DueAs I tried to get this working, I returned frequently to plugforum (http://plugcomputer.org/plugforum/index.php?topic=149.0) where I got a lot of help from karurosu, sethlans, wb6ymh and cbxbiker61. They're smart. |
