Skip to content

Commit 9fd1c8c

Browse files
Inital Working Commit
0 parents  commit 9fd1c8c

File tree

179 files changed

+55899
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+55899
-0
lines changed

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ignore build folder
2+
build/
3+
4+
#ignore .vscode
5+
.vscode/
6+
7+
#ignore buildroot folder
8+
linux/buildroot
9+
10+
#ignore c4 source folder
11+
linux/c4/c4src

CMakeLists.txt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
3+
# Pull in SDK (must be before project)
4+
include(pico_sdk_import.cmake)
5+
6+
project(picorv C CXX ASM)
7+
set(CMAKE_C_STANDARD 11)
8+
set(CMAKE_CXX_STANDARD 17)
9+
10+
# Initialize the SDK
11+
pico_sdk_init()
12+
13+
add_subdirectory(no-OS-FatFS-SD-SPI-RPi-Pico/src)
14+
add_subdirectory(pico-displayDrivs)
15+
add_subdirectory(pico-ps2Driv)
16+
17+
add_subdirectory(pico-rv32ima)
18+
19+
add_compile_options(-Wall
20+
-Wno-format # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int
21+
-Wno-unused-function # we have some for the docs that aren't called
22+
-Wno-maybe-uninitialized
23+
)
24+
25+

LICENSE

