arm-ramdisk.html.md (3436B)
1 Setting up a sunxi board with a ramdisk and ATA over Ethernet rootfs boot 2 ========================================================================= 3 4 This setup has been tested with the Olimex A20 Lime2 and microsd cards. 5 6 7 Creating and filling the ramdisk 8 -------------------------------- 9 10 First let's create our initial ramdisk that will be 8M big. Format it, 11 and mount it: 12 13 # dd if=/dev/zero of=initrd.img bs=1k count=8192 14 # mke2fs -vm0 initrd.img 8192 15 # tune2fs -c 0 initrd.img 16 17 # mkdir mnt 18 # mount -o loop initrd.img ./mnt 19 20 After we've done this, let's setup the fs hierarchy we'll be using: 21 22 # cd mnt 23 # mkdir -p bin dev/etherd etc mnt/root proc sys tmp usr 24 # chmod 1777 tmp 25 # touch etc/fstab 26 27 We also need /dev nodes inside it. 28 29 # cp -a /dev/console /dev/null /dev/random /dev/tty /dev/urandom dev/ 30 31 And let's add add a statically linkedbusybox: 32 33 # cp /bin/busybox bin 34 # busybox --install -s ./bin 35 36 Add more files as needed. To boot AoE, we need aoetools. Find them here: 37 [https://github.com/OpenAoE/aoetools](https://github.com/OpenAoE/aoetools) 38 39 40 Finally, we need an init script that will set up the things needed and 41 switch root once mounted. The following scripts implies an available AoE 42 mount at **/dev/etherd/e0.1p1**. It also implies having a directory 43 called **old_root** in that rootfs. 44 45 #!/bin/busybox sh 46 47 rescue_shell() { 48 echo "$@" 49 echo " * dropping to a shell" 50 exec /bin/sh 51 } 52 53 ifconfig eth0 up || rescue_shell 54 55 mount -t sysfs none /sys 56 mount -t proc none /proc 57 echo 0 > /proc/sys/kernel/printk 58 sleep 2 59 60 echo " * discovering AoE block devices" 61 /usr/sbin/aoe-discover 62 sleep 3 63 /usr/sbin/aoe-discover 64 sleep 3 65 66 echo " * mounting AoE root" 67 mount -t ext4 -o ro /dev/etherd/e0.1p1 /mnt/root || rescue_shell 68 69 echo " * mounting to /mnt/root" 70 mount -t devtmpfs none /mnt/root/dev 71 mount -t sysfs none /mnt/root/sys 72 mount -t proc none /mnt/root/proc 73 74 echo 1 > /proc/sys/kernel/printk 75 76 echo " * pivoting root" 77 cd /mnt/root 78 pivot_root . old_root || rescue_shell "Failed pivoting" 79 umount /old_root/proc /old_root/sys /old_root/dev 80 81 echo " * exec-ing init" 82 exec /sbin/init 3 || rescue_shell "init failed" 83 84 85 Kernel config 86 ------------- 87 88 To use this setup, our kernel needs the following: 89 90 # 91 # General setup 92 # 93 ... 94 CONFIG_BLK_DEV_INITRD=y 95 CONFIG_INITRAMFS_SOURCE="" 96 ... 97 98 # 99 # UBI - Unsorted block images 100 # 101 ... 102 CONFIG_BLK_DEV_RAM=y 103 CONFIG_BLK_DEV_RAM_COUNT=1 104 CONFIG_BLK_DEV_RAM_SIZE=8192 105 CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024 106 ... 107 108 109 U-Boot 110 ------ 111 112 For u-boot, we have to make an uInitrd out of the initrd.img we've 113 previously created. This can be achieved with the following: 114 115 # mkimage -A arm -T ramdisk -C none -n uInitrd -d /path/to/initrd.img /path/to/uInitrd 116 117 Copy this to the microsd card or push it in FEL mode. 118 119 If we're doing the microsd card boot, we can use a boot.scr like the 120 following: 121 122 setenv bootargs console=ttyS0,115200 root=/dev/ram0 ro rootwait 123 load mmc 0 0x43000000 ${fdtfile} 124 load mmc 0 0x41000000 zImage 125 load mmc 0 0x50000000 uInitrd 126 #setenv initrd_high 0xffffffff 127 bootz 0x41000000 0x50000000 0x43000000 128 129 Convert to boot.scr: 130 131 # mkimage -A arm -T script -C none -d boot.cmd boot.scr 132 133 134 Resources 135 --------- 136 137 * [http://processors.wiki.ti.com/index.php/Initrd](http://processors.wiki.ti.com/index.php/Initrd) 138 * [http://linux-sunxi.org/Initial_Ramdisk](http://linux-sunxi.org/Initial_Ramdisk)