buildKernel.sh 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/sh -xe
  2. #Build kenerl, wifi firmware
  3. # This file is part of PrawnOS (http://www.prawnos.com)
  4. # Copyright (c) 2018 Hal Emmerich <hal@halemmerich.com>
  5. # PrawnOS is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License version 2
  7. # as published by the Free Software Foundation.
  8. # PrawnOS is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with PrawnOS. If not, see <https://www.gnu.org/licenses/>.
  14. if [ -z "$1" ]
  15. then
  16. echo "No kernel version supplied"
  17. exit 1
  18. fi
  19. KVER=$1
  20. TEST_PATCHES=false
  21. ROOT_DIR=`pwd`
  22. RESOURCES=$ROOT_DIR/resources/BuildResources
  23. [ ! -d build ] && mkdir build
  24. cd build
  25. if [ ! -f PrawnOS-initramfs.cpio.gz ]
  26. then
  27. echo "No initramfs image, run 'make initramfs' first"
  28. cd $ROOT_DIR
  29. exit 1
  30. fi
  31. # build AR9271 firmware
  32. [ ! -d open-ath9k-htc-firmware ] && git clone --depth 1 https://github.com/qca/open-ath9k-htc-firmware.git
  33. cd open-ath9k-htc-firmware
  34. make toolchain
  35. make -C target_firmware
  36. cd ..
  37. # build Linux-libre, with ath9k_htc
  38. [ ! -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
  39. [ ! -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
  40. #verify the signature
  41. gpg --import $RESOURCES/linux-libre-signing-key.gpg
  42. gpg --verify linux-libre-$KVER-gnu.tar.lz.sign linux-libre-$KVER-gnu.tar.lz
  43. [ ! -d linux-$KVER ] && tar --lzip -xvf linux-libre-$KVER-gnu.tar.lz && FRESH=true
  44. cd linux-$KVER
  45. make clean
  46. make mrproper
  47. #Apply the usb and mmc patches if unapplied
  48. [ "$FRESH" = true ] && for i in $RESOURCES/patches-tested/kernel/5.x-dwc2/*.patch; do echo $i; patch -p1 < $i; done
  49. [ "$FRESH" = true ] && for i in $RESOURCES/patches-tested/DTS/5.x-dts/*.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 `grep ^processor /proc/cpuinfo | wc -l` 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