slitaz-arm view sat-rpi @ rev 89
Rpi install: no cp -a for FAT32, add tazberry desktop entry
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sun Apr 06 14:50:56 2014 +0200 (2014-04-06) |
parents | bfdc7cc1c657 |
children | 232f979c80ea |
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
54 release Release an installable tarball
56 $(boldify "Options:")
57 --up Update for commands: firmware and kernel
58 --turbo Force the RPi to run at the highest arm_freq
59 --oclock= Set the RPi overclocking mode in config.txt
60 --vc Install the RPi VC libraries in /opt/vc
61 --nosat Don't regenerate the distro with sat
63 EOT
64 }
66 error() {
67 echo "[ $(colorize 31 'ERROR') ] $@"
68 }
70 header() {
71 newline && colorize 35 "$@" && separator
72 }
74 # Get minimal RPi firmware
75 get_fw() {
76 mkdir -p $firmware/boot
77 for fw in $fwlist
78 do
79 [ "$up" ] && rm -f $firmware/boot/$fw
80 if [ ! -f "$firmware/boot/$fw" ]; then
81 echo -n "Fetching: $fw"
82 wget -q --no-check-certificate ${fw_url}${fw} \
83 -O $firmware/boot/${fw}; status
84 fi
85 done
86 }
88 # Get all RPi firmware
89 clone_fw() {
90 [ -d "${rpi_git}/firmware" ] && return 0
91 mkdir -p ${rpi_git} && cd ${rpi_git}
92 git clone --depth 1 ${rpi_git_url}firmware.git
93 }
95 # --> will move to tazberry
96 set_oclock() {
97 case "$oclock" in
98 none)
99 arm_freq=700
100 core_freq=250
101 sdram_freq=400
102 over_voltage=0 ;;
103 modest)
104 arm_freq=800
105 core_freq=300
106 sdram_freq=400
107 over_voltage=0 ;;
108 medium)
109 arm_freq=900
110 core_freq=333
111 sdram_freq=450
112 over_voltage=2 ;;
113 hight)
114 arm_freq=950
115 core_freq=450
116 sdram_freq=450
117 over_voltage=6 ;;
118 turbo)
119 arm_freq=1000
120 core_freq=500
121 sdram_freq=500
122 over_voltage=6 ;;
123 esac
124 cat >> ${boot}/config.txt << EOT
125 arm_freq=$arm_freq
126 core_freq=$core_freq
127 sdram_freq=$sdram_freq
128 over_voltage=$over_voltage
129 EOT
130 }
132 umount_sd() {
133 umount /dev/${dev}1 2>/dev/null || exit 1
134 umount /dev/${dev}3 2>/dev/null || exit 1
135 }
137 #
138 # Commands
139 #
141 case "$1" in
142 info)
143 header "SliTaz Raspberry Pi info"
144 echo "Firmware : $fwlist"
145 echo "RPi path : $rpi"
146 colorize 36 "/boot/cmdline.txt:"
147 cat ${boot}/cmdline.txt
148 colorize 36 "/boot/config.txt:"
149 cat ${boot}/config.txt
150 separator && newline ;;
152 install)
153 rpiboot="/media/rpi/boot"
154 rpiroot="/media/rpi/rootfs"
155 header "SliTaz Raspberry Pi install"
156 if [ ! "$dev" ]; then
157 echo -n "SD card disk name (ex sdc): "; read dev
158 fi
159 [ ! "$dev" ] && exit 1
161 # Store sdcard partition(s) list
162 fdisk -l /dev/${dev} | grep "^/dev/$dev" | awk '{print $1}' \
163 > ${data}/sdcard.part
164 partnb=$(cat ${data}/sdcard.part | wc -l)
165 if [ "$partnb" != 3 ]; then
166 error "SliTaz RPi needs 3 partitions on the sdcard"
167 newline && exit 1
168 fi
170 # Mount sdcard
171 if mount | grep -q "^/dev/$dev[1-3]"; then
172 debug "Unmounting: /dev/$dev"
173 umount_sd
174 fi
175 echo -n "Mounting: /dev/$dev partitions"
176 mkdir -p ${rpiboot} ${rpiroot}
177 mount /dev/${dev}1 ${rpiboot} || exit 1
178 mount /dev/${dev}3 ${rpiroot} || exit 1
179 status
180 echo -n "Cleaning: filesystem directories"
181 for dir in bin dev etc lib media mnt proc sbin sys tmp usr var run
182 do
183 rm -rf ${rpiroot}/${dir}
184 done; status
185 echo -n "Installing: boot files"
186 cp -rf ${boot}/* ${rpiboot}; status
187 echo -n "Installing: rootfs files"
188 cp -a ${rootfs}/* ${rpiroot}; status
190 # Unmount
191 echo -n "Unmounting: RPi sdcard"
192 umount_sd; status
194 rm -f ${data}/sdcard.part
195 separator
196 echo "Insert the SD card into your Raspberry Pi and boot!"
197 newline ;;
199 ls-dev)
200 newline
201 fdisk -l | grep "^Disk /dev/sd*"
202 newline ;;
204 gen)
205 # Separate boot files since the Raspberry Pi boots off a FAT32 /boot
206 # partition on the sdcard.
207 : ${flavor=rpi-base}
208 : ${oclock=none}
210 # Use the rootfs generated by sat
211 if [ ! -x "/usr/bin/sat" ]; then
212 error "Sat is not installed" && exit 1
213 fi
214 check_root
216 # We may want to simply regenerate the RPi distro
217 if [ ! "$nosat" ]; then
218 sat gen --work="$work" --flavor="$flavor" --noinit --nolinux
219 else
220 newline
221 fi
223 colorize 35 "SliTaz Raspberry Pi distro"
224 separator
225 mkdir -p ${boot}
227 # Custom RPi rootfs: make sure all files belong to root
228 if [ -d "$rpi/rootfs" ]; then
229 size=$(du -sh $rpi/rootfs | awk '{print $1}')
230 echo -n "Copying custom RPi rootfs: $size"
231 tmp=$distro/tmp-$$
232 mkdir -p $tmp
233 cp -r $rpi/rootfs/* $tmp
234 chown -R root.root $tmp
235 cp -a $tmp/* ${rootfs} && rm -rf $tmp
236 mv -f ${rootfs}/boot/* ${boot}
237 status
238 fi
240 # Boot firmware
241 echo -n "Copying: firmware files..."
242 get_fw
243 for fw in $fwlist
244 do
245 cp ${firmware}/boot/${fw} ${boot}
246 done
247 status
249 # TazBerry
250 echo -n "Copying: TazBerry..."
251 cp -f ${rpi}/tazberry ${rootfs}/usr/bin
252 cp -a ${rpi}/cgi-adm/* ${rootfs}/var/www/adm
253 status
255 # Overclocking
256 echo -n "Setting: Overclocking..."
257 set_oclock; status
259 # Force turbo
260 if [ "$turbo" ]; then
261 if ! fgrep 'force_turbo=1' ${boot}/config.txt; then
262 echo -n "Config: force_turbo=1"
263 echo "force_turbo=1" >> ${boot}/config.txt; status
264 fi
265 fi
267 # RPi VC libraries
268 if [ "$vc" ]; then
269 vc="${rootfs}/opt/vc"
270 if [ ! -d "$firmware/opt/vc" ]; then
271 error "Missing firmware git repository" && exit 1
272 fi
273 echo -n "Copying: standard VC libraries"
274 cp -a ${firmware}/opt ${rootfs}
275 # --> armv6hf
276 #cp -a ${firmware}/hardfp/opt ${rootfs}
277 chown -R root.root ${rootfs}/opt
278 status
279 echo -n "Cleaning: VC libraries devel files"
280 cross_tools="/cross/${arch}/tools/bin"
281 rm -rf ${vc}/include ${vc}/src ${vc}/lib/*.a
282 ${cross_tools}/${arch}-slitaz-linux-gnueabi-strip -s ${vc}/lib/*.so
283 status
284 fi
286 # Kernel at last
287 . $data/linux-*/receipt
288 kvers="$VERSION"
289 kpkg="$rootfs/var/lib/tazpkg/installed/linux"
290 fs="$data/linux-$kvers/fs"
291 ksize=$(du -sh $fs | awk '{print $1}')
292 if [ -d "$fs" ]; then
293 echo -n "Copying: kernel $kvers ($ksize)"
294 rm -rf ${rootfs}/lib/modules
295 cp -rf ${fs}/lib/* ${rootfs}/lib
296 cp -f ${fs}/boot/* ${boot}
297 mkdir -p ${kpkg}
298 cd ${data}/linux-${kvers}
299 cp -f files.list md5sum receipt ${kpkg}
300 status
301 else
302 echo "SliTaz RPi Kernel: not used"
303 fi
305 separator
306 echo -n "Boot: $(du -sh $boot | awk '{print $1}') "
307 echo "- Rootfs: $(du -sh $rootfs | awk '{print $1}')"
308 newline ;;
310 cook-linux)
311 # Native SliTaz Toolchain and cross toolchain must be installed
312 check_root
313 install="$data/linux-install"
314 if [ ! -d "/cross/$arch" ]; then
315 error "Missing cross toolchain in: /cross/$arch" && exit 1
316 fi
318 # Kernel source
319 cd ${rpi_git}
320 [ -d "$kernel" ] || git clone --depth 1 ${rpi_git_url}linux.git
322 # Compile
323 [ "$clean" ] && rm -rf ${install}
324 if [ ! -d "$install" ]; then
325 cd ${kernel}
326 export PATH=$PATH:/cross/${arch}/tools/bin
327 export HOST_SYSTEM=${arch}-slitaz-linux-gnueabi
328 make mrproper &&
329 make ARCH=arm bcmrpi_defconfig
330 echo "Patching SliTaz RPi Linux .config"
331 patch -p0 -i ${rpi}/linux-rpi.patch || exit 1
332 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- zImage &&
333 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- modules &&
334 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- \
335 INSTALL_MOD_PATH=${install} modules_install || exit 1
336 mkdir -p ${install}/boot
337 cp -a arch/arm/boot/zImage ${install}/boot/kernel.img
338 fi
340 # Kernel version
341 kvers=$(ls ${install}/lib/modules)
342 kvers=${kvers%-slitaz-rpi+}+
344 # Compress modules
345 cd ${install}/lib/modules/${kvers%+}-slitaz-rpi+/ || exit 1
346 mods=$(find . -name "*.ko$" | wc -l)
347 newline
348 echo "Compressing kernel modules: $mods"
349 find . -name "*.ko$" -exec gzip '{}' \; #2> /dev/null
351 # Rebuild modules.dep
352 cd ${install}
353 depmod -b . ${kvers%+}-slitaz-rpi+
355 # Kernel
356 fs="$data/linux-$kvers/fs"
357 echo "Kernel version: $kvers"
358 if [ -d "$install" ]; then
359 rm -rf ${data}/linux-${kvers}
360 mkdir -p ${data}/linux-${kvers}
361 cp -a ${install} ${fs}
362 rm -f ${fs}/lib/modules/*/build \
363 ${fs}/lib/modules/*/source
364 fi
366 # Pack .tazpkg
367 cd ${data}
368 echo "Creating package: receipt"
369 cat > linux-$kvers/receipt << EOT
370 # SliTaz package receipt
372 PACKAGE="linux"
373 VERSION="$kvers"
374 SHORT_DESC="SliTaz Linux Kernel for the Raspberry Pi."
375 WEB_SITE="http://www.kernel.org"
377 EOT
378 tazpkg pack linux-$kvers ;;
380 get-fw)
381 get_fw ;;
383 clone-fw)
384 clone_fw ;;
386 get-linux)
387 # Precook RPi kernel
388 check_root
389 mkdir -p ${data}
391 # Last version
392 rm -f ${data}/linux-version.txt
393 if busybox wget -q -s ${rpi_mirror}/last-linux.txt; then
394 echo -n "Fetching latest Kernel string..."
395 wget -q ${rpi_mirror}/last-linux.txt \
396 -O ${data}/linux-version.txt || exit 1
397 status
398 else
399 echo "Mirror is unreachable" && exit 1
400 fi
401 kvers=$(cat $data/linux-version.txt)
402 [ "$up" ] && rm -rf ${data}/linux-${kvers}*
403 echo "Kernel version: $kvers"
405 # Download
406 if [ ! -f "$data/linux-$kvers.tazpkg" ]; then
407 echo -n "Fetching latest Linux package..."
408 wget -q ${rpi_mirror}/linux-${kvers}.tazpkg \
409 -O ${data}/linux-${kvers}.tazpkg; status
410 fi
412 # Extract
413 if [ ! -d "$data/linux-$kvers" ]; then
414 cd ${data} && tazpkg extract linux-${kvers}.tazpkg
415 fi
416 rm -f ${data}/linux-version.txt ;;
418 get-prebuilt)
419 # --> in cross ??
420 : ${arch=arm}
421 name="slitaz-$arch-toolchain"
422 vers="20140304"
423 tarball="$name-$vers.tar.bz2"
424 url="http://mirror.slitaz.org/packages/cross/"
425 mkdir -p /cross
426 cd /cross
427 if [ ! -f "$tarball" ]; then
428 if busybox wget -qs ${url%/}/${tarball}; then
429 busybox wget ${url%/}/${tarball}
430 else
431 echo "Toolchain URL is unreachable" && exit 1
432 fi
433 fi
434 if [ ! -d "${name}-${vers}" ]; then
435 echo "Extracting: $tarball"
436 tar xjf ${tarball}
437 fi
438 echo "Copying: ${name}-${vers}/${arch}"
439 mkdir -p ${arch}
440 cp -a ${name}-${vers}/${arch}/* ${arch}
441 echo "Tools path: /cross/${arch}/tools/bin" ;;
443 release)
444 # Used to release official SliTaz RPi images
445 cd ${distro} || exit 1
446 if [ ! "$flavor" ]; then
447 . $distro/rootfs/etc/slitaz/flavor.conf || exit 1
448 flavor="$FLAVOR"
449 fi
450 dname="slitaz-$flavor-$(date +%Y%m%d)"
451 dsize=$(du -sh $distro | awk '{print $1}' | cut -d "." -f 1)
452 rm -rf ${dname} && mkdir ${dname}
453 cp -a boot rootfs ${dname}
454 echo "Copying: SliTaz release files"
455 cp ${rpi}/release/* ${dname}
456 echo "Creating: ${dname}.tar.bz2"
457 tar -cjf ${dname}.tar.bz2 ${dname}
458 echo "Creating: ${dname}.md5"
459 md5sum ${dname}.tar.bz2 > ${dname}.md5
460 rm -rf ${dname} ;;
462 clean)
463 echo "Cleaning: $rpi"
464 rm -rf ${data} ${rpi_git} ;;
466 *|*help) usage ;;
467 esac
468 exit 0