Skip to content

Commit 0164e14

Browse files
authored
Merge pull request #3 from pulp-platform/linux
Add linux support
2 parents 59a47b5 + 90aedad commit 0164e14

14 files changed

+1508
-15
lines changed

.gitignore

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
install
1+
install
2+
bbl*
3+
vmlinux
4+
build
5+
6+
riscv-gnu-toolchain/build
7+
riscv-fesvr/build
8+
riscv-isa-sim/build
9+
riscv-pk/build
10+
riscv-tests/build

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818
path = riscv-fesvr
1919
url = https://github.com/riscv/riscv-fesvr.git
2020
branch = master
21+
[submodule "buildroot"]
22+
path = buildroot
23+
url = git://git.buildroot.net/buildroot

Makefile

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ gnu-toolchain-libc-mk = linux -j$(NR_CORES)
2323
pk-mk = -j$(NR_CORES)
2424
tests-mk = -j$(NR_CORES)
2525

26+
#linux image
27+
buildroot_defconfig = configs/buildroot_defconfig
28+
linux_defconfig = configs/linux_defconfig
29+
busybox_defconfig = configs/busybox.config
30+
2631

2732
install-dir:
2833
mkdir -p $(RISCV)
@@ -35,13 +40,13 @@ $(RISCV)/bin/riscv64-unknown-elf-gcc: gnu-toolchain-no-multilib
3540

3641
gnu-toolchain-newlib: $(RISCV)/bin/riscv64-unknown-elf-gcc
3742

38-
$(RISCV)/bin/riscv64-unknown-linux-gnu-gcc: gnu-toolchain
43+
$(RISCV)/bin/riscv64-unknown-linux-gnu-gcc: gnu-toolchain-no-multilib
3944
cd riscv-gnu-toolchain/build;\
4045
make $(gnu-toolchain-libc-mk);\
4146
cd $(ROOT)
4247

4348
gnu-toolchain-libc: $(RISCV)/bin/riscv64-unknown-linux-gnu-gcc
44-
49+
4550

4651
gnu-toolchain: install-dir
4752
mkdir -p riscv-gnu-toolchain/build
@@ -54,7 +59,7 @@ gnu-toolchain-no-multilib: install-dir
5459
cd riscv-gnu-toolchain/build;\
5560
../configure $(gnu-toolchain-co-fast);\
5661
cd $(ROOT)
57-
62+
5863
fesvr: install-dir $(RISCV)/bin/riscv64-unknown-elf-gcc
5964
mkdir -p riscv-fesvr/build
6065
cd riscv-fesvr/build;\
@@ -90,22 +95,51 @@ pk: install-dir $(RISCV)/bin/riscv64-unknown-elf-gcc
9095

9196
all: gnu-toolchain-newlib gnu-toolchain-libc fesvr isa-sim tests pk
9297

93-
linux: gnu-toolchain-newlib $(RISCV)/bin/riscv64-unknown-elf-gcc fesvr
94-
RISCV=$(RISCV) make -C ariane-linux bbl
9598

99+
vmlinux: $(buildroot_defconfig) $(linux_defconfig) $(busybox_defconfig) $(RISCV)/bin/riscv64-unknown-elf-gcc $(RISCV)/bin/riscv64-unknown-linux-gnu-gcc
100+
mkdir -p build
101+
make -C buildroot clean
102+
make -C buildroot defconfig BR2_DEFCONFIG=../configs/buildroot_defconfig
103+
make -C buildroot
104+
cp buildroot/output/images/vmlinux build/vmlinux
105+
cp build/vmlinux vmlinux
106+
107+
bbl: vmlinux
108+
cd build && ../riscv-pk/configure --host=riscv64-unknown-elf --with-payload=vmlinux --enable-logo --with-logo=../configs/logo.txt
109+
make -C build
110+
cp build/bbl bbl
111+
112+
bbl_binary: bbl
113+
riscv64-unknown-elf-objcopy -O binary bbl bbl_binary
114+
115+
clean:
116+
rm -rf vmlinux bbl riscv-pk/build/vmlinux riscv-pk/build/bbl
117+
make -C buildroot distclean
96118

97-
clean:
98-
rm -rf install riscv-fesvr/build riscv-isa-sim/build riscv-gnu-toolchain/build riscv-tests/build riscv-pk/build
119+
bbl.bin: bbl
120+
riscv64-unknown-elf-objcopy -S -O binary --change-addresses -0x80000000 $< $@
99121

122+
clean-all: clean
123+
rm -rf riscv-fesvr/build riscv-isa-sim/build riscv-gnu-toolchain/build riscv-tests/build riscv-pk/build
100124

