slitaz-arm annotate sat-rpi @ rev 207
tazbian: check for model 1 in postinstall
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Aug 08 23:42:01 2015 +0200 (2015-08-08) |
parents | abffc259e9cb |
children |
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@189 | 178 for tool in tazberry piboot pileds raspicomm piface pitft-setup \ |
pankso@189 | 179 pibrella piborg/piborg |
pankso@163 | 180 do |
pankso@163 | 181 echo -n "Copying utility: $tool" |
pankso@168 | 182 cp -f ${rpi}/${tool} ${rootfs}/usr/sbin |
pankso@163 | 183 status |
pankso@163 | 184 done |
pankso@163 | 185 |
pankso@163 | 186 # CGI Plugins |
pankso@163 | 187 echo -n "Copying CGI/adm plugins..." |
pankso@58 | 188 cp -a ${rpi}/cgi-adm/* ${rootfs}/var/www/adm |
pankso@49 | 189 status |
pankso@49 | 190 |
pankso@49 | 191 # Kernel at last |
pankso@157 | 192 . $cache/linux-*-arm/receipt |
pankso@49 | 193 kvers="$VERSION" |
pankso@49 | 194 kpkg="$rootfs/var/lib/tazpkg/installed/linux" |
pankso@157 | 195 fs="$cache/linux-$kvers-arm/fs" |
pankso@49 | 196 ksize=$(du -sh $fs | awk '{print $1}') |
pankso@49 | 197 if [ -d "$fs" ]; then |
pankso@49 | 198 echo -n "Copying: kernel $kvers ($ksize)" |
pankso@49 | 199 rm -rf ${rootfs}/lib/modules |
pankso@49 | 200 cp -rf ${fs}/lib/* ${rootfs}/lib |
pankso@49 | 201 cp -f ${fs}/boot/* ${boot} |
pankso@49 | 202 mkdir -p ${kpkg} |
pankso@157 | 203 cd ${cache}/linux-${kvers}-arm |
pankso@49 | 204 cp -f files.list md5sum receipt ${kpkg} |
pankso@49 | 205 status |
pankso@49 | 206 else |
pankso@50 | 207 echo "SliTaz RPi Kernel: not used" |
pankso@49 | 208 fi |
pankso@49 | 209 |
pankso@49 | 210 separator |
pankso@49 | 211 echo -n "Boot: $(du -sh $boot | awk '{print $1}') " |
pankso@49 | 212 echo "- Rootfs: $(du -sh $rootfs | awk '{print $1}')" |
pankso@49 | 213 newline ;; |
pankso@49 | 214 |
pankso@49 | 215 cook-linux) |
pankso@49 | 216 # Native SliTaz Toolchain and cross toolchain must be installed |
pankso@49 | 217 check_root |
pankso@94 | 218 install="$cache/linux-install" |
pankso@49 | 219 if [ ! -d "/cross/$arch" ]; then |
pankso@67 | 220 error "Missing cross toolchain in: /cross/$arch" && exit 1 |
pankso@49 | 221 fi |
pankso@49 | 222 |
pankso@145 | 223 # Kernel source and --clean |
pankso@143 | 224 mkdir -p ${rpi_git} && cd ${rpi_git} |
pankso@49 | 225 [ -d "$kernel" ] || git clone --depth 1 ${rpi_git_url}linux.git |
pankso@145 | 226 [ "$clean" ] && rm -rf ${install} |
pankso@145 | 227 |
paul@153 | 228 # FBtft drivers for small touchscreens such PiTFT, PiScreen |
pankso@145 | 229 if [ "$fbtft" ] && [ ! -d "${kernel}/drivers/video/fbtft" ]; then |
pankso@145 | 230 cd ${kernel}/drivers/video |
pankso@163 | 231 #git clone git://github.com/notro/fbtft.git |
pankso@163 | 232 git clone https://github.com/adafruit/adafruit-rpi-fbtft |
pankso@163 | 233 mv adafruit-rpi-fbtft fbtft |
pankso@145 | 234 cd ${kernel} |
pankso@145 | 235 echo 'source "drivers/video/fbtft/Kconfig"' >> drivers/video/Kconfig |
pankso@145 | 236 echo 'obj-y += fbtft/' >> drivers/video/Makefile |
pankso@145 | 237 cd ${rpi_git} |
pankso@145 | 238 fi |
pankso@49 | 239 |
pankso@49 | 240 # Compile |
pankso@49 | 241 if [ ! -d "$install" ]; then |
pankso@49 | 242 cd ${kernel} |
pankso@49 | 243 export PATH=$PATH:/cross/${arch}/tools/bin |
pankso@49 | 244 export HOST_SYSTEM=${arch}-slitaz-linux-gnueabi |
pankso@189 | 245 make mrproper && |
pankso@189 | 246 make ARCH=arm bcmrpi_defconfig |
pankso@141 | 247 if [ ! "$nopatch" ]; then |
pankso@141 | 248 echo "Patching SliTaz RPi Linux .config" |
pankso@141 | 249 patch -p0 -i ${data}/linux-rpi.patch || exit 1 |
pankso@141 | 250 fi |
pankso@141 | 251 [ "$gconfig" ] && make ARCH=arm gconfig |
pankso@49 | 252 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- zImage && |
pankso@49 | 253 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- modules && |
pankso@49 | 254 make ARCH=arm CROSS_COMPILE=${HOST_SYSTEM}- \ |
pankso@49 | 255 INSTALL_MOD_PATH=${install} modules_install || exit 1 |
pankso@49 | 256 mkdir -p ${install}/boot |
pankso@50 | 257 cp -a arch/arm/boot/zImage ${install}/boot/kernel.img |
pankso@49 | 258 fi |
pankso@49 | 259 |
pankso@49 | 260 # Kernel version |
pankso@49 | 261 kvers=$(ls ${install}/lib/modules) |
pankso@141 | 262 kvers=${kvers%-tazberry+}+ |
pankso@49 | 263 |
pankso@49 | 264 # Compress modules |
pankso@141 | 265 #cd ${install}/lib/modules/*/kernel || exit 1 |
pankso@141 | 266 #mods=$(find . -name "*.ko$" | wc -l) |
pankso@141 | 267 #newline |
pankso@141 | 268 #echo "Compressing kernel modules: $mods" |
pankso@141 | 269 #find . -name "*.ko$" -exec xz '{}' \; 2> /dev/null |
pankso@50 | 270 |
pankso@49 | 271 # Rebuild modules.dep |
pankso@49 | 272 cd ${install} |
pankso@141 | 273 depmod -b . ${kvers%+}-tazberry+ |
pankso@49 | 274 |
pankso@50 | 275 # Kernel |
pankso@145 | 276 pkg="linux" |
pankso@145 | 277 [ "$fbtft" ] && pkg="linux-fbtft" |
pankso@157 | 278 fs="$cache/$pkg-$kvers-arm/fs" |
pankso@49 | 279 echo "Kernel version: $kvers" |
pankso@49 | 280 if [ -d "$install" ]; then |
pankso@157 | 281 rm -rf ${cache}/${pkg}-${kvers}-arm |
pankso@157 | 282 mkdir -p ${fs} |
pankso@157 | 283 cp -a ${install}/* ${fs} |
pankso@50 | 284 rm -f ${fs}/lib/modules/*/build \ |
pankso@50 | 285 ${fs}/lib/modules/*/source |
pankso@157 | 286 else |
pankso@157 | 287 echo "Kernel is not built..." && exit 1 |
pankso@49 | 288 fi |
pankso@50 | 289 |
pankso@50 | 290 # Pack .tazpkg |
pankso@94 | 291 cd ${cache} |
pankso@49 | 292 echo "Creating package: receipt" |
pankso@157 | 293 cat > ${pkg}-${kvers}-arm/receipt << EOT |
pankso@49 | 294 # SliTaz package receipt |
pankso@49 | 295 |
pankso@145 | 296 PACKAGE="${pkg}" |
pankso@49 | 297 VERSION="$kvers" |
pankso@141 | 298 SHORT_DESC="SliTaz GNU/Linux Kernel for the Raspberry Pi." |
pankso@157 | 299 MAINTAINER="pankso@slitaz.org" |
pankso@49 | 300 WEB_SITE="http://www.kernel.org" |
pankso@157 | 301 HOST_ARCH="arm" |
pankso@49 | 302 |
pankso@49 | 303 EOT |
pankso@157 | 304 tazpkg pack ${pkg}-${kvers}-arm ;; |
pankso@49 | 305 |
pankso@67 | 306 clone-fw) |
pankso@67 | 307 clone_fw ;; |
pankso@49 | 308 |
pankso@49 | 309 get-linux) |
pankso@49 | 310 # Precook RPi kernel |
pankso@55 | 311 check_root |
pankso@94 | 312 mkdir -p ${cache} |
pankso@49 | 313 |
pankso@49 | 314 # Last version |
pankso@94 | 315 rm -f ${cache}/linux-version.txt |
pankso@175 | 316 if busybox wget -q -s ${rpi_mirror}/packages/last-linux.txt; then |
pankso@49 | 317 echo -n "Fetching latest Kernel string..." |
pankso@175 | 318 wget -q ${rpi_mirror}/packages/last-linux.txt \ |
pankso@94 | 319 -O ${cache}/linux-version.txt || exit 1 |
pankso@49 | 320 status |
pankso@49 | 321 else |
pankso@49 | 322 echo "Mirror is unreachable" && exit 1 |
pankso@49 | 323 fi |
pankso@94 | 324 kvers=$(cat $cache/linux-version.txt) |
pankso@94 | 325 [ "$up" ] && rm -rf ${cache}/linux-${kvers}* |
pankso@49 | 326 echo "Kernel version: $kvers" |
pankso@49 | 327 |
pankso@49 | 328 # Download |
pankso@94 | 329 if [ ! -f "$cache/linux-$kvers.tazpkg" ]; then |
pankso@49 | 330 echo -n "Fetching latest Linux package..." |
pankso@176 | 331 wget -q ${rpi_mirror}/packages/linux-${kvers}-arm.tazpkg \ |
pankso@176 | 332 -O ${cache}/linux-${kvers}-arm.tazpkg; status |
pankso@49 | 333 fi |
pankso@49 | 334 |
pankso@49 | 335 # Extract |
pankso@94 | 336 if [ ! -d "$cache/linux-$kvers" ]; then |
pankso@176 | 337 cd ${cache} && tazpkg extract linux-${kvers}-arm.tazpkg |
pankso@49 | 338 fi |
pankso@94 | 339 rm -f ${cache}/linux-version.txt ;; |
pankso@49 | 340 |
pankso@49 | 341 get-prebuilt) |
pankso@49 | 342 # --> in cross ?? |
pankso@49 | 343 : ${arch=arm} |
pankso@49 | 344 name="slitaz-$arch-toolchain" |
pankso@49 | 345 vers="20140304" |
pankso@49 | 346 tarball="$name-$vers.tar.bz2" |
pankso@49 | 347 url="http://mirror.slitaz.org/packages/cross/" |
pankso@49 | 348 mkdir -p /cross |
pankso@49 | 349 cd /cross |
pankso@49 | 350 if [ ! -f "$tarball" ]; then |
pankso@49 | 351 if busybox wget -qs ${url%/}/${tarball}; then |
pankso@49 | 352 busybox wget ${url%/}/${tarball} |
pankso@49 | 353 else |
pankso@49 | 354 echo "Toolchain URL is unreachable" && exit 1 |
pankso@49 | 355 fi |
pankso@49 | 356 fi |
pankso@49 | 357 if [ ! -d "${name}-${vers}" ]; then |
pankso@49 | 358 echo "Extracting: $tarball" |
pankso@49 | 359 tar xjf ${tarball} |
pankso@49 | 360 fi |
pankso@49 | 361 echo "Copying: ${name}-${vers}/${arch}" |
pankso@49 | 362 mkdir -p ${arch} |
pankso@49 | 363 cp -a ${name}-${vers}/${arch}/* ${arch} |
pankso@49 | 364 echo "Tools path: /cross/${arch}/tools/bin" ;; |
pankso@49 | 365 |
pankso@49 | 366 release) |
pankso@49 | 367 # Used to release official SliTaz RPi images |
pankso@49 | 368 cd ${distro} || exit 1 |
pankso@49 | 369 if [ ! "$flavor" ]; then |
pankso@49 | 370 . $distro/rootfs/etc/slitaz/flavor.conf || exit 1 |
pankso@49 | 371 flavor="$FLAVOR" |
pankso@49 | 372 fi |
pankso@54 | 373 dname="slitaz-$flavor-$(date +%Y%m%d)" |
pankso@49 | 374 dsize=$(du -sh $distro | awk '{print $1}' | cut -d "." -f 1) |
pankso@54 | 375 rm -rf ${dname} && mkdir ${dname} |
pankso@54 | 376 cp -a boot rootfs ${dname} |
pankso@67 | 377 echo "Copying: SliTaz release files" |
pankso@67 | 378 cp ${rpi}/release/* ${dname} |
pankso@84 | 379 echo "Creating: ${dname}.tar.bz2" |
pankso@84 | 380 tar -cjf ${dname}.tar.bz2 ${dname} |
pankso@55 | 381 echo "Creating: ${dname}.md5" |
pankso@84 | 382 md5sum ${dname}.tar.bz2 > ${dname}.md5 |
pankso@55 | 383 rm -rf ${dname} ;; |
pankso@49 | 384 |
pankso@49 | 385 clean) |
pankso@49 | 386 echo "Cleaning: $rpi" |
pankso@94 | 387 rm -rf ${cache} ${rpi_git} ;; |
pankso@67 | 388 |
pankso@67 | 389 *|*help) usage ;; |
pankso@49 | 390 esac |
pankso@49 | 391 exit 0 |