slitaz-arm view sat-rpi @ rev 100

Start Rpi GPIO + leds CGI plugin and improve tazberry
author Christophe Lincoln <pankso@slitaz.org>
date Sun Apr 13 05:24:04 2014 +0200 (2014-04-13)
parents fc765bf5cd6f
children ca38563ed48f
line source
1 #!/bin/sh
2 #
3 # Sat RPi - SliTaz Raspberry Pi Build 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 cache="$rpi/cache"
19 boot="$distro/boot"
20 rootfs="$distro/rootfs"
21 rpi_git="$rpi/git"
22 kernel="$rpi_git/linux"
23 firmware="$rpi_git/firmware"
24 dev="$2"
26 # URLs
27 rpi_mirror="http://mirror.slitaz.org/arm/rpi/"
28 fw_url="https://github.com/raspberrypi/firmware/raw/master/boot/"
29 rpi_git_url="git://github.com/raspberrypi/"
31 # Lists
32 fwlist="bootcode.bin fixup.dat start.elf"
34 #
35 # Functions
36 #
38 usage() {
39 cat << EOT
41 $(boldify "Usage:") $(basename $0) [command] [--option]
43 SliTaz Raspberry Pi Tool
45 $(boldify "Commands:")
46 info Display paths and distro info
47 install Install SliTaz RPi to sdcard
48 gen Generate a new SliTaz RPi distro
49 cook-linux Build the Raspberry Pi Linux kernel
50 get-linux Get the SliTaz RPi linux package
51 get-fw Download or update minimal RPi firmware
52 clone-fw Clone the RPi firmware repository
53 get-prebuilt Get a prebuilt SliTaz ARM toolchain
54 clean Clean the current work directory
55 release Release an installable tarball
57 $(boldify "Options:")
58 --up Update for commands: firmware and kernel
59 --turbo Force the RPi to run at the highest arm_freq
60 --oclock= Set the RPi overclocking mode in config.txt
61 --vc Install the RPi VC libraries in /opt/vc
62 --nosat Don't regenerate the distro with sat
64 EOT
65 }
67 error() {
68 echo "[ $(colorize 31 'ERROR') ] $@"
69 }
71 header() {
72 newline && colorize 35 "$@" && separator
73 }
75 # Get minimal RPi firmware
76 get_fw() {
77 mkdir -p $firmware/boot
78 for fw in $fwlist
79 do
80 [ "$up" ] && rm -f $firmware/boot/$fw
81 if [ ! -f "$firmware/boot/$fw" ]; then
82 echo -n "Fetching: $fw"
83 wget -q --no-check-certificate ${fw_url}${fw} \
84 -O $firmware/boot/${fw}; status
85 fi
86 done
87 }
89 # Get all RPi firmware
90 clone_fw() {
91 [ -d "${rpi_git}/firmware" ] && return 0
92 mkdir -p ${rpi_git} && cd ${rpi_git}
93 git clone --depth 1 ${rpi_git_url}firmware.git
94 }
96 # --> will move to tazberry
97 set_oclock() {
98 case "$oclock" in
99 none)
100 arm_freq=700
101 core_freq=250
102 sdram_freq=400
103 over_voltage=0 ;;
104 modest)
105 arm_freq=800
106 core_freq=300
107 sdram_freq=400
108 over_voltage=0 ;;
109 medium)
110 arm_freq=900
111 core_freq=333
112 sdram_freq=450
113 over_voltage=2 ;;
114 hight)
115 arm_freq=950
116 core_freq=450
117 sdram_freq=450
118 over_voltage=6 ;;
119 turbo)
120 arm_freq=1000
121 core_freq=500
122 sdram_freq=500
123 over_voltage=6 ;;
124 esac
125 cat >> ${boot}/config.txt << EOT
126 arm_freq=$arm_freq
127 core_freq=$core_freq
128 sdram_freq=$sdram_freq
129 over_voltage=$over_voltage
130 EOT
131 }
133 umount_sd() {
134 umount /dev/${dev}1 2>/dev/null || exit 1
135 umount /dev/${dev}3 2>/dev/null || exit 1
136 }
138 #
139 # Commands
140 #
142 case "$1" in
143 info)
144 header "SliTaz Raspberry Pi info"
145 echo "Firmware : $fwlist"
146 echo "RPi path : $rpi"
147 colorize 36 "/boot/cmdline.txt:"
148 cat ${boot}/cmdline.txt
149 colorize 36 "/boot/config.txt:"
150 cat ${boot}/config.txt
151 separator && newline ;;
153 install)
154 rpiboot="/media/rpi/boot"
155 rpiroot="/media/rpi/rootfs"
156 header "SliTaz Raspberry Pi install"
157 if [ ! "$dev" ]; then
158 echo -n "SD card disk name (ex sdc): "; read dev
159 fi
160 [ ! "$dev" ] && exit 1
162 # Store sdcard partition(s) list
163 fdisk -l /dev/${dev} | grep "^/dev/$dev" | awk '{print $1}' \
164 > ${cache}/sdcard.part
165 partnb=$(cat ${cache}/sdcard.part | wc -l)
166 if [ "$partnb" != 3 ]; then
167 error "SliTaz RPi needs 3 partitions on the sdcard"
168 newline && exit 1
169 fi
171 # Mount sdcard
172 if mount | grep -q "^/dev/$dev[1-3]"; then
173 debug "Unmounting: /dev/$dev"
174 umount_sd
175 fi
176 echo -n "Mounting: /dev/$dev partitions"
177 mkdir -p ${rpiboot} ${rpiroot}
178 mount /dev/${dev}1 ${rpiboot} || exit 1
179 mount /dev/${dev}3 ${rpiroot} || exit 1
180 status
181 echo -n "Cleaning: filesystem directories"
182 for dir in bin dev etc lib media mnt proc sbin sys tmp usr var run
183 do
184 rm -rf ${rpiroot}/${dir}
185 done; status
186 echo -n "Installing: boot files"
187 cp -rf ${boot}/* ${rpiboot}; status
188 echo -n "Installing: rootfs files"
189 cp -a ${rootfs}/* ${rpiroot}; status
191 # Unmount
192 echo -n "Unmounting: RPi sdcard"
193 umount_sd; status
195 rm -f ${cache}/sdcard.part
196 separator
197 echo "Insert the SD card into your Raspberry Pi and boot!"
198 newline ;;
200 ls-dev)
201 newline
202 fdisk -l | grep "^Disk /dev/sd*"
203 newline ;;
205 gen)
206 # Separate boot files since the Raspberry Pi boots off a FAT32 /boot
207 # partition on the sdcard.
208 : ${flavor=rpi-base}
209 : ${oclock=none}
211 # Use the rootfs generated by sat
212 if [ ! -x "/usr/bin/sat" ]; then
213 error "Sat is not installed" && exit 1
214 fi
215 check_root
217 # We may want to simply regenerate the RPi distro
218 if [ ! "$nosat" ]; then
219 sat gen --work="$work" --flavor="$flavor" --noinit --nolinux
220 else
221 newline
222 fi
224 colorize 35 "SliTaz Raspberry Pi distro"
225 separator
226 mkdir -p ${boot}
228 # Custom RPi rootfs: make sure all files belong to root
229 if [ -d "$rpi/rootfs" ]; then
230 size=$(du -sh $rpi/rootfs | awk '{print $1}')
231 echo -n "Copying custom RPi rootfs: $size"
232 tmp=$distro/tmp-$$
233 mkdir -p $tmp
234 cp -r $rpi/rootfs/* $tmp
235 chown -R root.root $tmp
236 cp -a $tmp/* ${rootfs} && rm -rf $tmp
237 mv -f ${rootfs}/boot/* ${boot}
238 status
239 fi
241 # Boot firmware
242 echo -n "Copying: firmware files..."
243 get_fw
244 for fw in $fwlist
245 do
246 cp ${firmware}/boot/${fw} ${boot}
247 done
248 status
250 # TazBerry
251 echo -n "Copying: TazBerry..."
252 cp -f ${rpi}/tazberry ${rootfs}/usr/bin
253 cp -a ${rpi}/cgi-adm/* ${rootfs}/var/www/adm
254 status
256 # Overclocking
257 echo -n "Setting: Overclocking..."
258 set_oclock; status
260 # Force turbo
261 if [ "$turbo" ]; then
262 if ! fgrep 'force_turbo=1' ${boot}/config.txt; then
263 echo -n "Config: force_turbo=1"
264 echo "force_turbo=1" >> ${boot}/config.txt; status
265 fi
266 fi
268 # RPi VC libraries
269 if [ "$vc" ]; then
270 vc="${rootfs}/opt/vc"
271 if [ ! -d "$firmware/opt/vc" ]; then
272 error "Missing firmware git repository" && exit 1
273 fi
274 echo -n "Copying: standard VC libraries"
275 cp -a ${firmware}/opt ${rootfs}
276 # --> armv6hf
277 #cp -a ${firmware}/hardfp/opt ${rootfs}
278 chown -R root.root ${rootfs}/opt
279 status
280 echo -n "Cleaning: VC libraries devel files"
281 cross_tools="/cross/${arch}/tools/bin"
282 rm -rf ${vc}/include ${vc}/src ${vc}/lib/*.a
283 ${cross_tools}/${arch}-slitaz-linux-gnueabi-strip -s ${vc}/lib/*.so
284 status
285 fi
287 # Kernel at last
288 . $cache/linux-*/receipt
289 kvers="$VERSION"
290 kpkg="$rootfs/var/lib/tazpkg/installed/linux"
291 fs="$cache/linux-$kvers/fs"
292 ksize=$(du -sh $fs | awk '{print $1}')
293 if [ -d "$fs" ]; then
294 echo -n "Copying: kernel $kvers ($ksize)"
295 rm -rf ${rootfs}/lib/modules
296 cp -rf ${fs}/lib/* ${rootfs}/lib
297 cp -f ${fs}/boot/* ${boot}
298 mkdir -p ${kpkg}
299 cd ${cache}/linux-${kvers}
300 cp -f files.list md5sum receipt ${kpkg}
301 status
302 else
303 echo "SliTaz RPi Kernel: not used"
304 fi
306 separator
307 echo -n "Boot: $(du -sh $boot | awk '{print $1}') "
308 echo "- Rootfs: $(du -sh $rootfs | awk '{print $1}')"
309 newline ;;
311 cook-linux)
312 # Native SliTaz Toolchain and cross toolchain must be installed
313 check_root
314 install="$cache/linux-install"
315 if [ ! -d "/cross/$arch" ]; then
316 error "Missing cross toolchain in: /cross/$arch" && exit 1
317 fi
319 # Kernel source
320 cd ${rpi_git}
321 [ -d "$kernel" ] || git clone --depth 1 ${rpi_git_url}linux.git
323 # Compile
324 [ "$clean" ] && rm -rf ${install}
325 if [ ! -d "$install" ]; then
326 cd ${kernel}
327 export PATH=$PATH:/cross/${arch}/tools/bin
328 export HOST_SYSTEM=${arch}-slitaz-linux-gnueabi
329 make mrproper &&
330 make ARCH=arm bcmrpi_defconfig
331 echo "Patching SliTaz RPi Linux .config"
332 patch -p0 -i ${data}/linux-rpi.patch || exit 1
333 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- zImage &&
334 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- modules &&
335 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- \
336 INSTALL_MOD_PATH=${install} modules_install || exit 1
337 mkdir -p ${install}/boot
338 cp -a arch/arm/boot/zImage ${install}/boot/kernel.img
339 fi
341 # Kernel version
342 kvers=$(ls ${install}/lib/modules)
343 kvers=${kvers%-slitaz-rpi+}+
345 # Compress modules
346 cd ${install}/lib/modules/${kvers%+}-slitaz-rpi+/ || exit 1
347 mods=$(find . -name "*.ko$" | wc -l)
348 newline
349 echo "Compressing kernel modules: $mods"
350 find . -name "*.ko$" -exec gzip '{}' \; #2> /dev/null
352 # Rebuild modules.dep
353 cd ${install}
354 depmod -b . ${kvers%+}-slitaz-rpi+
356 # Kernel
357 fs="$cache/linux-$kvers/fs"
358 echo "Kernel version: $kvers"
359 if [ -d "$install" ]; then
360 rm -rf ${cache}/linux-${kvers}
361 mkdir -p ${cache}/linux-${kvers}
362 cp -a ${install} ${fs}
363 rm -f ${fs}/lib/modules/*/build \
364 ${fs}/lib/modules/*/source
365 fi
367 # Pack .tazpkg
368 cd ${cache}
369 echo "Creating package: receipt"
370 cat > linux-$kvers/receipt << EOT
371 # SliTaz package receipt
373 PACKAGE="linux"
374 VERSION="$kvers"
375 SHORT_DESC="SliTaz Linux Kernel for the Raspberry Pi."
376 WEB_SITE="http://www.kernel.org"
378 EOT
379 tazpkg pack linux-$kvers ;;
381 get-fw)
382 get_fw ;;
384 clone-fw)
385 clone_fw ;;
387 get-linux)
388 # Precook RPi kernel
389 check_root
390 mkdir -p ${cache}
392 # Last version
393 rm -f ${cache}/linux-version.txt
394 if busybox wget -q -s ${rpi_mirror}/last-linux.txt; then
395 echo -n "Fetching latest Kernel string..."
396 wget -q ${rpi_mirror}/last-linux.txt \
397 -O ${cache}/linux-version.txt || exit 1
398 status
399 else
400 echo "Mirror is unreachable" && exit 1
401 fi
402 kvers=$(cat $cache/linux-version.txt)
403 [ "$up" ] && rm -rf ${cache}/linux-${kvers}*
404 echo "Kernel version: $kvers"
406 # Download
407 if [ ! -f "$cache/linux-$kvers.tazpkg" ]; then
408 echo -n "Fetching latest Linux package..."
409 wget -q ${rpi_mirror}/linux-${kvers}.tazpkg \
410 -O ${cache}/linux-${kvers}.tazpkg; status
411 fi
413 # Extract
414 if [ ! -d "$cache/linux-$kvers" ]; then
415 cd ${cache} && tazpkg extract linux-${kvers}.tazpkg
416 fi
417 rm -f ${cache}/linux-version.txt ;;
419 get-prebuilt)
420 # --> in cross ??
421 : ${arch=arm}
422 name="slitaz-$arch-toolchain"
423 vers="20140304"
424 tarball="$name-$vers.tar.bz2"
425 url="http://mirror.slitaz.org/packages/cross/"
426 mkdir -p /cross
427 cd /cross
428 if [ ! -f "$tarball" ]; then
429 if busybox wget -qs ${url%/}/${tarball}; then
430 busybox wget ${url%/}/${tarball}
431 else
432 echo "Toolchain URL is unreachable" && exit 1
433 fi
434 fi
435 if [ ! -d "${name}-${vers}" ]; then
436 echo "Extracting: $tarball"
437 tar xjf ${tarball}
438 fi
439 echo "Copying: ${name}-${vers}/${arch}"
440 mkdir -p ${arch}
441 cp -a ${name}-${vers}/${arch}/* ${arch}
442 echo "Tools path: /cross/${arch}/tools/bin" ;;
444 release)
445 # Used to release official SliTaz RPi images
446 cd ${distro} || exit 1
447 if [ ! "$flavor" ]; then
448 . $distro/rootfs/etc/slitaz/flavor.conf || exit 1
449 flavor="$FLAVOR"
450 fi
451 dname="slitaz-$flavor-$(date +%Y%m%d)"
452 dsize=$(du -sh $distro | awk '{print $1}' | cut -d "." -f 1)
453 rm -rf ${dname} && mkdir ${dname}
454 cp -a boot rootfs ${dname}
455 echo "Copying: SliTaz release files"
456 cp ${rpi}/release/* ${dname}
457 echo "Creating: ${dname}.tar.bz2"
458 tar -cjf ${dname}.tar.bz2 ${dname}
459 echo "Creating: ${dname}.md5"
460 md5sum ${dname}.tar.bz2 > ${dname}.md5
461 rm -rf ${dname} ;;
463 clean)
464 echo "Cleaning: $rpi"
465 rm -rf ${cache} ${rpi_git} ;;
467 *|*help) usage ;;
468 esac
469 exit 0