1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
19 (define-module (gnu packages raspberry-pi)
20 #:use-module (gnu packages)
21 #:use-module (gnu packages admin)
22 #:use-module (gnu packages algebra)
23 #:use-module (gnu packages base)
24 #:use-module (gnu packages bash)
25 #:use-module (gnu packages commencement)
26 #:use-module (gnu packages cross-base)
27 #:use-module (gnu packages documentation)
28 #:use-module (gnu packages file)
29 #:use-module (gnu packages gcc)
30 #:use-module (gnu packages embedded)
31 #:use-module (guix build-system gnu)
32 #:use-module (guix download)
33 #:use-module (guix git-download)
34 #:use-module ((guix licenses) #:prefix license:)
35 #:use-module (guix packages)
36 #:use-module (guix gexp)
37 #:use-module (guix store)
38 #:use-module (guix monads)
39 #:use-module (guix utils)
40 #:use-module (srfi srfi-1)
41 #:use-module (srfi srfi-2)
42 #:use-module (srfi srfi-26)
43 #:use-module (ice-9 match))
45 (define-public bcm2835
52 "http://www.airspayce.com/mikem/bcm2835/bcm2835-"
56 "06s81540iz4vsh0cm6jwah2x0hih79v42pfa4pgr8kcbv56158h6"))))
57 (build-system gnu-build-system)
59 `(#:tests? #f)) ; Would need to be root
60 ;; doc/html docs would not be installed anyway.
62 ; `(("doxygen" ,doxygen)))
63 (synopsis "C library for Broadcom BCM 2835 as used in Raspberry Pi")
64 (description "This package provides a C library for Broadcom BCM 2835 as
65 used in the Raspberry Pi")
66 (home-page "http://www.airspayce.com/mikem/bcm2835/")
67 (supported-systems '("armhf-linux" "aarch64-linux"))
68 (license license:gpl3)))
71 (let ((commit "6d0769ac04760b6e9f33b4aa1f11c682237bf368")
75 (version (git-version "0.1" revision commit))
79 (url "https://github.com/RPi-Distro/raspi-gpio")
81 (file-name (git-file-name name version))
84 "1fia1ma586hwhpda0jz86j6i55andq0wncbhzhzvhf7yc773cpi4"))))
85 (build-system gnu-build-system)
86 (synopsis "State dumper for BCM270x GPIOs")
87 (description "Tool to help debug / hack at the BCM283x GPIO. You can dump
88 the state of a GPIO or (all GPIOs). You can change a GPIO mode and pulls (and
89 level if set as an output). Beware this tool writes directly to the BCM283x
90 GPIO reisters, ignoring anything else that may be using them (like Linux
92 (home-page "https://github.com/RPi-Distro/raspi-gpio")
93 (supported-systems '("armhf-linux" "aarch64-linux"))
94 (license license:bsd-3))))
96 (define %rpi-open-firmware-version "0.1")
97 (define %rpi-open-firmware-origin
101 (url "https://github.com/librerpi/rpi-open-firmware")
102 (commit "6be45466e0be437a1b0b3512a86f3d9627217006")))
103 (file-name "rpi-open-firmware-checkout")
105 (base32 "1wyxvv62i3rjicg4hd94pzbgpadinnrgs27sk39md706mm0qixbh"))))
107 (define-public raspi-arm-chainloader
109 (name "raspi-arm-chainloader")
110 (version %rpi-open-firmware-version)
111 (source %rpi-open-firmware-origin)
112 (build-system gnu-build-system)
114 `(#:tests? #f ; No tests exist
116 (modify-phases %standard-phases
118 (add-before 'build 'setenv
120 (setenv "CC" "arm-none-eabi-gcc")
121 (setenv "CXX" "arm-none-eabi-g++")
122 (setenv "AS" "arm-none-eabi-as")
123 (setenv "OBJCOPY" "arm-none-eabi-objcopy")
124 (setenv "BAREMETAL" "1")
126 (add-after 'setenv 'build-tlsf
128 (with-directory-excursion "tlsf"
129 ;; Note: Adding "-I../common -I../notc/include".
131 "CFLAGS=-mtune=arm1176jzf-s -march=armv6zk -mfpu=vfp -mfloat-abi=softfp -I../common -I../notc/include"))))
132 (add-after 'build-tlsf 'build-common
134 (with-directory-excursion "common"
136 ;; Note: Adding "-I.. -I../notc/include".
137 "ARMCFLAGS=-mtune=arm1176jzf-s -march=armv6zk -marm -I.. -I../notc/include"))))
138 (add-after 'build-common 'build-notc
140 (with-directory-excursion "notc"
142 (add-after 'build-notc 'chdir
144 (chdir "arm_chainloader")
145 (substitute* "Makefile"
147 "-I../common -I../common/include -I../notc/include -I../")
149 "-L../common -L../notc -L../tlsf -ltlsf"))
152 (lambda* (#:key outputs #:allow-other-keys)
153 (let* ((out (assoc-ref outputs "out"))
154 (libexec (string-append out "/libexec")))
156 (install-file "build/arm_chainloader.elf" libexec)
157 (install-file "build/arm_chainloader.map" libexec)
158 (install-file "build/arm_chainloader.bin" libexec)
161 `(("binutils" ,(cross-binutils "arm-none-eabi"))
162 ("gcc" ,gcc-arm-none-eabi-6)))
165 (synopsis "Raspberry Pi ARM bootloader")
166 (description "This package provides a bootloader for the ARM part of a
167 Raspberry Pi. Note: It does not work on Raspberry Pi 1.")
168 (home-page "https://github.com/librerpi/rpi-open-firmware/")
169 (license license:gpl2+)))
171 (define-public raspi-arm64-chainloader
173 (inherit raspi-arm-chainloader)
174 (name "raspi-arm64-chainloader")
175 ;; These native-inputs especially don't contain a libc.
178 ("binutils" ,binutils)
179 ("coreutils" ,coreutils)
181 ("ld-wrapper" ,ld-wrapper)
184 ("locales" ,glibc-utf8-locales)))
188 `(#:implicit-inputs? #f
189 ,@(substitute-keyword-arguments (package-arguments raspi-arm-chainloader)
191 `(modify-phases ,phases
194 (setenv "AS" "as") ; TODO: as-for-target
195 (setenv "OBJCOPY" "objcopy")
196 (setenv "CC" ,(cc-for-target))
197 (setenv "CXX" ,(cc-for-target))
198 (setenv "BAREMETAL" "1")
200 (add-after 'setenv 'build-tlsf
202 (with-directory-excursion "tlsf"
204 "CFLAGS=-I../common -I../notc/include"))))
205 (replace 'build-common
207 (with-directory-excursion "common"
208 ;; Autodetection uses the CC filename for detecting the architecture.
209 ;; Since we are not using a cross-compiler, we side-step that.
211 "CFLAGS=-Ilib -I. -Iinclude -ffunction-sections -Wall -g -nostdlib -nostartfiles -ffreestanding -DBAREMETAL"))))
214 (with-directory-excursion "notc"
215 ;; Autodetection uses the CC filename for detecting the architecture.
216 ;; Since we are not using a cross-compiler, we side-step that.
218 "CFLAGS=-Iinclude -g"))))
222 (substitute* "Makefile"
224 "CFLAGS = -I../common -I../common/include -I../notc/include -I.. -DBAREMETAL")
226 "-L../common -L../notc -lcommon"))
229 (lambda* (#:key outputs #:allow-other-keys)
230 (let* ((out (assoc-ref outputs "out"))
231 (libexec (string-append out "/libexec")))
233 (install-file "arm64.elf" libexec)
234 (install-file "arm64.map" libexec)
235 (install-file "arm64.bin" libexec)
237 (supported-systems '("aarch64-linux"))))