injectKernelIntoFS.sh 2.2 KB

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