101125
help:
102-
@echo "usage: $(MAKE) [RISCV='<install/here>'] [<tool>] [<tool>='--<flag> ...'] ..."
126+
@echo "usage: $(MAKE) [RISCV='<install/here>'] [tool/img] ..."
103127
@echo ""
104128
@echo "install [tool] to \$$RISCV with compiler <flag>'s"
129+
@echo " where tool can be any one of:"
130+
@echo " fesvr isa-sim gnu-toolchain tests pk"
105131
@echo ""
106-
@echo "where tool can be any one of:"
132+
@echo "build linux images for ariane"
133+
@echo " build vmlinux with"
134+
@echo " make vmlinux"
135+
@echo " build bbl (with vmlinux) with"
136+
@echo " make bbl"
107137
@echo ""
108-
@echo " fesvr isa-sim gnu-toolchain tests pk"
138+
@echo "There are two clean targets:"
139+
@echo " Clean only buildroot"
140+
@echo " make clean"
141+
@echo " Clean everything (including toolchain etc)"
142+
@echo " make clean-all"
109143
@echo ""
110144
@echo "defaults:"
111145
@echo " RISCV='$(DEST)'"

README.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,36 @@ Add `$RISCV/bin` to your path in order to later make use of the installed tools
3535

3636
Example for `.bashrc` or `.zshrc`:
3737
```bash
38-
export RISCV=/opt/riscv
39-
export PATH=$PATH:$RISCV/bin
38+
$ export RISCV=/opt/riscv
39+
$ export PATH=$PATH:$RISCV/bin
40+
```
41+
42+
## Linux
43+
You can also build a compatible linux image with bbl that boots linux on the ariane fpga mapping:
44+
```bash
45+
$ make vmlinux # make only the vmlinux image
46+
# outputs a vmlinux file in the top directory
47+
$ make bbl.bin # generate the entire bootable image
48+
# outputs bbl and bbl.bin
49+
```
50+
51+
### Booting from an SD card
52+
The bootloader of ariane requires a GPT partition table so you first have to create one with gdisk.
53+
54+
```bash
55+
$ sudo fdisk -l # search for the corresponding disk label (e.g. /dev/sdb)
56+
$ sudo sgdisk --clear --new=1:2048:67583 --new=2 --typecode=1:3000 --typecode=2:8300 /dev/sdb # create a new gpt partition table and two partitions: 1st partition: 32mb (ONIE boot), second partition: rest (Linux root)
57+
```
58+
59+
Now you have to compile the linux kernel:
60+
```bash
61+
$ make bbl.bin # generate the entire bootable image
62+
```
63+
64+
Then the bbl+linux kernel image can get copied to the sd card with `dd`. __Careful:__ use the same disk label that you found before with `fdisk -l` but with a 1 in the end, e.g. `/dev/sdb` -> `/dev/sdb1`.
65+
```bash
66+
$ sudo dd if=bbl.bin of=/dev/sdb1 status=progress oflag=sync bs=1M
4067
```
4168

