Commit | Line | Data |
---|---|---|
c298c889 DM |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org> | |
3 | ;;; | |
4 | ;;; This file is part of GNU Guix. | |
5 | ;;; | |
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. | |
10 | ;;; | |
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. | |
15 | ;;; | |
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/>. | |
18 | ||
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) | |
2ea99f4e DM |
24 | #:use-module (gnu packages bash) |
25 | #:use-module (gnu packages commencement) | |
6084dd93 | 26 | #:use-module (gnu packages cross-base) |
c298c889 | 27 | #:use-module (gnu packages documentation) |
2ea99f4e DM |
28 | #:use-module (gnu packages file) |
29 | #:use-module (gnu packages gcc) | |
c298c889 DM |
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)) | |
44 | ||
45 | (define-public bcm2835 | |
46 | (package | |
47 | (name "bcm2835") | |
48 | (version "1.64") | |
49 | (source (origin | |
50 | (method url-fetch) | |
51 | (uri (string-append | |
52 | "http://www.airspayce.com/mikem/bcm2835/bcm2835-" | |
53 | version ".tar.gz")) | |
54 | (sha256 | |
55 | (base32 | |
56 | "06s81540iz4vsh0cm6jwah2x0hih79v42pfa4pgr8kcbv56158h6")))) | |
57 | (build-system gnu-build-system) | |
58 | (arguments | |
59 | `(#:tests? #f)) ; Would need to be root | |
60 | ;; doc/html docs would not be installed anyway. | |
61 | ;(native-inputs | |
ade77dd0 | 62 | ; `(("doxygen" ,doxygen))) |
c298c889 DM |
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))) | |
69 | ||
22c48767 DM |
70 | (define raspi-gpio |
71 | (let ((commit "6d0769ac04760b6e9f33b4aa1f11c682237bf368") | |
72 | (revision "1")) | |
73 | (package | |
74 | (name "raspi-gpio") | |
75 | (version (git-version "0.1" revision commit)) | |
76 | (source (origin | |
77 | (method git-fetch) | |
78 | (uri (git-reference | |
8ed4c468 | 79 | (url "https://github.com/RPi-Distro/raspi-gpio") |
22c48767 DM |
80 | (commit commit))) |
81 | (file-name (git-file-name name version)) | |
82 | (sha256 | |
83 | (base32 | |
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 | |
91 | drivers).") | |
92 | (home-page "https://github.com/RPi-Distro/raspi-gpio") | |
93 | (supported-systems '("armhf-linux" "aarch64-linux")) | |
94 | (license license:bsd-3)))) | |
6084dd93 DM |
95 | |
96 | (define %rpi-open-firmware-version "0.1") | |
97 | (define %rpi-open-firmware-origin | |
98 | (origin | |
99 | (method git-fetch) | |
100 | (uri (git-reference | |
8ed4c468 | 101 | (url "https://github.com/librerpi/rpi-open-firmware") |
6084dd93 DM |
102 | (commit "6be45466e0be437a1b0b3512a86f3d9627217006"))) |
103 | (file-name "rpi-open-firmware-checkout") | |
104 | (sha256 | |
105 | (base32 "1wyxvv62i3rjicg4hd94pzbgpadinnrgs27sk39md706mm0qixbh")))) | |
106 | ||
107 | (define-public raspi-arm-chainloader | |
108 | (package | |
109 | (name "raspi-arm-chainloader") | |
110 | (version %rpi-open-firmware-version) | |
111 | (source %rpi-open-firmware-origin) | |
112 | (build-system gnu-build-system) | |
113 | (arguments | |
114 | `(#:tests? #f ; No tests exist | |
115 | #:phases | |
116 | (modify-phases %standard-phases | |
117 | (delete 'configure) | |
118 | (add-before 'build 'setenv | |
119 | (lambda _ | |
120 | (setenv "CC" "arm-none-eabi-gcc") | |
121 | (setenv "CXX" "arm-none-eabi-g++") | |
122 | (setenv "AS" "arm-none-eabi-as") | |
b522686e | 123 | (setenv "OBJCOPY" "arm-none-eabi-objcopy") |
6084dd93 DM |
124 | (setenv "BAREMETAL" "1") |
125 | #t)) | |
126 | (add-after 'setenv 'build-tlsf | |
127 | (lambda _ | |
128 | (with-directory-excursion "tlsf" | |
53aa680e | 129 | ;; Note: Adding "-I../common -I../notc/include". |
6084dd93 | 130 | (invoke "make" |
53aa680e | 131 | "CFLAGS=-mtune=arm1176jzf-s -march=armv6zk -mfpu=vfp -mfloat-abi=softfp -I../common -I../notc/include")))) |
6084dd93 DM |
132 | (add-after 'build-tlsf 'build-common |
133 | (lambda _ | |
134 | (with-directory-excursion "common" | |
135 | (invoke "make" | |
53aa680e DM |
136 | ;; Note: Adding "-I.. -I../notc/include". |
137 | "ARMCFLAGS=-mtune=arm1176jzf-s -march=armv6zk -marm -I.. -I../notc/include")))) | |
6084dd93 DM |
138 | (add-after 'build-common 'build-notc |
139 | (lambda _ | |
140 | (with-directory-excursion "notc" | |
141 | (invoke "make")))) | |
142 | (add-after 'build-notc 'chdir | |
143 | (lambda _ | |
144 | (chdir "arm_chainloader") | |
145 | (substitute* "Makefile" | |
146 | (("-I[.][.]/") | |
147 | "-I../common -I../common/include -I../notc/include -I../") | |
148 | (("-ltlsf") | |
149 | "-L../common -L../notc -L../tlsf -ltlsf")) | |
150 | #t)) | |
151 | (replace 'install | |
152 | (lambda* (#:key outputs #:allow-other-keys) | |
153 | (let* ((out (assoc-ref outputs "out")) | |
154 | (libexec (string-append out "/libexec"))) | |
155 | (mkdir-p libexec) | |
156 | (install-file "build/arm_chainloader.elf" libexec) | |
157 | (install-file "build/arm_chainloader.map" libexec) | |
b522686e | 158 | (install-file "build/arm_chainloader.bin" libexec) |
6084dd93 DM |
159 | #t)))))) |
160 | (native-inputs | |
161 | `(("binutils" ,(cross-binutils "arm-none-eabi")) | |
162 | ("gcc" ,gcc-arm-none-eabi-6))) | |
163 | (inputs | |
164 | `()) | |
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+))) | |
2ea99f4e DM |
170 | |
171 | (define-public raspi-arm64-chainloader | |
172 | (package | |
173 | (inherit raspi-arm-chainloader) | |
174 | (name "raspi-arm64-chainloader") | |
175 | ;; These native-inputs especially don't contain a libc. | |
176 | (native-inputs | |
177 | `(("bash" ,bash) | |
178 | ("binutils" ,binutils) | |
179 | ("coreutils" ,coreutils) | |
180 | ("file" ,file) | |
181 | ("ld-wrapper" ,ld-wrapper) | |
182 | ("make" ,gnu-make) | |
183 | ("gcc" ,gcc-6) | |
184 | ("locales" ,glibc-utf8-locales))) | |
185 | (inputs | |
186 | `()) | |
187 | (arguments | |
188 | `(#:implicit-inputs? #f | |
189 | ,@(substitute-keyword-arguments (package-arguments raspi-arm-chainloader) | |
190 | ((#:phases phases) | |
191 | `(modify-phases ,phases | |
192 | (replace 'setenv | |
193 | (lambda _ | |
194 | (setenv "AS" "as") ; TODO: as-for-target | |
7abe768e | 195 | (setenv "OBJCOPY" "objcopy") |
2ea99f4e DM |
196 | (setenv "CC" ,(cc-for-target)) |
197 | (setenv "CXX" ,(cc-for-target)) | |
198 | (setenv "BAREMETAL" "1") | |
199 | #t)) | |
200 | (add-after 'setenv 'build-tlsf | |
201 | (lambda _ | |
202 | (with-directory-excursion "tlsf" | |
203 | (invoke "make" | |
204 | "CFLAGS=-I../common -I../notc/include")))) | |
205 | (replace 'build-common | |
206 | (lambda _ | |
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. | |
210 | (invoke "make" | |
211 | "CFLAGS=-Ilib -I. -Iinclude -ffunction-sections -Wall -g -nostdlib -nostartfiles -ffreestanding -DBAREMETAL")))) | |
212 | (replace 'build-notc | |
213 | (lambda _ | |
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. | |
217 | (invoke "make" | |
218 | "CFLAGS=-Iinclude -g")))) | |
219 | (replace 'chdir | |
220 | (lambda _ | |
221 | (chdir "arm64") | |
222 | (substitute* "Makefile" | |
223 | (("CFLAGS =") | |
224 | "CFLAGS = -I../common -I../common/include -I../notc/include -I.. -DBAREMETAL") | |
225 | (("-lcommon") | |
226 | "-L../common -L../notc -lcommon")) | |
2ea99f4e DM |
227 | #t)) |
228 | (replace 'install | |
229 | (lambda* (#:key outputs #:allow-other-keys) | |
230 | (let* ((out (assoc-ref outputs "out")) | |
231 | (libexec (string-append out "/libexec"))) | |
232 | (mkdir-p libexec) | |
233 | (install-file "arm64.elf" libexec) | |
7abe768e | 234 | (install-file "arm64.map" libexec) |
a1721d43 DM |
235 | (install-file "arm64.bin" libexec) |
236 | #t)))))))) | |
2ea99f4e | 237 | (supported-systems '("aarch64-linux")))) |