slitaz-arm diff sat-rpi @ rev 49
Renamed spi to sat-rpi (avoid name confusion)
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Mon Mar 10 22:56:34 2014 +0100 (2014-03-10) |
parents | |
children | 77d9496b62f5 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/sat-rpi Mon Mar 10 22:56:34 2014 +0100 1.3 @@ -0,0 +1,485 @@ 1.4 +#!/bin/sh 1.5 +# 1.6 +# Sat RPi - SliTaz Raspberry Pi Build Tool 1.7 +# 1.8 +# Copyright (C) 2012-2014 SliTaz ARM - BSD License 1.9 +# Author: Christophe Lincoln <pankso@slitaz.org> 1.10 +# 1.11 +. /lib/libtaz.sh 1.12 + 1.13 +#: ${arch=armv6hf} 1.14 +: ${arch=arm} 1.15 + 1.16 +# Paths 1.17 +[ "$work" ] || work="$(pwd)" 1.18 +distro="$work/distro" 1.19 +rpi="$work/rpi" 1.20 +data="$rpi/data" 1.21 +boot="$distro/boot" 1.22 +rootfs="$distro/rootfs" 1.23 +rpi_git="$rpi/git" 1.24 +kernel="$rpi_git/linux" 1.25 +firmware="$rpi_git/firmware" 1.26 +tools="$rpi_git/tools" 1.27 + 1.28 +# URLs 1.29 +rpi_mirror="http://mirror.slitaz.org/arm/rpi/" 1.30 +fw_url="https://github.com/raspberrypi/firmware/raw/master/boot/" 1.31 +tools_url="https://raw.github.com/raspberrypi/tools/master/mkimage/" 1.32 +rpi_git_url="git://github.com/raspberrypi/" 1.33 + 1.34 +# Lists 1.35 +fwlist="bootcode.bin fixup.dat start.elf" 1.36 +toolslist="imagetool-uncompressed.py args-uncompressed.txt \ 1.37 +boot-uncompressed.txt" 1.38 + 1.39 +# 1.40 +# Functions 1.41 +# 1.42 + 1.43 +usage() { 1.44 + cat << EOT 1.45 + 1.46 +$(boldify "Usage:") $(basename $0) [command] [--option] 1.47 + 1.48 +SliTaz Raspberry Pi Tool 1.49 + 1.50 +$(boldify "Commands:") 1.51 + info Display paths and distro info 1.52 + install Install SliTaz RPi to sdcard 1.53 + gen Generate a new SliTaz RPi distro 1.54 + cook-linux Build the Raspberry Pi Linux kernel 1.55 + get-linux Get the SliTaz RPi linux package 1.56 + get-fw Download or update minimal RPi firmware 1.57 + clone-fw Clone the RPi firmware repository 1.58 + get-tools Download or update RPi Tools (mkimage) 1.59 + get-prebuilt Get a prebuilt SliTaz ARM toolchain 1.60 + clean Clean the current work directory 1.61 + 1.62 +$(boldify "Options:") 1.63 + --up Update for commands: firmware, tools, kernel 1.64 + --turbo Force the RPi to run at the highest arm_freq 1.65 + --oclock= Set the RPi overclocking mode in config.txt 1.66 + --vc Install the RPi VC libraries in /opt/vc 1.67 + --nosat Don't regenerate the distro with sat 1.68 + --git Remove RPi git files on clean up 1.69 + 1.70 +EOT 1.71 +} 1.72 + 1.73 +error() { 1.74 + echo "[ $(colorize 31 'ERROR') ] $@" 1.75 +} 1.76 + 1.77 +header() { 1.78 + newline 1.79 + boldify "$@" 1.80 + separator 1.81 +} 1.82 + 1.83 +# Get minimal RPi firmware 1.84 +get_fw() { 1.85 + mkdir -p $firmware/boot 1.86 + for fw in $fwlist 1.87 + do 1.88 + [ "$up" ] && rm -f $firmware/boot/$fw 1.89 + if [ ! -f "$firmware/boot/$fw" ]; then 1.90 + echo -n "Fetching: $fw" 1.91 + wget -q --no-check-certificate ${fw_url}${fw} \ 1.92 + -O $firmware/boot/${fw}; status 1.93 + fi 1.94 + done 1.95 +} 1.96 + 1.97 +# Get all RPi firmware 1.98 +clone_fw() { 1.99 + [ -d "${rpi_git}/firmware" ] && return 0 1.100 + mkdir -p ${rpi_git} && cd ${rpi_git} 1.101 + git clone --depth 1 ${rpi_git_url}firmware.git 1.102 +} 1.103 + 1.104 +# Get RPi tools 1.105 +get_tools() { 1.106 + mkdir -p $tools 1.107 + for t in $toolslist 1.108 + do 1.109 + [ "$up" ] && rm -f ${tools}/${t} 1.110 + if [ ! -f "$tools/$t" ]; then 1.111 + echo -n "Fetching: $t" 1.112 + wget -q --no-check-certificate ${tools_url}${t} \ 1.113 + -O ${tools}/${t}; status 1.114 + fi 1.115 + done 1.116 +} 1.117 + 1.118 +# --> will move to tazberry 1.119 +set_oclock() { 1.120 + case "$oclock" in 1.121 + none) 1.122 + arm_freq=700 1.123 + core_freq=250 1.124 + sdram_freq=400 1.125 + over_voltage=0 ;; 1.126 + modest) 1.127 + arm_freq=800 1.128 + core_freq=300 1.129 + sdram_freq=400 1.130 + over_voltage=0 ;; 1.131 + medium) 1.132 + arm_freq=900 1.133 + core_freq=333 1.134 + sdram_freq=450 1.135 + over_voltage=2 ;; 1.136 + hight) 1.137 + arm_freq=950 1.138 + core_freq=450 1.139 + sdram_freq=450 1.140 + over_voltage=6 ;; 1.141 + turbo) 1.142 + arm_freq=1000 1.143 + core_freq=500 1.144 + sdram_freq=500 1.145 + over_voltage=6 ;; 1.146 + esac 1.147 + cat >> ${boot}/config.txt << EOT 1.148 +arm_freq=$arm_freq 1.149 +core_freq=$core_freq 1.150 +sdram_freq=$sdram_freq 1.151 +over_voltage=$over_voltage 1.152 +EOT 1.153 +} 1.154 + 1.155 +# 1.156 +# Commands 1.157 +# 1.158 + 1.159 +case "$1" in 1.160 + info) 1.161 + header "SliTaz Raspberry Pi info" 1.162 + echo "Firmware : $fwlist" 1.163 + echo "RPi path : $rpi" 1.164 + colorize 36 "/boot/cmdline.txt:" 1.165 + cat ${boot}/cmdline.txt 1.166 + colorize 36 "/boot/config.txt:" 1.167 + cat ${boot}/config.txt 1.168 + separator && newline ;; 1.169 + 1.170 + install) 1.171 + rpiboot="/media/rpi/boot" 1.172 + rpiroot="/media/rpi/rootfs" 1.173 + header "SliTaz Raspberry Pi install" 1.174 + if [ ! "$dev" ]; then 1.175 + echo "Missing: --dev= cmdline option" 1.176 + newline && exit 1 1.177 + fi 1.178 + 1.179 + # Store sdcard partition(s) list 1.180 + fdisk -l /dev/${dev} | grep "^/dev/$dev" | awk '{print $1}' \ 1.181 + > ${data}/sdcard.part 1.182 + partnb=$(cat ${data}/sdcard.part | wc -l) 1.183 + if [ "$partnb" != 3 ]; then 1.184 + error "SliTaz RPi needs 3 partitions on the sdcard" 1.185 + newline && exit 1 1.186 + fi 1.187 + 1.188 + # Mount sdcard 1.189 + if mount | grep -q "^/dev/$dev[1-3]"; then 1.190 + debug "Unmounting: /dev/$dev" 1.191 + umount /dev/${dev}1 2>/dev/null || exit 1 1.192 + umount /dev/${dev}3 2>/dev/null || exit 1 1.193 + fi 1.194 + echo -n "Mounting: /dev/$dev partitions" 1.195 + mkdir -p ${rpiboot} ${rpiroot} 1.196 + mount /dev/${dev}1 ${rpiboot} 1.197 + mount /dev/${dev}3 ${rpiroot}; status 1.198 + echo -n "Cleaning: filesystem directories" 1.199 + for dir in bin dev etc lib media mnt proc sbin sys tmp usr var run 1.200 + do 1.201 + rm -rf ${rpiroot}/${dir} 1.202 + done; status 1.203 + echo -n "Installing: boot files" 1.204 + cp -rf ${boot}/* ${rpiboot}; status 1.205 + echo -n "Installing: rootfs files" 1.206 + cp -a ${rootfs}/* ${rpiroot}; status 1.207 + 1.208 + # Unmount 1.209 + echo -n "Unmounting: RPi sdcard" 1.210 + umount ${rpiboot} || exit 1 1.211 + umount ${rpiroot} || exit 1 1.212 + status 1.213 + 1.214 + # Boot flag 1.215 + #echo -n "Setting boot flag on: /dev/${dev}1" 1.216 + #fdisk /dev/${dev} >/dev/null << EOF 1.217 +#a 1.218 +#1 1.219 +#w 1.220 +#EOF 1.221 + #status 1.222 + rm -f ${data}/sdcard.part 1.223 + separator && newline ;; 1.224 + 1.225 + ls-dev) 1.226 + newline 1.227 + fdisk -l | grep "^Disk /dev/sd*" 1.228 + newline ;; 1.229 + 1.230 + gen) 1.231 + # Separate boot files since the Raspberry Pi boots off a FAT32 /boot 1.232 + # partition on the sdcard. 1.233 + : ${flavor=rpi} 1.234 + : ${oclock=none} 1.235 + 1.236 + # Use the rootfs generated by sat 1.237 + if [ ! -x "/usr/bin/sat" ]; then 1.238 + error "Sat is not installed" && exit 1 1.239 + fi 1.240 + 1.241 + # We may want to simply regenerate the RPi distro 1.242 + if [ ! "$nosat" ]; then 1.243 + sat gen --work="$work" --flavor="$flavor" --kmap --noinit --rpi 1.244 + fi 1.245 + 1.246 + header "SliTaz Raspberry Pi distro" 1.247 + 1.248 + # Boot firmware 1.249 + echo -n "Copying: firmware files..." 1.250 + mkdir -p ${boot} && get_fw 1.251 + for fw in $fwlist 1.252 + do 1.253 + cp ${firmware}/boot/${fw} ${boot} 1.254 + done 1.255 + status 1.256 + 1.257 + # SliTaz Raspberry Pi custom rootfs files. Make sure all files 1.258 + # belong to root 1.259 + if [ -d "$rpi/rootfs" ]; then 1.260 + size=$(du -sh $rpi/rootfs | awk '{print $1}') 1.261 + echo -n "Copying: SliTaz RPi rootfs ($size)" 1.262 + tmp=${distro}/tmp-$$ 1.263 + mkdir -p ${tmp} 1.264 + cp -r ${rpi}/rootfs/* ${tmp} 1.265 + chown -R root.root ${tmp} 1.266 + cp -a ${tmp}/* ${rootfs} && rm -rf ${tmp} 1.267 + # Move files to $boot 1.268 + mv -f ${rootfs}/boot/* ${boot} 1.269 + status 1.270 + fi 1.271 + 1.272 + # TazBerry 1.273 + echo -n "Installing TazBerry..." 1.274 + cp -f ${rpi}/tazberry ${rootfs}/usr/bin 1.275 + status 1.276 + 1.277 + # Overclocking 1.278 + echo -n "Setting: Overclocking..." 1.279 + set_oclock; status 1.280 + 1.281 + # Force turbo 1.282 + if [ "$turbo" ]; then 1.283 + if ! fgrep 'force_turbo=1' ${boot}/config.txt; then 1.284 + echo -n "Config: force_turbo=1" 1.285 + echo "force_turbo=1" >> ${boot}/config.txt; status 1.286 + fi 1.287 + fi 1.288 + 1.289 + # RPi VC libraries 1.290 + if [ "$vc" ]; then 1.291 + vc="${rootfs}/opt/vc" 1.292 + if [ ! -d "$firmware/opt/vc" ]; then 1.293 + error "Missing firmware git repository" && exit 1 1.294 + fi 1.295 + echo -n "Copying: standard VC libraries" 1.296 + cp -a ${firmware}/opt ${rootfs} 1.297 + # --> armv6hf 1.298 + #cp -a ${firmware}/hardfp/opt ${rootfs} 1.299 + chown -R root.root ${rootfs}/opt 1.300 + status 1.301 + echo -n "Cleaning: VC libraries devel files" 1.302 + cross_tools="/cross/${arch}/tools/bin" 1.303 + rm -rf ${vc}/include ${vc}/src ${vc}/lib/*.a 1.304 + ${cross_tools}/${arch}-slitaz-linux-gnueabi-strip -s ${vc}/lib/*.so 1.305 + status 1.306 + fi 1.307 + 1.308 + # Kernel at last 1.309 + . $data/linux-*/receipt 1.310 + kvers="$VERSION" 1.311 + kpkg="$rootfs/var/lib/tazpkg/installed/linux" 1.312 + fs="$data/linux-$kvers/fs" 1.313 + ksize=$(du -sh $fs | awk '{print $1}') 1.314 + if [ -d "$fs" ]; then 1.315 + echo -n "Copying: kernel $kvers ($ksize)" 1.316 + rm -rf ${rootfs}/lib/modules 1.317 + cp -rf ${fs}/lib/* ${rootfs}/lib 1.318 + cp -f ${fs}/boot/* ${boot} 1.319 + mkdir -p ${kpkg} 1.320 + cd ${data}/linux-${kvers} 1.321 + cp -f files.list md5sum receipt ${kpkg} 1.322 + status 1.323 + else 1.324 + echo "RPi Kernel: not used" 1.325 + fi 1.326 + 1.327 + separator 1.328 + echo -n "Boot: $(du -sh $boot | awk '{print $1}') " 1.329 + echo "- Rootfs: $(du -sh $rootfs | awk '{print $1}')" 1.330 + newline ;; 1.331 + 1.332 + cook-linux) 1.333 + # Native SliTaz Toolchain and cross toolchain must be installed 1.334 + check_root 1.335 + install="$data/linux-install" 1.336 + if [ ! -d "/cross/$arch" ]; then 1.337 + error "Missing cross toolchain in: /cross/$arch" 1.338 + exit 1 1.339 + fi 1.340 + 1.341 + # Kernel source 1.342 + cd ${rpi_git} 1.343 + [ -d "$kernel" ] || git clone --depth 1 ${rpi_git_url}linux.git 1.344 + 1.345 + # Compile 1.346 + if [ ! -d "$install" ]; then 1.347 + cd ${kernel} 1.348 + export PATH=$PATH:/cross/${arch}/tools/bin 1.349 + export HOST_SYSTEM=${arch}-slitaz-linux-gnueabi 1.350 + make mrproper && 1.351 + make ARCH=arm bcmrpi_defconfig 1.352 + echo "Patching SliTaz RPi Linux .config" 1.353 + patch -p1 -i ${rpi}/linux-rpi.config || exit 1 1.354 + make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- zImage && 1.355 + make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- modules && 1.356 + make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- \ 1.357 + INSTALL_MOD_PATH=${install} modules_install || exit 1 1.358 + mkdir -p ${install}/boot 1.359 + cp -a arch/arm/boot/zImage ${install}/boot 1.360 + fi 1.361 + 1.362 + # Kernel version 1.363 + kvers=$(ls ${install}/lib/modules) 1.364 + kvers=${kvers%-slitaz-rpi+}+ 1.365 + 1.366 + # Compress modules 1.367 + cd ${install}/lib/modules/${kvers%+}-slitaz-rpi+/ || exit 1 1.368 + mods=$(find . -name "*.ko$" | wc -l) 1.369 + newline 1.370 + echo "Compressing kernel modules: $mods" 1.371 + find . -name "*.ko$" -exec gzip '{}' \; #2> /dev/null 1.372 + #find . -name "*.ko" -exec rm '{}' \; 1.373 + # Rebuild modules.dep 1.374 + cd ${install} 1.375 + depmod -b . ${kvers%+}-slitaz-rpi+ 1.376 + 1.377 + # Pack 1.378 + fs="$data/linux-$kvers/fs" 1.379 + echo "Kernel version: $kvers" 1.380 + if [ -d "$install" ]; then 1.381 + rm -rf ${data}/linux-${kvers} 1.382 + mkdir -p ${data}/linux-${kvers} 1.383 + cp -a ${install} ${fs} 1.384 + rm -f ${fs}/lib/modules/*/build ${fs}/lib/modules/*/source 1.385 + fi 1.386 + get_tools 1.387 + echo "Compressing: zImage to kernel.img" 1.388 + cd ${tools} 1.389 + python imagetool-uncompressed.py ${fs}/boot/zImage 1.390 + mv -f kernel.img ${fs}/boot && rm ${fs}/boot/zImage 1.391 + cd ${data} 1.392 + echo "Creating package: receipt" 1.393 + cat > linux-$kvers/receipt << EOT 1.394 +# SliTaz package receipt 1.395 + 1.396 +PACKAGE="linux" 1.397 +VERSION="$kvers" 1.398 +SHORT_DESC="SliTaz Linux Kernel for the Raspberry Pi." 1.399 +WEB_SITE="http://www.kernel.org" 1.400 + 1.401 +EOT 1.402 + tazpkg pack linux-$kvers ;; 1.403 + 1.404 + get-fw) 1.405 + get_fw ;; 1.406 + 1.407 + get-tools) 1.408 + get_tools ;; 1.409 + 1.410 + get-linux) 1.411 + # Precook RPi kernel 1.412 + mkdir -p ${data} 1.413 + 1.414 + # Last version 1.415 + rm -f ${data}/linux-version.txt 1.416 + if busybox wget -q -s ${rpi_mirror}/last-linux.txt; then 1.417 + echo -n "Fetching latest Kernel string..." 1.418 + wget -q ${rpi_mirror}/last-linux.txt \ 1.419 + -O ${data}/linux-version.txt || exit 1 1.420 + status 1.421 + else 1.422 + echo "Mirror is unreachable" && exit 1 1.423 + fi 1.424 + kvers=$(cat $data/linux-version.txt) 1.425 + [ "$up" ] && rm -rf ${data}/linux-${kvers}* 1.426 + echo "Kernel version: $kvers" 1.427 + 1.428 + # Download 1.429 + if [ ! -f "$data/linux-$kvers.tazpkg" ]; then 1.430 + echo -n "Fetching latest Linux package..." 1.431 + wget -q ${rpi_mirror}/linux-${kvers}.tazpkg \ 1.432 + -O ${data}/linux-${kvers}.tazpkg; status 1.433 + fi 1.434 + 1.435 + # Extract 1.436 + if [ ! -d "$data/linux-$kvers" ]; then 1.437 + cd ${data} && tazpkg extract linux-${kvers}.tazpkg 1.438 + fi 1.439 + rm -f ${data}/linux-version.txt ;; 1.440 + 1.441 + get-prebuilt) 1.442 + # --> in cross ?? 1.443 + : ${arch=arm} 1.444 + name="slitaz-$arch-toolchain" 1.445 + vers="20140304" 1.446 + tarball="$name-$vers.tar.bz2" 1.447 + url="http://mirror.slitaz.org/packages/cross/" 1.448 + mkdir -p /cross 1.449 + cd /cross 1.450 + if [ ! -f "$tarball" ]; then 1.451 + if busybox wget -qs ${url%/}/${tarball}; then 1.452 + busybox wget ${url%/}/${tarball} 1.453 + else 1.454 + echo "Toolchain URL is unreachable" && exit 1 1.455 + fi 1.456 + fi 1.457 + if [ ! -d "${name}-${vers}" ]; then 1.458 + echo "Extracting: $tarball" 1.459 + tar xjf ${tarball} 1.460 + fi 1.461 + echo "Copying: ${name}-${vers}/${arch}" 1.462 + mkdir -p ${arch} 1.463 + cp -a ${name}-${vers}/${arch}/* ${arch} 1.464 + echo "Tools path: /cross/${arch}/tools/bin" ;; 1.465 + 1.466 + clone-fw) 1.467 + clone_fw ;; 1.468 + 1.469 + release) 1.470 + # Used to release official SliTaz RPi images 1.471 + cd ${distro} || exit 1 1.472 + if [ ! "$flavor" ]; then 1.473 + . $distro/rootfs/etc/slitaz/flavor.conf || exit 1 1.474 + flavor="$FLAVOR" 1.475 + fi 1.476 + dirname="slitaz-$flavor-$(date +%Y%m%d)" 1.477 + dsize=$(du -sh $distro | awk '{print $1}' | cut -d "." -f 1) 1.478 + mkdir ${dirname} 1.479 + # To be continued... 1.480 + ;; 1.481 + 1.482 + clean) 1.483 + echo "Cleaning: $rpi" 1.484 + rm -rf ${data} 1.485 + [ "$git" ] && rm -rf ${rpi_git} ;; 1.486 + *) usage ;; 1.487 +esac 1.488 +exit 0