slitaz-arm view sat-rpi @ rev 114

Fix rpi-blacklist.conf in CGI plugin
author Christophe Lincoln <pankso@slitaz.org>
date Sat Apr 19 23:19:55 2014 +0200 (2014-04-19)
parents 232f979c80ea
children 349fa2f9498f
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 --vc Install the RPi VC libraries in /opt/vc
60 --nosat Don't regenerate the distro with sat
62 EOT
63 }
65 error() {
66 echo "[ $(colorize 31 'ERROR') ] $@"
67 }
69 header() {
70 newline && colorize 35 "$@" && 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 # --> will move to tazberry
95 set_oclock() {
96 case "$oclock" in
97 none)
98 arm_freq=700
99 core_freq=250
100 sdram_freq=400
101 over_voltage=0 ;;
102 modest)
103 arm_freq=800
104 core_freq=300
105 sdram_freq=400
106 over_voltage=0 ;;
107 medium)
108 arm_freq=900
109 core_freq=333
110 sdram_freq=450
111 over_voltage=2 ;;
112 hight)
113 arm_freq=950
114 core_freq=450
115 sdram_freq=450
116 over_voltage=6 ;;
117 turbo)
118 arm_freq=1000
119 core_freq=500
120 sdram_freq=500
121 over_voltage=6 ;;
122 esac
123 cat >> ${boot}/config.txt << EOT
124 # Overclocking Settings
125 arm_freq=$arm_freq
126 core_freq=$core_freq
127 sdram_freq=$sdram_freq
128 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 # RPi VC libraries
257 if [ "$vc" ]; then
258 vc="${rootfs}/opt/vc"
259 if [ ! -d "$firmware/opt/vc" ]; then
260 error "Missing firmware git repository" && exit 1
261 fi
262 echo -n "Copying: standard VC libraries"
263 cp -a ${firmware}/opt ${rootfs}
264 # --> armv6hf
265 #cp -a ${firmware}/hardfp/opt ${rootfs}
266 chown -R root.root ${rootfs}/opt
267 status
268 echo -n "Cleaning: VC libraries devel files"
269 cross_tools="/cross/${arch}/tools/bin"
270 rm -rf ${vc}/include ${vc}/src ${vc}/lib/*.a
271 ${cross_tools}/${arch}-slitaz-linux-gnueabi-strip -s ${vc}/lib/*.so
272 status
273 fi
275 # Kernel at last
276 . $cache/linux-*/receipt
277 kvers="$VERSION"
278 kpkg="$rootfs/var/lib/tazpkg/installed/linux"
279 fs="$cache/linux-$kvers/fs"
280 ksize=$(du -sh $fs | awk '{print $1}')
281 if [ -d "$fs" ]; then
282 echo -n "Copying: kernel $kvers ($ksize)"
283 rm -rf ${rootfs}/lib/modules
284 cp -rf ${fs}/lib/* ${rootfs}/lib
285 cp -f ${fs}/boot/* ${boot}
286 mkdir -p ${kpkg}
287 cd ${cache}/linux-${kvers}
288 cp -f files.list md5sum receipt ${kpkg}
289 status
290 else
291 echo "SliTaz RPi Kernel: not used"
292 fi
294 separator
295 echo -n "Boot: $(du -sh $boot | awk '{print $1}') "
296 echo "- Rootfs: $(du -sh $rootfs | awk '{print $1}')"
297 newline ;;
299 cook-linux)
300 # Native SliTaz Toolchain and cross toolchain must be installed
301 check_root
302 install="$cache/linux-install"
303 if [ ! -d "/cross/$arch" ]; then
304 error "Missing cross toolchain in: /cross/$arch" && exit 1
305 fi
307 # Kernel source
308 cd ${rpi_git}
309 [ -d "$kernel" ] || git clone --depth 1 ${rpi_git_url}linux.git
311 # Compile
312 [ "$clean" ] && rm -rf ${install}
313 if [ ! -d "$install" ]; then
314 cd ${kernel}
315 export PATH=$PATH:/cross/${arch}/tools/bin
316 export HOST_SYSTEM=${arch}-slitaz-linux-gnueabi
317 make mrproper &&
318 make ARCH=arm bcmrpi_defconfig
319 echo "Patching SliTaz RPi Linux .config"
320 patch -p0 -i ${data}/linux-rpi.patch || exit 1
321 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- zImage &&
322 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- modules &&
323 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- \
324 INSTALL_MOD_PATH=${install} modules_install || exit 1
325 mkdir -p ${install}/boot
326 cp -a arch/arm/boot/zImage ${install}/boot/kernel.img
327 fi
329 # Kernel version
330 kvers=$(ls ${install}/lib/modules)
331 kvers=${kvers%-slitaz-rpi+}+
333 # Compress modules
334 cd ${install}/lib/modules/${kvers%+}-slitaz-rpi+/ || exit 1
335 mods=$(find . -name "*.ko$" | wc -l)
336 newline
337 echo "Compressing kernel modules: $mods"
338 find . -name "*.ko$" -exec gzip '{}' \; #2> /dev/null
340 # Rebuild modules.dep
341 cd ${install}
342 depmod -b . ${kvers%+}-slitaz-rpi+
344 # Kernel
345 fs="$cache/linux-$kvers/fs"
346 echo "Kernel version: $kvers"
347 if [ -d "$install" ]; then
348 rm -rf ${cache}/linux-${kvers}
349 mkdir -p ${cache}/linux-${kvers}
350 cp -a ${install} ${fs}
351 rm -f ${fs}/lib/modules/*/build \
352 ${fs}/lib/modules/*/source
353 fi
355 # Pack .tazpkg
356 cd ${cache}
357 echo "Creating package: receipt"
358 cat > linux-$kvers/receipt << EOT
359 # SliTaz package receipt
361 PACKAGE="linux"
362 VERSION="$kvers"
363 SHORT_DESC="SliTaz Linux Kernel for the Raspberry Pi."
364 WEB_SITE="http://www.kernel.org"
366 EOT
367 tazpkg pack linux-$kvers ;;
369 get-fw)
370 get_fw ;;
372 clone-fw)
373 clone_fw ;;
375 get-linux)
376 # Precook RPi kernel
377 check_root
378 mkdir -p ${cache}
380 # Last version
381 rm -f ${cache}/linux-version.txt
382 if busybox wget -q -s ${rpi_mirror}/last-linux.txt; then
383 echo -n "Fetching latest Kernel string..."
384 wget -q ${rpi_mirror}/last-linux.txt \
385 -O ${cache}/linux-version.txt || exit 1
386 status
387 else
388 echo "Mirror is unreachable" && exit 1
389 fi
390 kvers=$(cat $cache/linux-version.txt)
391 [ "$up" ] && rm -rf ${cache}/linux-${kvers}*
392 echo "Kernel version: $kvers"
394 # Download
395 if [ ! -f "$cache/linux-$kvers.tazpkg" ]; then
396 echo -n "Fetching latest Linux package..."
397 wget -q ${rpi_mirror}/linux-${kvers}.tazpkg \
398 -O ${cache}/linux-${kvers}.tazpkg; status
399 fi
401 # Extract
402 if [ ! -d "$cache/linux-$kvers" ]; then
403 cd ${cache} && tazpkg extract linux-${kvers}.tazpkg
404 fi
405 rm -f ${cache}/linux-version.txt ;;
407 get-prebuilt)
408 # --> in cross ??
409 : ${arch=arm}
410 name="slitaz-$arch-toolchain"
411 vers="20140304"
412 tarball="$name-$vers.tar.bz2"
413 url="http://mirror.slitaz.org/packages/cross/"
414 mkdir -p /cross
415 cd /cross
416 if [ ! -f "$tarball" ]; then
417 if busybox wget -qs ${url%/}/${tarball}; then
418 busybox wget ${url%/}/${tarball}
419 else
420 echo "Toolchain URL is unreachable" && exit 1
421 fi
422 fi
423 if [ ! -d "${name}-${vers}" ]; then
424 echo "Extracting: $tarball"
425 tar xjf ${tarball}
426 fi
427 echo "Copying: ${name}-${vers}/${arch}"
428 mkdir -p ${arch}
429 cp -a ${name}-${vers}/${arch}/* ${arch}
430 echo "Tools path: /cross/${arch}/tools/bin" ;;
432 release)
433 # Used to release official SliTaz RPi images
434 cd ${distro} || exit 1
435 if [ ! "$flavor" ]; then
436 . $distro/rootfs/etc/slitaz/flavor.conf || exit 1
437 flavor="$FLAVOR"
438 fi
439 dname="slitaz-$flavor-$(date +%Y%m%d)"
440 dsize=$(du -sh $distro | awk '{print $1}' | cut -d "." -f 1)
441 rm -rf ${dname} && mkdir ${dname}
442 cp -a boot rootfs ${dname}
443 echo "Copying: SliTaz release files"
444 cp ${rpi}/release/* ${dname}
445 echo "Creating: ${dname}.tar.bz2"
446 tar -cjf ${dname}.tar.bz2 ${dname}
447 echo "Creating: ${dname}.md5"
448 md5sum ${dname}.tar.bz2 > ${dname}.md5
449 rm -rf ${dname} ;;
451 clean)
452 echo "Cleaning: $rpi"
453 rm -rf ${cache} ${rpi_git} ;;
455 *|*help) usage ;;
456 esac
457 exit 0