+285
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
MIT License
2+
3+
Copyright (c) 2023 tvlad1234
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
SOFTWARE.
21+
22+
----
23+
24+
https://github.com/cnlohr/mini-rv32ima
25+
26+
MIT License
27+
28+
Copyright (c) 2022 CNLohr
29+
30+
Permission is hereby granted, free of charge, to any person obtaining a copy
31+
of this software and associated documentation files (the "Software"), to deal
32+
in the Software without restriction, including without limitation the rights
33+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
34+
copies of the Software, and to permit persons to whom the Software is
35+
furnished to do so, subject to the following conditions:
36+
37+
The above copyright notice and this permission notice shall be included in all
38+
copies or substantial portions of the Software.
39+
40+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
43+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
44+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
45+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
46+
SOFTWARE.
47+
48+
----
49+
50+
parts of https://github.com/xhackerustc/uc-rv32ima
51+
52+
The software is provided under a BSD-3-Clause license (below). Contributions to
53+
this project are accepted under the same license.
54+
55+
Copyright (c) 2023, Jisheng Zhang. All rights reserved.
56+
57+
Redistribution and use in source and binary forms, with or without modification,
58+
are permitted provided that the following conditions are met:
59+
60+
- Redistributions of source code must retain the above copyright notice, this
61+
list of conditions and the following disclaimer.
62+
63+
- Redistributions in binary form must reproduce the above copyright notice,
64+
this list of conditions and the following disclaimer in the documentation
65+
and/or other materials provided with the distribution.
66+
67+
- Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific
68+
prior written permission.
69+
70+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
71+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
72+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
73+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
74+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
75+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
76+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
77+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
78+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
79+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
80+
81+
----
82+
83+
https://github.com/carlk3/no-OS-FatFS-SD-SPI-RPi-Pico
84+
85+
Apache License
86+
Version 2.0, January 2004
87+
http://www.apache.org/licenses/
88+
89+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
90+
91+
1. Definitions.
92+
93+
"License" shall mean the terms and conditions for use, reproduction,
94+
and distribution as defined by Sections 1 through 9 of this document.
95+
96+
"Licensor" shall mean the copyright owner or entity authorized by
97+
the copyright owner that is granting the License.
98+
99+
"Legal Entity" shall mean the union of the acting entity and all
100+
other entities that control, are controlled by, or are under common
101+
control with that entity. For the purposes of this definition,
102+
"control" means (i) the power, direct or indirect, to cause the
103+
direction or management of such entity, whether by contract or
104+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
105+
outstanding shares, or (iii) beneficial ownership of such entity.
106+
107+
"You" (or "Your") shall mean an individual or Legal Entity
108+
exercising permissions granted by this License.
109+
110+
"Source" form shall mean the preferred form for making modifications,
111+
including but not limited to software source code, documentation
112+
source, and configuration files.
113+
114+
"Object" form shall mean any form resulting from mechanical
115+
transformation or translation of a Source form, including but
116+
not limited to compiled object code, generated documentation,
117+
and conversions to other media types.
118+
119+
"Work" shall mean the work of authorship, whether in Source or
120+
Object form, made available under the License, as indicated by a
121+
copyright notice that is included in or attached to the work
122+
(an example is provided in the Appendix below).
123+
124+
"Derivative Works" shall mean any work, whether in Source or Object
125+
form, that is based on (or derived from) the Work and for which the
126+
editorial revisions, annotations, elaborations, or other modifications
127+
represent, as a whole, an original work of authorship. For the purposes
128+
of this License, Derivative Works shall not include works that remain
129+
separable from, or merely link (or bind by name) to the interfaces of,
130+
the Work and Derivative Works thereof.
131+
132+
"Contribution" shall mean any work of authorship, including
133+
the original version of the Work and any modifications or additions
134+
to that Work or Derivative Works thereof, that is intentionally
135+
submitted to Licensor for inclusion in the Work by the copyright owner
136+
or by an individual or Legal Entity authorized to submit on behalf of
137+
the copyright owner. For the purposes of this definition, "submitted"
138+
means any form of electronic, verbal, or written communication sent
139+
to the Licensor or its representatives, including but not limited to
140+
communication on electronic mailing lists, source code control systems,
141+
and issue tracking systems that are managed by, or on behalf of, the
142+
Licensor for the purpose of discussing and improving the Work, but
143+
excluding communication that is conspicuously marked or otherwise
144+
designated in writing by the copyright owner as "Not a Contribution."
145+
146+
"Contributor" shall mean Licensor and any individual or Legal Entity
147+
on behalf of whom a Contribution has been received by Licensor and
148+
subsequently incorporated within the Work.
149+
150+
2. Grant of Copyright License. Subject to the terms and conditions of
151+
this License, each Contributor hereby grants to You a perpetual,
152+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
153+
copyright license to reproduce, prepare Derivative Works of,
154+
publicly display, publicly perform, sublicense, and distribute the
155+
Work and such Derivative Works in Source or Object form.
156+
157+
3. Grant of Patent License. Subject to the terms and conditions of
158+
this License, each Contributor hereby grants to You a perpetual,
159+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
160+
(except as stated in this section) patent license to make, have made,
161+
use, offer to sell, sell, import, and otherwise transfer the Work,
162+
where such license applies only to those patent claims licensable
163+
by such Contributor that are necessarily infringed by their
164+
Contribution(s) alone or by combination of their Contribution(s)
165+
with the Work to which such Contribution(s) was submitted. If You
166+
institute patent litigation against any entity (including a
167+
cross-claim or counterclaim in a lawsuit) alleging that the Work
168+
or a Contribution incorporated within the Work constitutes direct
169+
or contributory patent infringement, then any patent licenses
170+
granted to You under this License for that Work shall terminate
171+
as of the date such litigation is filed.
172+
173+
4. Redistribution. You may reproduce and distribute copies of the
174+
Work or Derivative Works thereof in any medium, with or without
175+
modifications, and in Source or Object form, provided that You
176+
meet the following conditions:
177+
178+
(a) You must give any other recipients of the Work or
179+
Derivative Works a copy of this License; and
180+
181+
(b) You must cause any modified files to carry prominent notices
182+
stating that You changed the files; and
183+
184+
(c) You must retain, in the Source form of any Derivative Works
185+
that You distribute, all copyright, patent, trademark, and
186+
attribution notices from the Source form of the Work,
187+
excluding those notices that do not pertain to any part of
188+
the Derivative Works; and
189+
190+
(d) If the Work includes a "NOTICE" text file as part of its
191+
distribution, then any Derivative Works that You distribute must
192+
include a readable copy of the attribution notices contained
193+
within such NOTICE file, excluding those notices that do not
194+
pertain to any part of the Derivative Works, in at least one
195+
of the following places: within a NOTICE text file distributed
196+
as part of the Derivative Works; within the Source form or
197+
documentation, if provided along with the Derivative Works; or,
198+
within a display generated by the Derivative Works, if and
199+
wherever such third-party notices normally appear. The contents
200+
of the NOTICE file are for informational purposes only and
201+
do not modify the License. You may add Your own attribution
202+
notices within Derivative Works that You distribute, alongside
203+
or as an addendum to the NOTICE text from the Work, provided
204+
that such additional attribution notices cannot be construed
205+
as modifying the License.
206+
207+
You may add Your own copyright statement to Your modifications and
208+
may provide additional or different license terms and conditions
209+
for use, reproduction, or distribution of Your modifications, or
210+
for any such Derivative Works as a whole, provided Your use,
211+
reproduction, and distribution of the Work otherwise complies with
212+
the conditions stated in this License.
213+
214+
5. Submission of Contributions. Unless You explicitly state otherwise,
215+
any Contribution intentionally submitted for inclusion in the Work
216+
by You to the Licensor shall be under the terms and conditions of
217+
this License, without any additional terms or conditions.
218+
Notwithstanding the above, nothing herein shall supersede or modify
219+
the terms of any separate license agreement you may have executed
220+
with Licensor regarding such Contributions.
221+
222+
6. Trademarks. This License does not grant permission to use the trade
223+
names, trademarks, service marks, or product names of the Licensor,
224+
except as required for reasonable and customary use in describing the
225+
origin of the Work and reproducing the content of the NOTICE file.
226+
227+
7. Disclaimer of Warranty. Unless required by applicable law or
228+
agreed to in writing, Licensor provides the Work (and each
229+
Contributor provides its Contributions) on an "AS IS" BASIS,
230+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
231+
implied, including, without limitation, any warranties or conditions
232+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
233+
PARTICULAR PURPOSE. You are solely responsible for determining the
234+
appropriateness of using or redistributing the Work and assume any
235+
risks associated with Your exercise of permissions under this License.
236+
237+
8. Limitation of Liability. In no event and under no legal theory,
238+
whether in tort (including negligence), contract, or otherwise,
239+
unless required by applicable law (such as deliberate and grossly
240+
negligent acts) or agreed to in writing, shall any Contributor be
241+
liable to You for damages, including any direct, indirect, special,
242+
incidental, or consequential damages of any character arising as a
243+
result of this License or out of the use or inability to use the
244+
Work (including but not limited to damages for loss of goodwill,
245+
work stoppage, computer failure or malfunction, or any and all
246+
other commercial damages or losses), even if such Contributor
247+
has been advised of the possibility of such damages.
248+
249+
9. Accepting Warranty or Additional Liability. While redistributing
250+
the Work or Derivative Works thereof, You may choose to offer,
251+
and charge a fee for, acceptance of support, warranty, indemnity,
252+
or other liability obligations and/or rights consistent with this
253+
License. However, in accepting such obligations, You may act only
254+
on Your own behalf and on Your sole responsibility, not on behalf
255+
of any other Contributor, and only if You agree to indemnify,
256+
defend, and hold each Contributor harmless for any liability
257+
incurred by, or claims asserted against, such Contributor by reason
258+
of your accepting any such warranty or additional liability.
259+
260+
END OF TERMS AND CONDITIONS
261+
262+
APPENDIX: How to apply the Apache License to your work.
263+
264+
To apply the Apache License to your work, attach the following
265+
boilerplate notice, with the fields enclosed by brackets "[]"
266+
replaced with your own identifying information. (Don't include
267+
the brackets!) The text should be enclosed in the appropriate
268+
comment syntax for the file format. We also recommend that a
269+
file or class name and description of purpose be included on the
270+
same "printed page" as the copyright notice for easier
271+
identification within third-party archives.
272+
273+
Copyright [yyyy] [name of copyright owner]
274+
275+
Licensed under the Apache License, Version 2.0 (the "License");
276+
you may not use this file except in compliance with the License.
277+
You may obtain a copy of the License at
278+
279+
http://www.apache.org/licenses/LICENSE-2.0
280+
281+
Unless required by applicable law or agreed to in writing, software
282+
distributed under the License is distributed on an "AS IS" BASIS,
283+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
284+
See the License for the specific language governing permissions and
285+
limitations under the License.

