slitaz-arm view spi @ rev 45
merge
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sun Mar 09 10:14:33 2014 +0100 (2014-03-09) |
parents | 839d11d53db8 f4e0ff9dd9d3 |
children | b946dc4f933a |
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 "$data/$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" && exit 1
173 fi
175 # Store sdcard partition(s) list
176 fdisk -l /dev/${dev} | grep "^/dev/$dev" | awk '{print $1}' \
177 > ${data}/sdcard.part
178 partnb=$(cat ${data}/sdcard.part | wc -l)
179 if [ "$partnb" != 3 ]; then
180 error "SliTaz RPi needs 3 partitions on the sdcard"
181 newline && exit 1
182 fi
184 # Mount sdcard
185 if mount | grep -q "^/dev/$dev[1-3]"; then
186 debug "Unmounting: /dev/$dev"
187 umount /dev/${dev}1 2>/dev/null || exit 1
188 umount /dev/${dev}3 2>/dev/null || exit 1
189 fi
190 echo -n "Mounting: /dev/$dev partitions"
191 mkdir -p ${rpiboot} ${rpiroot}
192 mount /dev/${dev}1 ${rpiboot}
193 mount /dev/${dev}3 ${rpiroot}; status
194 echo -n "Installing: boot files"
195 cp -rf ${boot}/* ${rpiboot}; status
196 echo -n "Installing: rootfs files"
197 cp -a ${rootfs}/* ${rpiroot}; status
199 # Unmount
200 echo -n "Unmounting: RPi sdcard"
201 umount ${rpiboot} || exit 1
202 umount ${rpiroot} || exit 1
203 status
205 # Boot flag
206 #echo -n "Setting boot flag on: /dev/${dev}1"
207 #fdisk /dev/${dev} >/dev/null << EOF
208 #a
209 #1
210 #w
211 #EOF
212 #status
213 rm -f ${data}/sdcard.part
214 separator && newline ;;
216 ls-dev)
217 newline
218 fdisk -l | grep "^Disk /dev/sd*"
219 newline ;;
221 gen)
222 # Separate boot files since the Raspberry Pi boots off a FAT32 /boot
223 # partition on the sdcard.
224 : ${flavor=rpi}
225 : ${oclock=none}
227 # Use the rootfs generated by sat
228 if [ ! -x "/usr/bin/sat" ]; then
229 error "Sat is not installed" && exit 1
230 fi
232 # We may want to simply regenerate the RPi distro
233 if [ ! "$nosat" ]; then
234 sat gen --work="$work" --flavor="$flavor" --kmap --noinit --rpi
235 fi
237 header "SliTaz Raspberry Pi distro"
239 # Boot firmware
240 echo -n "Copying: firmware files..."
241 mkdir -p ${boot} && get_fw
242 for fw in $fwlist
243 do
244 cp ${firmware}/boot/${fw} ${boot}
245 done
246 status
248 # SliTaz Raspberry Pi custom rootfs files. Make sure all files
249 # belong to root
250 if [ -d "$rpi/rootfs" ]; then
251 size=$(du -sh $rpi/rootfs | awk '{print $1}')
252 echo -n "Copying: SliTaz RPi rootfs ($size)"
253 tmp=${distro}/tmp-$$
254 mkdir -p ${tmp}
255 cp -r ${rpi}/rootfs/* ${tmp}
256 chown -R root.root ${tmp}
257 cp -a ${tmp}/* ${rootfs} && rm -rf ${tmp}
258 # Move files to $boot
259 mv -f ${rootfs}/boot/* ${boot}
260 status
261 fi
263 # TazBerry
264 echo -n "Installing TazBerry..."
265 cp -f ${rpi}/tazberry ${rootfs}/usr/bin
266 status
268 # Overclocking
269 echo -n "Setting: Overclocking..."
270 set_oclock; status
272 # Force turbo
273 if [ "$turbo" ]; then
274 if ! fgrep 'force_turbo=1' ${boot}/config.txt; then
275 echo -n "Config: force_turbo=1"
276 echo "force_turbo=1" >> ${boot}/config.txt; status
277 fi
278 fi
280 # Kernel
281 kvers=$(ls $data/linux-*/fs/lib/modules)
282 kvers=${kvers%-slitaz-rpi}
283 kpkg="$rootfs/var/lib/tazpkg/installed/linux"
284 fs="$data/linux-$kvers/fs"
285 ksize=$(du -sh $fs | awk '{print $1}')
286 if [ -d "$fs" ]; then
287 echo -n "Copying: kernel $kvers ($ksize)"
288 rm -rf ${rootfs}/lib/modules
289 cp -rf ${fs}/lib/* ${rootfs}/lib
290 cp -f ${fs}/boot/* ${boot}
291 mkdir -p ${kpkg}
292 cd ${data}/linux-${kvers}
293 cp -f files.list md5sum receipt ${kpkg}
294 status
295 else
296 echo "RPi Kernel: not used"
297 fi
299 # RPi VC libraries
300 if [ "$vc" ]; then
301 vc="${rootfs}/opt/vc"
302 if [ ! -d "$firmware/opt/vc" ]; then
303 error "Missing firmware git repository" && exit 1
304 fi
305 echo -n "Copying: standard VC libraries"
306 cp -a ${firmware}/opt ${rootfs}
307 # --> armv6hf
308 #cp -a ${firmware}/hardfp/opt ${rootfs}
309 chown -R root.root ${rootfs}/opt
310 status
311 echo -n "Cleaning: VC libraries devel files"
312 cross_tools="/cross/${arch}/tools/bin"
313 rm -rf ${vc}/include ${vc}/src ${vc}/lib/*.a
314 ${cross_tools}/${arch}-slitaz-linux-gnueabi-strip -s ${vc}/lib/*.so
315 status
316 fi
318 separator
319 echo -n "Boot: $(du -sh $boot | awk '{print $1}') "
320 echo "- Rootfs: $(du -sh $rootfs | awk '{print $1}')"
321 newline ;;
323 cook-linux)
324 # Native SliTaz Toolchain and cross toolchain must be installed
325 check_root
326 install="$data/linux-install"
327 if [ ! -d "/cross/$arch" ]; then
328 error "Missing cross toolchain in: /cross/$arch"
329 exit 1
330 fi
332 # Kernel source
333 cd ${rpi_git}
334 [ -d "$kernel" ] || git clone --depth 1 ${rpi_git_url}linux.git
336 # Compile
337 if [ ! -d "$install" ]; then
338 cd ${kernel}
339 export PATH=$PATH:/cross/${arch}/tools/bin
340 export HOST_SYSTEM=${arch}-slitaz-linux-gnueabi
341 make mrproper &&
342 make ARCH=arm bcmrpi_defconfig
343 echo "Patching SliTaz RPi Linux .config"
344 patch -p1 -i ${rpi}/linux-rpi.config || exit 1
345 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- zImage &&
346 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- modules &&
347 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- \
348 INSTALL_MOD_PATH=${install} modules_install || exit 1
349 mkdir -p ${install}/boot
350 cp -a arch/arm/boot/zImage ${install}/boot
351 fi
353 # Compress modules
354 mods=$(find . -name "*.ko" | wc -l)
355 newline
356 echo "Kernel modules: $mods"
357 #echo -n "Compressing modules: $mods"
358 #find . -name "*.ko" -exec gz '{}' \; 2> /dev/null
360 # Pack
361 kvers=$(ls ${install}/lib/modules)
362 kvers=${kvers%-slitaz-rpi}
363 fs="$data/linux-$kvers/fs"
364 newline
365 echo "Kernel version: $kvers"
366 if [ -d "$install" ]; then
367 rm -rf ${data}/linux-${kvers}
368 mkdir -p ${data}/linux-${kvers}
369 cp -a ${install} ${fs}
370 rm ${fs}/lib/modules/build ${fs}/lib/modules/source
371 fi
372 get_tools
373 echo "Compressing: zImage to kernel.img"
374 cd ${tools}
375 python imagetool-uncompressed.py ${fs}/boot/zImage
376 cd ${data}
377 mv kernel.img ${fs}/boot && rm ${fs}/boot/zImage
378 echo "Creating package: receipt"
379 cat > linux-$kvers/receipt << EOT
380 # SliTaz package receipt
382 PACKAGE="linux"
383 VERSION="$kvers"
384 SHORT_DESC="SliTaz Linux Kernel for the Raspberry Pi."
385 WEB_SITE="http://www.kernel.org"
387 EOT
388 tazpkg pack linux-$kvers ;;
390 get-fw)
391 get_fw ;;
393 get-tools)
394 get_tools ;;
396 get-linux)
397 # Precook RPi kernel
398 mkdir -p ${data}
400 # Last version
401 rm -f ${data}/linux-version.txt
402 if busybox wget -q -s ${rpi_mirror}/last-linux.txt; then
403 echo -n "Fetching latest Kernel string..."
404 wget -q ${rpi_mirror}/last-linux.txt \
405 -O ${data}/linux-version.txt || exit 1
406 status
407 else
408 echo "Mirror is unreachable" && exit 1
409 fi
410 kvers=$(cat $data/linux-version.txt)
411 [ "$up" ] && rm -rf ${data}/linux-${kvers}*
412 echo "Kernel version: $kvers"
414 # Download
415 if [ ! -f "$data/linux-$kvers.tazpkg" ]; then
416 echo -n "Fetching latest Linux package..."
417 wget -q ${rpi_mirror}/linux-${kvers}.tazpkg \
418 -O ${data}/linux-${kvers}.tazpkg; status
419 fi
421 # Extract
422 if [ ! -d "$data/linux-$kvers" ]; then
423 cd ${data} && tazpkg extract linux-${kvers}.tazpkg
424 fi
425 rm -f ${data}/linux-version.txt ;;
427 get-prebuilt)
428 # --> in cross ??
429 : ${arch=arm}
430 name="slitaz-$arch-toolchain"
431 vers="20140304"
432 tarball="$name-$vers.tar.bz2"
433 url="http://mirror.slitaz.org/packages/cross/"
434 mkdir -p /cross
435 cd /cross
436 if [ ! -f "$tarball" ]; then
437 if busybox wget -qs ${url%/}/${tarball}; then
438 busybox wget ${url%/}/${tarball}
439 else
440 echo "Toolchain URL is unreachable" && exit 1
441 fi
442 fi
443 if [ ! -d "${name}-${vers}" ]; then
444 echo "Extracting: $tarball"
445 tar xjf ${tarball}
446 fi
447 echo "Copying: ${name}-${vers}/${arch}"
448 mkdir -p ${arch}
449 cp -a ${name}-${vers}/${arch}/* ${arch}
450 echo "Tools path: /cross/${arch}/tools/bin" ;;
452 clone-fw)
453 clone_fw ;;
455 clean)
456 echo "Cleaning: $rpi"
457 rm -rf ${data}
458 [ "$git" ] && rm -rf ${rpi_git} ;;
459 *) usage ;;
460 esac
461 exit 0