injectKernelIntoFS.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/sh -xe
  2. # This file is part of PrawnOS (http://www.prawnos.com)
  3. # Copyright (c) 2018 Hal Emmerich <hal@halemmerich.com>
  4. # PrawnOS is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License version 2
  6. # as published by the Free Software Foundation.
  7. # PrawnOS is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. # You should have received a copy of the GNU General Public License
  12. # along with PrawnOS. If not, see <https://www.gnu.org/licenses/>.
  13. if [ -z "$1" ]
  14. then
  15. echo "No kernel version supplied"
  16. exit 1
  17. fi
  18. KVER=$1
  19. if [ -z "$2" ]
  20. then
  21. echo "No image filesystem image supplied"
  22. exit 1
  23. fi
  24. outmnt=$(mktemp -d -p `pwd`)
  25. outdev=/dev/loop7
  26. build_resources=resources/BuildResources
  27. #A hacky way to ensure the loops are properly unmounted and the temp files are properly deleted.
  28. #Without this, a reboot is sometimes required to properly clean the loop devices and ensure a clean build
  29. cleanup() {
  30. set +e
  31. umount -l $outmnt > /dev/null 2>&1
  32. rmdir $outmnt > /dev/null 2>&1
  33. losetup -d $outdev > /dev/null 2>&1
  34. set +e
  35. umount -l $outmnt > /dev/null 2>&1
  36. rmdir $outmnt > /dev/null 2>&1
  37. losetup -d $outdev > /dev/null 2>&1
  38. }
  39. trap cleanup INT TERM EXIT
  40. #Mount the build filesystem image
  41. losetup -P $outdev $2
  42. mount -o noatime ${outdev}p2 $outmnt
  43. # put the kernel in the kernel partition, modules in /lib/modules and AR9271
  44. # firmware in /lib/firmware
  45. dd if=$build_resources/blank_kernel of=${outdev}p1 conv=notrunc
  46. dd if=build/linux-$KVER/vmlinux.kpart of=${outdev}p1 conv=notrunc
  47. make -C build/linux-$KVER ARCH=arm INSTALL_MOD_PATH=$outmnt modules_install
  48. rm -f $outmnt/lib/modules/3.14.0/{build,source}
  49. install -D -m 644 build/open-ath9k-htc-firmware/target_firmware/htc_9271.fw $outmnt/lib/firmware/ath9k_htc/htc_9271-1.4.0.fw
  50. umount -l $outmnt > /dev/null 2>&1
  51. rmdir $outmnt > /dev/null 2>&1
  52. losetup -d $outdev > /dev/null 2>&1
  53. echo "DONE!"
  54. trap - INT TERM EXIT