buildKernel.sh 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. [ ! -d linux-$KVER ] && tar --lzip -xvf linux-libre-$KVER-gnu.tar.lz && FRESH=true
  40. cd linux-$KVER
  41. make clean
  42. make mrproper
  43. #Apply the usb and mmc patches if unapplied
  44. [ "$FRESH" = true ] && for i in $RESOURCES/patches-tested/kernel/5.x-dwc2/*.patch; do echo $i; patch -p1 < $i; done
  45. [ "$FRESH" = true ] && for i in $RESOURCES/patches-tested/DTS/5.x-dts/*.patch; do echo $i; patch -p1 < $i; done
  46. [ "$FRESH" = true ] && for i in $RESOURCES/patches-tested/DTS/*.patch; do echo $i; patch -p1 < $i; done
  47. [ "$FRESH" = true ] && for i in $RESOURCES/patches-tested/kernel/*.patch; do echo $i; patch -p1 < $i; done
  48. #Apply all of the rockMyy patches that make sense
  49. [ "$TEST_PATCHES" = true ] && for i in $RESOURCES/patches-untested/kernel/*.patch; do patch -p1 < $i; done
  50. [ "$TEST_PATCHES" = true ] && for i in $RESOURCES/patches-untested/DTS/*.patch; do patch -p1 < $i; done
  51. #copy in the initramfs and kernel config
  52. cp $ROOT_DIR/build/PrawnOS-initramfs.cpio.gz .
  53. cp $RESOURCES/config .config
  54. make -j `grep ^processor /proc/cpuinfo | wc -l` CROSS_COMPILE=arm-none-eabi- ARCH=arm zImage modules dtbs
  55. [ ! -h kernel.its ] && ln -s $RESOURCES/kernel.its .
  56. mkimage -D "-I dts -O dtb -p 2048" -f kernel.its vmlinux.uimg
  57. dd if=/dev/zero of=bootloader.bin bs=512 count=1
  58. vbutil_kernel --pack vmlinux.kpart \
  59. --version 1 \
  60. --vmlinuz vmlinux.uimg \
  61. --arch arm \
  62. --keyblock /usr/share/vboot/devkeys/kernel.keyblock \
  63. --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \
  64. --config $RESOURCES/cmdline \
  65. --bootloader bootloader.bin
  66. cd ..
  67. cd $ROOT_DIR