slitaz-arm annotate sat-rpi @ rev 179
pileds: fix PiClass code path
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Wed May 07 14:04:19 2014 +0200 (2014-05-07) |
parents | c0f6d2a62d0d |
children | 1bf7d711c88d |
rev | line source |
---|---|
pankso@49 | 1 #!/bin/sh |
pankso@49 | 2 # |
pankso@49 | 3 # Sat RPi - SliTaz Raspberry Pi Build Tool |
pankso@49 | 4 # |
pankso@49 | 5 # Copyright (C) 2012-2014 SliTaz ARM - BSD License |
pankso@49 | 6 # Author: Christophe Lincoln <pankso@slitaz.org> |
pankso@49 | 7 # |
pankso@49 | 8 . /lib/libtaz.sh |
pankso@49 | 9 |
pankso@49 | 10 #: ${arch=armv6hf} |
pankso@49 | 11 : ${arch=arm} |
pankso@49 | 12 |
pankso@49 | 13 # Paths |
pankso@49 | 14 [ "$work" ] || work="$(pwd)" |
pankso@49 | 15 distro="$work/distro" |
pankso@49 | 16 rpi="$work/rpi" |
pankso@49 | 17 data="$rpi/data" |
pankso@94 | 18 cache="$rpi/cache" |
pankso@49 | 19 boot="$distro/boot" |
pankso@49 | 20 rootfs="$distro/rootfs" |
pankso@49 | 21 rpi_git="$rpi/git" |
pankso@49 | 22 kernel="$rpi_git/linux" |
pankso@67 | 23 dev="$2" |
pankso@49 | 24 |
pankso@49 | 25 # URLs |
pankso@49 | 26 rpi_mirror="http://mirror.slitaz.org/arm/rpi/" |
pankso@49 | 27 rpi_git_url="git://github.com/raspberrypi/" |
pankso@49 | 28 |
pankso@49 | 29 # |
pankso@49 | 30 # Functions |
pankso@49 | 31 # |
pankso@49 | 32 |
pankso@49 | 33 usage() { |
pankso@49 | 34 cat << EOT |
pankso@49 | 35 |
pankso@49 | 36 $(boldify "Usage:") $(basename $0) [command] [--option] |
pankso@49 | 37 |
pankso@49 | 38 SliTaz Raspberry Pi Tool |
pankso@49 | 39 |
pankso@49 | 40 $(boldify "Commands:") |
pankso@49 | 41 info Display paths and distro info |
pankso@49 | 42 install Install SliTaz RPi to sdcard |
pankso@49 | 43 gen Generate a new SliTaz RPi distro |
pankso@49 | 44 cook-linux Build the Raspberry Pi Linux kernel |
pankso@49 | 45 get-linux Get the SliTaz RPi linux package |
pankso@49 | 46 clone-fw Clone the RPi firmware repository |
pankso@49 | 47 get-prebuilt Get a prebuilt SliTaz ARM toolchain |
pankso@49 | 48 clean Clean the current work directory |
paul@85 | 49 release Release an installable tarball |
pankso@49 | 50 |
pankso@49 | 51 $(boldify "Options:") |
pankso@49 | 52 --nosat Don't regenerate the distro with sat |
pankso@141 | 53 --nopatch Don't patch the kernel before cooking |
pankso@141 | 54 --gconfig Configure the kernel before cooking |
pankso@145 | 55 --fbtft Try to compile the Framebuffer touch screen driver |
pankso@49 | 56 |
pankso@49 | 57 EOT |
pankso@49 | 58 } |
pankso@49 | 59 |
pankso@49 | 60 error() { |
pankso@49 | 61 echo "[ $(colorize 31 'ERROR') ] $@" |
pankso@49 | 62 } |
pankso@49 | 63 |
pankso@49 | 64 header() { |
pankso@67 | 65 newline && colorize 35 "$@" && separator |
pankso@49 | 66 } |
pankso@49 | 67 |
pankso@49 | 68 # Get all RPi firmware |
pankso@49 | 69 clone_fw() { |
pankso@49 | 70 [ -d "${rpi_git}/firmware" ] && return 0 |
pankso@49 | 71 mkdir -p ${rpi_git} && cd ${rpi_git} |
pankso@49 | 72 git clone --depth 1 ${rpi_git_url}firmware.git |
pankso@49 | 73 } |
pankso@49 | 74 |
pankso@67 | 75 umount_sd() { |
pankso@67 | 76 umount /dev/${dev}1 2>/dev/null || exit 1 |
pankso@67 | 77 umount /dev/${dev}3 2>/dev/null || exit 1 |
pankso@67 | 78 } |
pankso@67 | 79 |
pankso@49 | 80 # |
pankso@49 | 81 # Commands |
pankso@49 | 82 # |
pankso@49 | 83 |
pankso@49 | 84 case "$1" in |
pankso@49 | 85 info) |
pankso@49 | 86 header "SliTaz Raspberry Pi info" |
pankso@49 | 87 echo "RPi path : $rpi" |
pankso@49 | 88 colorize 36 "/boot/cmdline.txt:" |
pankso@49 | 89 cat ${boot}/cmdline.txt |
pankso@49 | 90 colorize 36 "/boot/config.txt:" |
pankso@49 | 91 cat ${boot}/config.txt |
pankso@49 | 92 separator && newline ;; |
pankso@49 | 93 |
pankso@49 | 94 install) |
pankso@49 | 95 rpiboot="/media/rpi/boot" |
pankso@49 | 96 rpiroot="/media/rpi/rootfs" |
pankso@49 | 97 header "SliTaz Raspberry Pi install" |
pankso@69 | 98 if [ ! "$dev" ]; then |
pankso@69 | 99 echo -n "SD card disk name (ex sdc): "; read dev |
pankso@69 | 100 fi |
pankso@69 | 101 [ ! "$dev" ] && exit 1 |
pankso@49 | 102 |
pankso@49 | 103 # Store sdcard partition(s) list |
pankso@49 | 104 fdisk -l /dev/${dev} | grep "^/dev/$dev" | awk '{print $1}' \ |
pankso@94 | 105 > ${cache}/sdcard.part |
pankso@94 | 106 partnb=$(cat ${cache}/sdcard.part | wc -l) |
pankso@49 | 107 if [ "$partnb" != 3 ]; then |
pankso@49 | 108 error "SliTaz RPi needs 3 partitions on the sdcard" |
pankso@49 | 109 newline && exit 1 |
pankso@49 | 110 fi |
pankso@49 | 111 |
pankso@49 | 112 # Mount sdcard |
pankso@49 | 113 if mount | grep -q "^/dev/$dev[1-3]"; then |
pankso@49 | 114 debug "Unmounting: /dev/$dev" |
pankso@67 | 115 umount_sd |
pankso@49 | 116 fi |
pankso@49 | 117 echo -n "Mounting: /dev/$dev partitions" |
pankso@49 | 118 mkdir -p ${rpiboot} ${rpiroot} |
pankso@58 | 119 mount /dev/${dev}1 ${rpiboot} || exit 1 |
pankso@58 | 120 mount /dev/${dev}3 ${rpiroot} || exit 1 |
pankso@58 | 121 status |
pankso@49 | 122 echo -n "Cleaning: filesystem directories" |
pankso@49 | 123 for dir in bin dev etc lib media mnt proc sbin sys tmp usr var run |
pankso@49 | 124 do |
pankso@49 | 125 rm -rf ${rpiroot}/${dir} |
pankso@49 | 126 done; status |
pankso@49 | 127 echo -n "Installing: boot files" |
pankso@49 | 128 cp -rf ${boot}/* ${rpiboot}; status |
pankso@49 | 129 echo -n "Installing: rootfs files" |
pankso@49 | 130 cp -a ${rootfs}/* ${rpiroot}; status |
pankso@49 | 131 |
pankso@49 | 132 # Unmount |
pankso@49 | 133 echo -n "Unmounting: RPi sdcard" |
pankso@67 | 134 umount_sd; status |
pankso@49 | 135 |
pankso@94 | 136 rm -f ${cache}/sdcard.part |
pankso@67 | 137 separator |
pankso@67 | 138 echo "Insert the SD card into your Raspberry Pi and boot!" |
pankso@67 | 139 newline ;; |
pankso@122 | 140 |
pankso@49 | 141 gen) |
pankso@49 | 142 # Separate boot files since the Raspberry Pi boots off a FAT32 /boot |
pankso@49 | 143 # partition on the sdcard. |
pankso@54 | 144 : ${flavor=rpi-base} |
pankso@49 | 145 |
pankso@49 | 146 # Use the rootfs generated by sat |
pankso@49 | 147 if [ ! -x "/usr/bin/sat" ]; then |
pankso@49 | 148 error "Sat is not installed" && exit 1 |
pankso@49 | 149 fi |
pankso@55 | 150 check_root |
pankso@49 | 151 |
pankso@49 | 152 # We may want to simply regenerate the RPi distro |
pankso@49 | 153 if [ ! "$nosat" ]; then |
pankso@144 | 154 sat gen --work="$work" --flavor="$flavor" \ |
pankso@144 | 155 --noinit --nolinux || exit 1 |
pankso@58 | 156 else |
pankso@58 | 157 newline |
pankso@49 | 158 fi |
pankso@49 | 159 |
pankso@67 | 160 colorize 35 "SliTaz Raspberry Pi distro" |
pankso@58 | 161 separator |
pankso@63 | 162 mkdir -p ${boot} |
pankso@49 | 163 |
pankso@62 | 164 # Custom RPi rootfs: make sure all files belong to root |
pankso@62 | 165 if [ -d "$rpi/rootfs" ]; then |
pankso@62 | 166 size=$(du -sh $rpi/rootfs | awk '{print $1}') |
pankso@62 | 167 echo -n "Copying custom RPi rootfs: $size" |
pankso@62 | 168 tmp=$distro/tmp-$$ |
pankso@62 | 169 mkdir -p $tmp |
pankso@62 | 170 cp -r $rpi/rootfs/* $tmp |
pankso@62 | 171 chown -R root.root $tmp |
pankso@62 | 172 cp -a $tmp/* ${rootfs} && rm -rf $tmp |
pankso@63 | 173 mv -f ${rootfs}/boot/* ${boot} |
pankso@62 | 174 status |
pankso@62 | 175 fi |
pankso@62 | 176 |
pankso@163 | 177 # TazBerry, Piboot, Pileds, ... |
pankso@163 | 178 for tool in tazberry piboot pileds |
pankso@163 | 179 do |
pankso@163 | 180 echo -n "Copying utility: $tool" |
pankso@168 | 181 cp -f ${rpi}/${tool} ${rootfs}/usr/sbin |
pankso@163 | 182 status |
pankso@163 | 183 done |
pankso@163 | 184 |
pankso@163 | 185 # CGI Plugins |
pankso@163 | 186 echo -n "Copying CGI/adm plugins..." |
pankso@58 | 187 cp -a ${rpi}/cgi-adm/* ${rootfs}/var/www/adm |
pankso@49 | 188 status |
pankso@49 | 189 |
pankso@49 | 190 # Kernel at last |
pankso@157 | 191 . $cache/linux-*-arm/receipt |
pankso@49 | 192 kvers="$VERSION" |
pankso@49 | 193 kpkg="$rootfs/var/lib/tazpkg/installed/linux" |
pankso@157 | 194 fs="$cache/linux-$kvers-arm/fs" |
pankso@49 | 195 ksize=$(du -sh $fs | awk '{print $1}') |
pankso@49 | 196 if [ -d "$fs" ]; then |
pankso@49 | 197 echo -n "Copying: kernel $kvers ($ksize)" |
pankso@49 | 198 rm -rf ${rootfs}/lib/modules |
pankso@49 | 199 cp -rf ${fs}/lib/* ${rootfs}/lib |
pankso@49 | 200 cp -f ${fs}/boot/* ${boot} |
pankso@49 | 201 mkdir -p ${kpkg} |
pankso@157 | 202 cd ${cache}/linux-${kvers}-arm |
pankso@49 | 203 cp -f files.list md5sum receipt ${kpkg} |
pankso@49 | 204 status |
pankso@49 | 205 else |
pankso@50 | 206 echo "SliTaz RPi Kernel: not used" |
pankso@49 | 207 fi |
pankso@49 | 208 |
pankso@49 | 209 separator |
pankso@49 | 210 echo -n "Boot: $(du -sh $boot | awk '{print $1}') " |
pankso@49 | 211 echo "- Rootfs: $(du -sh $rootfs | awk '{print $1}')" |
pankso@49 | 212 newline ;; |
pankso@49 | 213 |
pankso@49 | 214 cook-linux) |
pankso@49 | 215 # Native SliTaz Toolchain and cross toolchain must be installed |
pankso@49 | 216 check_root |
pankso@94 | 217 install="$cache/linux-install" |
pankso@49 | 218 if [ ! -d "/cross/$arch" ]; then |
pankso@67 | 219 error "Missing cross toolchain in: /cross/$arch" && exit 1 |
pankso@49 | 220 fi |
pankso@49 | 221 |
pankso@145 | 222 # Kernel source and --clean |
pankso@143 | 223 mkdir -p ${rpi_git} && cd ${rpi_git} |
pankso@49 | 224 [ -d "$kernel" ] || git clone --depth 1 ${rpi_git_url}linux.git |
pankso@145 | 225 [ "$clean" ] && rm -rf ${install} |
pankso@145 | 226 |
paul@153 | 227 # FBtft drivers for small touchscreens such PiTFT, PiScreen |
pankso@145 | 228 if [ "$fbtft" ] && [ ! -d "${kernel}/drivers/video/fbtft" ]; then |
pankso@145 | 229 cd ${kernel}/drivers/video |
pankso@163 | 230 #git clone git://github.com/notro/fbtft.git |
pankso@163 | 231 git clone https://github.com/adafruit/adafruit-rpi-fbtft |
pankso@163 | 232 mv adafruit-rpi-fbtft fbtft |
pankso@145 | 233 cd ${kernel} |
pankso@145 | 234 echo 'source "drivers/video/fbtft/Kconfig"' >> drivers/video/Kconfig |
pankso@145 | 235 echo 'obj-y += fbtft/' >> drivers/video/Makefile |
pankso@145 | 236 cd ${rpi_git} |
pankso@145 | 237 fi |
pankso@49 | 238 |
pankso@49 | 239 # Compile |
pankso@49 | 240 if [ ! -d "$install" ]; then |
pankso@49 | 241 cd ${kernel} |
pankso@49 | 242 export PATH=$PATH:/cross/${arch}/tools/bin |
pankso@49 | 243 export HOST_SYSTEM=${arch}-slitaz-linux-gnueabi |
pankso@49 | 244 make mrproper && |
pankso@49 | 245 make ARCH=arm bcmrpi_defconfig |
pankso@141 | 246 if [ ! "$nopatch" ]; then |
pankso@141 | 247 echo "Patching SliTaz RPi Linux .config" |
pankso@141 | 248 patch -p0 -i ${data}/linux-rpi.patch || exit 1 |
pankso@141 | 249 fi |
pankso@141 | 250 [ "$gconfig" ] && make ARCH=arm gconfig |
pankso@49 | 251 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- zImage && |
pankso@49 | 252 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- modules && |
pankso@49 | 253 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- \ |
pankso@49 | 254 INSTALL_MOD_PATH=${install} modules_install || exit 1 |
pankso@49 | 255 mkdir -p ${install}/boot |
pankso@50 | 256 cp -a arch/arm/boot/zImage ${install}/boot/kernel.img |
pankso@49 | 257 fi |
pankso@49 | 258 |
pankso@49 | 259 # Kernel version |
pankso@49 | 260 kvers=$(ls ${install}/lib/modules) |
pankso@141 | 261 kvers=${kvers%-tazberry+}+ |
pankso@49 | 262 |
pankso@49 | 263 # Compress modules |
pankso@141 | 264 #cd ${install}/lib/modules/*/kernel || exit 1 |
pankso@141 | 265 #mods=$(find . -name "*.ko$" | wc -l) |
pankso@141 | 266 #newline |
pankso@141 | 267 #echo "Compressing kernel modules: $mods" |
pankso@141 | 268 #find . -name "*.ko$" -exec xz '{}' \; 2> /dev/null |
pankso@50 | 269 |
pankso@49 | 270 # Rebuild modules.dep |
pankso@49 | 271 cd ${install} |
pankso@141 | 272 depmod -b . ${kvers%+}-tazberry+ |
pankso@49 | 273 |
pankso@50 | 274 # Kernel |
pankso@145 | 275 pkg="linux" |
pankso@145 | 276 [ "$fbtft" ] && pkg="linux-fbtft" |
pankso@157 | 277 fs="$cache/$pkg-$kvers-arm/fs" |
pankso@49 | 278 echo "Kernel version: $kvers" |
pankso@49 | 279 if [ -d "$install" ]; then |
pankso@157 | 280 rm -rf ${cache}/${pkg}-${kvers}-arm |
pankso@157 | 281 mkdir -p ${fs} |
pankso@157 | 282 cp -a ${install}/* ${fs} |
pankso@50 | 283 rm -f ${fs}/lib/modules/*/build \ |
pankso@50 | 284 ${fs}/lib/modules/*/source |
pankso@157 | 285 else |
pankso@157 | 286 echo "Kernel is not built..." && exit 1 |
pankso@49 | 287 fi |
pankso@50 | 288 |
pankso@50 | 289 # Pack .tazpkg |
pankso@94 | 290 cd ${cache} |
pankso@49 | 291 echo "Creating package: receipt" |
pankso@157 | 292 cat > ${pkg}-${kvers}-arm/receipt << EOT |
pankso@49 | 293 # SliTaz package receipt |
pankso@49 | 294 |
pankso@145 | 295 PACKAGE="${pkg}" |
pankso@49 | 296 VERSION="$kvers" |
pankso@141 | 297 SHORT_DESC="SliTaz GNU/Linux Kernel for the Raspberry Pi." |
pankso@157 | 298 MAINTAINER="pankso@slitaz.org" |
pankso@49 | 299 WEB_SITE="http://www.kernel.org" |
pankso@157 | 300 HOST_ARCH="arm" |
pankso@49 | 301 |
pankso@49 | 302 EOT |
pankso@157 | 303 tazpkg pack ${pkg}-${kvers}-arm ;; |
pankso@49 | 304 |
pankso@67 | 305 clone-fw) |
pankso@67 | 306 clone_fw ;; |
pankso@49 | 307 |
pankso@49 | 308 get-linux) |
pankso@49 | 309 # Precook RPi kernel |
pankso@55 | 310 check_root |
pankso@94 | 311 mkdir -p ${cache} |
pankso@49 | 312 |
pankso@49 | 313 # Last version |
pankso@94 | 314 rm -f ${cache}/linux-version.txt |
pankso@175 | 315 if busybox wget -q -s ${rpi_mirror}/packages/last-linux.txt; then |
pankso@49 | 316 echo -n "Fetching latest Kernel string..." |
pankso@175 | 317 wget -q ${rpi_mirror}/packages/last-linux.txt \ |
pankso@94 | 318 -O ${cache}/linux-version.txt || exit 1 |
pankso@49 | 319 status |
pankso@49 | 320 else |
pankso@49 | 321 echo "Mirror is unreachable" && exit 1 |
pankso@49 | 322 fi |
pankso@94 | 323 kvers=$(cat $cache/linux-version.txt) |
pankso@94 | 324 [ "$up" ] && rm -rf ${cache}/linux-${kvers}* |
pankso@49 | 325 echo "Kernel version: $kvers" |
pankso@49 | 326 |
pankso@49 | 327 # Download |
pankso@94 | 328 if [ ! -f "$cache/linux-$kvers.tazpkg" ]; then |
pankso@49 | 329 echo -n "Fetching latest Linux package..." |
pankso@176 | 330 wget -q ${rpi_mirror}/packages/linux-${kvers}-arm.tazpkg \ |
pankso@176 | 331 -O ${cache}/linux-${kvers}-arm.tazpkg; status |
pankso@49 | 332 fi |
pankso@49 | 333 |
pankso@49 | 334 # Extract |
pankso@94 | 335 if [ ! -d "$cache/linux-$kvers" ]; then |
pankso@176 | 336 cd ${cache} && tazpkg extract linux-${kvers}-arm.tazpkg |
pankso@49 | 337 fi |
pankso@94 | 338 rm -f ${cache}/linux-version.txt ;; |
pankso@49 | 339 |
pankso@49 | 340 get-prebuilt) |
pankso@49 | 341 # --> in cross ?? |
pankso@49 | 342 : ${arch=arm} |
pankso@49 | 343 name="slitaz-$arch-toolchain" |
pankso@49 | 344 vers="20140304" |
pankso@49 | 345 tarball="$name-$vers.tar.bz2" |
pankso@49 | 346 url="http://mirror.slitaz.org/packages/cross/" |
pankso@49 | 347 mkdir -p /cross |
pankso@49 | 348 cd /cross |
pankso@49 | 349 if [ ! -f "$tarball" ]; then |
pankso@49 | 350 if busybox wget -qs ${url%/}/${tarball}; then |
pankso@49 | 351 busybox wget ${url%/}/${tarball} |
pankso@49 | 352 else |
pankso@49 | 353 echo "Toolchain URL is unreachable" && exit 1 |
pankso@49 | 354 fi |
pankso@49 | 355 fi |
pankso@49 | 356 if [ ! -d "${name}-${vers}" ]; then |
pankso@49 | 357 echo "Extracting: $tarball" |
pankso@49 | 358 tar xjf ${tarball} |
pankso@49 | 359 fi |
pankso@49 | 360 echo "Copying: ${name}-${vers}/${arch}" |
pankso@49 | 361 mkdir -p ${arch} |
pankso@49 | 362 cp -a ${name}-${vers}/${arch}/* ${arch} |
pankso@49 | 363 echo "Tools path: /cross/${arch}/tools/bin" ;; |
pankso@49 | 364 |
pankso@49 | 365 release) |
pankso@49 | 366 # Used to release official SliTaz RPi images |
pankso@49 | 367 cd ${distro} || exit 1 |
pankso@49 | 368 if [ ! "$flavor" ]; then |
pankso@49 | 369 . $distro/rootfs/etc/slitaz/flavor.conf || exit 1 |
pankso@49 | 370 flavor="$FLAVOR" |
pankso@49 | 371 fi |
pankso@54 | 372 dname="slitaz-$flavor-$(date +%Y%m%d)" |
pankso@49 | 373 dsize=$(du -sh $distro | awk '{print $1}' | cut -d "." -f 1) |
pankso@54 | 374 rm -rf ${dname} && mkdir ${dname} |
pankso@54 | 375 cp -a boot rootfs ${dname} |
pankso@67 | 376 echo "Copying: SliTaz release files" |
pankso@67 | 377 cp ${rpi}/release/* ${dname} |
pankso@84 | 378 echo "Creating: ${dname}.tar.bz2" |
pankso@84 | 379 tar -cjf ${dname}.tar.bz2 ${dname} |
pankso@55 | 380 echo "Creating: ${dname}.md5" |
pankso@84 | 381 md5sum ${dname}.tar.bz2 > ${dname}.md5 |
pankso@55 | 382 rm -rf ${dname} ;; |
pankso@49 | 383 |
pankso@49 | 384 clean) |
pankso@49 | 385 echo "Cleaning: $rpi" |
pankso@94 | 386 rm -rf ${cache} ${rpi_git} ;; |
pankso@67 | 387 |
pankso@67 | 388 *|*help) usage ;; |
pankso@49 | 389 esac |
pankso@49 | 390 exit 0 |