buildKernel.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. set -x
  3. set -e
  4. #Build kenerl, wifi firmware
  5. # This file is part of PrawnOS (http://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. TEST_PATCHES=false
  23. ROOT_DIR=`pwd`
  24. RESOURCES=$ROOT_DIR/resources/BuildResources
  25. [ ! -d build ] && mkdir build
  26. cd build
  27. if [ ! -f PrawnOS-initramfs.cpio.gz ]
  28. then
  29. echo "No initramfs image, run 'make initramfs' first"
  30. cd $ROOT_DIR
  31. exit 1
  32. fi
  33. # build AR9271 firmware
  34. [ ! -d open-ath9k-htc-firmware ] && git clone --depth 1 https://github.com/qca/open-ath9k-htc-firmware.git
  35. cd open-ath9k-htc-firmware
  36. make toolchain
  37. make -C target_firmware
  38. cd ..
  39. # build Linux-libre, with ath9k_htc
  40. [ ! -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
  41. [ ! -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
  42. #verify the signature
  43. gpg --import $RESOURCES/linux-libre-signing-key.gpg
  44. gpg --verify linux-libre-$KVER-gnu.tar.lz.sign linux-libre-$KVER-gnu.tar.lz
  45. [ ! -d linux-$KVER ] && tar --lzip -xvf linux-libre-$KVER-gnu.tar.lz && FRESH=true
  46. cd linux-$KVER
  47. make clean
  48. make mrproper
  49. #Apply the usb and mmc patches if unapplied
  50. [ "$FRESH" = true ] && for i in $RESOURCES/patches-tested/kernel/5.x-dwc2/*.patch; do echo $i; patch -p1 < $i; done
  51. [ "$FRESH" = true ] && for i in $RESOURCES/patches-tested/DTS/*.patch; do echo $i; patch -p1 < $i; done
  52. [ "$FRESH" = true ] && for i in $RESOURCES/patches-tested/kernel/*.patch; do echo $i; patch -p1 < $i; done
  53. #copy in the initramfs and kernel config
  54. cp $ROOT_DIR/build/PrawnOS-initramfs.cpio.gz .
  55. cp $RESOURCES/config .config
  56. make -j $((`nproc` +1)) CROSS_COMPILE=arm-none-eabi- ARCH=arm zImage modules dtbs
  57. [ ! -h kernel.its ] && ln -s $RESOURCES/kernel.its .
  58. mkimage -D "-I dts -O dtb -p 2048" -f kernel.its vmlinux.uimg
  59. dd if=/dev/zero of=bootloader.bin bs=512 count=1
  60. vbutil_kernel --pack vmlinux.kpart \
  61. --version 1 \
  62. --vmlinuz vmlinux.uimg \
  63. --arch arm \
  64. --keyblock /usr/share/vboot/devkeys/kernel.keyblock \
  65. --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \
  66. --config $RESOURCES/cmdline \
  67. --bootloader bootloader.bin
  68. cd ..
  69. cd $ROOT_DIR