bootloader.scm 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
  3. ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (gnu build bootloader)
  20. #:use-module (ice-9 binary-ports)
  21. #:export (write-file-on-device))
  22. ;;;
  23. ;;; Writing utils.
  24. ;;;
  25. (define (write-file-on-device file size device offset)
  26. "Write SIZE bytes from FILE to DEVICE starting at OFFSET."
  27. (call-with-input-file file
  28. (lambda (input)
  29. (let ((bv (get-bytevector-n input size)))
  30. (call-with-output-file device
  31. (lambda (output)
  32. (seek output offset SEEK_SET)
  33. (put-bytevector output bv))
  34. #:binary #t)))))