slitaz-arm view sat-rpi @ rev 75

Add slim support and custom rpi theme
author Christophe Lincoln <pankso@slitaz.org>
date Sun Mar 23 14:37:38 2014 +0100 (2014-03-23)
parents d81795f58d28
children bfdc7cc1c657
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 boot="$distro/boot"
19 rootfs="$distro/rootfs"
20 rpi_git="$rpi/git"
21 kernel="$rpi_git/linux"
22 firmware="$rpi_git/firmware"
23 dev="$2"
25 # URLs
26 rpi_mirror="http://mirror.slitaz.org/arm/rpi/"
27 fw_url="https://github.com/raspberrypi/firmware/raw/master/boot/"
28 rpi_git_url="git://github.com/raspberrypi/"
30 # Lists
31 fwlist="bootcode.bin fixup.dat start.elf"
33 #
34 # Functions
35 #
37 usage() {
38 cat << EOT
40 $(boldify "Usage:") $(basename $0) [command] [--option]
42 SliTaz Raspberry Pi Tool
44 $(boldify "Commands:")
45 info Display paths and distro info
46 install Install SliTaz RPi to sdcard
47 gen Generate a new SliTaz RPi distro
48 cook-linux Build the Raspberry Pi Linux kernel
49 get-linux Get the SliTaz RPi linux package
50 get-fw Download or update minimal RPi firmware
51 clone-fw Clone the RPi firmware repository
52 get-prebuilt Get a prebuilt SliTaz ARM toolchain
53 clean Clean the current work directory
55 $(boldify "Options:")
56 --up Update for commands: firmware and kernel
57 --turbo Force the RPi to run at the highest arm_freq
58 --oclock= Set the RPi overclocking mode in config.txt
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 arm_freq=$arm_freq
125 core_freq=$core_freq
126 sdram_freq=$sdram_freq
127 over_voltage=$over_voltage
128 EOT
129 }
131 umount_sd() {
132 umount /dev/${dev}1 2>/dev/null || exit 1
133 umount /dev/${dev}3 2>/dev/null || exit 1
134 }
136 #
137 # Commands
138 #
140 case "$1" in
141 info)
142 header "SliTaz Raspberry Pi info"
143 echo "Firmware : $fwlist"
144 echo "RPi path : $rpi"
145 colorize 36 "/boot/cmdline.txt:"
146 cat ${boot}/cmdline.txt
147 colorize 36 "/boot/config.txt:"
148 cat ${boot}/config.txt
149 separator && newline ;;
151 install)
152 rpiboot="/media/rpi/boot"
153 rpiroot="/media/rpi/rootfs"
154 header "SliTaz Raspberry Pi install"
155 if [ ! "$dev" ]; then
156 echo -n "SD card disk name (ex sdc): "; read dev
157 fi
158 [ ! "$dev" ] && exit 1
160 # Store sdcard partition(s) list
161 fdisk -l /dev/${dev} | grep "^/dev/$dev" | awk '{print $1}' \
162 > ${data}/sdcard.part
163 partnb=$(cat ${data}/sdcard.part | wc -l)
164 if [ "$partnb" != 3 ]; then
165 error "SliTaz RPi needs 3 partitions on the sdcard"
166 newline && exit 1
167 fi
169 # Mount sdcard
170 if mount | grep -q "^/dev/$dev[1-3]"; then
171 debug "Unmounting: /dev/$dev"
172 umount_sd
173 fi
174 echo -n "Mounting: /dev/$dev partitions"
175 mkdir -p ${rpiboot} ${rpiroot}
176 mount /dev/${dev}1 ${rpiboot} || exit 1
177 mount /dev/${dev}3 ${rpiroot} || exit 1
178 status
179 echo -n "Cleaning: filesystem directories"
180 for dir in bin dev etc lib media mnt proc sbin sys tmp usr var run
181 do
182 rm -rf ${rpiroot}/${dir}
183 done; status
184 echo -n "Installing: boot files"
185 cp -rf ${boot}/* ${rpiboot}; status
186 echo -n "Installing: rootfs files"
187 cp -a ${rootfs}/* ${rpiroot}; status
189 # Unmount
190 echo -n "Unmounting: RPi sdcard"
191 umount_sd; status
193 rm -f ${data}/sdcard.part
194 separator
195 echo "Insert the SD card into your Raspberry Pi and boot!"
196 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-base}
207 : ${oclock=none}
209 # Use the rootfs generated by sat
210 if [ ! -x "/usr/bin/sat" ]; then
211 error "Sat is not installed" && exit 1
212 fi
213 check_root
215 # We may want to simply regenerate the RPi distro
216 if [ ! "$nosat" ]; then
217 sat gen --work="$work" --flavor="$flavor" --noinit --nolinux
218 else
219 newline
220 fi
222 colorize 35 "SliTaz Raspberry Pi distro"
223 separator
224 mkdir -p ${boot}
226 # Custom RPi rootfs: make sure all files belong to root
227 if [ -d "$rpi/rootfs" ]; then
228 size=$(du -sh $rpi/rootfs | awk '{print $1}')
229 echo -n "Copying custom RPi rootfs: $size"
230 tmp=$distro/tmp-$$
231 mkdir -p $tmp
232 cp -r $rpi/rootfs/* $tmp
233 chown -R root.root $tmp
234 cp -a $tmp/* ${rootfs} && rm -rf $tmp
235 mv -f ${rootfs}/boot/* ${boot}
236 status
237 fi
239 # Boot firmware
240 echo -n "Copying: firmware files..."
241 get_fw
242 for fw in $fwlist
243 do
244 cp ${firmware}/boot/${fw} ${boot}
245 done
246 status
248 # TazBerry
249 echo -n "Copying: TazBerry..."
250 cp -f ${rpi}/tazberry ${rootfs}/usr/bin
251 cp -a ${rpi}/cgi-adm/* ${rootfs}/var/www/adm
252 status
254 # Overclocking
255 echo -n "Setting: Overclocking..."
256 set_oclock; status
258 # Force turbo
259 if [ "$turbo" ]; then
260 if ! fgrep 'force_turbo=1' ${boot}/config.txt; then
261 echo -n "Config: force_turbo=1"
262 echo "force_turbo=1" >> ${boot}/config.txt; status
263 fi
264 fi
266 # RPi VC libraries
267 if [ "$vc" ]; then
268 vc="${rootfs}/opt/vc"
269 if [ ! -d "$firmware/opt/vc" ]; then
270 error "Missing firmware git repository" && exit 1
271 fi
272 echo -n "Copying: standard VC libraries"
273 cp -a ${firmware}/opt ${rootfs}
274 # --> armv6hf
275 #cp -a ${firmware}/hardfp/opt ${rootfs}
276 chown -R root.root ${rootfs}/opt
277 status
278 echo -n "Cleaning: VC libraries devel files"
279 cross_tools="/cross/${arch}/tools/bin"
280 rm -rf ${vc}/include ${vc}/src ${vc}/lib/*.a
281 ${cross_tools}/${arch}-slitaz-linux-gnueabi-strip -s ${vc}/lib/*.so
282 status
283 fi
285 # Kernel at last
286 . $data/linux-*/receipt
287 kvers="$VERSION"
288 kpkg="$rootfs/var/lib/tazpkg/installed/linux"
289 fs="$data/linux-$kvers/fs"
290 ksize=$(du -sh $fs | awk '{print $1}')
291 if [ -d "$fs" ]; then
292 echo -n "Copying: kernel $kvers ($ksize)"
293 rm -rf ${rootfs}/lib/modules
294 cp -rf ${fs}/lib/* ${rootfs}/lib
295 cp -f ${fs}/boot/* ${boot}
296 mkdir -p ${kpkg}
297 cd ${data}/linux-${kvers}
298 cp -f files.list md5sum receipt ${kpkg}
299 status
300 else
301 echo "SliTaz RPi Kernel: not used"
302 fi
304 separator
305 echo -n "Boot: $(du -sh $boot | awk '{print $1}') "
306 echo "- Rootfs: $(du -sh $rootfs | awk '{print $1}')"
307 newline ;;
309 cook-linux)
310 # Native SliTaz Toolchain and cross toolchain must be installed
311 check_root
312 install="$data/linux-install"
313 if [ ! -d "/cross/$arch" ]; then
314 error "Missing cross toolchain in: /cross/$arch" && exit 1
315 fi
317 # Kernel source
318 cd ${rpi_git}
319 [ -d "$kernel" ] || git clone --depth 1 ${rpi_git_url}linux.git
321 # Compile
322 [ "$clean" ] && rm -rf ${install}
323 if [ ! -d "$install" ]; then
324 cd ${kernel}
325 export PATH=$PATH:/cross/${arch}/tools/bin
326 export HOST_SYSTEM=${arch}-slitaz-linux-gnueabi
327 make mrproper &&
328 make ARCH=arm bcmrpi_defconfig
329 echo "Patching SliTaz RPi Linux .config"
330 patch -p0 -i ${rpi}/linux-rpi.patch || exit 1
331 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- zImage &&
332 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- modules &&
333 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- \
334 INSTALL_MOD_PATH=${install} modules_install || exit 1
335 mkdir -p ${install}/boot
336 cp -a arch/arm/boot/zImage ${install}/boot/kernel.img
337 fi
339 # Kernel version
340 kvers=$(ls ${install}/lib/modules)
341 kvers=${kvers%-slitaz-rpi+}+
343 # Compress modules
344 cd ${install}/lib/modules/${kvers%+}-slitaz-rpi+/ || exit 1
345 mods=$(find . -name "*.ko$" | wc -l)
346 newline
347 echo "Compressing kernel modules: $mods"
348 find . -name "*.ko$" -exec gzip '{}' \; #2> /dev/null
350 # Rebuild modules.dep
351 cd ${install}
352 depmod -b . ${kvers%+}-slitaz-rpi+
354 # Kernel
355 fs="$data/linux-$kvers/fs"
356 echo "Kernel version: $kvers"
357 if [ -d "$install" ]; then
358 rm -rf ${data}/linux-${kvers}
359 mkdir -p ${data}/linux-${kvers}
360 cp -a ${install} ${fs}
361 rm -f ${fs}/lib/modules/*/build \
362 ${fs}/lib/modules/*/source
363 fi
365 # Pack .tazpkg
366 cd ${data}
367 echo "Creating package: receipt"
368 cat > linux-$kvers/receipt << EOT
369 # SliTaz package receipt
371 PACKAGE="linux"
372 VERSION="$kvers"
373 SHORT_DESC="SliTaz Linux Kernel for the Raspberry Pi."
374 WEB_SITE="http://www.kernel.org"
376 EOT
377 tazpkg pack linux-$kvers ;;
379 get-fw)
380 get_fw ;;
382 clone-fw)
383 clone_fw ;;
385 get-linux)
386 # Precook RPi kernel
387 check_root
388 mkdir -p ${data}
390 # Last version
391 rm -f ${data}/linux-version.txt
392 if busybox wget -q -s ${rpi_mirror}/last-linux.txt; then
393 echo -n "Fetching latest Kernel string..."
394 wget -q ${rpi_mirror}/last-linux.txt \
395 -O ${data}/linux-version.txt || exit 1
396 status
397 else
398 echo "Mirror is unreachable" && exit 1
399 fi
400 kvers=$(cat $data/linux-version.txt)
401 [ "$up" ] && rm -rf ${data}/linux-${kvers}*
402 echo "Kernel version: $kvers"
404 # Download
405 if [ ! -f "$data/linux-$kvers.tazpkg" ]; then
406 echo -n "Fetching latest Linux package..."
407 wget -q ${rpi_mirror}/linux-${kvers}.tazpkg \
408 -O ${data}/linux-${kvers}.tazpkg; status
409 fi
411 # Extract
412 if [ ! -d "$data/linux-$kvers" ]; then
413 cd ${data} && tazpkg extract linux-${kvers}.tazpkg
414 fi
415 rm -f ${data}/linux-version.txt ;;
417 get-prebuilt)
418 # --> in cross ??
419 : ${arch=arm}
420 name="slitaz-$arch-toolchain"
421 vers="20140304"
422 tarball="$name-$vers.tar.bz2"
423 url="http://mirror.slitaz.org/packages/cross/"
424 mkdir -p /cross
425 cd /cross
426 if [ ! -f "$tarball" ]; then
427 if busybox wget -qs ${url%/}/${tarball}; then
428 busybox wget ${url%/}/${tarball}
429 else
430 echo "Toolchain URL is unreachable" && exit 1
431 fi
432 fi
433 if [ ! -d "${name}-${vers}" ]; then
434 echo "Extracting: $tarball"
435 tar xjf ${tarball}
436 fi
437 echo "Copying: ${name}-${vers}/${arch}"
438 mkdir -p ${arch}
439 cp -a ${name}-${vers}/${arch}/* ${arch}
440 echo "Tools path: /cross/${arch}/tools/bin" ;;
442 release)
443 # Used to release official SliTaz RPi images
444 cd ${distro} || exit 1
445 if [ ! "$flavor" ]; then
446 . $distro/rootfs/etc/slitaz/flavor.conf || exit 1
447 flavor="$FLAVOR"
448 fi
449 dname="slitaz-$flavor-$(date +%Y%m%d)"
450 dsize=$(du -sh $distro | awk '{print $1}' | cut -d "." -f 1)
451 rm -rf ${dname} && mkdir ${dname}
452 cp -a boot rootfs ${dname}
453 echo "Copying: SliTaz release files"
454 cp ${rpi}/release/* ${dname}
455 echo "Creating: ${dname}.tar.xz"
456 tar -cJf ${dname}.tar.xz ${dname}
457 echo "Creating: ${dname}.md5"
458 md5sum ${dname}.tar.xz > ${dname}.md5
459 rm -rf ${dname} ;;
461 clean)
462 echo "Cleaning: $rpi"
463 rm -rf ${data} ${rpi_git} ;;
465 *|*help) usage ;;
466 esac
467 exit 0