slitaz-arm view sat-rpi @ rev 122

Full overcloking support in tazberry
author Christophe Lincoln <pankso@slitaz.org>
date Mon Apr 21 10:59:25 2014 +0200 (2014-04-21)
parents 73088f03f824
children aea5676e77c8
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 umount_sd() {
95 umount /dev/${dev}1 2>/dev/null || exit 1
96 umount /dev/${dev}3 2>/dev/null || exit 1
97 }
99 #
100 # Commands
101 #
103 case "$1" in
104 info)
105 header "SliTaz Raspberry Pi info"
106 echo "Firmware : $fwlist"
107 echo "RPi path : $rpi"
108 colorize 36 "/boot/cmdline.txt:"
109 cat ${boot}/cmdline.txt
110 colorize 36 "/boot/config.txt:"
111 cat ${boot}/config.txt
112 separator && newline ;;
114 install)
115 rpiboot="/media/rpi/boot"
116 rpiroot="/media/rpi/rootfs"
117 header "SliTaz Raspberry Pi install"
118 if [ ! "$dev" ]; then
119 echo -n "SD card disk name (ex sdc): "; read dev
120 fi
121 [ ! "$dev" ] && exit 1
123 # Store sdcard partition(s) list
124 fdisk -l /dev/${dev} | grep "^/dev/$dev" | awk '{print $1}' \
125 > ${cache}/sdcard.part
126 partnb=$(cat ${cache}/sdcard.part | wc -l)
127 if [ "$partnb" != 3 ]; then
128 error "SliTaz RPi needs 3 partitions on the sdcard"
129 newline && exit 1
130 fi
132 # Mount sdcard
133 if mount | grep -q "^/dev/$dev[1-3]"; then
134 debug "Unmounting: /dev/$dev"
135 umount_sd
136 fi
137 echo -n "Mounting: /dev/$dev partitions"
138 mkdir -p ${rpiboot} ${rpiroot}
139 mount /dev/${dev}1 ${rpiboot} || exit 1
140 mount /dev/${dev}3 ${rpiroot} || exit 1
141 status
142 echo -n "Cleaning: filesystem directories"
143 for dir in bin dev etc lib media mnt proc sbin sys tmp usr var run
144 do
145 rm -rf ${rpiroot}/${dir}
146 done; status
147 echo -n "Installing: boot files"
148 cp -rf ${boot}/* ${rpiboot}; status
149 echo -n "Installing: rootfs files"
150 cp -a ${rootfs}/* ${rpiroot}; status
152 # Unmount
153 echo -n "Unmounting: RPi sdcard"
154 umount_sd; status
156 rm -f ${cache}/sdcard.part
157 separator
158 echo "Insert the SD card into your Raspberry Pi and boot!"
159 newline ;;
161 gen)
162 # Separate boot files since the Raspberry Pi boots off a FAT32 /boot
163 # partition on the sdcard.
164 : ${flavor=rpi-base}
165 : ${oclock=none}
167 # Use the rootfs generated by sat
168 if [ ! -x "/usr/bin/sat" ]; then
169 error "Sat is not installed" && exit 1
170 fi
171 check_root
173 # We may want to simply regenerate the RPi distro
174 if [ ! "$nosat" ]; then
175 sat gen --work="$work" --flavor="$flavor" --noinit --nolinux
176 else
177 newline
178 fi
180 colorize 35 "SliTaz Raspberry Pi distro"
181 separator
182 mkdir -p ${boot}
184 # Custom RPi rootfs: make sure all files belong to root
185 if [ -d "$rpi/rootfs" ]; then
186 size=$(du -sh $rpi/rootfs | awk '{print $1}')
187 echo -n "Copying custom RPi rootfs: $size"
188 tmp=$distro/tmp-$$
189 mkdir -p $tmp
190 cp -r $rpi/rootfs/* $tmp
191 chown -R root.root $tmp
192 cp -a $tmp/* ${rootfs} && rm -rf $tmp
193 mv -f ${rootfs}/boot/* ${boot}
194 status
195 fi
197 # Boot firmware
198 echo -n "Copying: firmware files..."
199 get_fw
200 for fw in $fwlist
201 do
202 cp ${firmware}/boot/${fw} ${boot}
203 done
204 status
206 # TazBerry
207 echo -n "Copying utility: TazBerry..."
208 cp -f ${rpi}/tazberry ${rootfs}/usr/bin
209 cp -a ${rpi}/cgi-adm/* ${rootfs}/var/www/adm
210 status
212 # PiBoot
213 echo -n "Copying bootloader: PiBoot..."
214 cp -f ${rpi}/piboot ${rootfs}/sbin
215 status
217 # RPi VC libraries
218 if [ "$vc" ]; then
219 vc="${rootfs}/opt/vc"
220 if [ ! -d "$firmware/opt/vc" ]; then
221 error "Missing firmware git repository" && exit 1
222 fi
223 echo -n "Copying: standard VC libraries"
224 cp -a ${firmware}/opt ${rootfs}
225 # --> armv6hf
226 #cp -a ${firmware}/hardfp/opt ${rootfs}
227 chown -R root.root ${rootfs}/opt
228 status
229 echo -n "Cleaning: VC libraries devel files"
230 cross_tools="/cross/${arch}/tools/bin"
231 rm -rf ${vc}/include ${vc}/src ${vc}/lib/*.a
232 ${cross_tools}/${arch}-slitaz-linux-gnueabi-strip -s ${vc}/lib/*.so
233 status
234 echo -n "Adding: VC binaries to PATH"
235 echo -e '\n# Raspberry Pi VC tools' >> ${rootfs}/etc/profile
236 echo 'export PATH=$PATH:/opt/vc/bin' >> ${rootfs}/etc/profile
237 status
238 fi
240 # Kernel at last
241 . $cache/linux-*/receipt
242 kvers="$VERSION"
243 kpkg="$rootfs/var/lib/tazpkg/installed/linux"
244 fs="$cache/linux-$kvers/fs"
245 ksize=$(du -sh $fs | awk '{print $1}')
246 if [ -d "$fs" ]; then
247 echo -n "Copying: kernel $kvers ($ksize)"
248 rm -rf ${rootfs}/lib/modules
249 cp -rf ${fs}/lib/* ${rootfs}/lib
250 cp -f ${fs}/boot/* ${boot}
251 mkdir -p ${kpkg}
252 cd ${cache}/linux-${kvers}
253 cp -f files.list md5sum receipt ${kpkg}
254 status
255 else
256 echo "SliTaz RPi Kernel: not used"
257 fi
259 separator
260 echo -n "Boot: $(du -sh $boot | awk '{print $1}') "
261 echo "- Rootfs: $(du -sh $rootfs | awk '{print $1}')"
262 newline ;;
264 cook-linux)
265 # Native SliTaz Toolchain and cross toolchain must be installed
266 check_root
267 install="$cache/linux-install"
268 if [ ! -d "/cross/$arch" ]; then
269 error "Missing cross toolchain in: /cross/$arch" && exit 1
270 fi
272 # Kernel source
273 cd ${rpi_git}
274 [ -d "$kernel" ] || git clone --depth 1 ${rpi_git_url}linux.git
276 # Compile
277 [ "$clean" ] && rm -rf ${install}
278 if [ ! -d "$install" ]; then
279 cd ${kernel}
280 export PATH=$PATH:/cross/${arch}/tools/bin
281 export HOST_SYSTEM=${arch}-slitaz-linux-gnueabi
282 make mrproper &&
283 make ARCH=arm bcmrpi_defconfig
284 echo "Patching SliTaz RPi Linux .config"
285 patch -p0 -i ${data}/linux-rpi.patch || exit 1
286 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- zImage &&
287 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- modules &&
288 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- \
289 INSTALL_MOD_PATH=${install} modules_install || exit 1
290 mkdir -p ${install}/boot
291 cp -a arch/arm/boot/zImage ${install}/boot/kernel.img
292 fi
294 # Kernel version
295 kvers=$(ls ${install}/lib/modules)
296 kvers=${kvers%-slitaz-rpi+}+
298 # Compress modules
299 cd ${install}/lib/modules/${kvers%+}-slitaz-rpi+/ || exit 1
300 mods=$(find . -name "*.ko$" | wc -l)
301 newline
302 echo "Compressing kernel modules: $mods"
303 find . -name "*.ko$" -exec gzip '{}' \; #2> /dev/null
305 # Rebuild modules.dep
306 cd ${install}
307 depmod -b . ${kvers%+}-slitaz-rpi+
309 # Kernel
310 fs="$cache/linux-$kvers/fs"
311 echo "Kernel version: $kvers"
312 if [ -d "$install" ]; then
313 rm -rf ${cache}/linux-${kvers}
314 mkdir -p ${cache}/linux-${kvers}
315 cp -a ${install} ${fs}
316 rm -f ${fs}/lib/modules/*/build \
317 ${fs}/lib/modules/*/source
318 fi
320 # Pack .tazpkg
321 cd ${cache}
322 echo "Creating package: receipt"
323 cat > linux-$kvers/receipt << EOT
324 # SliTaz package receipt
326 PACKAGE="linux"
327 VERSION="$kvers"
328 SHORT_DESC="SliTaz Linux Kernel for the Raspberry Pi."
329 WEB_SITE="http://www.kernel.org"
331 EOT
332 tazpkg pack linux-$kvers ;;
334 get-fw)
335 get_fw ;;
337 clone-fw)
338 clone_fw ;;
340 get-linux)
341 # Precook RPi kernel
342 check_root
343 mkdir -p ${cache}
345 # Last version
346 rm -f ${cache}/linux-version.txt
347 if busybox wget -q -s ${rpi_mirror}/last-linux.txt; then
348 echo -n "Fetching latest Kernel string..."
349 wget -q ${rpi_mirror}/last-linux.txt \
350 -O ${cache}/linux-version.txt || exit 1
351 status
352 else
353 echo "Mirror is unreachable" && exit 1
354 fi
355 kvers=$(cat $cache/linux-version.txt)
356 [ "$up" ] && rm -rf ${cache}/linux-${kvers}*
357 echo "Kernel version: $kvers"
359 # Download
360 if [ ! -f "$cache/linux-$kvers.tazpkg" ]; then
361 echo -n "Fetching latest Linux package..."
362 wget -q ${rpi_mirror}/linux-${kvers}.tazpkg \
363 -O ${cache}/linux-${kvers}.tazpkg; status
364 fi
366 # Extract
367 if [ ! -d "$cache/linux-$kvers" ]; then
368 cd ${cache} && tazpkg extract linux-${kvers}.tazpkg
369 fi
370 rm -f ${cache}/linux-version.txt ;;
372 get-prebuilt)
373 # --> in cross ??
374 : ${arch=arm}
375 name="slitaz-$arch-toolchain"
376 vers="20140304"
377 tarball="$name-$vers.tar.bz2"
378 url="http://mirror.slitaz.org/packages/cross/"
379 mkdir -p /cross
380 cd /cross
381 if [ ! -f "$tarball" ]; then
382 if busybox wget -qs ${url%/}/${tarball}; then
383 busybox wget ${url%/}/${tarball}
384 else
385 echo "Toolchain URL is unreachable" && exit 1
386 fi
387 fi
388 if [ ! -d "${name}-${vers}" ]; then
389 echo "Extracting: $tarball"
390 tar xjf ${tarball}
391 fi
392 echo "Copying: ${name}-${vers}/${arch}"
393 mkdir -p ${arch}
394 cp -a ${name}-${vers}/${arch}/* ${arch}
395 echo "Tools path: /cross/${arch}/tools/bin" ;;
397 release)
398 # Used to release official SliTaz RPi images
399 cd ${distro} || exit 1
400 if [ ! "$flavor" ]; then
401 . $distro/rootfs/etc/slitaz/flavor.conf || exit 1
402 flavor="$FLAVOR"
403 fi
404 dname="slitaz-$flavor-$(date +%Y%m%d)"
405 dsize=$(du -sh $distro | awk '{print $1}' | cut -d "." -f 1)
406 rm -rf ${dname} && mkdir ${dname}
407 cp -a boot rootfs ${dname}
408 echo "Copying: SliTaz release files"
409 cp ${rpi}/release/* ${dname}
410 echo "Creating: ${dname}.tar.bz2"
411 tar -cjf ${dname}.tar.bz2 ${dname}
412 echo "Creating: ${dname}.md5"
413 md5sum ${dname}.tar.bz2 > ${dname}.md5
414 rm -rf ${dname} ;;
416 clean)
417 echo "Cleaning: $rpi"
418 rm -rf ${cache} ${rpi_git} ;;
420 *|*help) usage ;;
421 esac
422 exit 0