slitaz-arm view spi @ rev 47

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