slitaz-arm view spi @ rev 31

Add 'spi' SliTaz Raspberry Pi Tool
author Christophe Lincoln <pankso@slitaz.org>
date Wed Mar 05 23:40:22 2014 +0100 (2014-03-05)
parents
children b38c9a3fca9a
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 # Path's
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 # URL's
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 # List's
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 linux 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 need 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" --kmap --spk --rpi
219 fi
220 header "SliTaz Raspberry Pi distro"
221 dsize="$(du -sh ${distro}/rootfs | awk '{print $1}')"
222 echo -n "Copying the rootfs: $dsize"
223 cp -a ${distro}/rootfs ${rootfs}; status
225 # Boot firmware
226 echo -n "Installing: firmware files"
227 get_fw
228 cp $firmware/* ${boot}; status
230 # /boot/cmdline.txt
231 echo -n "Creating: /boot/cmdline.txt"
232 echo 'root=/dev/mmcblk0p3 rootwait quiet' >> \
233 ${boot}/cmdline.txt; status
235 # /boot/config.txt
236 echo -n "Creating: /boot/config.txt"
237 echo 'kernel=kernel.img' > ${boot}/config.txt
238 set_oclock; status
239 if [ "$turbo" ]; then
240 echo "force_turbo=1" >> ${boot}/config.txt
241 fi
243 # /etc/fstab
244 echo -n "Creating: /etc/fstab"
245 cat > ${rootfs}/etc/fstab << EOT
246 # /etc/fstab: Slitaz ARM static filesystems.
247 #
248 proc /proc proc defaults 0 0
249 sysfs /sys sysfs defaults 0 0
250 /dev/mmcblk0p1 /boot auto noauto,noatime 1 2
251 /dev/mmcblk0p2 none swap sw 0 0
252 /dev/mmcblk0p3 / ext3 noatime 0 1
253 EOT
254 status
256 # Kernel
257 kvers=$(ls $data/linux-*/fs/lib/modules)
258 kpkg="$rootfs/var/lib/tazpkg/installed/linux"
259 if [ -d "$data/linux-$kvers/fs" ]; then
260 echo -n "Installing: Linux Kernel $kvers"
261 rm -rf ${rootfs}/lib/modules
262 cp -rf ${data}/linux-${kvers}/fs/lib/* ${rootfs}/lib
263 cp -f ${data}/linux-${kvers}/fs/boot/* ${boot}
264 mkdir -p ${kpkg}
265 cd ${data}/linux-${kvers}
266 cp -f files.list md5sum receipt ${kpkg}
267 status
268 else
269 echo "RPi Kernel: not used"
270 fi
271 mkdir -p ${rootfs}/boot
272 separator
273 echo -n "Boot: $(du -sh $boot | awk '{print $1}') "
274 echo "- Rootfs: $(du -sh $rootfs | awk '{print $1}')"
275 newline ;;
277 linux)
278 # Native SliTaz Toolchain and cross toolchain must be installed
279 check_root
280 #: ${arch=armv6hf}
281 : ${arch=arm}
282 install="$data/linux-install"
283 if [ ! -d "/cross/$arch" ]; then
284 error "Missing cross toolchain in: /cross/$arch"
285 exit 1
286 fi
287 # Kernel source
288 [ -d "$kernel" ] || git clone --depth 1 ${lkgit_url}
290 if [ ! -d "$install" ]; then
291 cd ${kernel}
292 export PATH=$PATH:/cross/${arch}/tools/bin
293 export HOST_SYSTEM=${arch}-slitaz-linux-gnueabi
294 make ARCH=arm bcmrpi_defconfig &&
295 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- zImage &&
296 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- modules &&
297 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- \
298 INSTALL_MOD_PATH=${install} modules_install || exit 1
299 mkdir -p ${install}/boot
300 cp -a arch/arm/boot/zImage ${install}/boot
301 fi
303 # Pack
304 fs="$data/linux-$kvers/fs"
305 kvers=$(ls ${install}/lib/modules)
306 newline
307 echo "Kernel version: $kvers"
308 if [ -d "$install" ]; then
309 rm -rf ${data}/linux-${kvers}
310 mkdir -p ${data}/linux-${kvers}
311 cp -a ${install} ${fs}
312 rm ${fs}/lib/modules/build ${fs}/lib/modules/source
313 fi
314 get_tools
315 echo "Compressing: zImage to kernel.img"
316 cd ${data}
317 python imagetool-uncompressed.py ${fs}/boot/zImage
318 mv kernel.img ${fs}/boot && rm ${fs}/boot/zImage
319 echo "Creating package: receipt"
320 cat > linux-$kvers/receipt << EOT
321 # SliTaz package receipt
323 PACKAGE="linux"
324 VERSION="$kvers"
325 SHORT_DESC="SliTaz Linux Kernel for the Raspberry Pi."
326 WEB_SITE="http://www.kernel.org"
328 EOT
329 tazpkg pack linux-$kvers ;;
331 get-fw)
332 get_fw ;;
334 get-tools)
335 get_tools ;;
337 get-linux)
338 # Precook RPi kernel
339 rm -f ${data}/linux-version.txt
340 if busybox wget -q -s ${rpi_url}/last-linux.txt; then
341 echo -n "Fetching latest Kernel string..."
342 wget -q ${rpi_url}/last-linux.txt \
343 -O ${data}/linux-version.txt || exit 1
344 status
345 else
346 echo "Mirror is unreatchable" && exit 1
347 fi
348 kvers=$(cat $data/linux-version.txt)
349 [ "$up" ] && rm -rf ${data}/linux-${kvers}*
350 echo "Kernel version: $kvers"
351 # Download
352 if [ ! -f "$data/linux-$kvers.tazpkg" ]; then
353 echo -n "Fetching latest Linux package..."
354 wget -q ${rpi_url}/linux-${kvers}.tazpkg \
355 -O ${data}/linux-${kvers}.tazpkg; status
356 fi
357 # Extract
358 if [ ! -d "$data/linux-$kvers" ]; then
359 cd ${data} && tazpkg extract linux-${kvers}.tazpkg
360 fi ;;
362 get-prebuilt)
363 # --> in cross ??
364 : ${arch=arm}
365 name="slitaz-$arch-toolchain"
366 vers="20140304"
367 tarball="$name-$vers.tar.bz2"
368 url="http://mirror.slitaz.org/packages/cross/"
369 mkdir -p /cross
370 cd /cross
371 if [ ! -f "$tarball" ]; then
372 if busybox wget -qs ${url%/}/${tarball}; then
373 busybox wget ${url%/}/${tarball}
374 else
375 echo "Toolchain URL is unreachable" && exit 1
376 fi
377 fi
378 if [ ! -d "${name}-${vers}" ]; then
379 echo "Extracting: $tarball"
380 tar xjf ${tarball}
381 fi
382 echo "Copying: ${name}-${vers}/${arch}"
383 mkdir -p ${arch}
384 cp -a ${name}-${vers}/${arch}/* ${arch}
385 echo "Tools path: /cross/${arch}/tools/bin" ;;
387 oclock)
388 cat << EOT
390 $(boldify "Overclocking modes:")
391 none 700MHz ARM 250MHz core 400MHz SDRAM 0 overvolt
392 modest 800MHz ARM 300MHz core 400MHz SDRAM 0 overvolt
393 medium 900MHz ARM 333MHz core 450MHz SDRAM 2 overvolt
394 high 950MHz ARM 450MHz core 450MHz SDRAM 6 overvolt
395 turbo 1000MHz ARM 500MHz core 500MHz SDRAM 6 overvolt
397 EOT
398 if [ -f "$boot/config.txt" ]; then
399 boldify "Current config.txt:"
400 cat ${boot}/config.txt
401 newline
402 fi ;;
403 *) usage ;;
404 esac
405 exit 0