buildKernel.sh 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. set -x
  3. set -e
  4. #Build kernel, wifi firmware
  5. # This file is part of PrawnOS (https://www.prawnos.com)
  6. # Copyright (c) 2018 Hal Emmerich <hal@halemmerich.com>
  7. # PrawnOS is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License version 2
  9. # as published by the Free Software Foundation.
  10. # PrawnOS is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. # You should have received a copy of the GNU General Public License
  15. # along with PrawnOS. If not, see <https://www.gnu.org/licenses/>.
  16. if [ -z "$1" ]
  17. then
  18. echo "No kernel version supplied"
  19. exit 1
  20. fi
  21. KVER=$1
  22. ROOT_DIR=`pwd`
  23. RESOURCES=$ROOT_DIR/resources/BuildResources
  24. [ ! -d build ] && mkdir build
  25. cd build
  26. if [ ! -f PrawnOS-initramfs.cpio.gz ]
  27. then
  28. echo "No initramfs image, run 'make initramfs' first"
  29. cd $ROOT_DIR
  30. exit 1
  31. fi
  32. # build AR9271 firmware
  33. [ ! -d open-ath9k-htc-firmware ] && git clone --depth 1 https://github.com/qca/open-ath9k-htc-firmware.git
  34. cd open-ath9k-htc-firmware
  35. make toolchain
  36. make -C target_firmware
  37. cd ..
  38. # build Linux-libre, with ath9k_htc
  39. [ ! -f linux-libre-$KVER-gnu.tar.lz ] && wget https://www.linux-libre.fsfla.org/pub/linux-libre/releases/$KVER-gnu/linux-libre-$KVER-gnu.tar.lz
  40. [ ! -f linux-libre-$KVER-gnu.tar.lz.sign ] && wget https://www.linux-libre.fsfla.org/pub/linux-libre/releases/$KVER-gnu/linux-libre-$KVER-gnu.tar.lz.sign
  41. #verify the signature
  42. gpg --import $RESOURCES/linux-libre-signing-key.gpg
  43. gpg --verify linux-libre-$KVER-gnu.tar.lz.sign linux-libre-$KVER-gnu.tar.lz
  44. [ ! -d linux-$KVER ] && tar --lzip -xvf linux-libre-$KVER-gnu.tar.lz && FRESH=true
  45. cd linux-$KVER
  46. make clean
  47. make mrproper
  48. #Apply the usb and mmc patches if unapplied
  49. [ "$FRESH" = true ] && for i in $RESOURCES/patches-tested/kernel/5.x-dwc2/*.patch; do echo $i; patch -p1 < $i; done
  50. [ "$FRESH" = true ] && for i in $RESOURCES/patches-tested/DTS/*.patch; do echo $i; patch -p1 < $i; done
  51. [ "$FRESH" = true ] && for i in $RESOURCES/patches-tested/kernel/*.patch; do echo $i; patch -p1 < $i; done
  52. #copy in the initramfs and kernel config
  53. cp $ROOT_DIR/build/PrawnOS-initramfs.cpio.gz .
  54. cp $RESOURCES/config .config
  55. make -j $((`nproc` +1)) CROSS_COMPILE=arm-none-eabi- ARCH=arm zImage modules dtbs
  56. [ ! -h kernel.its ] && ln -s $RESOURCES/kernel.its .
  57. mkimage -D "-I dts -O dtb -p 2048" -f kernel.its vmlinux.uimg
  58. dd if=/dev/zero of=bootloader.bin bs=512 count=1
  59. vbutil_kernel --pack vmlinux.kpart \
  60. --version 1 \
  61. --vmlinuz vmlinux.uimg \
  62. --arch arm \
  63. --keyblock /usr/share/vboot/devkeys/kernel.keyblock \
  64. --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \
  65. --config $RESOURCES/cmdline \
  66. --bootloader bootloader.bin
  67. cd ..
  68. cd $ROOT_DIR