slitaz-arm view sat-rpi @ rev 207
tazbian: check for model 1 in postinstall
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Aug 08 23:42:01 2015 +0200 (2015-08-08) |
parents | abffc259e9cb |
children |
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 raspicomm piface pitft-setup \
179 pibrella piborg/piborg
180 do
181 echo -n "Copying utility: $tool"
182 cp -f ${rpi}/${tool} ${rootfs}/usr/sbin
183 status
184 done
186 # CGI Plugins
187 echo -n "Copying CGI/adm plugins..."
188 cp -a ${rpi}/cgi-adm/* ${rootfs}/var/www/adm
189 status
191 # Kernel at last
192 . $cache/linux-*-arm/receipt
193 kvers="$VERSION"
194 kpkg="$rootfs/var/lib/tazpkg/installed/linux"
195 fs="$cache/linux-$kvers-arm/fs"
196 ksize=$(du -sh $fs | awk '{print $1}')
197 if [ -d "$fs" ]; then
198 echo -n "Copying: kernel $kvers ($ksize)"
199 rm -rf ${rootfs}/lib/modules
200 cp -rf ${fs}/lib/* ${rootfs}/lib
201 cp -f ${fs}/boot/* ${boot}
202 mkdir -p ${kpkg}
203 cd ${cache}/linux-${kvers}-arm
204 cp -f files.list md5sum receipt ${kpkg}
205 status
206 else
207 echo "SliTaz RPi Kernel: not used"
208 fi
210 separator
211 echo -n "Boot: $(du -sh $boot | awk '{print $1}') "
212 echo "- Rootfs: $(du -sh $rootfs | awk '{print $1}')"
213 newline ;;
215 cook-linux)
216 # Native SliTaz Toolchain and cross toolchain must be installed
217 check_root
218 install="$cache/linux-install"
219 if [ ! -d "/cross/$arch" ]; then
220 error "Missing cross toolchain in: /cross/$arch" && exit 1
221 fi
223 # Kernel source and --clean
224 mkdir -p ${rpi_git} && cd ${rpi_git}
225 [ -d "$kernel" ] || git clone --depth 1 ${rpi_git_url}linux.git
226 [ "$clean" ] && rm -rf ${install}
228 # FBtft drivers for small touchscreens such PiTFT, PiScreen
229 if [ "$fbtft" ] && [ ! -d "${kernel}/drivers/video/fbtft" ]; then
230 cd ${kernel}/drivers/video
231 #git clone git://github.com/notro/fbtft.git
232 git clone https://github.com/adafruit/adafruit-rpi-fbtft
233 mv adafruit-rpi-fbtft fbtft
234 cd ${kernel}
235 echo 'source "drivers/video/fbtft/Kconfig"' >> drivers/video/Kconfig
236 echo 'obj-y += fbtft/' >> drivers/video/Makefile
237 cd ${rpi_git}
238 fi
240 # Compile
241 if [ ! -d "$install" ]; then
242 cd ${kernel}
243 export PATH=$PATH:/cross/${arch}/tools/bin
244 export HOST_SYSTEM=${arch}-slitaz-linux-gnueabi
245 make mrproper &&
246 make ARCH=arm bcmrpi_defconfig
247 if [ ! "$nopatch" ]; then
248 echo "Patching SliTaz RPi Linux .config"
249 patch -p0 -i ${data}/linux-rpi.patch || exit 1
250 fi
251 [ "$gconfig" ] && make ARCH=arm gconfig
252 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- zImage &&
253 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- modules &&
254 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- \
255 INSTALL_MOD_PATH=${install} modules_install || exit 1
256 mkdir -p ${install}/boot
257 cp -a arch/arm/boot/zImage ${install}/boot/kernel.img
258 fi
260 # Kernel version
261 kvers=$(ls ${install}/lib/modules)
262 kvers=${kvers%-tazberry+}+
264 # Compress modules
265 #cd ${install}/lib/modules/*/kernel || exit 1
266 #mods=$(find . -name "*.ko$" | wc -l)
267 #newline
268 #echo "Compressing kernel modules: $mods"
269 #find . -name "*.ko$" -exec xz '{}' \; 2> /dev/null
271 # Rebuild modules.dep
272 cd ${install}
273 depmod -b . ${kvers%+}-tazberry+
275 # Kernel
276 pkg="linux"
277 [ "$fbtft" ] && pkg="linux-fbtft"
278 fs="$cache/$pkg-$kvers-arm/fs"
279 echo "Kernel version: $kvers"
280 if [ -d "$install" ]; then
281 rm -rf ${cache}/${pkg}-${kvers}-arm
282 mkdir -p ${fs}
283 cp -a ${install}/* ${fs}
284 rm -f ${fs}/lib/modules/*/build \
285 ${fs}/lib/modules/*/source
286 else
287 echo "Kernel is not built..." && exit 1
288 fi
290 # Pack .tazpkg
291 cd ${cache}
292 echo "Creating package: receipt"
293 cat > ${pkg}-${kvers}-arm/receipt << EOT
294 # SliTaz package receipt
296 PACKAGE="${pkg}"
297 VERSION="$kvers"
298 SHORT_DESC="SliTaz GNU/Linux Kernel for the Raspberry Pi."
299 MAINTAINER="pankso@slitaz.org"
300 WEB_SITE="http://www.kernel.org"
301 HOST_ARCH="arm"
303 EOT
304 tazpkg pack ${pkg}-${kvers}-arm ;;
306 clone-fw)
307 clone_fw ;;
309 get-linux)
310 # Precook RPi kernel
311 check_root
312 mkdir -p ${cache}
314 # Last version
315 rm -f ${cache}/linux-version.txt
316 if busybox wget -q -s ${rpi_mirror}/packages/last-linux.txt; then
317 echo -n "Fetching latest Kernel string..."
318 wget -q ${rpi_mirror}/packages/last-linux.txt \
319 -O ${cache}/linux-version.txt || exit 1
320 status
321 else
322 echo "Mirror is unreachable" && exit 1
323 fi
324 kvers=$(cat $cache/linux-version.txt)
325 [ "$up" ] && rm -rf ${cache}/linux-${kvers}*
326 echo "Kernel version: $kvers"
328 # Download
329 if [ ! -f "$cache/linux-$kvers.tazpkg" ]; then
330 echo -n "Fetching latest Linux package..."
331 wget -q ${rpi_mirror}/packages/linux-${kvers}-arm.tazpkg \
332 -O ${cache}/linux-${kvers}-arm.tazpkg; status
333 fi
335 # Extract
336 if [ ! -d "$cache/linux-$kvers" ]; then
337 cd ${cache} && tazpkg extract linux-${kvers}-arm.tazpkg
338 fi
339 rm -f ${cache}/linux-version.txt ;;
341 get-prebuilt)
342 # --> in cross ??
343 : ${arch=arm}
344 name="slitaz-$arch-toolchain"
345 vers="20140304"
346 tarball="$name-$vers.tar.bz2"
347 url="http://mirror.slitaz.org/packages/cross/"
348 mkdir -p /cross
349 cd /cross
350 if [ ! -f "$tarball" ]; then
351 if busybox wget -qs ${url%/}/${tarball}; then
352 busybox wget ${url%/}/${tarball}
353 else
354 echo "Toolchain URL is unreachable" && exit 1
355 fi
356 fi
357 if [ ! -d "${name}-${vers}" ]; then
358 echo "Extracting: $tarball"
359 tar xjf ${tarball}
360 fi
361 echo "Copying: ${name}-${vers}/${arch}"
362 mkdir -p ${arch}
363 cp -a ${name}-${vers}/${arch}/* ${arch}
364 echo "Tools path: /cross/${arch}/tools/bin" ;;
366 release)
367 # Used to release official SliTaz RPi images
368 cd ${distro} || exit 1
369 if [ ! "$flavor" ]; then
370 . $distro/rootfs/etc/slitaz/flavor.conf || exit 1
371 flavor="$FLAVOR"
372 fi
373 dname="slitaz-$flavor-$(date +%Y%m%d)"
374 dsize=$(du -sh $distro | awk '{print $1}' | cut -d "." -f 1)
375 rm -rf ${dname} && mkdir ${dname}
376 cp -a boot rootfs ${dname}
377 echo "Copying: SliTaz release files"
378 cp ${rpi}/release/* ${dname}
379 echo "Creating: ${dname}.tar.bz2"
380 tar -cjf ${dname}.tar.bz2 ${dname}
381 echo "Creating: ${dname}.md5"
382 md5sum ${dname}.tar.bz2 > ${dname}.md5
383 rm -rf ${dname} ;;
385 clean)
386 echo "Cleaning: $rpi"
387 rm -rf ${cache} ${rpi_git} ;;
389 *|*help) usage ;;
390 esac
391 exit 0