README.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# pico-rv32ima
2+
RISC-V emulator for RP2040, capable of running Linux.\
3+
Based on [mini-rv32ima by CNLohr](https://github.com/cnlohr/mini-rv32ima).
4+
5+
## How it works
6+
This project uses [CNLohr's mini-rv32ima](https://github.com/cnlohr/mini-rv32ima) RISC-V emulator core to run Linux on a Raspberry Pi Pico. It uses two 8 megabyte SPI PSRAM chips as system memory. To alleviate the bottleneck introduced by the SPI interface of the PSRAM, a 4kb cache is used. The cache implementation comes from [xhackerustc's uc32-rvima project](https://github.com/xhackerustc/uc-rv32ima).
7+
8+
## Requirements
9+
- a Raspberry Pi Pico (or other RP2040 board)
10+
- an SD card
11+
- two 8 megabyte (64Mbit) SPI PSRAM chips (I used LY68L6400).
12+
- it is possible to use only one of these chips when running a reduced system image, by changing a setting in the config file.
13+
14+
_This project overvolts and overclocks the RP2040! Use at own risk!_
15+
16+
## How to use
17+
The configuration can be modified in the [rv32_config.h](pico-rv32ima/rv32_config.h) file. A schematic with the pin mappings described here is included in [this file](hardware/pico_linux.kicad_sch).
18+
19+
- By default, the SD card is connected via SPI, with the following pinout:
20+
- CLK: GPIO18
21+
- MISO: GPIO16
22+
- MOSI: GPIO19
23+
- CS: GPIO20
24+
- The SD card may also be connected over SDIO.
25+
26+
- The two RAM chips are connected with the following default pinout:
27+
- CLK: GPIO10
28+
- MISO: GPIO12
29+
- MOSI: GPIO11
30+
- CS1: GPIO21
31+
- CS2: GPIO22
32+
33+
- The RAM chips use hardware SPI by default. A flag in the config file allows them to use software bit-banged SPI (required for using the LCD console).
34+
35+
- The system console is accessible over USB-CDC, UART or an 128x160 ST7735 display paired with a PS2 keyboard. All three can be used at the same time, but keep in mind they point to the same virtual console. They can be enabled or disabled as desired in the config file. By default, only the USB console is enabled.
36+
- The use of the LCD console requires disabling the hardware SPI interface for the RAN in the config file.
37+
38+
The SD card needs to be formatted as FAT32 or exFAT. Block sizes from 1024 to 4096 bytes are confirmed to be working. A prebuilt Linux kernel and filesystem image is provided in [this file](linux/Image). It must be placed in the root of the SD card. If you want to build the image yourself, you need to run `make` in the [linux](linux) folder. This will clone the buildroot source tree, apply the necessary config files and build the kernel and system image.
39+
40+
## What it does
41+
On powerup, the Linux image will be copied into RAM. After a few seconds, Linux kernel messages will start streaming on the console. The boot process takes about one and a half minute. A video of the boot process can be seen [here](https://youtu.be/txgoWddk_2I). The Linux image includes a fork of the [c4 compiler/interpreter](https://github.com/rswier/c4). To run the included hello world example, type `c4 hello.c` in the shell after the system has booted. The source file of c4 can be found in `/usr/src/c4.c`. I have included it in the system image because this compiler is self-hosting and can run itself, which makes for a nice demo. You can use the vi editor to create or edit source files.
42+
43+
## Pictures
44+
- Serial (USB or UART) console:
45+
- ![Console boot log](pictures/screenshot.jpg)
46+
- LCD console:
47+
- ![LCD console](pictures/lcd.jpg)

linux/Image

2.68 MB
Binary file not shown.

linux/Makefile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
all : image
2+
3+
buildroot :
4+
git clone https://github.com/tvlad1234/buildroot --recurse-submodules --depth 1
5+
mkdir buildroot/output
6+
mkdir buildroot/output/target
7+
cp -a configs/custom_kernel_config buildroot/kernel_config
8+
cp -a configs/buildroot_config buildroot/.config
9+
cp -a configs/busybox_config buildroot/busybox_config
10+
cp -a configs/rootfsoverlay/* buildroot/output/target/
11+
12+
toolchain : buildroot
13+
make -C buildroot
14+
15+
image : toolchain
16+
make -C c4
17+

0 commit comments

Comments
 (0)