slitaz-arm view spi @ rev 38

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