slitaz-arm view spi @ rev 34
dropbear need zlib and use ext4 on sdcard since it's not as module in official RPi Kernel
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Thu Mar 06 22:58:40 2014 +0100 (2014-03-06) |
parents | 1066913cc1c4 |
children | bae84a6b7455 |
line source
1 #!/bin/sh
2 #
3 # Spi - SliTaz Raspberry Pi Tool
4 #
5 # Copyright (C) 2012-2014 SliTaz ARM - BSD License
6 # Author: Christophe Lincoln <pankso@slitaz.org>
7 #
8 . /lib/libtaz.sh
10 # Paths
11 [ "$work" ] || work="$(pwd)"
12 distro="$work/distro"
13 data="$work/rpi/data"
14 boot="$work/rpi/boot"
15 rootfs="$work/rpi/rootfs"
16 kernel="$data/linux"
17 firmware="$data/firmware"
18 tools="$data/tools"
20 # URLs
21 rpi_url="http://mirror.slitaz.org/arm/rpi/"
22 fw_url="https://github.com/raspberrypi/firmware/raw/master/boot/"
23 tools_url="https://raw.github.com/raspberrypi/tools/master/mkimage/"
24 lkgit_url="git://github.com/raspberrypi/linux.git"
26 # Lists
27 fwlist="bootcode.bin fixup.dat start.elf"
28 toolslist="imagetool-uncompressed.py args-uncompressed.txt \
29 boot-uncompressed.txt" #first32k.bin
31 #
32 # Functions
33 #
35 usage() {
36 cat << EOT
38 $(boldify "Usage:") $(basename $0) [command] [--option]
40 $(boldify "Commands:")
41 info Display paths and distro info
42 install Install SliTaz RPi to sdcard
43 gen Generate a new SliTaz RPi distro
44 cooklinux Build the Raspberry Pi Linux kernel
45 get-fw Download or update RPi Firmware
46 get-tools Download or update RPi Tools (mkimage)
47 get-prebuilt Get a prebuilt SliTaz ARM toolchain
48 oclock Display overclocking information
50 $(boldify "Options:")
51 --up Update firmware, tools or kernel
52 --clean Clean the distro tree (Sat can also be used)
53 --turbo Force the RPi to run at the highest arm_freq
54 --oclock= Set the RPi overclocking mode
56 EOT
57 }
59 error() {
60 echo "[ $(colorize 31 'ERROR') ] $@"
61 }
63 header() {
64 newline
65 boldify "$@"
66 separator
67 }
69 # Get RPi firmware
70 get_fw() {
71 mkdir -p $firmware
72 for fw in $fwlist
73 do
74 [ "$up" ] && rm -f $firmware/$fw
75 if [ ! -f "$firmware/$fw" ]; then
76 echo -n "Fetching: $fw"
77 wget -q --no-check-certificate ${fw_url}${fw} \
78 -O $firmware/${fw}; status
79 fi
80 done
81 }
83 # Get RPi tools
84 get_tools() {
85 mkdir -p $data
86 for t in $toolslist
87 do
88 [ "$up" ] && rm -f $data/$t
89 if [ ! -f "$data/$t" ]; then
90 echo -n "Fetching: $t"
91 wget -q --no-check-certificate ${tools_url}${t} \
92 -O $data/${t}; status
93 fi
94 done
95 }
97 # Configure overclocking
98 set_oclock() {
99 case "$oclock" in
100 none)
101 arm_freq=700
102 core_freq=250
103 sdram_freq=400
104 over_voltage=0 ;;
105 modest)
106 arm_freq=800
107 core_freq=300
108 sdram_freq=400
109 over_voltage=0 ;;
110 medium)
111 arm_freq=900
112 core_freq=333
113 sdram_freq=450
114 over_voltage=2 ;;
115 hight)
116 arm_freq=950
117 core_freq=450
118 sdram_freq=450
119 over_voltage=6 ;;
120 turbo)
121 arm_freq=1000
122 core_freq=500
123 sdram_freq=500
124 over_voltage=6 ;;
125 esac
126 cat >> ${boot}/config.txt << EOT
127 arm_freq=$arm_freq
128 core_freq=$core_freq
129 sdram_freq=$sdram_freq
130 over_voltage=$over_voltage
131 EOT
132 }
134 #
135 # Commands
136 #
138 case "$1" in
139 info)
140 header "SliTaz Raspberry Pi info"
141 echo "Firmware : $fwlist"
142 echo "RPi path : $work/rpi"
143 colorize 36 "/boot/cmdline.txt:"
144 cat ${boot}/cmdline.txt
145 colorize 36 "/boot/config.txt:"
146 cat ${boot}/config.txt
147 separator && newline ;;
149 install)
150 rpiboot="/media/rpi/boot"
151 rpiroot="/media/rpi/rootfs"
152 header "SliTaz Raspberry Pi install"
153 if [ ! "$dev" ]; then
154 echo "Missing: --dev= cmdline option" && exit 1
155 fi
157 # Store sdcard partition(s) list
158 fdisk -l /dev/${dev} | grep "^/dev/$dev" | awk '{print $1}' \
159 > ${data}/sdcard.part
160 partnb=$(cat ${data}/sdcard.part | wc -l)
161 if [ "$partnb" != 3 ]; then
162 error "SliTaz RPi needs 3 partitions on the sdcard"
163 newline && exit 1
164 fi
166 # Mount sdcard
167 if mount | grep -q "^/dev/$dev[1-3]"; then
168 debug "Unmounting: /dev/$dev"
169 umount /dev/${dev}1 2>/dev/null || exit 1
170 umount /dev/${dev}3 2>/dev/null || exit 1
171 fi
172 echo -n "Mounting: /dev/$dev partitions"
173 mkdir -p ${rpiboot} ${rpiroot}
174 mount /dev/${dev}1 ${rpiboot}
175 mount /dev/${dev}3 ${rpiroot}; status
176 echo -n "Installing: boot files"
177 cp -rf ${boot}/* ${rpiboot}; status
178 echo -n "Installing: rootfs files"
179 cp -a ${rootfs}/* ${rpiroot}; status
181 # Unmount
182 echo -n "Unmounting: RPi sdcard"
183 umount ${rpiboot} || exit 1
184 umount ${rpiroot} || exit 1
185 status
187 # Boot flag
188 #echo -n "Setting boot flag on: /dev/${dev}1"
189 #fdisk /dev/${dev} >/dev/null << EOF
190 #a
191 #1
192 #w
193 #EOF
194 #status
195 rm -f ${data}/sdcard.part
196 separator && newline ;;
198 ls-dev)
199 newline
200 fdisk -l | grep "^Disk /dev/sd*"
201 newline ;;
203 gen)
204 # Separate boot files since the Raspberry Pi boots off a FAT32 /boot
205 # partition on the sdcard.
206 : ${flavor=rpi}
207 : ${oclock=none}
208 check_root
209 rm -rf ${rootfs} ${boot}
210 mkdir -p ${boot}
212 # Use the rootfs generated by sat
213 if [ ! -x "/usr/bin/sat" ]; then
214 error "Sat is not installed" && exit 1
215 fi
216 [ "$clean" ] && sat clean --work="$work"
217 if [ ! -d "$distro/rootfs/etc" ]; then
218 sat gen --work="$work" --flavor="$flavor" \
219 --kmap --spk --noinit --rpi
220 fi
221 header "SliTaz Raspberry Pi distro"
222 dsize="$(du -sh ${distro}/rootfs | awk '{print $1}')"
223 echo -n "Copying the rootfs: $dsize"
224 cp -a ${distro}/rootfs ${rootfs}; status
226 # Boot firmware
227 echo -n "Installing: firmware files"
228 get_fw
229 cp $firmware/* ${boot}; status
231 # /boot/cmdline.txt
232 echo -n "Creating: /boot/cmdline.txt"
233 echo 'root=/dev/mmcblk0p3 rootwait quiet' >> \
234 ${boot}/cmdline.txt; status
236 # /boot/config.txt
237 echo -n "Creating: /boot/config.txt"
238 echo 'kernel=kernel.img' > ${boot}/config.txt
239 set_oclock; status
240 if [ "$turbo" ]; then
241 echo "force_turbo=1" >> ${boot}/config.txt
242 fi
244 # /etc/fstab
245 echo -n "Creating: /etc/fstab"
246 cat > ${rootfs}/etc/fstab << EOT
247 # /etc/fstab: Slitaz ARM static filesystems.
248 #
249 proc /proc proc defaults 0 0
250 sysfs /sys sysfs defaults 0 0
251 /dev/mmcblk0p1 /boot auto noauto,noatime 1 2
252 /dev/mmcblk0p2 none swap sw 0 0
253 /dev/mmcblk0p3 / ext4 noatime 0 1
254 EOT
255 status
257 # Kernel
258 kvers=$(ls $data/linux-*/fs/lib/modules)
259 kpkg="$rootfs/var/lib/tazpkg/installed/linux"
260 if [ -d "$data/linux-$kvers/fs" ]; then
261 echo -n "Installing: Linux Kernel $kvers"
262 rm -rf ${rootfs}/lib/modules
263 cp -rf ${data}/linux-${kvers}/fs/lib/* ${rootfs}/lib
264 cp -f ${data}/linux-${kvers}/fs/boot/* ${boot}
265 mkdir -p ${kpkg}
266 cd ${data}/linux-${kvers}
267 cp -f files.list md5sum receipt ${kpkg}
268 status
269 else
270 echo "RPi Kernel: not used"
271 fi
272 mkdir -p ${rootfs}/boot
274 # RPi VC libraries
275 if [ "$vc" ]; then
276 echo "Installing: VC libraries"
277 echo "TODO"
278 fi
280 separator
281 echo -n "Boot: $(du -sh $boot | awk '{print $1}') "
282 echo "- Rootfs: $(du -sh $rootfs | awk '{print $1}')"
283 newline ;;
285 linux)
286 # Native SliTaz Toolchain and cross toolchain must be installed
287 check_root
288 #: ${arch=armv6hf}
289 : ${arch=arm}
290 install="$data/linux-install"
291 if [ ! -d "/cross/$arch" ]; then
292 error "Missing cross toolchain in: /cross/$arch"
293 exit 1
294 fi
295 # Kernel source
296 [ -d "$kernel" ] || git clone --depth 1 ${lkgit_url}
298 if [ ! -d "$install" ]; then
299 cd ${kernel}
300 export PATH=$PATH:/cross/${arch}/tools/bin
301 export HOST_SYSTEM=${arch}-slitaz-linux-gnueabi
302 make ARCH=arm bcmrpi_defconfig &&
303 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- zImage &&
304 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- modules &&
305 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- \
306 INSTALL_MOD_PATH=${install} modules_install || exit 1
307 mkdir -p ${install}/boot
308 cp -a arch/arm/boot/zImage ${install}/boot
309 fi
311 # Pack
312 fs="$data/linux-$kvers/fs"
313 kvers=$(ls ${install}/lib/modules)
314 newline
315 echo "Kernel version: $kvers"
316 if [ -d "$install" ]; then
317 rm -rf ${data}/linux-${kvers}
318 mkdir -p ${data}/linux-${kvers}
319 cp -a ${install} ${fs}
320 rm ${fs}/lib/modules/build ${fs}/lib/modules/source
321 fi
322 get_tools
323 echo "Compressing: zImage to kernel.img"
324 cd ${data}
325 python imagetool-uncompressed.py ${fs}/boot/zImage
326 mv kernel.img ${fs}/boot && rm ${fs}/boot/zImage
327 echo "Creating package: receipt"
328 cat > linux-$kvers/receipt << EOT
329 # SliTaz package receipt
331 PACKAGE="linux"
332 VERSION="$kvers"
333 SHORT_DESC="SliTaz Linux Kernel for the Raspberry Pi."
334 WEB_SITE="http://www.kernel.org"
336 EOT
337 tazpkg pack linux-$kvers ;;
339 get-fw)
340 get_fw ;;
342 get-tools)
343 get_tools ;;
345 get-linux)
346 # Precook RPi kernel
347 rm -f ${data}/linux-version.txt
348 if busybox wget -q -s ${rpi_url}/last-linux.txt; then
349 echo -n "Fetching latest Kernel string..."
350 wget -q ${rpi_url}/last-linux.txt \
351 -O ${data}/linux-version.txt || exit 1
352 status
353 else
354 echo "Mirror is unreachable" && exit 1
355 fi
356 kvers=$(cat $data/linux-version.txt)
357 [ "$up" ] && rm -rf ${data}/linux-${kvers}*
358 echo "Kernel version: $kvers"
359 # Download
360 if [ ! -f "$data/linux-$kvers.tazpkg" ]; then
361 echo -n "Fetching latest Linux package..."
362 wget -q ${rpi_url}/linux-${kvers}.tazpkg \
363 -O ${data}/linux-${kvers}.tazpkg; status
364 fi
365 # Extract
366 if [ ! -d "$data/linux-$kvers" ]; then
367 cd ${data} && tazpkg extract linux-${kvers}.tazpkg
368 fi ;;
370 get-prebuilt)
371 # --> in cross ??
372 : ${arch=arm}
373 name="slitaz-$arch-toolchain"
374 vers="20140304"
375 tarball="$name-$vers.tar.bz2"
376 url="http://mirror.slitaz.org/packages/cross/"
377 mkdir -p /cross
378 cd /cross
379 if [ ! -f "$tarball" ]; then
380 if busybox wget -qs ${url%/}/${tarball}; then
381 busybox wget ${url%/}/${tarball}
382 else
383 echo "Toolchain URL is unreachable" && exit 1
384 fi
385 fi
386 if [ ! -d "${name}-${vers}" ]; then
387 echo "Extracting: $tarball"
388 tar xjf ${tarball}
389 fi
390 echo "Copying: ${name}-${vers}/${arch}"
391 mkdir -p ${arch}
392 cp -a ${name}-${vers}/${arch}/* ${arch}
393 echo "Tools path: /cross/${arch}/tools/bin" ;;
395 oclock)
396 cat << EOT
398 $(boldify "Overclocking modes:")
399 none 700MHz ARM 250MHz core 400MHz SDRAM 0 overvolt
400 modest 800MHz ARM 300MHz core 400MHz SDRAM 0 overvolt
401 medium 900MHz ARM 333MHz core 450MHz SDRAM 2 overvolt
402 high 950MHz ARM 450MHz core 450MHz SDRAM 6 overvolt
403 turbo 1000MHz ARM 500MHz core 500MHz SDRAM 6 overvolt
405 EOT
406 if [ -f "$boot/config.txt" ]; then
407 boldify "Current config.txt:"
408 cat ${boot}/config.txt
409 newline
410 fi ;;
411 *) usage ;;
412 esac
413 exit 0