slitaz-arm view spi @ rev 35

Improve Raspberry Pi support
author Christophe Lincoln <pankso@slitaz.org>
date Fri Mar 07 01:31:58 2014 +0100 (2014-03-07)
parents eeb23d633529
children 5445fd3856ad
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 rpi="$work/rpi"
14 data="$rpi/distro/data"
15 boot="$rpi/distro/boot"
16 rootfs="$rpi/distro/rootfs"
17 rpi_git="$rpi/git"
18 kernel="$rpi_git/linux"
19 firmware="$rpi_git/firmware"
20 tools="$rpi_git/tools"
22 # URLs
23 rpi_mirror="http://mirror.slitaz.org/arm/rpi/"
24 fw_url="https://github.com/raspberrypi/firmware/raw/master/boot/"
25 tools_url="https://raw.github.com/raspberrypi/tools/master/mkimage/"
26 rpi_git_url="git://github.com/raspberrypi/"
28 # Lists
29 fwlist="bootcode.bin fixup.dat start.elf"
30 toolslist="imagetool-uncompressed.py args-uncompressed.txt \
31 boot-uncompressed.txt"
33 #
34 # Functions
35 #
37 usage() {
38 cat << EOT
40 $(boldify "Usage:") $(basename $0) [command] [--option]
42 $(boldify "Commands:")
43 info Display paths and distro info
44 install Install SliTaz RPi to sdcard
45 gen Generate a new SliTaz RPi distro
46 cook-linux Build the Raspberry Pi Linux kernel
47 get-linux Get a the SliTaz RPi linux package
48 get-fw Download or update RPi Firmware
49 clone-fw Clone the RPi Firmware repository
50 get-tools Download or update RPi Tools (mkimage)
51 get-prebuilt Get a prebuilt SliTaz ARM toolchain
52 oclock Display overclocking information
54 $(boldify "Options:")
55 --up Update firmware, tools or kernel
56 --clean Clean the distro tree (Sat can also be used)
57 --turbo Force the RPi to run at the highest arm_freq
58 --oclock= Set the RPi overclocking mode
60 EOT
61 }
63 error() {
64 echo "[ $(colorize 31 'ERROR') ] $@"
65 }
67 header() {
68 newline
69 boldify "$@"
70 separator
71 }
73 # Get minimal RPi firmware
74 get_fw() {
75 mkdir -p $firmware/boot
76 for fw in $fwlist
77 do
78 [ "$up" ] && rm -f $firmware/boot/$fw
79 if [ ! -f "$firmware/boot/$fw" ]; then
80 echo -n "Fetching: $fw"
81 wget -q --no-check-certificate ${fw_url}${fw} \
82 -O $firmware/boot/${fw}; status
83 fi
84 done
85 }
87 # Get all RPi firmware
88 clone_fw() {
89 [ -d "${rpi_git}/firmware" ] && return 0
90 mkdir -p ${rpi_git} && cd ${rpi_git}
91 git clone --depth 1 ${rpi_git_url}firmware.git
92 }
94 # Get RPi tools
95 get_tools() {
96 mkdir -p $tools
97 for t in $toolslist
98 do
99 [ "$up" ] && rm -f ${tools}/${t}
100 if [ ! -f "$data/$t" ]; then
101 echo -n "Fetching: $t"
102 wget -q --no-check-certificate ${tools_url}${t} \
103 -O ${tools}/${t}; status
104 fi
105 done
106 }
108 # Configure overclocking
109 set_oclock() {
110 case "$oclock" in
111 none)
112 arm_freq=700
113 core_freq=250
114 sdram_freq=400
115 over_voltage=0 ;;
116 modest)
117 arm_freq=800
118 core_freq=300
119 sdram_freq=400
120 over_voltage=0 ;;
121 medium)
122 arm_freq=900
123 core_freq=333
124 sdram_freq=450
125 over_voltage=2 ;;
126 hight)
127 arm_freq=950
128 core_freq=450
129 sdram_freq=450
130 over_voltage=6 ;;
131 turbo)
132 arm_freq=1000
133 core_freq=500
134 sdram_freq=500
135 over_voltage=6 ;;
136 esac
137 cat >> ${boot}/config.txt << EOT
138 arm_freq=$arm_freq
139 core_freq=$core_freq
140 sdram_freq=$sdram_freq
141 over_voltage=$over_voltage
142 EOT
143 }
145 #
146 # Commands
147 #
149 case "$1" in
150 info)
151 header "SliTaz Raspberry Pi info"
152 echo "Firmware : $fwlist"
153 echo "RPi path : $rpi"
154 colorize 36 "/boot/cmdline.txt:"
155 cat ${boot}/cmdline.txt
156 colorize 36 "/boot/config.txt:"
157 cat ${boot}/config.txt
158 separator && newline ;;
160 install)
161 rpiboot="/media/rpi/boot"
162 rpiroot="/media/rpi/rootfs"
163 header "SliTaz Raspberry Pi install"
164 if [ ! "$dev" ]; then
165 echo "Missing: --dev= cmdline option" && exit 1
166 fi
168 # Store sdcard partition(s) list
169 fdisk -l /dev/${dev} | grep "^/dev/$dev" | awk '{print $1}' \
170 > ${data}/sdcard.part
171 partnb=$(cat ${data}/sdcard.part | wc -l)
172 if [ "$partnb" != 3 ]; then
173 error "SliTaz RPi needs 3 partitions on the sdcard"
174 newline && exit 1
175 fi
177 # Mount sdcard
178 if mount | grep -q "^/dev/$dev[1-3]"; then
179 debug "Unmounting: /dev/$dev"
180 umount /dev/${dev}1 2>/dev/null || exit 1
181 umount /dev/${dev}3 2>/dev/null || exit 1
182 fi
183 echo -n "Mounting: /dev/$dev partitions"
184 mkdir -p ${rpiboot} ${rpiroot}
185 mount /dev/${dev}1 ${rpiboot}
186 mount /dev/${dev}3 ${rpiroot}; status
187 echo -n "Installing: boot files"
188 cp -rf ${boot}/* ${rpiboot}; status
189 echo -n "Installing: rootfs files"
190 cp -a ${rootfs}/* ${rpiroot}; status
192 # Unmount
193 echo -n "Unmounting: RPi sdcard"
194 umount ${rpiboot} || exit 1
195 umount ${rpiroot} || exit 1
196 status
198 # Boot flag
199 #echo -n "Setting boot flag on: /dev/${dev}1"
200 #fdisk /dev/${dev} >/dev/null << EOF
201 #a
202 #1
203 #w
204 #EOF
205 #status
206 rm -f ${data}/sdcard.part
207 separator && newline ;;
209 ls-dev)
210 newline
211 fdisk -l | grep "^Disk /dev/sd*"
212 newline ;;
214 gen)
215 # Separate boot files since the Raspberry Pi boots off a FAT32 /boot
216 # partition on the sdcard.
217 : ${flavor=rpi}
218 : ${oclock=none}
219 check_root
220 rm -rf ${rootfs} ${boot}
221 mkdir -p ${boot}
223 # Use the rootfs generated by sat
224 if [ ! -x "/usr/bin/sat" ]; then
225 error "Sat is not installed" && exit 1
226 fi
227 [ "$clean" ] && sat clean --work="$work"
228 if [ ! -d "$distro/rootfs/etc" ]; then
229 sat gen --work="$work" --flavor="$flavor" \
230 --kmap --spk --noinit --rpi
231 fi
232 header "SliTaz Raspberry Pi distro"
233 dsize="$(du -sh ${distro}/rootfs | awk '{print $1}')"
234 echo -n "Copying: rootfs ($dsize)"
235 cp -a ${distro}/rootfs ${rootfs}; status
237 # Boot firmware
238 echo -n "Copying: firmware files..."
239 get_fw
240 for fw in $fwlist
241 do
242 cp $firmware/boot/${fw} ${boot}
243 done
244 status
246 # SliTaz Raspberry Pi custom rootfs files. Make sure all files
247 # belong to root
248 if [ -d "$work/rootfs" ]; then
249 size=$(du -sh $work/rootfs | awk '{print $1}')
250 echo -n "Copying: SliTaz RPi rootfs ($size)"
251 tmp=$distro/tmp-$$
252 mkdir -p $tmp
253 cp -r $work/rootfs/* $tmp
254 chown -R root.root $tmp
255 cp -a $tmp/* ${rootfs} && rm -rf $tmp
256 status
257 fi
259 # /boot/config.txt
260 echo -n "Creating: /boot/config.txt"
261 echo 'kernel=kernel.img' > ${boot}/config.txt
262 set_oclock; status
263 if [ "$turbo" ]; then
264 echo "force_turbo=1" >> ${boot}/config.txt
265 fi
267 # /etc/fstab
268 echo -n "Creating: /etc/fstab"
269 cat > ${rootfs}/etc/fstab << EOT
270 # /etc/fstab: Slitaz ARM static filesystems.
271 #
272 proc /proc proc defaults 0 0
273 sysfs /sys sysfs defaults 0 0
274 /dev/mmcblk0p1 /boot auto noauto,noatime 1 2
275 /dev/mmcblk0p2 none swap sw 0 0
276 /dev/mmcblk0p3 / ext4 noatime 0 1
277 EOT
278 status
280 # Kernel
281 kvers=$(ls $data/linux-*/fs/lib/modules)
282 kpkg="$rootfs/var/lib/tazpkg/installed/linux"
283 if [ -d "$data/linux-$kvers/fs" ]; then
284 echo -n "Copying: Linux Kernel $kvers"
285 rm -rf ${rootfs}/lib/modules
286 cp -rf ${data}/linux-${kvers}/fs/lib/* ${rootfs}/lib
287 cp -f ${data}/linux-${kvers}/fs/boot/* ${boot}
288 mkdir -p ${kpkg}
289 cd ${data}/linux-${kvers}
290 cp -f files.list md5sum receipt ${kpkg}
291 status
292 else
293 echo "RPi Kernel: not used"
294 fi
295 mkdir -p ${rootfs}/boot
297 # RPi VC libraries
298 if [ "$vc" ]; then
299 echo "Installing: VC libraries"
300 echo "TODO"
301 fi
303 separator
304 echo -n "Boot: $(du -sh $boot | awk '{print $1}') "
305 echo "- Rootfs: $(du -sh $rootfs | awk '{print $1}')"
306 newline ;;
308 cook-linux)
309 # Native SliTaz Toolchain and cross toolchain must be installed
310 check_root
311 #: ${arch=armv6hf}
312 : ${arch=arm}
313 install="$data/linux-install"
314 if [ ! -d "/cross/$arch" ]; then
315 error "Missing cross toolchain in: /cross/$arch"
316 exit 1
317 fi
318 # Kernel source
319 [ -d "$kernel" ] || git clone --depth 1 ${rpi_git_url}linux.git
321 if [ ! -d "$install" ]; then
322 cd ${kernel}
323 export PATH=$PATH:/cross/${arch}/tools/bin
324 export HOST_SYSTEM=${arch}-slitaz-linux-gnueabi
325 make ARCH=arm bcmrpi_defconfig &&
326 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- zImage &&
327 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- modules &&
328 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- \
329 INSTALL_MOD_PATH=${install} modules_install || exit 1
330 mkdir -p ${install}/boot
331 cp -a arch/arm/boot/zImage ${install}/boot
332 fi
334 # Compress all modules
335 #echo -n "Searching all modules to compress them... "
336 #find . -name "*.ko" -exec xz '{}' \; 2> /dev/null
338 # Pack
339 fs="$data/linux-$kvers/fs"
340 kvers=$(ls ${install}/lib/modules)
341 newline
342 echo "Kernel version: $kvers"
343 if [ -d "$install" ]; then
344 rm -rf ${data}/linux-${kvers}
345 mkdir -p ${data}/linux-${kvers}
346 cp -a ${install} ${fs}
347 rm ${fs}/lib/modules/build ${fs}/lib/modules/source
348 fi
349 get_tools
350 echo "Compressing: zImage to kernel.img"
351 cd ${tools}
352 python imagetool-uncompressed.py ${fs}/boot/zImage
353 cd ${data}
354 mv kernel.img ${fs}/boot && rm ${fs}/boot/zImage
355 echo "Creating package: receipt"
356 cat > linux-$kvers/receipt << EOT
357 # SliTaz package receipt
359 PACKAGE="linux"
360 VERSION="$kvers"
361 SHORT_DESC="SliTaz Linux Kernel for the Raspberry Pi."
362 WEB_SITE="http://www.kernel.org"
364 EOT
365 tazpkg pack linux-$kvers ;;
367 get-fw)
368 get_fw ;;
370 get-tools)
371 get_tools ;;
373 get-linux)
374 # Precook RPi kernel
375 mkdir -p ${data}
376 rm -f ${data}/linux-version.txt
377 if busybox wget -q -s ${rpi_mirror}/last-linux.txt; then
378 echo -n "Fetching latest Kernel string..."
379 wget -q ${rpi_mirror}/last-linux.txt \
380 -O ${data}/linux-version.txt || exit 1
381 status
382 else
383 echo "Mirror is unreachable" && exit 1
384 fi
385 kvers=$(cat $data/linux-version.txt)
386 [ "$up" ] && rm -rf ${data}/linux-${kvers}*
387 echo "Kernel version: $kvers"
388 # Download
389 if [ ! -f "$data/linux-$kvers.tazpkg" ]; then
390 echo -n "Fetching latest Linux package..."
391 wget -q ${rpi_mirror}/linux-${kvers}.tazpkg \
392 -O ${data}/linux-${kvers}.tazpkg; status
393 fi
394 # Extract
395 if [ ! -d "$data/linux-$kvers" ]; then
396 cd ${data} && tazpkg extract linux-${kvers}.tazpkg
397 fi ;;
399 get-prebuilt)
400 # --> in cross ??
401 : ${arch=arm}
402 name="slitaz-$arch-toolchain"
403 vers="20140304"
404 tarball="$name-$vers.tar.bz2"
405 url="http://mirror.slitaz.org/packages/cross/"
406 mkdir -p /cross
407 cd /cross
408 if [ ! -f "$tarball" ]; then
409 if busybox wget -qs ${url%/}/${tarball}; then
410 busybox wget ${url%/}/${tarball}
411 else
412 echo "Toolchain URL is unreachable" && exit 1
413 fi
414 fi
415 if [ ! -d "${name}-${vers}" ]; then
416 echo "Extracting: $tarball"
417 tar xjf ${tarball}
418 fi
419 echo "Copying: ${name}-${vers}/${arch}"
420 mkdir -p ${arch}
421 cp -a ${name}-${vers}/${arch}/* ${arch}
422 echo "Tools path: /cross/${arch}/tools/bin" ;;
424 clone-fw)
425 clone_fw ;;
427 oclock)
428 cat << EOT
430 $(boldify "Overclocking modes:")
431 none 700MHz ARM 250MHz core 400MHz SDRAM 0 overvolt
432 modest 800MHz ARM 300MHz core 400MHz SDRAM 0 overvolt
433 medium 900MHz ARM 333MHz core 450MHz SDRAM 2 overvolt
434 high 950MHz ARM 450MHz core 450MHz SDRAM 6 overvolt
435 turbo 1000MHz ARM 500MHz core 500MHz SDRAM 6 overvolt
437 EOT
438 if [ -f "$boot/config.txt" ]; then
439 boldify "Current config.txt:"
440 cat ${boot}/config.txt
441 newline
442 fi ;;
443 *) usage ;;
444 esac
445 exit 0