depthcharge.scm 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2019 Timothy Sample <samplet@ngyro.com>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (gnu bootloader depthcharge)
  19. #:use-module (gnu bootloader extlinux)
  20. #:use-module (gnu bootloader)
  21. #:use-module (gnu packages bootloaders)
  22. #:use-module (guix gexp)
  23. #:use-module (guix utils)
  24. #:use-module (ice-9 match)
  25. #:export (depthcharge-bootloader))
  26. (define (signed-kernel kernel kernel-arguments initrd)
  27. (define builder
  28. (with-imported-modules '((guix build utils))
  29. #~(begin
  30. (use-modules (guix build utils)
  31. (ice-9 binary-ports)
  32. (rnrs bytevectors))
  33. (set-path-environment-variable "PATH" '("bin") (list #$dtc))
  34. ;; TODO: These files have to be writable, so we copy them.
  35. ;; This can probably be fixed by using a ".its" file, just
  36. ;; be careful not to break initrd loading.
  37. (copy-file #$kernel "zImage")
  38. (chmod "zImage" #o755)
  39. (copy-file (string-append (dirname #$kernel) "/lib/dtbs/"
  40. "rk3288-veyron-speedy.dtb")
  41. "rk3288-veyron-speedy.dtb")
  42. (chmod "rk3288-veyron-speedy.dtb" #o644)
  43. (copy-file #$initrd "initrd")
  44. (chmod "initrd" #o644)
  45. (invoke (string-append #$u-boot-tools "/bin/mkimage")
  46. "-D" "-I dts -O dtb -p 2048"
  47. "-f" "auto"
  48. "-A" "arm"
  49. "-O" "linux"
  50. "-T" "kernel"
  51. "-C" "None"
  52. "-d" "zImage"
  53. "-a" "0"
  54. "-b" "rk3288-veyron-speedy.dtb"
  55. "-i" "initrd"
  56. "image.itb")
  57. (call-with-output-file "bootloader.bin"
  58. (lambda (port)
  59. (put-bytevector port (make-bytevector 512 0))))
  60. (with-output-to-file "kernel-arguments"
  61. (lambda ()
  62. (display (string-join (list #$@kernel-arguments)))))
  63. (invoke (string-append #$vboot-utils "/bin/vbutil_kernel")
  64. "--pack" #$output
  65. "--version" "1"
  66. "--vmlinuz" "image.itb"
  67. "--arch" "arm"
  68. "--keyblock" (string-append #$vboot-utils
  69. "/share/vboot-utils/devkeys/"
  70. "kernel.keyblock")
  71. "--signprivate" (string-append #$vboot-utils
  72. "/share/vboot-utils/devkeys/"
  73. "kernel_data_key.vbprivk")
  74. "--config" "kernel-arguments"
  75. "--bootloader" "bootloader.bin"))))
  76. (computed-file "vmlinux.kpart" builder))
  77. (define* (depthcharge-configuration-file config entries
  78. #:key
  79. (system (%current-system))
  80. (old-entries '())
  81. #:allow-other-keys)
  82. (match entries
  83. ((entry)
  84. (let ((kernel (menu-entry-linux entry))
  85. (kernel-arguments (menu-entry-linux-arguments entry))
  86. (initrd (menu-entry-initrd entry)))
  87. ;; XXX: Make this a symlink.
  88. (signed-kernel kernel kernel-arguments initrd)))
  89. (_ (error "Too many bootloader menu entries!"))))
  90. (define install-depthcharge
  91. #~(lambda (bootloader device mount-point)
  92. (let ((kpart (string-append mount-point
  93. "/boot/depthcharge/vmlinux.kpart")))
  94. (write-file-on-device kpart (stat:size (stat kpart)) device 0))))
  95. (define depthcharge-bootloader
  96. (bootloader
  97. (name 'depthcharge)
  98. (package #f)
  99. (installer install-depthcharge)
  100. (configuration-file "/boot/depthcharge/vmlinux.kpart")
  101. (configuration-file-generator depthcharge-configuration-file)))