@@ -33,161 +33,158 @@ Prerequisites
33
33
$ cd libtock-c
34
34
```
35
35
36
- 1. The main requirement to build the C applications in this repository is having
37
- cross compilers for embedded targets. You will need an `arm-none-eabi`
38
- toolchain for Cortex-M targets.
36
+ 1. There are two requirements for building libtock-c applications.
39
37
40
- **MacOS**:
41
- ```
42
- $ brew tap ARMmbed/homebrew-formulae && brew update && brew install arm-none-eabi-gcc
43
- ```
38
+ 1. Cross compiler for embedded targets
44
39
45
- **Ubuntu (18.04LTS or later)**:
46
- ```
47
- $ sudo apt install gcc-arm-none-eabi
48
- ```
40
+ *ARM*
49
41
50
- **Arch**:
51
- ```
52
- $ sudo pacman -Syu arm-none-eabi-gcc arm-none-eabi-newlib
53
- ```
42
+ You will need an `arm-none-eabi` toolchain for Cortex-M targets.
54
43
55
- **Fedora **:
56
- ```
57
- $ sudo dnf install arm-none-eabi-newlib arm-none-eabi- gcc-cs
58
- ```
44
+ **MacOS **:
45
+ ```
46
+ $ brew tap ARMmbed/homebrew-formulae && brew update && brew install arm-none-eabi-gcc
47
+ ```
59
48
60
- 2. Optional: libtock-c also includes support for building for ***RISC-V
61
- targets***. These are not included by default since obtaining the toolchain
62
- can be difficult (as of July 2022). You will need a RISC-V toolchain that
63
- supports rv32 targets (64 bit toolchains support rv32 if compiled with
64
- multilib support). Some toolchains that can work:
49
+ **Ubuntu (18.04LTS or later)**:
50
+ ```
51
+ $ sudo apt install gcc-arm-none-eabi
52
+ ```
65
53
66
- - riscv64-none-elf
67
- - riscv32-none-elf
68
- - riscv64-elf
69
- - riscv64-unknown-elf
70
- - riscv32-unknown-elf
54
+ **Arch**:
55
+ ```
56
+ $ sudo pacman -Syu arm-none-eabi-gcc
57
+ ```
71
58
72
- To actually build for the RISC-V targets, add `RISCV=1` to the make command:
59
+ **Fedora**:
60
+ ```
61
+ $ sudo dnf install arm-none-eabi-gcc-cs
62
+ ```
73
63
74
- $ make RISCV=1
64
+ *RISC-V*
75
65
76
- **MacOS**:
77
- ```
78
- $ brew tap riscv/riscv && brew update && brew install riscv-gnu-toolchain
79
- ```
66
+ You will need a RISC-V toolchain that supports rv32 targets (64 bit
67
+ toolchains support rv32 if compiled with multilib support).
68
+ Some toolchains that can work:
69
+ - riscv64-none-elf
70
+ - riscv32-none-elf
71
+ - riscv64-elf
72
+ - riscv64-unknown-elf
73
+ - riscv32-unknown-elf
80
74
81
- **Ubuntu (21.10 or later)**:
82
- ```
83
- $ sudo apt install gcc-riscv64-unknown-elf picolibc-riscv64-unknown-elf
84
- ```
75
+ **MacOS**:
85
76
86
- **Ubuntu (21.04 or earlier)**:
77
+ ```shell
78
+ $ brew tap riscv/riscv && brew update && brew install riscv-gnu-toolchain
79
+ ```
87
80
88
- Unfortunately, older Ubuntu does not provide a package for RISC-V libc. We
89
- have created a .deb file you can use to install a suitable libc based on
90
- newlib:
91
- ```
92
- $ wget http://cs.virginia.edu/~bjc8c/archive/newlib_3.3.0-1_amd64.deb
93
- $ sudo dpkg -i newlib_3.3.0-1_amd64.deb
94
- ```
81
+ **Ubuntu (21.10 or later) or Debian (11 or later)**:
95
82
96
- If you would rather compile your own newlib-based libc, follow the steps
97
- below. Section [newlib-nano](newlib-nano) describes some extra config options
98
- to build a size optimised newlib.
99
- ```
100
- # Download newlib 3.3 from https://sourceware.org/newlib/
101
- $ wget ftp://sourceware.org/pub/newlib/newlib-3.3.0.tar.gz
102
- $ tar -xvf newlib-3.3.0.tar.gz
103
- $ cd newlib-3.3.0
104
- # Disable stdlib for building
105
- $ export CFLAGS=-nostdlib
106
- # Run configure
107
- $ ./configure --disable-newlib-supplied-syscalls --with-gnu-ld --with-newlib --enable-languages=c --target=riscv64-unknown-elf --host=x86 --disable-multi-lib --prefix /usr
108
- # Build and then install
109
- $ make -j8
110
- $ sudo make install
111
- ```
83
+ ```shell
84
+ $ sudo apt install gcc-riscv64-unknown-elf
85
+ ```
112
86
113
- Alternatively, you may use a pre-compiled toolchain that we created with
114
- Crosstool-NG.
115
- ```
116
- $ wget http://cs.virginia.edu/~bjc8c/archive/gcc-riscv64-unknown-elf-8.3.0-ubuntu.zip
117
- $ unzip gcc-riscv64-unknown-elf-8.3.0-ubuntu.zip
118
- # add gcc-riscv64-unknown-elf-8.3.0-ubuntu/bin to your ` $PATH ` variable.
119
- ```
87
+ **Arch**:
88
+ ```shell
89
+ $ sudo pacman -Syu riscv64-elf-gcc
90
+ ```
120
91
121
- **Arch**:
122
- ```
123
- $ sudo pacman -Syu riscv64-elf-gcc riscv32-elf-newlib arm-none-eabi-newlib riscv64-elf-newlib
124
- ```
92
+ **Other distros**:
125
93
126
- **Fedora**:
94
+ If your distro doesn't provide a RISC-V toolchain you can build one yourself
95
+ or just disable RISC-V support by running
127
96
128
- **dnf** does not contain the `riscv-gnu-toolchain`, an alternative is to
129
- compile from source. Start with some of the tools we need to compile the
130
- source.
131
- ```
132
- $ sudo dnf install make automake gcc gcc-c++ kernel-devel texinfo expat expat-devel
133
- $ sudo dnf group install "Development Tools" "C Development Tools and Libraries"
134
- ```
135
- Get `riscv-gnu-toolchain`, [summarised instructions as stated
136
- here](https://github.com/riscv-collab/riscv-gnu-toolchain/blob/master/README.md)
137
- ```
138
- $ git clone https://github.com/riscv/riscv-gnu-toolchain
139
- $ cd riscv-gnu-toolchain/
140
- ```
141
- **Note: add /opt/riscv/bin to your PATH**, then,
142
- ```
143
- $ ./configure --prefix=/opt/riscv --enable-multilib
144
- ```
145
- `--enable-multilib` ensures that "the multilib compiler will have the prefix
146
- riscv64-unknown-elf- or riscv64-unknown-linux-gnu- but will be able to target
147
- both 32-bit and 64-bit systems."
148
- ```
149
- $ sudo make [ might need elevated privileges writing to ` /opt/ ` ]
150
- ```
151
- additionally, with
152
- ```
153
- $ sudo make linux
154
- ```
155
- you can also build `riscv64-unknown-linux-gnu`, which can be useful with tock
156
- where `riscv64-unknown-linux-gnu-objcopy` is used.
97
+ ```shell
98
+ NORISCV=1 make
99
+ ```
157
100
158
- After the the source has been compiled and copied to `/opt/riscv` and
159
- `/opt/riscv/bin`has appended to the PATH, the toolchain is ready to be used.
101
+ 1. libc for embedded targets
160
102
103
+ *ARM*
161
104
162
- **newlib-nano **:
105
+ **Ubuntu (21.10 or later) or Debian (11 or later) **:
163
106
164
- newlib can require a large amount of memory, especially for printing.
165
- If this is a concern you can instead use a more size optimised version.
166
- As of August 2020 there are a few options for this.
107
+ ```shell
108
+ $ sudo apt install picolibc-arm-unknown-elf libnewlib-arm-none-eabi
109
+ ```
167
110
168
- - See if the version of newlib from your distro already has the flags below
169
- enabled. If it does it's already size optimsed.
170
- - See if your distro pacakges a newlib-nano (Debian does this) that will
171
- already include the flags below.
172
- - See if your distro packages picolibc, which is a optimised fork of newlib.
173
- - You can compile newlib with these extra flags:
111
+ **Arch**:
174
112
```
175
- --enable-newlib-reent-small \
176
- --disable-newlib-fvwrite-in-streamio \
177
- --disable-newlib-fseek-optimization \
178
- --disable-newlib-wide-orient \
179
- --enable-newlib-nano-malloc \
180
- --disable-newlib-unbuf-stream-opt \
181
- --enable-lite-exit \
182
- --enable-newlib-global-atexit \
183
- --enable-newlib-nano-formatted-io
113
+ $ sudo pacman -Syu arm-none-eabi-newlib
184
114
```
185
115
186
- 3. Optional: libtock-c also includes support for building RISC-V targets with
116
+ **Fedora**:
117
+ ```
118
+ $ sudo dnf install arm-none-eabi-newlib
119
+ ```
120
+
121
+ *RISC-V*
122
+
123
+ **Ubuntu (21.10 or later) or Debian (11 or later)**:
124
+
125
+ Use picolibc instead of newlib
126
+
127
+ ```shell
128
+ $ sudo apt install picolibc-riscv64-unknown-elf
129
+ ```
130
+ **Arch**:
131
+ ```shell
132
+ $ sudo pacman -Syu riscv32-elf-newlib
133
+ ```
134
+
135
+ *newlib-nano*
136
+
137
+ newlib can require a large amount of memory, especially for printing.
138
+ If this is a concern you can instead use a more size optimised version.
139
+ As of August 2020 there are a few options for this.
140
+
141
+ - See if the version of newlib from your distro already has the flags below
142
+ enabled. If it does it's already size optimsed.
143
+ - See if your distro packages picolibc, which is a optimised fork of newlib.
144
+ - You can compile newlib with these extra flags:
145
+ ```shell
146
+ --enable-newlib-reent-small \
147
+ --disable-newlib-fvwrite-in-streamio \
148
+ --disable-newlib-fseek-optimization \
149
+ --disable-newlib-wide-orient \
150
+ --enable-newlib-nano-malloc \
151
+ --disable-newlib-unbuf-stream-opt \
152
+ --enable-lite-exit \
153
+ --enable-newlib-global-atexit \
154
+ --enable-newlib-nano-formatted-io
155
+ ```
156
+
157
+ If you would rather compile your own newlib-based libc, follow the steps
158
+ below.
159
+
160
+ ```shell
161
+ # Download newlib 4.1 from https://sourceware.org/newlib/
162
+ $ wget ftp://sourceware.org/pub/newlib/newlib-4.1.0.tar.gz
163
+ $ tar -xvf newlib-4.1.0.tar.gz
164
+ $ cd newlib-4.1.0
165
+ # Disable stdlib for building
166
+ $ export CFLAGS=-nostdlib
167
+ # Run configure
168
+ $ ./configure --disable-newlib-supplied-syscalls --with-gnu-ld --with-newlib --enable-languages=c --target=riscv64-unknown-elf --host=x86 --disable-multi-lib --prefix /usr
169
+ # Build and then install
170
+ $ make -j8
171
+ $ sudo make install
172
+ ```
173
+
174
+ 1. Optional: If using picolibc (Debian can do this) then specify the `PICOLIBC`
175
+ variable. picolibc is an optimised version of newlib
176
+
177
+ ```shell
178
+ $ make PICOLIBC=1
179
+ ```
180
+
181
+ 1. Optional: libtock-c also includes support for building RISC-V targets with
187
182
the LLVM clang compiler. If you have a compatible clang toolchain, you can
188
183
add `CLANG=1` to the make command to use clang instead of the default GCC.
189
184
190
- $ make RISCV=1 CLANG=1
185
+ ```shell
186
+ $ make CLANG=1
187
+ ```
191
188
192
189
This support is only included for RISC-V targets as Cortex-M targets require
193
190
the FDPIC support only present in GCC.
0 commit comments