injectKernelIntoFS.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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}p3 $outmnt
  44. #mount the initramfs partition
  45. # mount -o noatime ${outdev}p2 $outmnt/boot
  46. # put the kernel in the kernel partition, modules in /lib/modules and AR9271
  47. # firmware in /lib/firmware
  48. dd if=$build_resources/blank_kernel of=${outdev}p1 conv=notrunc
  49. dd if=build/linux-$KVER/vmlinux.kpart of=${outdev}p1 conv=notrunc
  50. make -C build/linux-$KVER ARCH=arm INSTALL_MOD_PATH=$outmnt modules_install
  51. # put the required kernel items into the initramfs aka the device tree and the kernel image
  52. # TODO: the in-place kernel upgrade script must be changed to copy in new versions of these files
  53. # cp build/linux-$KVER/arch/arm/boot/dts/rk3288-veyron-speedy.dtb $outmnt/boot/rk3288-veyron-speedy.dtb
  54. # cp build/linux-$KVER/vmlinux.kpart $outmnt/boot
  55. #TODO: do we actually need the kernel in /boot?? I think not. lets test and find out
  56. # the initramfs is build into the kernel image
  57. # the ath9k firmware is built into the kernel image, so nothing else must be done
  58. umount -l $outmnt > /dev/null 2>&1
  59. rmdir $outmnt > /dev/null 2>&1
  60. losetup -d $outdev > /dev/null 2>&1
  61. echo "DONE!"
  62. trap - INT TERM EXIT