From 67dac6b8920755cb011047157bb7b4fae4760143 Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Wed, 14 Aug 2019 13:46:53 -0400 Subject: gnu: mingw: Add x86_64 support. This patch parameterizes previously hard-coded instances of i686-w64-mingw32, adding support for x86_64-w64-mingw32. * gnu/packages/mingw.scm (make-mingw-w64): New procedure. (mingw-w64-i686, mingw-w64-x86_64): New variables. (%mingw-triplet): Remove. (mingw-w64): Update to point to 'mingw-w64-i686'. * gnu/packages/cross-base.scm (cross-gcc): Use 'libc' keyword argument if specified, instead of treating it as a boolean. (native-libc): Return the correct mingw-w64 depending on machine specified in target. * gnu/packages/bootstrap.scm (glibc-dynamic-linker): Add "x86_64-mingw". * gnu/build/cross-toolchain.scm (set-cross-path/mingw): Replace hardcoded 'i686-w64-mingw32' instances with 'target' keyword argument. (cross-gcc-build-phases): Update accordingly; use 'target-mingw?' implementation of target checking and add commentary. * gnu/ci.scm (%cross-targets): Add "x86_64-w64-mingw32". --- gnu/build/cross-toolchain.scm | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'gnu/build') diff --git a/gnu/build/cross-toolchain.scm b/gnu/build/cross-toolchain.scm index d430b8afc4..201b36ff7c 100644 --- a/gnu/build/cross-toolchain.scm +++ b/gnu/build/cross-toolchain.scm @@ -3,6 +3,7 @@ ;;; Copyright © 2014, 2015, 2018 Mark H Weaver ;;; Copyright © 2016 Jan Nieuwenhuizen ;;; Copyright © 2016 Manolis Fragkiskos Ragkousis +;;; Copyright © 2019 Carl Dong ;;; ;;; This file is part of GNU Guix. ;;; @@ -95,7 +96,7 @@ C_INCLUDE_PATH et al." ;; We're building the sans-libc cross-compiler, so nothing to do. #t))) -(define* (set-cross-path/mingw #:key inputs #:allow-other-keys) +(define* (set-cross-path/mingw #:key inputs target #:allow-other-keys) "Add the cross MinGW headers to CROSS_C_*_INCLUDE_PATH, and remove them from C_*INCLUDE_PATH." (let ((libc (assoc-ref inputs "libc")) @@ -112,7 +113,7 @@ C_*INCLUDE_PATH." (if libc (let ((cpath (string-append libc "/include" - ":" libc "/i686-w64-mingw32/include"))) + ":" libc "/" target "/include"))) (for-each (cut setenv <> cpath) %gcc-cross-include-paths)) @@ -142,7 +143,7 @@ C_*INCLUDE_PATH." (when libc (setenv "CROSS_LIBRARY_PATH" (string-append libc "/lib" - ":" libc "/i686-w64-mingw32/lib"))) + ":" libc "/" target "/lib"))) (setenv "CPP" (string-append gcc "/bin/cpp")) (for-each (lambda (var) @@ -168,8 +169,12 @@ C_*INCLUDE_PATH." a target triplet." (modify-phases phases (add-before 'configure 'set-cross-path - (if (string-contains target "mingw") - set-cross-path/mingw + ;; This mingw32 target checking logic should match that of target-mingw? + ;; in (guix utils), but (guix utils) is too large too copy over to the + ;; build side entirely and for now we have no way to select variables to + ;; copy over. See (gnu packages cross-base) for more details. + (if (string-suffix? "-mingw32" target) + (cut set-cross-path/mingw #:target target <...>) set-cross-path)) (add-after 'install 'make-cross-binutils-visible (cut make-cross-binutils-visible #:target target <...>)) -- cgit v1.2.3 From 4f8b9d1a6f551697996c77b6e1741007e1f7c9cd Mon Sep 17 00:00:00 2001 From: Danny Milosavljevic Date: Sun, 4 Mar 2018 02:09:08 +0100 Subject: linux-modules: Add "modules.alias" writer. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * gnu/build/linux-modules.scm (write-module-alias-database): New procedure. Co-authored-by: Ludovic Courtès --- gnu/build/linux-modules.scm | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'gnu/build') diff --git a/gnu/build/linux-modules.scm b/gnu/build/linux-modules.scm index c66ef97012..9b9fc0d9d8 100644 --- a/gnu/build/linux-modules.scm +++ b/gnu/build/linux-modules.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2014, 2016, 2018, 2019 Ludovic Courtès ;;; Copyright © 2017 Mathieu Othacehe +;;; Copyright © 2018 Danny Milosavljevic ;;; ;;; This file is part of GNU Guix. ;;; @@ -48,7 +49,9 @@ device-module-aliases known-module-aliases matching-modules - missing-modules)) + missing-modules + + write-module-alias-database)) ;;; Commentary: ;;; @@ -486,4 +489,22 @@ are required to access DEVICE." (remove (cut member <> provided) modules)) '())) +(define (write-module-alias-database directory) + "Traverse the '.ko' files in DIRECTORY and create the corresponding +'modules.alias' file." + (define aliases + (map (lambda (file) + (cons (file-name->module-name file) (module-aliases file))) + (find-files directory "\\.ko$"))) + + (call-with-output-file (string-append directory "/modules.alias") + (lambda (port) + (display "# Aliases extracted from modules themselves.\n" port) + (for-each (match-lambda + ((module . aliases) + (for-each (lambda (alias) + (format port "alias ~a ~a\n" alias module)) + aliases))) + aliases)))) + ;;; linux-modules.scm ends here -- cgit v1.2.3 From 2a693b69ca35ee942395e1adf458a666846881fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Mon, 12 Mar 2018 10:43:15 +0100 Subject: linux-modules: Add "modules.devname" writer. * gnu/build/linux-modules.scm (aliases->device-tuple) (write-module-device-database): New procedures. (%not-dash): New variable. Co-authored-by: Danny Milosavljevic . --- gnu/build/linux-modules.scm | 52 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'gnu/build') diff --git a/gnu/build/linux-modules.scm b/gnu/build/linux-modules.scm index 9b9fc0d9d8..a73ccaf511 100644 --- a/gnu/build/linux-modules.scm +++ b/gnu/build/linux-modules.scm @@ -51,7 +51,8 @@ matching-modules missing-modules - write-module-alias-database)) + write-module-alias-database + write-module-device-database)) ;;; Commentary: ;;; @@ -507,4 +508,53 @@ are required to access DEVICE." aliases))) aliases)))) +(define (aliases->device-tuple aliases) + "Traverse ALIASES, a list of module aliases, and search for +\"char-major-M-N\", \"block-major-M-N\", or \"devname:\" aliases. When they +are found, return a tuple (DEVNAME TYPE MAJOR MINOR), otherwise return #f." + (define (char/block-major? alias) + (or (string-prefix? "char-major-" alias) + (string-prefix? "block-major-" alias))) + + (define (char/block-major->tuple alias) + (match (string-tokenize alias %not-dash) + ((type "major" (= string->number major) (= string->number minor)) + (list (match type + ("char" "c") + ("block" "b")) + major minor)))) + + (let* ((devname (any (lambda (alias) + (and (string-prefix? "devname:" alias) + (string-drop alias 8))) + aliases)) + (major/minor (match (find char/block-major? aliases) + (#f #f) + (str (char/block-major->tuple str))))) + (and devname major/minor + (cons devname major/minor)))) + +(define %not-dash + (char-set-complement (char-set #\-))) + +(define (write-module-device-database directory) + "Traverse the '.ko' files in DIRECTORY and create the corresponding +'modules.devname' file. This file contains information about modules that can +be loaded on-demand, such as file system modules." + (define aliases + (filter-map (lambda (file) + (match (aliases->device-tuple (module-aliases file)) + (#f #f) + (tuple (cons (file-name->module-name file) tuple)))) + (find-files directory "\\.ko$"))) + + (call-with-output-file (string-append directory "/modules.devname") + (lambda (port) + (display "# Device nodes to trigger on-demand module loading.\n" port) + (for-each (match-lambda + ((module devname type major minor) + (format port "~a ~a ~a~a:~a~%" + module devname type major minor))) + aliases)))) + ;;; linux-modules.scm ends here -- cgit v1.2.3 From e1a9a7f2755dc23e1f4635c8aee45e1467c01619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Fri, 9 Mar 2018 10:41:46 +0100 Subject: linux-modules: Add 'load-linux-modules-from-directory'. * gnu/build/linux-modules.scm (load-linux-modules-from-directory): New procedure. * gnu/build/linux-boot.scm (boot-system)[lookup-module]: Remove. Use 'load-linux-modules-from-directory' instead. --- gnu/build/linux-boot.scm | 9 ++------- gnu/build/linux-modules.scm | 12 ++++++++++++ 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'gnu/build') diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm index 03f2ea245c..f273957d78 100644 --- a/gnu/build/linux-boot.scm +++ b/gnu/build/linux-boot.scm @@ -471,10 +471,6 @@ upon error." mounts) "ext4")) - (define (lookup-module name) - (string-append linux-module-directory "/" - (ensure-dot-ko name))) - (display "Welcome, this is GNU's early boot Guile.\n") (display "Use '--repl' for an initrd REPL.\n\n") @@ -489,9 +485,8 @@ upon error." (start-repl)) (display "loading kernel modules...\n") - (for-each (cut load-linux-module* <> - #:lookup-module lookup-module) - (map lookup-module linux-modules)) + (load-linux-modules-from-directory linux-modules + linux-module-directory) (when keymap-file (let ((status (system* "loadkeys" keymap-file))) diff --git a/gnu/build/linux-modules.scm b/gnu/build/linux-modules.scm index a73ccaf511..2af7c33d42 100644 --- a/gnu/build/linux-modules.scm +++ b/gnu/build/linux-modules.scm @@ -43,6 +43,7 @@ modules-loaded module-loaded? load-linux-module* + load-linux-modules-from-directory current-module-debugging-port @@ -314,6 +315,17 @@ appears in BLACK-LIST are not loaded." (or (and recursive? (= EEXIST (system-error-errno args))) (apply throw args))))))) +(define (load-linux-modules-from-directory modules directory) + "Load MODULES and their dependencies from DIRECTORY, a directory containing +the '.ko' files. The '.ko' suffix is automatically added to MODULES if +needed." + (define (lookup-module name) + (string-append directory "/" (ensure-dot-ko name))) + + (for-each (cut load-linux-module* <> + #:lookup-module lookup-module) + (map lookup-module modules))) + ;;; ;;; Device modules. -- cgit v1.2.3 From c85ccf60bfe4ef58110bb61f40df7f526d2a5735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Wed, 14 Mar 2018 23:11:01 +0100 Subject: linux-modules: Define and use a module name database. Fixes . Reported by Julien Lepiller . * gnu/build/linux-modules.scm (module-formal-name): New procedure. (load-linux-modules-from-directory)[lookup-module]: Remove. [module-name->file-name]: New variable. Use it. (module-name->file-name/guess, module-name-lookup) (write-module-name-database): New procedures. * gnu/system/linux-initrd.scm (flat-linux-module-directory): Call 'write-module-name-database'. --- gnu/build/linux-modules.scm | 72 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 5 deletions(-) (limited to 'gnu/build') diff --git a/gnu/build/linux-modules.scm b/gnu/build/linux-modules.scm index 2af7c33d42..a149eff329 100644 --- a/gnu/build/linux-modules.scm +++ b/gnu/build/linux-modules.scm @@ -31,8 +31,10 @@ #:use-module (ice-9 vlist) #:use-module (ice-9 match) #:use-module (ice-9 rdelim) + #:autoload (ice-9 pretty-print) (pretty-print) #:export (dot-ko ensure-dot-ko + module-formal-name module-aliases module-dependencies module-soft-dependencies @@ -52,6 +54,7 @@ matching-modules missing-modules + write-module-name-database write-module-alias-database write-module-device-database)) @@ -100,6 +103,14 @@ key/value pairs.." (define %not-comma (char-set-complement (char-set #\,))) +(define (module-formal-name file) + "Return the module name of FILE as it appears in its info section. Usually +the module name is the same as the base name of FILE, modulo hyphens and minus +the \".ko\" extension." + (match (assq 'name (modinfo-section-contents file)) + (('name . name) name) + (#f #f))) + (define (module-dependencies file) "Return the list of modules that FILE depends on. The returned list contains module names, not actual file names." @@ -319,12 +330,13 @@ appears in BLACK-LIST are not loaded." "Load MODULES and their dependencies from DIRECTORY, a directory containing the '.ko' files. The '.ko' suffix is automatically added to MODULES if needed." - (define (lookup-module name) - (string-append directory "/" (ensure-dot-ko name))) + (define module-name->file-name + (module-name-lookup directory)) - (for-each (cut load-linux-module* <> - #:lookup-module lookup-module) - (map lookup-module modules))) + (for-each (lambda (module) + (load-linux-module* (module-name->file-name module) + #:lookup-module module-name->file-name)) + modules)) ;;; @@ -502,6 +514,56 @@ are required to access DEVICE." (remove (cut member <> provided) modules)) '())) + +;;; +;;; Module databases. +;;; + +(define (module-name->file-name/guess directory name) + "Guess the file name corresponding to NAME, a module name. That doesn't +always work because sometimes underscores in NAME map to hyphens (e.g., +\"input-leds.ko\"), sometimes not (e.g., \"mac_hid.ko\")." + (string-append directory "/" (ensure-dot-ko name))) + +(define (module-name-lookup directory) + "Return a one argument procedure that takes a module name (e.g., +\"input_leds\") and returns its absolute file name (e.g., +\"/.../input-leds.ko\")." + (catch 'system-error + (lambda () + (define mapping + (call-with-input-file (string-append directory "/modules.name") + read)) + + (lambda (name) + (or (assoc-ref mapping name) + (module-name->file-name/guess directory name)))) + (lambda args + (if (= ENOENT (system-error-errno args)) + (cut module-name->file-name/guess directory <>) + (apply throw args))))) + +(define (write-module-name-database directory) + "Write a database that maps \"module names\" as they appear in the relevant +ELF section of '.ko' files, to actual file names. This format is +Guix-specific. It aims to deal with inconsistent naming, in particular +hyphens vs. underscores." + (define mapping + (map (lambda (file) + (match (module-formal-name file) + (#f (cons (basename file ".ko") file)) + (name (cons name file)))) + (find-files directory "\\.ko$"))) + + (call-with-output-file (string-append directory "/modules.name") + (lambda (port) + (display ";; Module name to file name mapping. +;; +;; This format is Guix-specific; it is not supported by upstream Linux tools. +\n" + port) + (pretty-print mapping port)))) + (define (write-module-alias-database directory) "Traverse the '.ko' files in DIRECTORY and create the corresponding 'modules.alias' file." -- cgit v1.2.3