slitaz-arm view sat-rpi @ rev 55
Finish sat-rpi release, some clean up and add suport for cgi-adm
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Fri Mar 14 00:00:28 2014 +0100 (2014-03-14) |
parents | f02931a2c41f |
children | e78c96840be9 |
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 tools="$rpi_git/tools"
25 # URLs
26 rpi_mirror="http://mirror.slitaz.org/arm/rpi/"
27 fw_url="https://github.com/raspberrypi/firmware/raw/master/boot/"
28 tools_url="https://raw.github.com/raspberrypi/tools/master/mkimage/"
29 rpi_git_url="git://github.com/raspberrypi/"
31 # Lists
32 fwlist="bootcode.bin fixup.dat start.elf"
33 toolslist="imagetool-uncompressed.py args-uncompressed.txt \
34 boot-uncompressed.txt"
36 #
37 # Functions
38 #
40 usage() {
41 cat << EOT
43 $(boldify "Usage:") $(basename $0) [command] [--option]
45 SliTaz Raspberry Pi Tool
47 $(boldify "Commands:")
48 info Display paths and distro info
49 install Install SliTaz RPi to sdcard
50 gen Generate a new SliTaz RPi distro
51 cook-linux Build the Raspberry Pi Linux kernel
52 get-linux Get the SliTaz RPi linux package
53 get-fw Download or update minimal RPi firmware
54 clone-fw Clone the RPi firmware repository
55 get-prebuilt Get a prebuilt SliTaz ARM toolchain
56 clean Clean the current work directory
58 $(boldify "Options:")
59 --up Update for commands: firmware, tools, kernel
60 --turbo Force the RPi to run at the highest arm_freq
61 --oclock= Set the RPi overclocking mode in config.txt
62 --vc Install the RPi VC libraries in /opt/vc
63 --nosat Don't regenerate the distro with sat
64 --git Remove RPi git files on clean up
66 EOT
67 }
69 error() {
70 echo "[ $(colorize 31 'ERROR') ] $@"
71 }
73 header() {
74 newline && boldify "$@" && separator
75 }
77 # Get minimal RPi firmware
78 get_fw() {
79 mkdir -p $firmware/boot
80 for fw in $fwlist
81 do
82 [ "$up" ] && rm -f $firmware/boot/$fw
83 if [ ! -f "$firmware/boot/$fw" ]; then
84 echo -n "Fetching: $fw"
85 wget -q --no-check-certificate ${fw_url}${fw} \
86 -O $firmware/boot/${fw}; status
87 fi
88 done
89 }
91 # Get all RPi firmware
92 clone_fw() {
93 [ -d "${rpi_git}/firmware" ] && return 0
94 mkdir -p ${rpi_git} && cd ${rpi_git}
95 git clone --depth 1 ${rpi_git_url}firmware.git
96 }
98 # --> will move to tazberry
99 set_oclock() {
100 case "$oclock" in
101 none)
102 arm_freq=700
103 core_freq=250
104 sdram_freq=400
105 over_voltage=0 ;;
106 modest)
107 arm_freq=800
108 core_freq=300
109 sdram_freq=400
110 over_voltage=0 ;;
111 medium)
112 arm_freq=900
113 core_freq=333
114 sdram_freq=450
115 over_voltage=2 ;;
116 hight)
117 arm_freq=950
118 core_freq=450
119 sdram_freq=450
120 over_voltage=6 ;;
121 turbo)
122 arm_freq=1000
123 core_freq=500
124 sdram_freq=500
125 over_voltage=6 ;;
126 esac
127 cat >> ${boot}/config.txt << EOT
128 arm_freq=$arm_freq
129 core_freq=$core_freq
130 sdram_freq=$sdram_freq
131 over_voltage=$over_voltage
132 EOT
133 }
135 #
136 # Commands
137 #
139 case "$1" in
140 info)
141 header "SliTaz Raspberry Pi info"
142 echo "Firmware : $fwlist"
143 echo "RPi path : $rpi"
144 colorize 36 "/boot/cmdline.txt:"
145 cat ${boot}/cmdline.txt
146 colorize 36 "/boot/config.txt:"
147 cat ${boot}/config.txt
148 separator && newline ;;
150 install)
151 rpiboot="/media/rpi/boot"
152 rpiroot="/media/rpi/rootfs"
153 header "SliTaz Raspberry Pi install"
154 if [ ! "$dev" ]; then
155 echo "Missing: --dev= cmdline option"
156 newline && exit 1
157 fi
159 # Store sdcard partition(s) list
160 fdisk -l /dev/${dev} | grep "^/dev/$dev" | awk '{print $1}' \
161 > ${data}/sdcard.part
162 partnb=$(cat ${data}/sdcard.part | wc -l)
163 if [ "$partnb" != 3 ]; then
164 error "SliTaz RPi needs 3 partitions on the sdcard"
165 newline && exit 1
166 fi
168 # Mount sdcard
169 if mount | grep -q "^/dev/$dev[1-3]"; then
170 debug "Unmounting: /dev/$dev"
171 umount /dev/${dev}1 2>/dev/null || exit 1
172 umount /dev/${dev}3 2>/dev/null || exit 1
173 fi
174 echo -n "Mounting: /dev/$dev partitions"
175 mkdir -p ${rpiboot} ${rpiroot}
176 mount /dev/${dev}1 ${rpiboot}
177 mount /dev/${dev}3 ${rpiroot}; status
178 echo -n "Cleaning: filesystem directories"
179 for dir in bin dev etc lib media mnt proc sbin sys tmp usr var run
180 do
181 rm -rf ${rpiroot}/${dir}
182 done; status
183 echo -n "Installing: boot files"
184 cp -rf ${boot}/* ${rpiboot}; status
185 echo -n "Installing: rootfs files"
186 cp -a ${rootfs}/* ${rpiroot}; status
188 # Unmount
189 echo -n "Unmounting: RPi sdcard"
190 umount ${rpiboot} || exit 1
191 umount ${rpiroot} || exit 1
192 status
194 rm -f ${data}/sdcard.part
195 separator && newline ;;
197 ls-dev)
198 newline
199 fdisk -l | grep "^Disk /dev/sd*"
200 newline ;;
202 gen)
203 # Separate boot files since the Raspberry Pi boots off a FAT32 /boot
204 # partition on the sdcard.
205 : ${flavor=rpi-base}
206 : ${oclock=none}
208 # Use the rootfs generated by sat
209 if [ ! -x "/usr/bin/sat" ]; then
210 error "Sat is not installed" && exit 1
211 fi
212 check_root
214 # We may want to simply regenerate the RPi distro
215 if [ ! "$nosat" ]; then
216 sat gen --work="$work" --flavor="$flavor" --kmap --noinit --nolinux
217 fi
219 header "SliTaz Raspberry Pi distro"
221 # Boot firmware
222 echo -n "Copying: firmware files..."
223 mkdir -p ${boot} && get_fw
224 for fw in $fwlist
225 do
226 cp ${firmware}/boot/${fw} ${boot}
227 done
228 status
230 # TazBerry
231 echo -n "Installing TazBerry..."
232 cp -f ${rpi}/tazberry ${rootfs}/usr/bin
233 status
235 # CGI Admin
236 #echo -n "Installing TazBerry CGI..."
237 #cp -a ${rpi}/cgi-adm/* ${rootfs}/var/www/adm
238 #status
240 # Overclocking
241 echo -n "Setting: Overclocking..."
242 set_oclock; status
244 # Force turbo
245 if [ "$turbo" ]; then
246 if ! fgrep 'force_turbo=1' ${boot}/config.txt; then
247 echo -n "Config: force_turbo=1"
248 echo "force_turbo=1" >> ${boot}/config.txt; status
249 fi
250 fi
252 # RPi VC libraries
253 if [ "$vc" ]; then
254 vc="${rootfs}/opt/vc"
255 if [ ! -d "$firmware/opt/vc" ]; then
256 error "Missing firmware git repository" && exit 1
257 fi
258 echo -n "Copying: standard VC libraries"
259 cp -a ${firmware}/opt ${rootfs}
260 # --> armv6hf
261 #cp -a ${firmware}/hardfp/opt ${rootfs}
262 chown -R root.root ${rootfs}/opt
263 status
264 echo -n "Cleaning: VC libraries devel files"
265 cross_tools="/cross/${arch}/tools/bin"
266 rm -rf ${vc}/include ${vc}/src ${vc}/lib/*.a
267 ${cross_tools}/${arch}-slitaz-linux-gnueabi-strip -s ${vc}/lib/*.so
268 status
269 fi
271 # Kernel at last
272 . $data/linux-*/receipt
273 kvers="$VERSION"
274 kpkg="$rootfs/var/lib/tazpkg/installed/linux"
275 fs="$data/linux-$kvers/fs"
276 ksize=$(du -sh $fs | awk '{print $1}')
277 if [ -d "$fs" ]; then
278 echo -n "Copying: kernel $kvers ($ksize)"
279 rm -rf ${rootfs}/lib/modules
280 cp -rf ${fs}/lib/* ${rootfs}/lib
281 cp -f ${fs}/boot/* ${boot}
282 mkdir -p ${kpkg}
283 cd ${data}/linux-${kvers}
284 cp -f files.list md5sum receipt ${kpkg}
285 status
286 else
287 echo "SliTaz RPi Kernel: not used"
288 fi
290 separator
291 echo -n "Boot: $(du -sh $boot | awk '{print $1}') "
292 echo "- Rootfs: $(du -sh $rootfs | awk '{print $1}')"
293 newline ;;
295 cook-linux)
296 # Native SliTaz Toolchain and cross toolchain must be installed
297 check_root
298 install="$data/linux-install"
299 if [ ! -d "/cross/$arch" ]; then
300 error "Missing cross toolchain in: /cross/$arch"
301 exit 1
302 fi
304 # Kernel source
305 cd ${rpi_git}
306 [ -d "$kernel" ] || git clone --depth 1 ${rpi_git_url}linux.git
308 # Compile
309 [ "$clean" ] && rm -rf ${install}
310 if [ ! -d "$install" ]; then
311 cd ${kernel}
312 export PATH=$PATH:/cross/${arch}/tools/bin
313 export HOST_SYSTEM=${arch}-slitaz-linux-gnueabi
314 make mrproper &&
315 make ARCH=arm bcmrpi_defconfig
316 echo "Patching SliTaz RPi Linux .config"
317 patch -p0 -i ${rpi}/linux-rpi.patch || exit 1
318 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- zImage &&
319 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- modules &&
320 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- \
321 INSTALL_MOD_PATH=${install} modules_install || exit 1
322 mkdir -p ${install}/boot
323 cp -a arch/arm/boot/zImage ${install}/boot/kernel.img
324 fi
326 # Kernel version
327 kvers=$(ls ${install}/lib/modules)
328 kvers=${kvers%-slitaz-rpi+}+
330 # Compress modules
331 cd ${install}/lib/modules/${kvers%+}-slitaz-rpi+/ || exit 1
332 mods=$(find . -name "*.ko$" | wc -l)
333 newline
334 echo "Compressing kernel modules: $mods"
335 find . -name "*.ko$" -exec gzip '{}' \; #2> /dev/null
337 # Rebuild modules.dep
338 cd ${install}
339 depmod -b . ${kvers%+}-slitaz-rpi+
341 # Kernel
342 fs="$data/linux-$kvers/fs"
343 echo "Kernel version: $kvers"
344 if [ -d "$install" ]; then
345 rm -rf ${data}/linux-${kvers}
346 mkdir -p ${data}/linux-${kvers}
347 cp -a ${install} ${fs}
348 rm -f ${fs}/lib/modules/*/build \
349 ${fs}/lib/modules/*/source
350 fi
352 # Pack .tazpkg
353 cd ${data}
354 echo "Creating package: receipt"
355 cat > linux-$kvers/receipt << EOT
356 # SliTaz package receipt
358 PACKAGE="linux"
359 VERSION="$kvers"
360 SHORT_DESC="SliTaz Linux Kernel for the Raspberry Pi."
361 WEB_SITE="http://www.kernel.org"
363 EOT
364 tazpkg pack linux-$kvers ;;
366 get-fw)
367 get_fw ;;
369 get-tools)
370 get_tools ;;
372 get-linux)
373 # Precook RPi kernel
374 check_root
375 mkdir -p ${data}
377 # Last version
378 rm -f ${data}/linux-version.txt
379 if busybox wget -q -s ${rpi_mirror}/last-linux.txt; then
380 echo -n "Fetching latest Kernel string..."
381 wget -q ${rpi_mirror}/last-linux.txt \
382 -O ${data}/linux-version.txt || exit 1
383 status
384 else
385 echo "Mirror is unreachable" && exit 1
386 fi
387 kvers=$(cat $data/linux-version.txt)
388 [ "$up" ] && rm -rf ${data}/linux-${kvers}*
389 echo "Kernel version: $kvers"
391 # Download
392 if [ ! -f "$data/linux-$kvers.tazpkg" ]; then
393 echo -n "Fetching latest Linux package..."
394 wget -q ${rpi_mirror}/linux-${kvers}.tazpkg \
395 -O ${data}/linux-${kvers}.tazpkg; status
396 fi
398 # Extract
399 if [ ! -d "$data/linux-$kvers" ]; then
400 cd ${data} && tazpkg extract linux-${kvers}.tazpkg
401 fi
402 rm -f ${data}/linux-version.txt ;;
404 get-prebuilt)
405 # --> in cross ??
406 : ${arch=arm}
407 name="slitaz-$arch-toolchain"
408 vers="20140304"
409 tarball="$name-$vers.tar.bz2"
410 url="http://mirror.slitaz.org/packages/cross/"
411 mkdir -p /cross
412 cd /cross
413 if [ ! -f "$tarball" ]; then
414 if busybox wget -qs ${url%/}/${tarball}; then
415 busybox wget ${url%/}/${tarball}
416 else
417 echo "Toolchain URL is unreachable" && exit 1
418 fi
419 fi
420 if [ ! -d "${name}-${vers}" ]; then
421 echo "Extracting: $tarball"
422 tar xjf ${tarball}
423 fi
424 echo "Copying: ${name}-${vers}/${arch}"
425 mkdir -p ${arch}
426 cp -a ${name}-${vers}/${arch}/* ${arch}
427 echo "Tools path: /cross/${arch}/tools/bin" ;;
429 clone-fw)
430 clone_fw ;;
432 release)
433 # Used to release official SliTaz RPi images
434 cd ${distro} || exit 1
435 if [ ! "$flavor" ]; then
436 . $distro/rootfs/etc/slitaz/flavor.conf || exit 1
437 flavor="$FLAVOR"
438 fi
439 dname="slitaz-$flavor-$(date +%Y%m%d)"
440 dsize=$(du -sh $distro | awk '{print $1}' | cut -d "." -f 1)
441 rm -rf ${dname} && mkdir ${dname}
442 cp -a boot rootfs ${dname}
443 cat > ${dname}/README << EOT
444 SliTaz Raspberry Pi - $flavor-$(date +%Y%m%d) - http://arm.slitaz.org/rpi
445 --------------------------------------------------------------------------------
447 boot/ : Must be copied to a FAT32 partition
448 rootfs/ : Must be copied to a ext4 or btrfs partition
450 Manual Installation. Assuming the sdcard is /dev/sdc and have got 3
451 partitions (boot,swap,root). Mount the sdcard, copy files, unmount:
453 # mkdir -p /media/rpi/boot /media/rpi/root
455 # mount /dev/sdc1 /media/rpi/boot
456 # mount /dev/sdc3 /media/rpi/root
458 # cp -a boot/* /media/rpi/boot
459 # cp -a rootfs/* /media/rpi/root
461 # umount /media/rpi/boot
462 # umount /media/rpi/root
464 --------------------------------------------------------------------------------
466 EOT
467 echo "Creating: ${dname}.tar.xz"
468 tar -cJf ${dname}.tar.xz ${dname}
469 echo "Creating: ${dname}.md5"
470 md5sum ${dname}.tar.xz > ${dname}.md5
471 rm -rf ${dname} ;;
473 clean)
474 echo "Cleaning: $rpi"
475 rm -rf ${data}
476 [ "$git" ] && rm -rf ${rpi_git} ;;
477 *) usage ;;
478 esac
479 exit 0