slitaz-arm view sat-rpi @ rev 175

sat-rpi: use new kernel packages path on mirror
author Christophe Lincoln <pankso@slitaz.org>
date Wed May 07 11:44:25 2014 +0200 (2014-05-07)
parents 9b1e4f9cf134
children bc5e3b44ff38
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 dev="$2"
25 # URLs
26 rpi_mirror="http://mirror.slitaz.org/arm/rpi/"
27 rpi_git_url="git://github.com/raspberrypi/"
29 #
30 # Functions
31 #
33 usage() {
34 cat << EOT
36 $(boldify "Usage:") $(basename $0) [command] [--option]
38 SliTaz Raspberry Pi Tool
40 $(boldify "Commands:")
41 info Display paths and distro info
42 install Install SliTaz RPi to sdcard
43 gen Generate a new SliTaz RPi distro
44 cook-linux Build the Raspberry Pi Linux kernel
45 get-linux Get the SliTaz RPi linux package
46 clone-fw Clone the RPi firmware repository
47 get-prebuilt Get a prebuilt SliTaz ARM toolchain
48 clean Clean the current work directory
49 release Release an installable tarball
51 $(boldify "Options:")
52 --nosat Don't regenerate the distro with sat
53 --nopatch Don't patch the kernel before cooking
54 --gconfig Configure the kernel before cooking
55 --fbtft Try to compile the Framebuffer touch screen driver
57 EOT
58 }
60 error() {
61 echo "[ $(colorize 31 'ERROR') ] $@"
62 }
64 header() {
65 newline && colorize 35 "$@" && separator
66 }
68 # Get all RPi firmware
69 clone_fw() {
70 [ -d "${rpi_git}/firmware" ] && return 0
71 mkdir -p ${rpi_git} && cd ${rpi_git}
72 git clone --depth 1 ${rpi_git_url}firmware.git
73 }
75 umount_sd() {
76 umount /dev/${dev}1 2>/dev/null || exit 1
77 umount /dev/${dev}3 2>/dev/null || exit 1
78 }
80 #
81 # Commands
82 #
84 case "$1" in
85 info)
86 header "SliTaz Raspberry Pi info"
87 echo "RPi path : $rpi"
88 colorize 36 "/boot/cmdline.txt:"
89 cat ${boot}/cmdline.txt
90 colorize 36 "/boot/config.txt:"
91 cat ${boot}/config.txt
92 separator && newline ;;
94 install)
95 rpiboot="/media/rpi/boot"
96 rpiroot="/media/rpi/rootfs"
97 header "SliTaz Raspberry Pi install"
98 if [ ! "$dev" ]; then
99 echo -n "SD card disk name (ex sdc): "; read dev
100 fi
101 [ ! "$dev" ] && exit 1
103 # Store sdcard partition(s) list
104 fdisk -l /dev/${dev} | grep "^/dev/$dev" | awk '{print $1}' \
105 > ${cache}/sdcard.part
106 partnb=$(cat ${cache}/sdcard.part | wc -l)
107 if [ "$partnb" != 3 ]; then
108 error "SliTaz RPi needs 3 partitions on the sdcard"
109 newline && exit 1
110 fi
112 # Mount sdcard
113 if mount | grep -q "^/dev/$dev[1-3]"; then
114 debug "Unmounting: /dev/$dev"
115 umount_sd
116 fi
117 echo -n "Mounting: /dev/$dev partitions"
118 mkdir -p ${rpiboot} ${rpiroot}
119 mount /dev/${dev}1 ${rpiboot} || exit 1
120 mount /dev/${dev}3 ${rpiroot} || exit 1
121 status
122 echo -n "Cleaning: filesystem directories"
123 for dir in bin dev etc lib media mnt proc sbin sys tmp usr var run
124 do
125 rm -rf ${rpiroot}/${dir}
126 done; status
127 echo -n "Installing: boot files"
128 cp -rf ${boot}/* ${rpiboot}; status
129 echo -n "Installing: rootfs files"
130 cp -a ${rootfs}/* ${rpiroot}; status
132 # Unmount
133 echo -n "Unmounting: RPi sdcard"
134 umount_sd; status
136 rm -f ${cache}/sdcard.part
137 separator
138 echo "Insert the SD card into your Raspberry Pi and boot!"
139 newline ;;
141 gen)
142 # Separate boot files since the Raspberry Pi boots off a FAT32 /boot
143 # partition on the sdcard.
144 : ${flavor=rpi-base}
146 # Use the rootfs generated by sat
147 if [ ! -x "/usr/bin/sat" ]; then
148 error "Sat is not installed" && exit 1
149 fi
150 check_root
152 # We may want to simply regenerate the RPi distro
153 if [ ! "$nosat" ]; then
154 sat gen --work="$work" --flavor="$flavor" \
155 --noinit --nolinux || exit 1
156 else
157 newline
158 fi
160 colorize 35 "SliTaz Raspberry Pi distro"
161 separator
162 mkdir -p ${boot}
164 # Custom RPi rootfs: make sure all files belong to root
165 if [ -d "$rpi/rootfs" ]; then
166 size=$(du -sh $rpi/rootfs | awk '{print $1}')
167 echo -n "Copying custom RPi rootfs: $size"
168 tmp=$distro/tmp-$$
169 mkdir -p $tmp
170 cp -r $rpi/rootfs/* $tmp
171 chown -R root.root $tmp
172 cp -a $tmp/* ${rootfs} && rm -rf $tmp
173 mv -f ${rootfs}/boot/* ${boot}
174 status
175 fi
177 # TazBerry, Piboot, Pileds, ...
178 for tool in tazberry piboot pileds
179 do
180 echo -n "Copying utility: $tool"
181 cp -f ${rpi}/${tool} ${rootfs}/usr/sbin
182 status
183 done
185 # CGI Plugins
186 echo -n "Copying CGI/adm plugins..."
187 cp -a ${rpi}/cgi-adm/* ${rootfs}/var/www/adm
188 status
190 # Kernel at last
191 . $cache/linux-*-arm/receipt
192 kvers="$VERSION"
193 kpkg="$rootfs/var/lib/tazpkg/installed/linux"
194 fs="$cache/linux-$kvers-arm/fs"
195 ksize=$(du -sh $fs | awk '{print $1}')
196 if [ -d "$fs" ]; then
197 echo -n "Copying: kernel $kvers ($ksize)"
198 rm -rf ${rootfs}/lib/modules
199 cp -rf ${fs}/lib/* ${rootfs}/lib
200 cp -f ${fs}/boot/* ${boot}
201 mkdir -p ${kpkg}
202 cd ${cache}/linux-${kvers}-arm
203 cp -f files.list md5sum receipt ${kpkg}
204 status
205 else
206 echo "SliTaz RPi Kernel: not used"
207 fi
209 separator
210 echo -n "Boot: $(du -sh $boot | awk '{print $1}') "
211 echo "- Rootfs: $(du -sh $rootfs | awk '{print $1}')"
212 newline ;;
214 cook-linux)
215 # Native SliTaz Toolchain and cross toolchain must be installed
216 check_root
217 install="$cache/linux-install"
218 if [ ! -d "/cross/$arch" ]; then
219 error "Missing cross toolchain in: /cross/$arch" && exit 1
220 fi
222 # Kernel source and --clean
223 mkdir -p ${rpi_git} && cd ${rpi_git}
224 [ -d "$kernel" ] || git clone --depth 1 ${rpi_git_url}linux.git
225 [ "$clean" ] && rm -rf ${install}
227 # FBtft drivers for small touchscreens such PiTFT, PiScreen
228 if [ "$fbtft" ] && [ ! -d "${kernel}/drivers/video/fbtft" ]; then
229 cd ${kernel}/drivers/video
230 #git clone git://github.com/notro/fbtft.git
231 git clone https://github.com/adafruit/adafruit-rpi-fbtft
232 mv adafruit-rpi-fbtft fbtft
233 cd ${kernel}
234 echo 'source "drivers/video/fbtft/Kconfig"' >> drivers/video/Kconfig
235 echo 'obj-y += fbtft/' >> drivers/video/Makefile
236 cd ${rpi_git}
237 fi
239 # Compile
240 if [ ! -d "$install" ]; then
241 cd ${kernel}
242 export PATH=$PATH:/cross/${arch}/tools/bin
243 export HOST_SYSTEM=${arch}-slitaz-linux-gnueabi
244 make mrproper &&
245 make ARCH=arm bcmrpi_defconfig
246 if [ ! "$nopatch" ]; then
247 echo "Patching SliTaz RPi Linux .config"
248 patch -p0 -i ${data}/linux-rpi.patch || exit 1
249 fi
250 [ "$gconfig" ] && make ARCH=arm gconfig
251 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- zImage &&
252 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- modules &&
253 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- \
254 INSTALL_MOD_PATH=${install} modules_install || exit 1
255 mkdir -p ${install}/boot
256 cp -a arch/arm/boot/zImage ${install}/boot/kernel.img
257 fi
259 # Kernel version
260 kvers=$(ls ${install}/lib/modules)
261 kvers=${kvers%-tazberry+}+
263 # Compress modules
264 #cd ${install}/lib/modules/*/kernel || exit 1
265 #mods=$(find . -name "*.ko$" | wc -l)
266 #newline
267 #echo "Compressing kernel modules: $mods"
268 #find . -name "*.ko$" -exec xz '{}' \; 2> /dev/null
270 # Rebuild modules.dep
271 cd ${install}
272 depmod -b . ${kvers%+}-tazberry+
274 # Kernel
275 pkg="linux"
276 [ "$fbtft" ] && pkg="linux-fbtft"
277 fs="$cache/$pkg-$kvers-arm/fs"
278 echo "Kernel version: $kvers"
279 if [ -d "$install" ]; then
280 rm -rf ${cache}/${pkg}-${kvers}-arm
281 mkdir -p ${fs}
282 cp -a ${install}/* ${fs}
283 rm -f ${fs}/lib/modules/*/build \
284 ${fs}/lib/modules/*/source
285 else
286 echo "Kernel is not built..." && exit 1
287 fi
289 # Pack .tazpkg
290 cd ${cache}
291 echo "Creating package: receipt"
292 cat > ${pkg}-${kvers}-arm/receipt << EOT
293 # SliTaz package receipt
295 PACKAGE="${pkg}"
296 VERSION="$kvers"
297 SHORT_DESC="SliTaz GNU/Linux Kernel for the Raspberry Pi."
298 MAINTAINER="pankso@slitaz.org"
299 WEB_SITE="http://www.kernel.org"
300 HOST_ARCH="arm"
302 EOT
303 tazpkg pack ${pkg}-${kvers}-arm ;;
305 clone-fw)
306 clone_fw ;;
308 get-linux)
309 # Precook RPi kernel
310 check_root
311 mkdir -p ${cache}
313 # Last version
314 rm -f ${cache}/linux-version.txt
315 if busybox wget -q -s ${rpi_mirror}/packages/last-linux.txt; then
316 echo -n "Fetching latest Kernel string..."
317 wget -q ${rpi_mirror}/packages/last-linux.txt \
318 -O ${cache}/linux-version.txt || exit 1
319 status
320 else
321 echo "Mirror is unreachable" && exit 1
322 fi
323 kvers=$(cat $cache/linux-version.txt)
324 [ "$up" ] && rm -rf ${cache}/linux-${kvers}*
325 echo "Kernel version: $kvers"
327 # Download
328 if [ ! -f "$cache/linux-$kvers.tazpkg" ]; then
329 echo -n "Fetching latest Linux package..."
330 wget -q ${rpi_mirror}/packages/linux-${kvers}.tazpkg \
331 -O ${cache}/linux-${kvers}.tazpkg; status
332 fi
334 # Extract
335 if [ ! -d "$cache/linux-$kvers" ]; then
336 cd ${cache} && tazpkg extract linux-${kvers}.tazpkg
337 fi
338 rm -f ${cache}/linux-version.txt ;;
340 get-prebuilt)
341 # --> in cross ??
342 : ${arch=arm}
343 name="slitaz-$arch-toolchain"
344 vers="20140304"
345 tarball="$name-$vers.tar.bz2"
346 url="http://mirror.slitaz.org/packages/cross/"
347 mkdir -p /cross
348 cd /cross
349 if [ ! -f "$tarball" ]; then
350 if busybox wget -qs ${url%/}/${tarball}; then
351 busybox wget ${url%/}/${tarball}
352 else
353 echo "Toolchain URL is unreachable" && exit 1
354 fi
355 fi
356 if [ ! -d "${name}-${vers}" ]; then
357 echo "Extracting: $tarball"
358 tar xjf ${tarball}
359 fi
360 echo "Copying: ${name}-${vers}/${arch}"
361 mkdir -p ${arch}
362 cp -a ${name}-${vers}/${arch}/* ${arch}
363 echo "Tools path: /cross/${arch}/tools/bin" ;;
365 release)
366 # Used to release official SliTaz RPi images
367 cd ${distro} || exit 1
368 if [ ! "$flavor" ]; then
369 . $distro/rootfs/etc/slitaz/flavor.conf || exit 1
370 flavor="$FLAVOR"
371 fi
372 dname="slitaz-$flavor-$(date +%Y%m%d)"
373 dsize=$(du -sh $distro | awk '{print $1}' | cut -d "." -f 1)
374 rm -rf ${dname} && mkdir ${dname}
375 cp -a boot rootfs ${dname}
376 echo "Copying: SliTaz release files"
377 cp ${rpi}/release/* ${dname}
378 echo "Creating: ${dname}.tar.bz2"
379 tar -cjf ${dname}.tar.bz2 ${dname}
380 echo "Creating: ${dname}.md5"
381 md5sum ${dname}.tar.bz2 > ${dname}.md5
382 rm -rf ${dname} ;;
384 clean)
385 echo "Cleaning: $rpi"
386 rm -rf ${cache} ${rpi_git} ;;
388 *|*help) usage ;;
389 esac
390 exit 0