浏览代码

Repacking the beaglebone kernel

Bob Mottram 8 年前
父节点
当前提交
e02268012b
共有 1 个文件被更改,包括 124 次插入101 次删除
  1. 124
    101
      src/freedombone-image-hardware-setup

+ 124
- 101
src/freedombone-image-hardware-setup 查看文件

@@ -38,35 +38,125 @@ enable_serial_console() {
38 38
     echo "T0:12345:respawn:/sbin/getty -L $device 115200 vt100" >> /etc/inittab
39 39
 }
40 40
 
41
-setup_flash_kernel() {
42
-    if [ ! -d /etc/flash-kernel ] ; then
43
-       mkdir /etc/flash-kernel
44
-    fi
45
-    echo -n "$1" > /etc/flash-kernel/machine
41
+beaglebone_setup_boot() {
42
+    bbb_version=$1
46 43
 
47
-    command_line=""
48
-    if [ -n "$2" ] ; then
49
-        command_line="console=$2"
44
+    # Setup uEnv.txt
45
+    if grep -q btrfs /etc/fstab ; then
46
+        fstype=btrfs
47
+    else
48
+        fstype=ext4
50 49
     fi
50
+    if [ ! $bbb_version ]; then
51
+        kernelVersion=$(ls /usr/lib/*/am335x-boneblack.dtb | head -1 | cut -d/ -f4)
52
+    else
53
+        kernelVersion=$(ls /usr/lib/*/am335x-boneblack-${1}.dtb | head -1 | cut -d/ -f4)
54
+    fi
55
+    version=$(echo $kernelVersion | sed 's/linux-image-\(.*\)/\1/')
56
+    initRd=initrd.img-$version
57
+    vmlinuz=vmlinuz-$version
58
+
59
+    bbb_loadaddr='0x82000000'
60
+    bbb_initrd_addr='0x88080000'
61
+    bbb_fdtaddr='0x88000000'
51 62
 
52
-    if [ -n "$command_line" ] ; then
53
-        echo flash-kernel flash-kernel/linux_cmdline string "$command_line" | debconf-set-selections
63
+    # uEnv.txt for Beaglebone
64
+    # based on https://github.com/beagleboard/image-builder/blob/master/target/boot/beagleboard.org.txt
65
+    cat >> /boot/uEnv.txt <<EOF
66
+mmcroot=/dev/mmcblk0p2 ro
67
+mmcrootfstype=$fstype rootwait fixrtc
68
+mmcrootflags=subvol=@
69
+
70
+console=ttyO0,115200n8
71
+
72
+kernel_file=$vmlinuz
73
+initrd_file=$initRd
74
+
75
+loadaddr=$bbb_loadaddr
76
+initrd_addr=$bbb_initrd_addr
77
+fdtaddr=$bbb_fdtaddr
78
+
79
+initrd_high=0xffffffff
80
+fdt_high=0xffffffff
81
+
82
+loadkernel=load mmc \${mmcdev}:\${mmcpart} \${loadaddr} \${kernel_file}
83
+loadinitrd=load mmc \${mmcdev}:\${mmcpart} \${initrd_addr} \${initrd_file}; setenv initrd_size \${filesize}
84
+loadfdt=load mmc \${mmcdev}:\${mmcpart} \${fdtaddr} /dtbs/\${fdtfile}
85
+
86
+loadfiles=run loadkernel; run loadinitrd; run loadfdt
87
+mmcargs=setenv bootargs console=tty0 console=\${console} root=\${mmcroot} rootfstype=\${mmcrootfstype} rootflags=\${mmcrootflags}
88
+
89
+uenvcmd=run loadfiles; run mmcargs; bootz \${loadaddr} \${initrd_addr}:\${initrd_size} \${fdtaddr}
90
+EOF
91
+
92
+    mkdir -p /boot/dtbs
93
+    cp /usr/lib/linux-image-*-armmp/* /boot/dtbs
94
+}
95
+
96
+beaglebone_flash() {
97
+    # allow flash-kernel to work without valid /proc contents
98
+    # ** this doesn't *really* work, since there are too many checks
99
+    #    that fail in an emulated environment!  We'll have to do it by
100
+    #    hand below anyway...
101
+    export FK_MACHINE="TI AM335x BeagleBone"
102
+    apt-get install -y flash-kernel
103
+}
104
+
105
+beaglebone_repack_kernel() {
106
+    bbb_version=$1
107
+    # process installed kernel to create uImage, uInitrd, dtb
108
+    # using flash-kernel would be a good approach, except it fails in the
109
+    # cross build environment due to too many environment checks...
110
+    #FK_MACHINE="TI AM335x BeagleBone" flash-kernel
111
+    #  so, let's do it manually...
112
+
113
+    # flash-kernel's hook-functions provided to mkinitramfs have the
114
+    # unfortunate side-effect of creating /conf/param.conf in the initrd
115
+    # when run from our emulated chroot environment, which means our root=
116
+    # on the kernel command line is completely ignored!  repack the initrd
117
+    # to remove this evil...
118
+
119
+    echo "info: repacking beaglebone kernel and initrd"
120
+
121
+    bbb_dtb='am335x-boneblack'
122
+    if [ $bbb_version ]; then
123
+        bbb_dtb="am335x-boneblack-${bbb_version}"
54 124
     fi
55 125
 
56
-    apt-get -yq install flash-kernel
126
+    kernelVersion=$(ls /usr/lib/*/${bbb_dtb}.dtb | head -1 | cut -d/ -f4)
127
+    version=$(echo $kernelVersion | sed 's/linux-image-\(.*\)/\1/')
128
+    initRd=initrd.img-$version
129
+    vmlinuz=vmlinuz-$version
130
+
131
+    mkdir /tmp/initrd-repack
132
+
133
+    (cd /tmp/initrd-repack ; \
134
+     zcat /boot/$initRd | cpio -i ; \
135
+     rm -f conf/param.conf ; \
136
+     find . | cpio --quiet -o -H newc | \
137
+         gzip -9 > /boot/$initRd )
138
+
139
+    rm -rf /tmp/initrd-repack
140
+
141
+    (cd /boot ; \
142
+     cp /usr/lib/$kernelVersion/${bbb_dtb}.dtb dtb ; \
143
+     cat $vmlinuz dtb >> temp-kernel ; \
144
+     mkimage -A arm -O linux -T kernel -n "Debian kernel ${version}" \
145
+             -C none -a 0x82000000 -e 0x82000000 -d temp-kernel uImage ; \
146
+     rm -f temp-kernel ; \
147
+     mkimage -A arm -O linux -T ramdisk -C gzip -a 0x88080000 -e 0x88080000 \
148
+             -n "Debian ramdisk ${version}" \
149
+             -d $initRd uInitrd )
57 150
 }
