slitaz-arm view sat-rpi @ rev 54

Rename default rpi flavor to rpi-base
author Christophe Lincoln <pankso@slitaz.org>
date Thu Mar 13 23:17:34 2014 +0100 (2014-03-13)
parents bc8365a12dc7
children 2677c4a43ce8
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
75 boldify "$@"
76 separator
77 }
79 # Get minimal RPi firmware
80 get_fw() {
81 mkdir -p $firmware/boot
82 for fw in $fwlist
83 do
84 [ "$up" ] && rm -f $firmware/boot/$fw
85 if [ ! -f "$firmware/boot/$fw" ]; then
86 echo -n "Fetching: $fw"
87 wget -q --no-check-certificate ${fw_url}${fw} \
88 -O $firmware/boot/${fw}; status
89 fi
90 done
91 }
93 # Get all RPi firmware
94 clone_fw() {
95 [ -d "${rpi_git}/firmware" ] && return 0
96 mkdir -p ${rpi_git} && cd ${rpi_git}
97 git clone --depth 1 ${rpi_git_url}firmware.git
98 }
100 # --> will move to tazberry
101 set_oclock() {
102 case "$oclock" in
103 none)
104 arm_freq=700
105 core_freq=250
106 sdram_freq=400
107 over_voltage=0 ;;
108 modest)
109 arm_freq=800
110 core_freq=300
111 sdram_freq=400
112 over_voltage=0 ;;
113 medium)
114 arm_freq=900
115 core_freq=333
116 sdram_freq=450
117 over_voltage=2 ;;
118 hight)
119 arm_freq=950
120 core_freq=450
121 sdram_freq=450
122 over_voltage=6 ;;
123 turbo)
124 arm_freq=1000
125 core_freq=500
126 sdram_freq=500
127 over_voltage=6 ;;
128 esac
129 cat >> ${boot}/config.txt << EOT
130 arm_freq=$arm_freq
131 core_freq=$core_freq
132 sdram_freq=$sdram_freq
133 over_voltage=$over_voltage
134 EOT
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 "Missing: --dev= cmdline option"
158 newline && exit 1
159 fi
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 /dev/${dev}1 2>/dev/null || exit 1
174 umount /dev/${dev}3 2>/dev/null || exit 1
175 fi
176 echo -n "Mounting: /dev/$dev partitions"
177 mkdir -p ${rpiboot} ${rpiroot}
178 mount /dev/${dev}1 ${rpiboot}
179 mount /dev/${dev}3 ${rpiroot}; 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 ${rpiboot} || exit 1
193 umount ${rpiroot} || exit 1
194 status
196 rm -f ${data}/sdcard.part
197 separator && 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
215 # We may want to simply regenerate the RPi distro
216 if [ ! "$nosat" ]; then
217 sat gen --work="$work" --flavor="$flavor" --kmap --noinit --nolinux
218 fi
220 header "SliTaz Raspberry Pi distro"
222 # Boot firmware
223 echo -n "Copying: firmware files..."
224 mkdir -p ${boot} && get_fw
225 for fw in $fwlist
226 do
227 cp ${firmware}/boot/${fw} ${boot}
228 done
229 status
231 # TazBerry
232 echo -n "Installing TazBerry..."
233 cp -f ${rpi}/tazberry ${rootfs}/usr/bin
234 status
236 # Overclocking
237 echo -n "Setting: Overclocking..."
238 set_oclock; status
240 # Force turbo
241 if [ "$turbo" ]; then
242 if ! fgrep 'force_turbo=1' ${boot}/config.txt; then
243 echo -n "Config: force_turbo=1"
244 echo "force_turbo=1" >> ${boot}/config.txt; status
245 fi
246 fi
248 # RPi VC libraries
249 if [ "$vc" ]; then
250 vc="${rootfs}/opt/vc"
251 if [ ! -d "$firmware/opt/vc" ]; then
252 error "Missing firmware git repository" && exit 1
253 fi
254 echo -n "Copying: standard VC libraries"
255 cp -a ${firmware}/opt ${rootfs}
256 # --> armv6hf
257 #cp -a ${firmware}/hardfp/opt ${rootfs}
258 chown -R root.root ${rootfs}/opt
259 status
260 echo -n "Cleaning: VC libraries devel files"
261 cross_tools="/cross/${arch}/tools/bin"
262 rm -rf ${vc}/include ${vc}/src ${vc}/lib/*.a
263 ${cross_tools}/${arch}-slitaz-linux-gnueabi-strip -s ${vc}/lib/*.so
264 status
265 fi
267 # Kernel at last
268 . $data/linux-*/receipt
269 kvers="$VERSION"
270 kpkg="$rootfs/var/lib/tazpkg/installed/linux"
271 fs="$data/linux-$kvers/fs"
272 ksize=$(du -sh $fs | awk '{print $1}')
273 if [ -d "$fs" ]; then
274 echo -n "Copying: kernel $kvers ($ksize)"
275 rm -rf ${rootfs}/lib/modules
276 cp -rf ${fs}/lib/* ${rootfs}/lib
277 cp -f ${fs}/boot/* ${boot}
278 mkdir -p ${kpkg}
279 cd ${data}/linux-${kvers}
280 cp -f files.list md5sum receipt ${kpkg}
281 status
282 else
283 echo "SliTaz RPi Kernel: not used"
284 fi
286 separator
287 echo -n "Boot: $(du -sh $boot | awk '{print $1}') "
288 echo "- Rootfs: $(du -sh $rootfs | awk '{print $1}')"
289 newline ;;
291 cook-linux)
292 # Native SliTaz Toolchain and cross toolchain must be installed
293 check_root
294 install="$data/linux-install"
295 if [ ! -d "/cross/$arch" ]; then
296 error "Missing cross toolchain in: /cross/$arch"
297 exit 1
298 fi
300 # Kernel source
301 cd ${rpi_git}
302 [ -d "$kernel" ] || git clone --depth 1 ${rpi_git_url}linux.git
304 # Compile
305 [ "$clean" ] && rm -rf ${install}
306 if [ ! -d "$install" ]; then
307 cd ${kernel}
308 export PATH=$PATH:/cross/${arch}/tools/bin
309 export HOST_SYSTEM=${arch}-slitaz-linux-gnueabi
310 make mrproper &&
311 make ARCH=arm bcmrpi_defconfig
312 echo "Patching SliTaz RPi Linux .config"
313 patch -p0 -i ${rpi}/linux-rpi.patch || exit 1
314 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- zImage &&
315 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- modules &&
316 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- \
317 INSTALL_MOD_PATH=${install} modules_install || exit 1
318 mkdir -p ${install}/boot
319 cp -a arch/arm/boot/zImage ${install}/boot/kernel.img
320 fi
322 # Kernel version
323 kvers=$(ls ${install}/lib/modules)
324 kvers=${kvers%-slitaz-rpi+}+
326 # Compress modules
327 cd ${install}/lib/modules/${kvers%+}-slitaz-rpi+/ || exit 1
328 mods=$(find . -name "*.ko$" | wc -l)
329 newline
330 echo "Compressing kernel modules: $mods"
331 find . -name "*.ko$" -exec gzip '{}' \; #2> /dev/null
333 # Rebuild modules.dep
334 cd ${install}
335 depmod -b . ${kvers%+}-slitaz-rpi+
337 # Kernel
338 fs="$data/linux-$kvers/fs"
339 echo "Kernel version: $kvers"
340 if [ -d "$install" ]; then
341 rm -rf ${data}/linux-${kvers}
342 mkdir -p ${data}/linux-${kvers}
343 cp -a ${install} ${fs}
344 rm -f ${fs}/lib/modules/*/build \
345 ${fs}/lib/modules/*/source
346 fi
348 #get_tools
349 #echo "Compressing: zImage to kernel.img"
350 #cd ${tools}
351 #python imagetool-uncompressed.py ${fs}/boot/zImage
352 #mv -f kernel.img ${fs}/boot && rm ${fs}/boot/zImage
354 # Pack .tazpkg
355 cd ${data}
356 echo "Creating package: receipt"
357 cat > linux-$kvers/receipt << EOT
358 # SliTaz package receipt
360 PACKAGE="linux"
361 VERSION="$kvers"
362 SHORT_DESC="SliTaz Linux Kernel for the Raspberry Pi."
363 WEB_SITE="http://www.kernel.org"
365 EOT
366 tazpkg pack linux-$kvers ;;
368 get-fw)
369 get_fw ;;
371 get-tools)
372 get_tools ;;
374 get-linux)
375 # Precook RPi kernel
376 mkdir -p ${data}
378 # Last version
379 rm -f ${data}/linux-version.txt
380 if busybox wget -q -s ${rpi_mirror}/last-linux.txt; then
381 echo -n "Fetching latest Kernel string..."
382 wget -q ${rpi_mirror}/last-linux.txt \
383 -O ${data}/linux-version.txt || exit 1
384 status
385 else
386 echo "Mirror is unreachable" && exit 1
387 fi
388 kvers=$(cat $data/linux-version.txt)
389 [ "$up" ] && rm -rf ${data}/linux-${kvers}*
390 echo "Kernel version: $kvers"
392 # Download
393 if [ ! -f "$data/linux-$kvers.tazpkg" ]; then
394 echo -n "Fetching latest Linux package..."
395 wget -q ${rpi_mirror}/linux-${kvers}.tazpkg \
396 -O ${data}/linux-${kvers}.tazpkg; status
397 fi
399 # Extract
400 if [ ! -d "$data/linux-$kvers" ]; then
401 cd ${data} && tazpkg extract linux-${kvers}.tazpkg
402 fi
403 rm -f ${data}/linux-version.txt ;;
405 get-prebuilt)
406 # --> in cross ??
407 : ${arch=arm}
408 name="slitaz-$arch-toolchain"
409 vers="20140304"
410 tarball="$name-$vers.tar.bz2"
411 url="http://mirror.slitaz.org/packages/cross/"
412 mkdir -p /cross
413 cd /cross
414 if [ ! -f "$tarball" ]; then
415 if busybox wget -qs ${url%/}/${tarball}; then
416 busybox wget ${url%/}/${tarball}
417 else
418 echo "Toolchain URL is unreachable" && exit 1
419 fi
420 fi
421 if [ ! -d "${name}-${vers}" ]; then
422 echo "Extracting: $tarball"
423 tar xjf ${tarball}
424 fi
425 echo "Copying: ${name}-${vers}/${arch}"
426 mkdir -p ${arch}
427 cp -a ${name}-${vers}/${arch}/* ${arch}
428 echo "Tools path: /cross/${arch}/tools/bin" ;;
430 clone-fw)
431 clone_fw ;;
433 release)
434 # Used to release official SliTaz RPi images
435 cd ${distro} || exit 1
436 if [ ! "$flavor" ]; then
437 . $distro/rootfs/etc/slitaz/flavor.conf || exit 1
438 flavor="$FLAVOR"
439 fi
440 dname="slitaz-$flavor-$(date +%Y%m%d)"
441 dsize=$(du -sh $distro | awk '{print $1}' | cut -d "." -f 1)
442 rm -rf ${dname} && mkdir ${dname}
443 cp -a boot rootfs ${dname}
444 cat > ${dname}/README << EOT
445 SliTaz Raspberry Pi - $flavor-$(date +%Y%m%d) -
446 --------------------------------------------------------------------------------
448 Manual Installation. Assuming the sdcard is /dev/sdc and have got 3
449 partitions (boot,swap,root). Mount the sdcard, copy files, unmount:
451 # mkdir -p /media/rpi/boot /media/rpi/root
452 # mount /dev/sdc1 /media/rpi/boot
453 # mount /dev/sdc3 /media/rpi/root
454 # cp -a boot/* /media/rpi/boot
455 # cp -a rootfs/* /media/rpi/root
456 # umount /media/rpi/boot
457 # umount /media/rpi/root
459 EOT
460 ;;
462 clean)
463 echo "Cleaning: $rpi"
464 rm -rf ${data}
465 [ "$git" ] && rm -rf ${rpi_git} ;;
466 *) usage ;;
467 esac
468 exit 0