Get gcc-arm-none-eabi, zephyr, ZMK, redox-neo-nrfmicro-13-zmk working.

This commit is contained in:
Stefan 2023-09-03 12:53:12 +02:00
parent 5557bf3001
commit 16b3f2b99c
5 changed files with 673 additions and 1944 deletions

File diff suppressed because it is too large Load diff

View file

@ -9,23 +9,21 @@
#:use-module (guix git-download)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (guix packages))
;; This is the common directory name for zephyr-modules to look for search-paths
;; to collect in the ZEPHYR_MODULES environment variable.
;; to collect in the ZEPHYR_MODULES environment variable. The build-system of
;; Zephyr searches for a file zephyr/module.yml in all paths listed in the
;; environment variable ZEPHYR_MODULES. If that file is missing a name
;; property, then the parent directory name is used as the module name. Having
;; two modules with the same name is treated as an error. As Guix needs a
;; common directory name for search-path-specification, we need this
;; intermediate directory as a pattern and to have unique module names.
;; Unfortunately search-path-specification is still not powerful enough, so
;; complete-zephyr-application needs the correct-ZEPHYR_MODULES build-phase.
(define-public %zephyr-module "zephyr-module")
;; This is the common directory prefix of zephyr-modules to collect for
;; search-paths in ZEPHYR_MODULES. The build-system of Zephyr searches for
;; a file zephyr/module.yml in all paths listed in the environment variable
;; ZEPHYR_MODULES. If that file is missing a name property, then the parent
;; directory name is used as the module name. Having two modules with the same
;; name is treated as an error. As Guix needs a common directory name for
;; search-path-specification, we need this intermediate directory prefix as a
;; pattern and to have unique module names.
(define-public %zephyr-module-tag "ZEPHYR-MODULE-TAG-")
(define-public zephyr
(let ((version "3.3.0"))
(let ((version "3.4.0"))
(package
(name "zephyr")
(version version)
@ -37,7 +35,7 @@
(commit (string-append "zephyr-v" version))))
(file-name (git-file-name name version))
(sha256 (base32
"05afpxlapqd7i9m03c8kj5ph9dbig94zhyb9mrwg41cm7725lw98"))))
"1gcry9fxv88js5nymi9akgrkghkwavggj3wqdgg2cz6brr5wg284"))))
(build-system copy-build-system)
(arguments
(list
@ -47,12 +45,15 @@
#~(modify-phases %standard-phases
(add-after 'unpack 'set-USER_CACHE_DIR-and-BUILD_VERSION
(lambda _
;; Avoid fetching the BUILD_VERSION from the git repository.
(substitute* "CMakeLists.txt"
(("if *\\(DEFINED BUILD_VERSION\\)")
(string-append
"if (NOT DEFINED BUILD_VERSION)\n"
" set(BUILD_VERSION " #$version ")\n"
"elseif (DEFINED BUILD_VERSION)")))
;; Avoid USER_CACHE_DIR to point to XDG_CACHE_HOME, HOME, or to
;; ZEPHYR_BASE inside the store. Instead use the build dir.
(with-output-to-file
"cmake/modules/user_cache.cmake"
(lambda ()
@ -65,9 +66,7 @@
(separator #f))
(search-path-specification
(variable "ZEPHYR_MODULES")
(files (list %zephyr-module))
(separator ";")
(file-pattern (string-append "^" %zephyr-module-tag)))))
(files (list %zephyr-module)))))
(home-page "https://zephyrproject.org")
(synopsis "Zephyr Project RTOS")
(description "The Zephyr Project is a scalable real-time operating system

View file

@ -33,7 +33,7 @@ boilerplate."
(package-inputs zephyr-application)
(prepend zephyr zephyr-build-tools)))
(cross-compile-prefix (file-append toolchain "/bin/" target "-")))
(package-with-c-toolchain
(package-with-c-toolchain
(package
(inherit zephyr-application)
(build-system cmake-build-system)
@ -49,14 +49,43 @@ boilerplate."
#:tests? #f
#:phases
#~(modify-phases %standard-phases
(add-after 'set-paths 'correct-ZEPHYR_MODULES
;; The search-path-specification is not powerful enough. Zephyr
;; modules contain a zephyr-module/<name>/zephyr directory
;; without a common pattern for <name> and the ZEPHYR_MODULES
;; environment variable needs to list the zephyr-module/<name>
;; directories separated by semicolons.
(lambda _
(use-modules (ice-9 regex))
(let ((zephyr-modules (getenv "ZEPHYR_MODULES")))
(when zephyr-modules
(setenv "ZEPHYR_MODULES"
(string-join
(map
(lambda (module)
(dirname
(car
(let ((length (string-length module)))
(find-files module
(lambda (name stat)
(string-match
"^/[^/]+/zephyr$"
(string-drop name length)))
#:directories? #t)))))
(string-split zephyr-modules #\:))
";"))
(format
#t
"environment variable `ZEPHYR_MODULES' set to `~a'~%"
(getenv "ZEPHYR_MODULES"))))))
(replace 'install
(lambda _
(let* ((source-prefix
#$(string-append directory-to-install-from "/"
source-prefix))
source-prefix))
(target-prefix
#$(string-append directory-to-install-from "/"
target-prefix))
target-prefix))
(source-prefix-length (string-length source-prefix))
(primary-files-to-install
(list (string-append source-prefix ".uf2")))
@ -141,10 +170,10 @@ the console.")
#:key
(configure-flags #~(list))
(key (file-append zephyr-module-mcuboot
(zephyr-module-installation-target
(zephyr-module-installation-target
zephyr-module-mcuboot)
"/main/root-rsa-2048.pem")))
"Make an MCUboot bootloader package for Zephyr targeting the Arm
"Make an MCUboot bootloader package for Zephyr targeting the Arm
microcontroller BOARD. Add EXTRA-INPUTS to the build and use the list of
optional CONFIGURE-FLAGS. Use the public KEY file for firmware decryption."
(make-zephyr-application-for-arm
@ -152,18 +181,28 @@ optional CONFIGURE-FLAGS. Use the public KEY file for firmware decryption."
(name (string-append "zephyr-mcuboot-" board))
(source
(file-append zephyr-module-mcuboot
(zephyr-module-installation-target zephyr-module-mcuboot)
"/boot/zephyr"))
(zephyr-module-installation-target zephyr-module-mcuboot)))
(arguments
(list
#:configure-flags
#~(append #$configure-flags
(list (string-append "-DBOARD=" #$board)))))
(inputs (append extra-inputs (list zephyr-module-mcuboot))))))
(list "-S../source/boot/zephyr"
(string-append "-DBOARD=" #$board)
(string-append "-DTINYCRYPT_DIR=PATH:"
#$zephyr-module-tinycrypt
"/zephyr-module/tinycrypt/lib")))))
(inputs (append extra-inputs (list python-cbor2
python-click
python-cryptography
python-intelhex
zephyr-module-mcuboot
zephyr-module-mbedtls
zephyr-module-zcbor))))))
(define-public zephyr-mcuboot-nrf52840dongle_nrf52840
(make-zephyr-mcuboot-for-arm "nrf52840dongle_nrf52840"
(list zephyr-module-hal-nordic)
(list zephyr-module-hal-nordic
zephyr-module-cmsis)
#:configure-flags
#~(list "-DMCUBOOT_USE_MBED_TLS=y"
"-DCONFIG_LOG=y")))
@ -174,23 +213,23 @@ optional CONFIGURE-FLAGS. Use the public KEY file for firmware decryption."
(version (package-version zephyr-module-mcuboot))
(source (file-append zephyr-module-mcuboot
(zephyr-module-installation-target
zephyr-module-mcuboot)
zephyr-module-mcuboot)
"mcuboot/scripts"))
(build-system python-build-system)
(arguments
(list #:phases
#~(modify-phases %standard-phases
(add-after 'unpack 'disable-broken-tests
(add-after 'unpack 'disable-broken-tests
(lambda _
(substitute* "imgtool/keys/ecdsa_test.py"
;; This one is calling _unsupported, which raises an
;; This one is calling _unsupported, which raises an
;; ECDSAUsageError.
(("def test_keygen") "def broken_test_keygen")
;; This one is failing with an AttributeError.
(("def test_emit_pub") "def broken_test_emit_pub")))))))
(propagated-inputs (list openssl-3.0
python-cbor2
python-click
python-cbor2
python-click
python-cryptography
python-intelhex
python-pyyaml))

View file

@ -9,18 +9,18 @@
(define-public (zephyr-module-installation-target zephyr-module)
"Return the target directory for the install-plan of the copy-build-system for
the ZEPHYR-MODULE package. It needs to match a certain pattern to collect
the ZEPHYR-MODULE package. It needs to match a certain pattern to collect
search-paths for zephyr-modules in the ZEPHYR_MOUDULES environment variable."
(string-append
;; Add the needed prefix to the module name.
"/" %zephyr-module "/" %zephyr-module-tag
"/" %zephyr-module "/"
;; Get the module name from the usually prefixed package name.
(regexp-substitute #f (string-match "^(zephyr-module-|)"
(package-name zephyr-module))
"" 'post)))
(define-public zephyr-module-template
"Return a template package to inherit zephyr module packages from. It
"Return a template package to inherit zephyr module packages from. It
provides the build-system and proper arguments."
(package
(name "zephyr-module-template")
@ -29,7 +29,7 @@ provides the build-system and proper arguments."
(build-system copy-build-system)
(arguments
(list #:install-plan
#~(list
#~(list
(list "." #$(zephyr-module-installation-target this-package)))))
(home-page #f)
(synopsis #f)
@ -59,10 +59,10 @@ Software Interface Standard.")
(define-public zephyr-module-hal-nordic
(let ((revision "1")
(commit "a1c3e0fbaafda091139b8744becd4853ada2f747"))
(commit "cf6e9fc5f7c2c98df26f2a4227a95df9a50823e7"))
(package/inherit zephyr-module-template
(name "zephyr-module-hal-nordic")
(version (git-version "3.0.0" revision commit))
(version (git-version "3.1.0" revision commit))
(source (origin
(method git-fetch)
(uri (git-reference
@ -71,7 +71,7 @@ Software Interface Standard.")
(file-name (git-file-name name version))
(sha256
(base32
"1y0sz6m0fpfwxrsqrn29vvd5dxmk9804s4gwpxc9rdd79adklbab"))))
"1zbnhf7r9sg67xjhbdh6fn4gvccc71pxqcmbfnsi6a75bhfv9y55"))))
(home-page "https://github.com/zephyrproject-rtos/hal_nordic")
(synopsis "Zephyr module for Nordic Semiconductor's SoCs and SiPs")
(description "Zephyr module providing the Hardware Abstraction Layer for
@ -113,10 +113,12 @@ Supported SoCs and SiPs:
(define-public zephyr-module-hal-stm32
(let ((revision "1")
(commit "c865374fc83d93416c0f380e6310368ff55d6ce2"))
(commit "d466dc8421ee0c6592bb5682aa93a671bc948107"))
(package/inherit zephyr-module-template
(name "zephyr-module-hal-stm32")
(version (git-version "1.16.0" revision commit))
;; Using highest version number listed in:
;; https://github.com/zephyrproject-rtos/hal_stm32/blob/main/stm32cube/common_ll/README.rst
(version (git-version "1.27.1" revision commit))
(source (origin
(method git-fetch)
(uri (git-reference
@ -128,17 +130,17 @@ Supported SoCs and SiPs:
"0q0ckial6a3lvlag44zm65dklbbdnqpzr1vbh85dhwx7acpjd5ni"))))
(home-page "https://github.com/zephyrproject-rtos/hal_stm32")
(synopsis "Zephyr module for STM32 microcontrollers")
(description "Zephyr module providing the required STM32cube packages,
(description "Zephyr module providing the required STM32cube packages,
dtsi files and libraries needed to build a Zephyr application running on STM32
silicon.")
(license license:bsd-3))))
(define-public zephyr-module-lvgl
(define-public zephyr-module-lvgl-8.2.0
(let ((revision "1")
(commit "70a7849726be8375e3d941153dc417823ea7f355"))
(package/inherit zephyr-module-template
(name "zephyr-module-lvgl")
(version (git-version "8.2.0" revision commit)) ; Taken from lvgl.h.
(version (git-version "8.2.0" revision commit)) ; Taken from lvgl.h.
(source (origin
(method git-fetch)
(uri (git-reference
@ -155,12 +157,28 @@ Graphics Library for an embedded GUI with graphical elements, visual effects
and a low memory footprint.")
(license license:apsl2))))
(define-public zephyr-module-lvgl
(let ((revision "2")
(commit "5da257f782a8f9c6e265bdc60ebc2a93fdee24de"))
(package/inherit zephyr-module-lvgl-8.2.0
(name "zephyr-module-lvgl")
(version (git-version "8.3.7" revision commit)) ; Taken from lvgl.h.
(source (origin
(method git-fetch)
(uri (git-reference
(url "https://github.com/zephyrproject-rtos/lvgl")
(commit commit)))
(file-name (git-file-name name version))
(sha256
(base32
"14isczxi36dasks1w4hwdlbzpvja4wal458i0km0hi92bbxayg0a")))))))
(define-public zephyr-module-mbedtls
(let ((revision "1")
(commit "711fd5ea13a5e018cebe1ac1f79c22d897e8b34d"))
(commit "c38dc78d9a8dcbe43b898cc1171ab33ba3e6fc26"))
(package/inherit zephyr-module-template
(name "zephyr-module-mbedtls")
(version (git-version "3.3.0" revision commit))
(version (git-version "3.4.0" revision commit))
(source (origin
(method git-fetch)
(uri (git-reference
@ -169,7 +187,7 @@ and a low memory footprint.")
(file-name (git-file-name name version))
(sha256
(base32
"0lvvarwx735g2bc272n03gp8dsx0bn0i4cywmi6igrc6dyqwkabq"))))
"0661myy0wjz38nypbyfw51x10mzg57syb5c28irblgjm2w25wbi7"))))
(home-page "https://github.com/zephyrproject-rtos/mbedtls")
(synopsis "Zephyr module for Mbed TLS")
(description "Zephyr module providing Mbed TLS, a C library that
@ -180,7 +198,7 @@ embedded systems.")
(define-public zephyr-module-mcuboot
(let ((revision "1")
(commit "74c4d1c52fd51d07904b27a7aa9b2303e896a4e3"))
(commit "76d19b3b8885ea7ae25a6f4f5d8501f7ec646447"))
(package/inherit zephyr-module-template
(name "zephyr-module-mcuboot")
(version (git-version "1.11.0-dev" revision commit))
@ -192,7 +210,7 @@ embedded systems.")
(file-name (git-file-name name version))
(sha256
(base32
"14g95wjqxchv2vnpzld8in6ljlw6s2cj43nlyf6g8czyy5rx99qb"))))
"1frm9330bir1cz7h87qq26r74igy3pvrz3iqpvc7r6l7silj0fxf"))))
(home-page "https://github.com/zephyrproject-rtos/mcuboot")
(synopsis "Zephyr module for MCUboot")
(description "Zephyr module providing the secure bootloader MCUboot for
@ -219,5 +237,27 @@ bootloader that enables easy software upgrade.")
(home-page "https://github.com/zephyrproject-rtos/tinycrypt")
(synopsis "Zephyr module for the TinyCrypt library")
(description "Zephyr module providing the TinyCrypt library.")
(license (license:non-copyleft "file://README")))))
(license (license:non-copyleft "file://README.zephyr")))))
(define-public zephyr-module-zcbor
(let ((revision "1")
(commit "67fd8bb88d3136738661fa8bb5f9989103f4599e"))
(package/inherit zephyr-module-template
(name "zephyr-module-zcbor")
(version (git-version "0.7.0" revision commit))
(source (origin
(method git-fetch)
(uri (git-reference
(url "https://github.com/zephyrproject-rtos/zcbor")
(commit commit)))
(file-name (git-file-name name version))
(sha256
(base32
"16138k7xlahf63dfvplm8c2m0kxs1g17gcx1fa31y4gcfbi3b0k7"))))
(home-page "https://github.com/zephyrproject-rtos/zcbor")
(synopsis "Zephyr module for the zcbor library")
(description "Zephyr module providing the zcbor low footprint CBOR
(Concise Binary Object Representation) library in the C language, tailored for
use in microcontrollers.")
(license license:apsl2))))

View file

@ -35,11 +35,11 @@ ZMK_CONFIG environment varibale during a ZMK Firmware package build to its
configuration input. Add a file-like object like a file-union or a package
containing a zmk-config/config folder as build input to a ZMK Firmare packege.")
(license license:expat)))
(define*-public (make-zmk board
#:key
(shield "")
#:key
(shield "")
(extra-inputs '())
(extra-name "")
(patches '())
@ -53,8 +53,8 @@ SNIPPET to modify the ZMK sources."
(commit "9d714c0b69fee2098a010d29e534051aeca26386")
(underscore->hyphen (lambda (name)
(string-map (lambda (char)
(if (char=? char #\_)
#\-
(if (char=? char #\_)
#\-
char))
name)))
(board-name (underscore->hyphen board))
@ -87,7 +87,7 @@ SNIPPET to modify the ZMK sources."
'()))))
(inputs (append extra-inputs
(list zephyr-module-cmsis
zephyr-module-lvgl
zephyr-module-lvgl-8.2.0
zephyr-module-tinycrypt
zmk-config)))
(home-page "https://zmk.dev")
@ -103,7 +103,7 @@ built on the Zephyr™ Project Real Time Operating System (RTOS).")
(define*-public (make-nrfmicro-13-zmk shield #:key zmk-config (extra-name ""))
"Make a ZMK firmware package for a keyboard consisting of the nrfmicro 1.3/1.4
board with a SHIELD PCB. Use the ZMK-CONFIG directory containing optional
board with a SHIELD PCB. Use the ZMK-CONFIG directory containing optional
boards/ or dts/ directories, or .conf, .keypad, .overlay files prefixed with
shield or board names."
(make-zmk
@ -145,7 +145,7 @@ settings-reset firmware files."
(define (hid-modifier modifier)
(define hid-modifier->zmk-macro
'(( . LS) ( . LC) ( . LA) ( . LG)
'(( . LS) ( . LC) ( . LA) ( . LG)
(R . RG) (R . RA) (R . RC) (R . RS)))
(or (assoc-ref hid-modifier->zmk-macro modifier) modifier))
@ -166,7 +166,7 @@ settings-reset firmware files."
;; Backlight, requires one parameter.
( . &bl)))
(or (assoc-ref special-bindings->zmk-name key-label) key-label))
(define-public (hid key-label)
(define hid->zmk-name
'(( . ESC) ( . PSCRN) ( . SLCK) ( . PAUSE_BREAK)
@ -187,12 +187,12 @@ settings-reset firmware files."
(÷ . KP_DIVIDE) (* . KP_MULTIPLY) ( . KP_MINUS) (+ . KP_PLUS)
(P1 . KP_N1) (P2 . KP_N2) (P3 . KP_N3) (P4 . KP_N4) (P5 . KP_N5)
(P6 . KP_N6) (P7 . KP_N7) (P8 . KP_N8) (P9 . KP_N9) (P0 . KP_N0)
(P. . KP_DOT) (P, . KP_COMMA) ( . ENTER)
(P. . KP_DOT) (P, . KP_COMMA) ( . ENTER)
( . C_AC_CUT) ( . C_AC_COPY) ( . C_AC_PASTE)
( . C_AC_UNDO) ( . C_AC_REDO)
( . C_AL_KEYBOARD_LAYOUT)))
(special-bindings (or (assoc-ref hid->zmk-name key-label) key-label)))
(define-public (de key-label)
(define de->hid
'((ß . -) (´ . =)
@ -201,14 +201,14 @@ settings-reset firmware files."
(< . \) (Y . Z) (- . /)
(P+ . +) (P, . P.) (P. . P,)))
(hid (or (assoc-ref de->hid key-label) key-label)))
(define-public (neo key-label)
(define neo->de
'((T1 . ^)
'((T1 . ^)
(X . Q) (V . W) (L . E) (C . R) (W . T)
(M3 . ) (U . A) (I . S) (A . D) (E . F) (O . G)
(M4 . <) (Ü . Y) (Ö . X) (Ä . C) (P . V) (Z . B)
(- . ß) (T2 . ´)
(- . ß) (T2 . ´)
(K . Z) (H . U) (G . I) (F . O) (Q . P) ( . Ü) (T3 . +)
(S . H) (N . J) (R . K) (T . L) (D . Ö) (Y . Ä) (RM3 . )
(B . N) (J . -) (RM4 . R)
@ -269,7 +269,7 @@ respresentation of ZMK."
(modified-key->zmk unmodified-key))
(key-label
(key-label->zmk key-label))))
(define (behavior->zmk behavior strings-of-layers-and-modified-keys)
"Join a BEHAVIOR symbol like '&mt with STRINGS-OF-LAYERS-AND-MODIFIED-KEYS
as parameters like '(\"LALT\" \"ESC\") into the \"&mt LALT ESC\" respresentation
@ -304,12 +304,12 @@ ZMK behavior for a keymap layer."
(string-join (map (lambda (zmk-behavior)
(string-pad-right
zmk-behavior
(max 12 (string-length zmk-behavior))))
(max 12 (string-length zmk-behavior))))
(map key-binding->zmk key-bindings))))
(string-append " " name "_layer {"
"\n bindings = <"
(string-join (map keys->zmk (drop-right rows 1))
(string-join (map keys->zmk (drop-right rows 1))
"\n " 'prefix)
"\n >;"
(if (null? (last rows))
@ -429,29 +429,29 @@ resolved by flashing this settings reset firmware to both controllers.")))
(zmk-keymap
#:layers
`(("default" ,neo
( N1 N2 N3 N4 N5 N6 N7 N8 N9 N0 )
( X V L C W T2 K H G F Q )
( N1 N2 N3 N4 N5 N6 N7 N8 N9 N0 )
( X V L C W T2 K H G F Q )
( M3 U I A E O T3 S N R T D ,M3Y)
(,- Ü Ö Ä P Z R R B M · J ,R)
( T1 ,l0 M4 RM4 R ,l1 ,l0 ,- R )
())
("cursor" ,neo
( F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 )
( )
( F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 )
( )
( )
(,- R R )
( ,l1 R ,l1 ,- R )
())
("keypad" ,neo
( F11 F12 F13 F14 F15 P ÷ * )
( P7 P8 P9 P+ )
( F11 F12 F13 F14 F15 P ÷ * )
( P7 P8 P9 P+ )
( M3 P4 P5 P6 P= M3 )
(,- R R P1 P2 P3 R )
( ,l2 M4 RM4 R P0 P, ,. R )
())
("zmk" ,neo
( ,1 ,2 ,3 ,4 ,5 )
( )
( ,1 ,2 ,3 ,4 ,5 )
( )
( , , , )
( )
( ,l3 ,l3 )