58 151
 
59
-a20_env() {
152
+a20_setup_boot() {
60 153
     dtb="$1"
61 154
 
62 155
     # Setup boot.cmd
63
-    fstype=ext4
64
-    if grep -q btrfs /etc/fstab; then
156
+    if grep -q btrfs /etc/fstab ; then
65 157
         fstype=btrfs
66
-    fi
67
-
68
-    if [ -n "$command_line" ] ; then
69
-        echo flash-kernel flash-kernel/linux_cmdline string "$command_line" | debconf-set-selections
158
+    else
159
+        fstype=ext4
70 160
     fi
71 161
     kernelVersion=$(ls /usr/lib/*/$dtb | head -1 | cut -d/ -f4)
72 162
     version=$(echo $kernelVersion | sed 's/linux-image-\(.*\)/\1/')
@@ -116,104 +206,37 @@ EOF
116 206
     echo "rtc_sunxi" >> /etc/initramfs-tools/modules
117 207
 }
118 208
 
119
-beaglebone_env() {
120
-    bbb_version=$1
121
-
122
-    # Setup uEnv.txt
123
-    fstype=ext4
124
-    if grep -q btrfs /etc/fstab ; then
125
-        fstype=btrfs
126
-    fi
127
-    if [ ! $bbb_version ]; then
128
-        kernelVersion=$(ls /usr/lib/*/am335x-boneblack.dtb | head -1 | cut -d/ -f4)
129
-    else
130
-        kernelVersion=$(ls /usr/lib/*/am335x-boneblack-${1}.dtb | head -1 | cut -d/ -f4)
131
-    fi
132
-    version=$(echo $kernelVersion | sed 's/linux-image-\(.*\)/\1/')
133
-    initRd=initrd.img-$version
134
-    vmlinuz=vmlinuz-$version
135
-
136
-    #bbb_loadaddr='0x80200000'
137
-    #bbb_initrd_addr='0x81000000'
138
-    #bbb_fdtaddr='0x80F80000'
139
-    #if [[ "$bbb_version" == "wireless" ]]; then
140
-        bbb_loadaddr='0x82000000'
141
-        bbb_initrd_addr='0x88080000'
142
-        bbb_fdtaddr='0x88000000'
143
-    #fi
144
-
145
-    # uEnv.txt for Beaglebone
146
-    # based on https://github.com/beagleboard/image-builder/blob/master/target/boot/beagleboard.org.txt
147
-    cat >> /boot/uEnv.txt <<EOF
148
-mmcroot=/dev/mmcblk0p2 ro
149
-mmcrootfstype=$fstype rootwait fixrtc
150
-mmcrootflags=subvol=@
151
-
152
-console=ttyO0,115200n8
153
-
154
-kernel_file=$vmlinuz
155
-initrd_file=$initRd
156
-
157
-loadaddr=$bbb_loadaddr
158
-initrd_addr=$bbb_initrd_addr
159
-fdtaddr=$bbb_fdtaddr
160
-
161
-initrd_high=0xffffffff
162
-fdt_high=0xffffffff
163
-
164
-loadkernel=load mmc \${mmcdev}:\${mmcpart} \${loadaddr} \${kernel_file}
165
-loadinitrd=load mmc \${mmcdev}:\${mmcpart} \${initrd_addr} \${initrd_file}; setenv intrd_size \${filesize}
166
-loadfdt=load mmc \${mmcdev}:\${mmcpart} \${fdtaddr} /dtbs/\${fdtfile}
167
-
168
-loadfiles=run loadkernel; run loadinitrd; run loadfdt
169
-mmcargs=setenv bootargs console=tty0 console=\${console} root=\${mmcroot} rootfstype=\${mmcrootfstype} rootflags=\${mmcrootflags}
170
-
171
-uenvcmd=run loadfiles; run mmcargs; bootz \${loadaddr} \${initrd_addr}:\${initrd_size} \${fdtaddr}
172
-EOF
173
-
174
-    mkdir -p /boot/dtbs
175
-    cp /usr/lib/linux-image-*-armmp/* /boot/dtbs
176
-}
177
-
178 209
 case "$MACHINE" in
179 210
     beaglebone)
180
-        beaglebone_env
211
+        beaglebone_setup_boot
212
+        beaglebone_flash
213
+        beaglebone_repack_kernel
181 214
         enable_serial_console ttyO0
182
-        setup_flash_kernel 'TI AM335x BeagleBone Black' 'ttyO0'
183 215
         ;;
184 216
     beaglebonewifi)
185
-        beaglebone_env
217
+        beaglebone_setup_boot wireless
218
+        beaglebone_flash
219
+        beaglebone_repack_kernel wireless
186 220
         enable_serial_console ttyO0
187
-        setup_flash_kernel 'TI AM335x BeagleBone Black Wireless' 'ttyO0'
188 221
         ;;
189 222
     cubietruck)
190
-        a20_env sun7i-a20-cubietruck.dtb
191
-        enable_serial_console ttyO0
192
-        setup_flash_kernel 'Cubietech Cubietruck'
223
+        a20_setup_boot sun7i-a20-cubietruck.dtb
224
+        enable_serial_console ttyS0
193 225
         ;;
194 226
     a20-olinuxino-lime)
195
-        a20_env sun7i-a20-olinuxino-lime.dtb
196
-        enable_serial_console ttyO0
197
-        setup_flash_kernel 'Olimex A20-OLinuXino-LIME'
227
+        a20_setup_boot sun7i-a20-olinuxino-lime.dtb
228
+        enable_serial_console ttyS0
198 229
         ;;
199 230
     a20-olinuxino-lime2)
200
-        a20_env sun7i-a20-olinuxino-lime2.dtb
201
-        enable_serial_console ttyO0
202
-        setup_flash_kernel 'Olimex A20-OLinuXino-LIME2'
231
+        a20_setup_boot sun7i-a20-olinuxino-lime2.dtb
232
+        enable_serial_console ttyS0
203 233
         ;;
204 234
     a20-olinuxino-micro)
205
-        a20_env sun7i-a20-olinuxino-micro.dtb
206
-        enable_serial_console ttyO0
207
-        setup_flash_kernel 'Olimex A20-Olinuxino Micro'
235
+        a20_setup_boot sun7i-a20-olinuxino-micro.dtb
236
+        enable_serial_console ttyS0
208 237
         ;;
209 238
     cubieboard2)
210
-        a20_env sun7i-a20-cubieboard2.dtb
211
-        enable_serial_console ttyO0
212
-        setup_flash_kernel 'Cubietech Cubieboard2'
213
-        ;;
214
-    pcduino3)
215
-        a20_env sun7i-a20-pcduino3.dtb
216
-        enable_serial_console ttyO0
217
-        setup_flash_kernel 'LinkSprite pcDuino3'
239
+        a20_setup_boot sun7i-a20-cubieboard2.dtb
240
+        enable_serial_console ttyS0
218 241
         ;;
219 242
 esac