Skip to content

Commit

Permalink
Merge pull request #3 from pulp-platform/linux
Browse files Browse the repository at this point in the history
Add linux support
  • Loading branch information
zarubaf authored Nov 28, 2018
2 parents 59a47b5 + 90aedad commit 0164e14
Show file tree
Hide file tree
Showing 14 changed files with 1,508 additions and 15 deletions.
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
install
install
bbl*
vmlinux
build

riscv-gnu-toolchain/build
riscv-fesvr/build
riscv-isa-sim/build
riscv-pk/build
riscv-tests/build
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@
path = riscv-fesvr
url = https://github.com/riscv/riscv-fesvr.git
branch = master
[submodule "buildroot"]
path = buildroot
url = git://git.buildroot.net/buildroot
54 changes: 44 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ gnu-toolchain-libc-mk = linux -j$(NR_CORES)
pk-mk = -j$(NR_CORES)
tests-mk = -j$(NR_CORES)

#linux image
buildroot_defconfig = configs/buildroot_defconfig
linux_defconfig = configs/linux_defconfig
busybox_defconfig = configs/busybox.config


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

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

$(RISCV)/bin/riscv64-unknown-linux-gnu-gcc: gnu-toolchain
$(RISCV)/bin/riscv64-unknown-linux-gnu-gcc: gnu-toolchain-no-multilib
cd riscv-gnu-toolchain/build;\
make $(gnu-toolchain-libc-mk);\
cd $(ROOT)

gnu-toolchain-libc: $(RISCV)/bin/riscv64-unknown-linux-gnu-gcc


gnu-toolchain: install-dir
mkdir -p riscv-gnu-toolchain/build
Expand All @@ -54,7 +59,7 @@ gnu-toolchain-no-multilib: install-dir
cd riscv-gnu-toolchain/build;\
../configure $(gnu-toolchain-co-fast);\
cd $(ROOT)

fesvr: install-dir $(RISCV)/bin/riscv64-unknown-elf-gcc
mkdir -p riscv-fesvr/build
cd riscv-fesvr/build;\
Expand Down Expand Up @@ -90,22 +95,51 @@ pk: install-dir $(RISCV)/bin/riscv64-unknown-elf-gcc

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

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

vmlinux: $(buildroot_defconfig) $(linux_defconfig) $(busybox_defconfig) $(RISCV)/bin/riscv64-unknown-elf-gcc $(RISCV)/bin/riscv64-unknown-linux-gnu-gcc
mkdir -p build
make -C buildroot clean
make -C buildroot defconfig BR2_DEFCONFIG=../configs/buildroot_defconfig
make -C buildroot
cp buildroot/output/images/vmlinux build/vmlinux
cp build/vmlinux vmlinux

bbl: vmlinux
cd build && ../riscv-pk/configure --host=riscv64-unknown-elf --with-payload=vmlinux --enable-logo --with-logo=../configs/logo.txt
make -C build
cp build/bbl bbl

bbl_binary: bbl
riscv64-unknown-elf-objcopy -O binary bbl bbl_binary

clean:
rm -rf vmlinux bbl riscv-pk/build/vmlinux riscv-pk/build/bbl
make -C buildroot distclean

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

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

help:
@echo "usage: $(MAKE) [RISCV='<install/here>'] [<tool>] [<tool>='--<flag> ...'] ..."
@echo "usage: $(MAKE) [RISCV='<install/here>'] [tool/img] ..."
@echo ""
@echo "install [tool] to \$$RISCV with compiler <flag>'s"
@echo " where tool can be any one of:"
@echo " fesvr isa-sim gnu-toolchain tests pk"
@echo ""
@echo "where tool can be any one of:"
@echo "build linux images for ariane"
@echo " build vmlinux with"
@echo " make vmlinux"
@echo " build bbl (with vmlinux) with"
@echo " make bbl"
@echo ""
@echo " fesvr isa-sim gnu-toolchain tests pk"
@echo "There are two clean targets:"
@echo " Clean only buildroot"
@echo " make clean"
@echo " Clean everything (including toolchain etc)"
@echo " make clean-all"
@echo ""
@echo "defaults:"
@echo " RISCV='$(DEST)'"
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,36 @@ Add `$RISCV/bin` to your path in order to later make use of the installed tools

Example for `.bashrc` or `.zshrc`:
```bash
export RISCV=/opt/riscv
export PATH=$PATH:$RISCV/bin
$ export RISCV=/opt/riscv
$ export PATH=$PATH:$RISCV/bin
```

## Linux
You can also build a compatible linux image with bbl that boots linux on the ariane fpga mapping:
```bash
$ make vmlinux # make only the vmlinux image
# outputs a vmlinux file in the top directory
$ make bbl.bin # generate the entire bootable image
# outputs bbl and bbl.bin
```

### Booting from an SD card
The bootloader of ariane requires a GPT partition table so you first have to create one with gdisk.

```bash
$ sudo fdisk -l # search for the corresponding disk label (e.g. /dev/sdb)
$ 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)
```

