[PATCH 0/3] Create "dev.cpio" for Heads.

  • Done
  • quality assurance status badge
Details
One participant
  • Danny Milosavljevic
Owner
unassigned
Submitted by
Danny Milosavljevic
Severity
normal

Debbugs page

Danny Milosavljevic wrote 4 years ago
(address . guix-patches@gnu.org)(name . Danny Milosavljevic)(address . dannym@scratchpost.org)
20201107204718.21824-1-dannym@scratchpost.org
This patch series dynamically creates "dev.cpio" for Heads instead of
carrying it as a binary blob.

Danny Milosavljevic (3):
linux-initrd: Handle 'block-special and 'char-special cpio headers as
well.
linux-initrd: Add special-file->cpio-header*
gnu: Add heads-dev-cpio.

gnu/packages/heads.scm | 34 ++++++++++++++++++++++++++++++++++
guix/cpio.scm | 33 ++++++++++++++++++++++++++++++---
2 files changed, 64 insertions(+), 3 deletions(-)
Danny Milosavljevic wrote 4 years ago
[PATCH 1/3] linux-initrd: Handle 'block-special and 'char-special cpio headers as well.
(address . 44507@debbugs.gnu.org)(name . Danny Milosavljevic)(address . dannym@scratchpost.org)
20201107212733.22326-1-dannym@scratchpost.org
* guix/cpio.scm (make-cpio-header): Handle size correctly for all file types.
(mode->type): Add 'block-special, 'char-special.
---
guix/cpio.scm | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

