devsus.sh 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #!/bin/sh -xe
  2. # this file is part of Devsus.
  3. #
  4. # Copyright 2017, 2018 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. KVER=4.9
  21. here=`pwd`
  22. outmnt=$(mktemp -d -p $here)
  23. inmnt=$(mktemp -d -p $here)
  24. cleanup() {
  25. set +e
  26. umount -l $inmnt > /dev/null 2>&1
  27. rmdir $inmnt > /dev/null 2>&1
  28. umount -l $outmnt > /dev/null 2>&1
  29. rmdir $outmnt > /dev/null 2>&1
  30. }
  31. install_devuan() {
  32. debootstrap --arch=armhf --foreign --variant=minbase --include=eudev,kmod,net-tools,inetutils-ping,traceroute,iproute2,isc-dhcp-client,wpasupplicant,iw,alsa-utils,cgpt,elvis-tiny,less,psmisc,netcat-traditional,ca-certificates,bzip2,xz-utils,unscd,dbus,dbus-x11,bluez,pulseaudio,pulseaudio-module-bluetooth,elogind,libpam-elogind,ntp,xserver-xorg-core,xserver-xorg-input-libinput,xserver-xorg-video-fbdev,libgl1-mesa-dri,xserver-xorg-input-synaptics,xinit,x11-xserver-utils,ratpoison,xbindkeys,xvkbd,rxvt-unicode,htop,firefox-esr,mupdf,locales,man-db,dmz-cursor-theme,apt-transport-https ascii $1 http://packages.devuan.org/merged
  33. install -D -m 644 devsus/sources.list $1/opt/devsus/sources.list
  34. for i in 80disable-recommends 99-brightness.rules 98-mac.rules fstab .xbindkeysrc htoprc .Xresources .ratpoisonrc 99-hinting.conf index.theme devsus-settings.js devsus.cfg
  35. do
  36. install -m 644 devsus/$i $1/opt/devsus/$i
  37. done
  38. install -m 644 dl/hosts $1/opt/devsus/hosts
  39. install -m 744 devsus/.xinitrc $1/opt/devsus/.xinitrc
  40. install -m 755 devsus/init $1/opt/devsus/init
  41. # put kernel modules in /lib/modules and AR9271 firmware in /lib/firmware
  42. $kmake -C linux-$KVER INSTALL_MOD_PATH=$1 modules_install
  43. rm -f $1/lib/modules/$KVER.0-gnu/{build,source}
  44. install -D -m 644 open-ath9k-htc-firmware/target_firmware/htc_9271.fw $1/lib/firmware/htc_9271.fw
  45. return 0
  46. }
  47. create_image() {
  48. # it's a sparse file - that's how we fit a 16GB image inside a 2GB one
  49. dd if=/dev/zero of=$1 bs=$2 count=$3 conv=sparse
  50. parted --script $1 mklabel gpt
  51. cgpt create $1
  52. cgpt add -i 1 -t kernel -b 8192 -s 65536 -l Kernel -S 1 -T 5 -P 10 $1
  53. start=$((8192 + 65536))
  54. end=`cgpt show $1 | grep 'Sec GPT table' | awk '{print $1}'`
  55. size=$(($end - $start))
  56. cgpt add -i 2 -t data -b $start -s $size -l Root $1
  57. # $size is in 512 byte blocks while ext4 uses a block size of 1024 bytes
  58. mkfs.ext4 -F -b 1024 -m 0 -O ^has_journal -E offset=$(($start * 512)) $1 $(($size / 2))
  59. }
  60. if [ "$CI" = true ]
  61. then
  62. minor=`wget -q -O- http://linux-libre.fsfla.org/pub/linux-libre/releases/LATEST-$KVER.N/ | grep -F patch-$KVER-gnu | head -n 1 | cut -f 9 -d . | cut -f 1 -d -`
  63. [ ! -f dl/linux-libre-$KVER-gnu.tar.xz ] && wget -O dl/linux-libre-$KVER-gnu.tar.xz http://linux-libre.fsfla.org/pub/linux-libre/releases/LATEST-4.9.0/linux-libre-$KVER-gnu.tar.xz
  64. [ ! -f dl/patch-$KVER-gnu-$KVER.$minor-gnu ] && wget -O- https://www.linux-libre.fsfla.org/pub/linux-libre/releases/LATEST-$KVER.N/patch-$KVER-gnu-$KVER.$minor-gnu.xz | xz -d > dl/patch-$KVER-gnu-$KVER.$minor-gnu
  65. [ ! -f dl/ath9k_htc_do_not_use_bulk_on_ep3_and_ep4.patch ] && wget -O dl/ath9k_htc_do_not_use_bulk_on_ep3_and_ep4.patch https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/patch/?id=2b721118b7821107757eb1d37af4b60e877b27e7
  66. [ ! -f dl/hosts ] && wget -O- https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews/hosts | grep ^0\.0\.0\.0 | awk '{print $1" "$2}' | grep -F -v "0.0.0.0 0.0.0.0" > dl/hosts
  67. [ ! -d open-ath9k-htc-firmware ] && git clone --depth 1 https://github.com/qca/open-ath9k-htc-firmware.git
  68. # build Linux-libre
  69. [ ! -d linux-$KVER ] && tar -xJf dl/linux-libre-$KVER-gnu.tar.xz
  70. cd linux-$KVER
  71. patch -p 1 < ../dl/patch-$KVER-gnu-$KVER.$minor-gnu
  72. make clean
  73. make mrproper
  74. # work around instability of ath9k_htc, see https://github.com/SolidHal/PrawnOS/issues/38
  75. patch -R -p 1 < ../dl/ath9k_htc_do_not_use_bulk_on_ep3_and_ep4.patch
  76. # reset the minor version number, so out-of-tree drivers continue to work after
  77. # a kernel upgrade
  78. sed s/'SUBLEVEL = .*'/'SUBLEVEL = 0'/ -i Makefile
  79. cp -f ../config .config
  80. kmake="make -j `grep ^processor /proc/cpuinfo | wc -l` CROSS_COMPILE=arm-none-eabi- ARCH=arm"
  81. $kmake olddefconfig
  82. $kmake modules_prepare
  83. $kmake SUBDIRS=drivers/usb/dwc2 modules
  84. $kmake SUBDIRS=drivers/net/wireless/ath/ath9k modules
  85. $kmake SUBDIRS=drivers/bluetooth modules
  86. $kmake dtbs
  87. $kmake zImage modules
  88. [ ! -h kernel.its ] && ln -s ../kernel.its .
  89. mkimage -D "-I dts -O dtb -p 2048" -f kernel.its vmlinux.uimg
  90. dd if=/dev/zero of=bootloader.bin bs=512 count=1
  91. vbutil_kernel --pack vmlinux.kpart \
  92. --version 1 \
  93. --vmlinuz vmlinux.uimg \
  94. --arch arm \
  95. --keyblock /usr/share/vboot/devkeys/kernel.keyblock \
  96. --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \
  97. --config ../cmdline \
  98. --bootloader bootloader.bin
  99. cd ..
  100. # build AR9271 firmware
  101. cd open-ath9k-htc-firmware
  102. if [ -d ../dl/xtensa-toolchain ]
  103. then
  104. mkdir toolchain
  105. mv ../dl/xtensa-toolchain toolchain/inst
  106. else
  107. make toolchain
  108. fi
  109. make -C target_firmware
  110. mv toolchain/inst ../dl/xtensa-toolchain
  111. cd ..
  112. install_devuan $here/devsus-rootfs
  113. install -D -m 644 linux-$KVER/vmlinux.kpart devsus-rootfs/boot/vmlinux.kpart
  114. tar -c devsus-rootfs | gzip -1 > devsus-rootfs.tar.gz
  115. # create 2GB and 16GB images with the Chrome OS partition layout
  116. create_image devuan-ascii-c201-libre-2GB.img 50M 40
  117. create_image devuan-ascii-c201-libre-16GB.img 512 30785536
  118. GZIP=-1 tar -cSzf devsus-templates.tar.gz devuan-ascii-c201-libre-2GB.img devuan-ascii-c201-libre-16GB.img
  119. else
  120. branch=`git symbolic-ref --short HEAD`
  121. commit=`git log --format=%h -1`
  122. [ ! -f dl/devsus-rootfs.tar.gz ] && wget -O dl/devsus-rootfs.tar.gz https://github.com/dimkr/devsus/releases/download/$branch-$commit/devsus-rootfs.tar.gz
  123. [ ! -f dl/devsus-templates.tar.gz ] && wget -O dl/devsus-templates.tar.gz https://github.com/dimkr/devsus/releases/download/$branch-$commit/devsus-templates.tar.gz
  124. tar -xzf dl/devsus-templates.tar.gz
  125. trap cleanup INT TERM EXIT
  126. # mount the / partition of both images
  127. off=$(((8192 + 65536) * 512))
  128. mount -o loop,noatime,offset=$off devuan-ascii-c201-libre-2GB.img $outmnt
  129. mount -o loop,noatime,offset=$off devuan-ascii-c201-libre-16GB.img $inmnt
  130. # unpack Devuan
  131. tar -C $outmnt -xf dl/devsus-rootfs.tar.gz --strip-components=1
  132. cp -a $outmnt/* $inmnt/
  133. # put the kernel in the kernel partition
  134. dd if=$outmnt/boot/vmlinux.kpart of=devuan-ascii-c201-libre-2GB.img conv=notrunc seek=8192
  135. dd if=$outmnt/boot/vmlinux.kpart of=devuan-ascii-c201-libre-16GB.img conv=notrunc seek=8192
  136. umount -l $inmnt
  137. rmdir $inmnt
  138. # put the 16GB image inside the 2GB one
  139. cp -f --sparse=always devuan-ascii-c201-libre-16GB.img $outmnt/
  140. fi