injectKernelIntoFS.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 the root filesystem
  43. mount -o noatime ${outdev}p2 $outmnt
  44. # put the kernel in the kernel partition, modules in /lib/modules and AR9271
  45. # firmware in /lib/firmware
  46. dd if=$build_resources/blank_kernel of=${outdev}p1 conv=notrunc
  47. dd if=build/linux-$KVER/vmlinux.kpart of=${outdev}p1 conv=notrunc
  48. make -C build/linux-$KVER ARCH=arm INSTALL_MOD_PATH=$outmnt modules_install
  49. # the ath9k firmware is built into the kernel image, so nothing else must be done
  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