injectKernelIntoFS.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. if [ -z "$2" ]
  19. then
  20. echo "No filesystem image supplied"
  21. exit 1
  22. fi
  23. KVER=$1
  24. OUTNAME=$2
  25. outmnt=$(mktemp -d -p `pwd`)
  26. outdev=/dev/loop7
  27. build_resources=resources/BuildResources
  28. #A hacky way to ensure the loops are properly unmounted and the temp files are properly deleted.
  29. #Without this, a reboot is sometimes required to properly clean the loop devices and ensure a clean build
  30. cleanup() {
  31. set +e
  32. umount -l $outmnt > /dev/null 2>&1
  33. rmdir $outmnt > /dev/null 2>&1
  34. losetup -d $outdev > /dev/null 2>&1
  35. set +e
  36. umount -l $outmnt > /dev/null 2>&1
  37. rmdir $outmnt > /dev/null 2>&1
  38. losetup -d $outdev > /dev/null 2>&1
  39. }
  40. trap cleanup INT TERM EXIT
  41. #Mount the build filesystem image
  42. losetup -P $outdev $OUTNAME
  43. #mount the root filesystem
  44. mount -o noatime ${outdev}p2 $outmnt
  45. # put the kernel in the kernel partition, modules in /lib/modules and AR9271
  46. # firmware in /lib/firmware
  47. dd if=$build_resources/blank_kernel of=${outdev}p1 conv=notrunc
  48. dd if=build/linux-$KVER/vmlinux.kpart of=${outdev}p1 conv=notrunc
  49. make -C build/linux-$KVER ARCH=arm INSTALL_MOD_PATH=$outmnt modules_install
  50. # the ath9k firmware is built into the kernel image, so nothing else must be done
  51. umount -l $outmnt > /dev/null 2>&1
  52. rmdir $outmnt > /dev/null 2>&1
  53. losetup -d $outdev > /dev/null 2>&1
  54. echo "DONE!"
  55. trap - INT TERM EXIT