Now you have to compile the linux kernel:
```bash
$ make bbl.bin # generate the entire bootable image
```

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`.
```bash
$ sudo dd if=bbl.bin of=/dev/sdb1 status=progress oflag=sync bs=1M
```

## OpenOCD - Optional
If you really need and want to debug on an FPGA/ASIC target the installation instructions are [here](https://github.com/riscv/riscv-openocd).
If you really need and want to debug on an FPGA/ASIC target the installation instructions are [here](https://github.com/riscv/riscv-openocd).
1 change: 1 addition & 0 deletions buildroot
Submodule buildroot added at d6fa6a
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
From c07d9ee579c8a2240ba3d403c6827afb1f5608ea Mon Sep 17 00:00:00 2001
From: Florian Zaruba <[email protected]>
Date: Tue, 20 Nov 2018 16:17:44 +0100
Subject: [PATCH] Add RISC-V architecture to Xilinx ethernet Kconfig

---
drivers/net/ethernet/xilinx/Kconfig | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/xilinx/Kconfig b/drivers/net/ethernet/xilinx/Kconfig
index da4ec575ccf9..0699b54ee759 100644
--- a/drivers/net/ethernet/xilinx/Kconfig
+++ b/drivers/net/ethernet/xilinx/Kconfig
@@ -5,7 +5,7 @@
config NET_VENDOR_XILINX
bool "Xilinx devices"
default y
- depends on PPC || PPC32 || MICROBLAZE || ARCH_ZYNQ || MIPS
+ depends on PPC || PPC32 || MICROBLAZE || ARCH_ZYNQ || MIPS || RISCV
---help---
If you have a network (Ethernet) card belonging to this class, say Y.

@@ -18,7 +18,7 @@ if NET_VENDOR_XILINX

config XILINX_EMACLITE
tristate "Xilinx 10/100 Ethernet Lite support"
- depends on PPC32 || MICROBLAZE || ARCH_ZYNQ || MIPS
+ depends on PPC32 || MICROBLAZE || ARCH_ZYNQ || MIPS || RISCV
select PHYLIB
---help---
This driver supports the 10/100 Ethernet Lite from Xilinx.
--
2.14.3

43 changes: 43 additions & 0 deletions configs/0002-emaclite-Align-buffer-and-iomem-on-64-bits.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
From 50dbaec9e56e5063036724e673529fc53f85a25e Mon Sep 17 00:00:00 2001
From: Florian Zaruba <[email protected]>
Date: Sun, 25 Nov 2018 00:19:03 +0100
Subject: [PATCH] [emaclite] Align buffer and iomem on 64 bits

---
drivers/net/ethernet/xilinx/xilinx_emaclite.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/xilinx/xilinx_emaclite.c b/drivers/net/ethernet/xilinx/xilinx_emaclite.c
index 639e3e9..5f9441c 100644
--- a/drivers/net/ethernet/xilinx/xilinx_emaclite.c
+++ b/drivers/net/ethernet/xilinx/xilinx_emaclite.c
@@ -99,7 +99,7 @@
#define ALIGNMENT 4

/* BUFFER_ALIGN(adr) calculates the number of bytes to the next alignment. */
-#define BUFFER_ALIGN(adr) ((ALIGNMENT - ((u32)adr)) % ALIGNMENT)
+#define BUFFER_ALIGN(adr) ((ALIGNMENT - ((u64)adr)) % ALIGNMENT)

#ifdef __BIG_ENDIAN
#define xemaclite_readl ioread32be
@@ -340,7 +340,7 @@ static int xemaclite_send_data(struct net_local *drvdata, u8 *data,
* if it is configured in HW
*/

- addr = (void __iomem __force *)((u32 __force)addr ^
+ addr = (void __iomem __force *)((u64 __force)addr ^
XEL_BUFFER_OFFSET);
reg_data = xemaclite_readl(addr + XEL_TSR_OFFSET);

@@ -401,7 +401,7 @@ static u16 xemaclite_recv_data(struct net_local *drvdata, u8 *data, int maxlen)
* will correct on subsequent calls
*/
if (drvdata->rx_ping_pong != 0)
- addr = (void __iomem __force *)((u32 __force)addr ^
+ addr = (void __iomem __force *)((u64 __force)addr ^
XEL_BUFFER_OFFSET);
else
return 0; /* No data was available */
--
2.4.8

33 changes: 33 additions & 0 deletions configs/buildroot_defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
BR2_riscv=y
BR2_riscv_custom=y
BR2_RISCV_ISA_CUSTOM_RVM=y
BR2_RISCV_ISA_CUSTOM_RVC=y
BR2_CCACHE=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TOOLCHAIN_EXTERNAL_PATH="$(RISCV)"
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX="$(ARCH)-unknown-linux-gnu"
BR2_TOOLCHAIN_EXTERNAL_GCC_8=y
BR2_TOOLCHAIN_EXTERNAL_HEADERS_4_13=y
BR2_TOOLCHAIN_EXTERNAL_CUSTOM_GLIBC=y
BR2_TOOLCHAIN_EXTERNAL_CXX=y
BR2_ROOTFS_OVERLAY="../rootfs"
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_VERSION=y
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.20-rc2"
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"
BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="../configs/linux_defconfig"
BR2_PACKAGE_BUSYBOX_CONFIG="../configs/busybox.config"
BR2_PACKAGE_DHRYSTONE=y
BR2_PACKAGE_MEMSTAT=y
BR2_PACKAGE_RAMSPEED=y
BR2_PACKAGE_STRACE=y
BR2_PACKAGE_STRESS=y
BR2_PACKAGE_STRESS_NG=y
BR2_PACKAGE_TRACE_CMD=y
# BR2_PACKAGE_IFUPDOWN_SCRIPTS is not set
BR2_PACKAGE_HTOP=y
BR2_PACKAGE_NANO=y
BR2_TARGET_ROOTFS_CPIO_GZIP=y
BR2_TARGET_ROOTFS_INITRAMFS=y
# BR2_TARGET_ROOTFS_TAR is not set
Loading

0 comments on commit 0164e14

Please sign in to comment.