4269
## OpenOCD - Optional
43-
If you really need and want to debug on an FPGA/ASIC target the installation instructions are [here](https://github.com/riscv/riscv-openocd).
70+
If you really need and want to debug on an FPGA/ASIC target the installation instructions are [here](https://github.com/riscv/riscv-openocd).

buildroot

Submodule buildroot added at d6fa6a4
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
From c07d9ee579c8a2240ba3d403c6827afb1f5608ea Mon Sep 17 00:00:00 2001
2+
From: Florian Zaruba <[email protected]>
3+
Date: Tue, 20 Nov 2018 16:17:44 +0100
4+
Subject: [PATCH] Add RISC-V architecture to Xilinx ethernet Kconfig
5+
6+
---
7+
drivers/net/ethernet/xilinx/Kconfig | 4 ++--
8+
1 file changed, 2 insertions(+), 2 deletions(-)
9+
10+
diff --git a/drivers/net/ethernet/xilinx/Kconfig b/drivers/net/ethernet/xilinx/Kconfig
11+
index da4ec575ccf9..0699b54ee759 100644
12+
--- a/drivers/net/ethernet/xilinx/Kconfig
13+
+++ b/drivers/net/ethernet/xilinx/Kconfig
14+
@@ -5,7 +5,7 @@
15+
config NET_VENDOR_XILINX
16+
bool "Xilinx devices"
17+
default y
18+
- depends on PPC || PPC32 || MICROBLAZE || ARCH_ZYNQ || MIPS
19+
+ depends on PPC || PPC32 || MICROBLAZE || ARCH_ZYNQ || MIPS || RISCV
20+
---help---
21+
If you have a network (Ethernet) card belonging to this class, say Y.
22+
23+
@@ -18,7 +18,7 @@ if NET_VENDOR_XILINX
24+
25+
config XILINX_EMACLITE
26+
tristate "Xilinx 10/100 Ethernet Lite support"
27+
- depends on PPC32 || MICROBLAZE || ARCH_ZYNQ || MIPS
28+
+ depends on PPC32 || MICROBLAZE || ARCH_ZYNQ || MIPS || RISCV
29+
select PHYLIB
30+
---help---
31+
This driver supports the 10/100 Ethernet Lite from Xilinx.
32+
--
33+
2.14.3
34+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
From 50dbaec9e56e5063036724e673529fc53f85a25e Mon Sep 17 00:00:00 2001
2+
From: Florian Zaruba <[email protected]>
3+
Date: Sun, 25 Nov 2018 00:19:03 +0100
4+
Subject: [PATCH] [emaclite] Align buffer and iomem on 64 bits
5+
6+
---
7+
drivers/net/ethernet/xilinx/xilinx_emaclite.c | 6 +++---
8+
1 file changed, 3 insertions(+), 3 deletions(-)
9+
10+
diff --git a/drivers/net/ethernet/xilinx/xilinx_emaclite.c b/drivers/net/ethernet/xilinx/xilinx_emaclite.c
11+
index 639e3e9..5f9441c 100644
12+
--- a/drivers/net/ethernet/xilinx/xilinx_emaclite.c
13+
+++ b/drivers/net/ethernet/xilinx/xilinx_emaclite.c
14+
@@ -99,7 +99,7 @@
15+
#define ALIGNMENT 4
16+
17+
/* BUFFER_ALIGN(adr) calculates the number of bytes to the next alignment. */
18+
-#define BUFFER_ALIGN(adr) ((ALIGNMENT - ((u32)adr)) % ALIGNMENT)
19+
+#define BUFFER_ALIGN(adr) ((ALIGNMENT - ((u64)adr)) % ALIGNMENT)
20+
21+
#ifdef __BIG_ENDIAN
22+
#define xemaclite_readl ioread32be
23+
@@ -340,7 +340,7 @@ static int xemaclite_send_data(struct net_local *drvdata, u8 *data,
24+
* if it is configured in HW
25+
*/
26+
27+
- addr = (void __iomem __force *)((u32 __force)addr ^
28+
+ addr = (void __iomem __force *)((u64 __force)addr ^
29+
XEL_BUFFER_OFFSET);
30+
reg_data = xemaclite_readl(addr + XEL_TSR_OFFSET);
31+
32+
@@ -401,7 +401,7 @@ static u16 xemaclite_recv_data(struct net_local *drvdata, u8 *data, int maxlen)
33+
* will correct on subsequent calls
34+
*/
35+
if (drvdata->rx_ping_pong != 0)
36+
- addr = (void __iomem __force *)((u32 __force)addr ^
37+
+ addr = (void __iomem __force *)((u64 __force)addr ^
38+
XEL_BUFFER_OFFSET);
39+
else
40+
return 0; /* No data was available */
41+
--
42+
2.4.8
43+

configs/buildroot_defconfig

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
BR2_riscv=y
2+
BR2_riscv_custom=y
3+
BR2_RISCV_ISA_CUSTOM_RVM=y
4+
BR2_RISCV_ISA_CUSTOM_RVC=y
5+
BR2_CCACHE=y
6+
BR2_TOOLCHAIN_EXTERNAL=y
7+
BR2_TOOLCHAIN_EXTERNAL_PATH="$(RISCV)"
8+
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX="$(ARCH)-unknown-linux-gnu"
9+
BR2_TOOLCHAIN_EXTERNAL_GCC_8=y
10+
BR2_TOOLCHAIN_EXTERNAL_HEADERS_4_13=y
11+
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_GLIBC=y
12+
BR2_TOOLCHAIN_EXTERNAL_CXX=y
13+
BR2_ROOTFS_OVERLAY="../rootfs"
14+
BR2_LINUX_KERNEL=y
15+
BR2_LINUX_KERNEL_CUSTOM_VERSION=y
16+
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.20-rc2"
17+
BR2_LINUX_KERNEL_PATCH="../configs/0001-Add-RISC-V-architecture-to-Xilinx-ethernet-Kconfig.patch ../configs/0002-emaclite-Align-buffer-and-iomem-on-64-bits.patch"
18+
BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
19+
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="../configs/linux_defconfig"
20+
BR2_PACKAGE_BUSYBOX_CONFIG="../configs/busybox.config"
21+
BR2_PACKAGE_DHRYSTONE=y
22+
BR2_PACKAGE_MEMSTAT=y
23+
BR2_PACKAGE_RAMSPEED=y
24+
BR2_PACKAGE_STRACE=y
25+
BR2_PACKAGE_STRESS=y
26+
BR2_PACKAGE_STRESS_NG=y
27+
BR2_PACKAGE_TRACE_CMD=y
28+
# BR2_PACKAGE_IFUPDOWN_SCRIPTS is not set
29+
BR2_PACKAGE_HTOP=y
30+
BR2_PACKAGE_NANO=y
31+
BR2_TARGET_ROOTFS_CPIO_GZIP=y
32+
BR2_TARGET_ROOTFS_INITRAMFS=y
33+
# BR2_TARGET_ROOTFS_TAR is not set

0 commit comments

Comments
 (0)