Toggle diff (37 lines)
diff --git a/guix/cpio.scm b/guix/cpio.scm
index e4692e2e9c..5d38573971 100644
--- a/guix/cpio.scm
+++ b/guix/cpio.scm
@@ -132,9 +132,10 @@
(%make-cpio-header MAGIC
inode mode uid gid
nlink mtime
- (if (= C_ISDIR (logand mode C_FMT))
- 0
- size)
+ (if (or (= C_ISLNK (logand mode C_FMT))
+ (= C_ISREG (logand mode C_FMT)))
+ size
+ 0)
major minor rmajor rminor
(+ name-size 1) ;include trailing zero
0))) ;checksum
@@ -146,6 +147,8 @@ denotes, similar to 'stat:type'."
(cond ((= C_ISREG fmt) 'regular)
((= C_ISDIR fmt) 'directory)
((= C_ISLNK fmt) 'symlink)
+ ((= C_ISBLK fmt) 'block-special)
+ ((= C_ISCHR fmt) 'char-special)
(else
(error "unsupported file type" mode)))))
@@ -233,6 +236,10 @@ produces with the '-H newc' option."
(put-string port target)))
((directory)
#t)
+ ((block-special)
+ #t)
+ ((char-special)
+ #t)
(else
(error "file type not supported")))
Danny Milosavljevic wrote 4 years ago
[PATCH 2/3] linux-initrd: Add special-file->cpio-header*
(address . 44507@debbugs.gnu.org)(name . Danny Milosavljevic)(address . dannym@scratchpost.org)
20201107212733.22326-2-dannym@scratchpost.org
* guix/cpio.scm (special-file->cpio-header*): New public procedure.
---
guix/cpio.scm | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)

Toggle diff (37 lines)
diff --git a/guix/cpio.scm b/guix/cpio.scm
index 5d38573971..c9932f5bf9 100644
--- a/guix/cpio.scm
+++ b/guix/cpio.scm
@@ -27,6 +27,7 @@
make-cpio-header
file->cpio-header
file->cpio-header*
+ special-file->cpio-header*
write-cpio-header
read-cpio-header
@@ -190,6 +191,25 @@ produced in a deterministic fashion."
#:size (stat:size st)
#:name-size (string-length file-name))))
+(define* (special-file->cpio-header* file
+ device-type
+ device-major
+ device-minor
+ permission-bits
+ #:optional (file-name file))
+ "Create a character or block device header.
+
+DEVICE-TYPE is either 'char-special or 'block-special.
+
+The number of hard links is assumed to be 1."
+ (make-cpio-header #:mode (logior (match device-type
+ ('block-special C_ISBLK)
+ ('char-special C_ISCHR))
+ permission-bits)
+ #:nlink 1
+ #:rdev (device-number device-major device-minor)
+ #:name-size (string-length file-name)))
+
(define %trailer
"TRAILER!!!")
Danny Milosavljevic wrote 4 years ago
[PATCH 3/3] gnu: Add heads-dev-cpio.
(address . 44507@debbugs.gnu.org)(name . Danny Milosavljevic)(address . dannym@scratchpost.org)
20201107212733.22326-3-dannym@scratchpost.org
* gnu/packages/heads.scm (heads-dev-cpio): New variable.
---
gnu/packages/heads.scm | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)

Toggle diff (49 lines)
diff --git a/gnu/packages/heads.scm b/gnu/packages/heads.scm
index b28433431c..d7e90471a2 100644
--- a/gnu/packages/heads.scm
+++ b/gnu/packages/heads.scm
@@ -19,6 +19,7 @@
(define-module (gnu packages heads)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (guix build-system gnu)
+ #:use-module (guix build-system trivial)
#:use-module (guix packages)
#:use-module (guix download)
#:use-module (guix git-download)
@@ -161,3 +162,36 @@ done
(synopsis "Musl-cross gcc 5 toolchain")
(description "Musl-cross toolchain: binutils, gcc 5 and musl.")
(license license:isc))))
+
+;; This package provides a "dev.cpio" file usable as a base for booting Heads.
+(define-public heads-dev-cpio
+ (package
+ (name "heads-dev-cpio")
+ (version "0.1")
+ (source #f)
+ (build-system trivial-build-system)
+ (arguments
+ `(#:modules ((guix build utils)
+ (guix cpio))
+ #:builder (begin
+ (use-modules (guix build utils)
+ (guix cpio)
+ (srfi srfi-26))
+ (mkdir-p "dev") ; input directory.
+ (let* ((out (assoc-ref %outputs "out"))
+ (libexec (string-append out "/libexec")))
+ (mkdir-p libexec)
+ (call-with-output-file (string-append libexec "/dev.cpio")
+ (lambda (port)
+ (write-cpio-archive '("dev" "dev/console") port
+ #:file->header
+ (lambda (name)
+ (if (string=? "dev/console" name)
+ (special-file->cpio-header* name 'char-special 5 1 #o600)
+ (file->cpio-header* name))))))
+ #t))))
+ (synopsis "\"dev.cpio\" for Heads")
+ (description "This package provides a \"dev.cpio\" file usable as a base for
+heads' initrd.")
+ (home-page "http://osresearch.net/")
+ (license license:bsd-2)))
Danny Milosavljevic wrote 4 years ago
Re: [PATCH 0/3] Create "dev.cpio" for Heads.
(address . 44507-done@debbugs.gnu.org)
20201122110747.17a61481@scratchpost.org
Pushed dev.cpio generator to guix master as these commits:

* b1dfc64552265d66e60d11c2a1b6f4da549cd495
* 8e7c98963f7e51b2ee9fd140f1aa59cf0f762a60
* d82f227291699e4bea655fbac23620576702667b
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCgAdFiEEds7GsXJ0tGXALbPZ5xo1VCwwuqUFAl+6OHMACgkQ5xo1VCww
uqXBvwf/S91MZnzw4t05KSvgAT7QJ03m7qSa9nbDK5DzUN6DEV3A8YMSd1+W4Q7K
ib2t1fWtKpvTdP5l5cT42UfUVkTaVrLzLNxh1P/80eyPzLLNjowTpEaibm3phRud
6yuZY9mBYNyeKLnzeL2xpBYBtkXHMHiAAv7AvwVyqj1H/XbxQLviaNan164k4ywz
qJ1wsj9J827g/ZqOk8Vws9awrb3iLGvIfLxc9il17XlY1ifbxQWXYgwgbLllaJ1B
8DApah8Q8MTVXLIh99LKk3oumQdkVw0M8u7uW+pXr1/jsMJC4EIQLZZWH0DfbfV7
BAt+xy7GbC1+e7H0W6Pw5eKMu89sPA==
=cR+x
-----END PGP SIGNATURE-----


Closed
?
Your comment

This issue is archived.

To comment on this conversation send an email to 44507@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 44507
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch
You may also tag this issue. See list of standard tags. For example, to set the confirmed and easy tags
mumi command -t +confirmed -t +easy
Or, remove the moreinfo tag and set the help tag
mumi command -t -moreinfo -t +help