devsus.sh 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/bin/sh -xe
  2. # this file is part of Devsus.
  3. #
  4. # Copyright 2017 Dima Krasner
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  19. # MA 02110-1301, USA.
  20. outmnt=$(mktemp -d -p `pwd`)
  21. inmnt=$(mktemp -d -p `pwd`)
  22. outdev=/dev/loop6
  23. indev=/dev/loop7
  24. cleanup() {
  25. set +e
  26. umount -l $inmnt > /dev/null 2>&1
  27. rmdir $inmnt > /dev/null 2>&1
  28. losetup -d $indev > /dev/null 2>&1
  29. umount -l $outmnt > /dev/null 2>&1
  30. rmdir $outmnt > /dev/null 2>&1
  31. losetup -d $outdev > /dev/null 2>&1
  32. }
  33. trap cleanup INT TERM EXIT
  34. # build the Chrome OS kernel, with ath9k_htc and without many useless drivers
  35. [ ! -d chromeos-3.14 ] && git clone --depth 1 -b chromeos-3.14 https://chromium.googlesource.com/chromiumos/third_party/kernel chromeos-3.14
  36. [ ! -f deblob-3.14 ] && wget http://linux-libre.fsfla.org/pub/linux-libre/releases/LATEST-3.14.N/deblob-3.14
  37. [ ! -f deblob-check ] && wget http://linux-libre.fsfla.org/pub/linux-libre/releases/LATEST-3.14.N/deblob-check
  38. cd chromeos-3.14
  39. # deblob as much as possible - the diff against vanilla 3.14.x is big but
  40. # blob-free ath9k_htc should be only driver that requests firmware
  41. AWK=gawk sh ../deblob-3.14 --force
  42. export WIFIVERSION=-3.8
  43. ./chromeos/scripts/prepareconfig chromiumos-rockchip
  44. cp ../config .config
  45. make -j `grep ^processor /proc/cpuinfo | wc -l` CROSS_COMPILE=arm-none-eabi- ARCH=arm zImage modules dtbs
  46. [ ! -h kernel.its ] && ln -s ../kernel.its .
  47. mkimage -D "-I dts -O dtb -p 2048" -f kernel.its vmlinux.uimg
  48. dd if=/dev/zero of=bootloader.bin bs=512 count=1
  49. vbutil_kernel --pack vmlinux.kpart \
  50. --version 1 \
  51. --vmlinuz vmlinux.uimg \
  52. --arch arm \
  53. --keyblock /usr/share/vboot/devkeys/kernel.keyblock \
  54. --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \
  55. --config ../cmdline \
  56. --bootloader bootloader.bin
  57. cd ..
  58. # build AR9271 firmware
  59. [ ! -d open-ath9k-htc-firmware ] && git clone --depth 1 https://github.com/qca/open-ath9k-htc-firmware.git
  60. cd open-ath9k-htc-firmware
  61. make toolchain
  62. make -C target_firmware
  63. cd ..
  64. create_image() {
  65. # it's a sparse file - that's how we fit a 16GB image inside a 2GB one
  66. dd if=/dev/zero of=$1 bs=$3 count=$4 conv=sparse
  67. parted --script $1 mklabel gpt
  68. cgpt create $1
  69. cgpt add -i 1 -t kernel -b 8192 -s 65536 -l Kernel -S 1 -T 5 -P 10 $1
  70. start=$((8192 + 65536))
  71. end=`cgpt show $1 | grep 'Sec GPT table' | awk '{print $1}'`
  72. size=$(($end - $start))
  73. cgpt add -i 2 -t data -b $start -s $size -l Root $1
  74. # $size is in 512 byte blocks while ext4 uses a block size of 1024 bytes
  75. losetup -P $2 $1
  76. mkfs.ext4 -F -b 1024 -m 0 -O ^has_journal ${2}p2 $(($size / 2))
  77. # mount the / partition
  78. mount -o noatime ${2}p2 $5
  79. }
  80. # create a 2GB image with the Chrome OS partition layout
  81. create_image devuan-jessie-c201-libre-2GB.img $outdev 50M 40 $outmnt
  82. # install Devuan on it
  83. qemu-debootstrap --arch=armhf jessie --variant minbase $outmnt http://packages.devuan.org/merged
  84. chroot $outmnt passwd -d root
  85. echo -n devsus > $outmnt/etc/hostname
  86. install -D -m 644 80disable-recommends $outmnt/etc/apt/apt.conf.d/80disable-recommends
  87. cp -f /etc/resolv.conf $outmnt/etc/
  88. chroot $outmnt apt update
  89. chroot $outmnt apt install -y udev kmod net-tools inetutils-ping traceroute iproute2 isc-dhcp-client wpasupplicant iw alsa-utils cgpt vim-tiny less psmisc netcat-openbsd ca-certificates bzip2 xz-utils unscd
  90. chroot $outmnt apt-get autoremove --purge
  91. chroot $outmnt apt-get clean
  92. sed -i s/^[3-6]/\#\&/g $outmnt/etc/inittab
  93. sed -i s/'enable-cache hosts no'/'enable-cache hosts yes'/ -i $outmnt/etc/nscd.conf
  94. rm -f $outmnt/etc/resolv.conf
  95. # put the kernel in the kernel partition, modules in /lib/modules and AR9271
  96. # firmware in /lib/firmware
  97. dd if=chromeos-3.14/vmlinux.kpart of=${outdev}p1 conv=notrunc
  98. make -C chromeos-3.14 ARCH=arm INSTALL_MOD_PATH=$outmnt modules_install
  99. rm -f $outmnt/lib/modules/3.14.0/{build,source}
  100. install -D -m 644 open-ath9k-htc-firmware/target_firmware/htc_9271.fw $outmnt/lib/firmware/htc_9271.fw
  101. # create a 16GB image
  102. create_image devuan-jessie-c201-libre-16GB.img $indev 512 30785536 $inmnt
  103. # copy the kernel and / of the 2GB image to the 16GB one
  104. dd if=${outdev}p1 of=${indev}p1 conv=notrunc
  105. cp -a $outmnt/* $inmnt/
  106. umount -l $inmnt
  107. rmdir $inmnt
  108. losetup -d $indev
  109. # move the 16GB image inside the 2GB one
  110. cp -f devuan-jessie-c201-libre-16GB.img $outmnt/