From 654703138c2ed00fe994608a02db73d0164b009e Mon Sep 17 00:00:00 2001
From: maskedarray <rao.arrn@gmail.com>
Date: Tue, 15 Aug 2023 13:10:56 -0400
Subject: [PATCH] linux dtb files used when compiling opensbi

---
 .gitignore                   |   2 +-
 linux/lloader/Makefile       |  30 +++++++++++++
 linux/lloader/ariane.dtb     |   0
 linux/lloader/loader_rv64.ld |  20 +++++++++
 linux/lloader/rv64.S         |  22 +++++++++
 linux/occamy.dtb             | Bin 0 -> 1845 bytes
 linux/occamy.dts             |  84 +++++++++++++++++++++++++++++++++++
 linux/occamy_bao.dtb         | Bin 0 -> 1593 bytes
 linux/occamy_bao.dts         |  73 ++++++++++++++++++++++++++++++
 9 files changed, 230 insertions(+), 1 deletion(-)
 create mode 100755 linux/lloader/Makefile
 create mode 100755 linux/lloader/ariane.dtb
 create mode 100755 linux/lloader/loader_rv64.ld
 create mode 100755 linux/lloader/rv64.S
 create mode 100755 linux/occamy.dtb
 create mode 100755 linux/occamy.dts
 create mode 100755 linux/occamy_bao.dtb
 create mode 100755 linux/occamy_bao.dts

diff --git a/.gitignore b/.gitignore
index fc09d23..38d73bd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,7 +6,7 @@ bao-hypervisor/.vscode/
 opensbi/build/
 opensbi/.git/
 bitstream/
-linux/
+
 linux_image/
 .vscode/
 *.bin
diff --git a/linux/lloader/Makefile b/linux/lloader/Makefile
new file mode 100755
index 0000000..e2f427c
--- /dev/null
+++ b/linux/lloader/Makefile
@@ -0,0 +1,30 @@
+
+ifeq ($(and $(IMAGE), $(DTB), $(TARGET), $(ARCH)),)
+ifneq ($(MAKECMDGOALS), clean)
+ $(error Linux image (IMAGE) and/or device tree (DTB) and/or target name \
+ 	(TARGET) and/or architecture (ARCH) not specified)
+endif
+endif
+
+ARCH ?=rv64
+
+ifeq ($(ARCH), rv64)
+CROSS_COMPILE ?=riscv64-unknown-elf-
+OPTIONS=-ffreestanding -nostartfiles -static -march=rv64imafdc -mcmodel=medany -mabi=lp64 -g3 -O3
+else
+$(error unkown architecture $(ARCH))
+endif
+
+all: $(TARGET).bin
+
+clean:
+	-rm *.elf *.bin
+
+.PHONY: all clean
+	
+$(TARGET).bin: $(TARGET).elf
+	$(CROSS_COMPILE)objcopy -S -O binary $(TARGET).elf $(TARGET).bin
+
+$(TARGET).elf: $(ARCH).S $(IMAGE) $(DTB) loader_$(ARCH).ld
+	$(CROSS_COMPILE)gcc -Wl,-build-id=none -nostdlib -T loader_$(ARCH).ld\
+		-o $(TARGET).elf $(OPTIONS) $(ARCH).S -I. -D IMAGE=$(IMAGE) -D DTB=$(DTB)
diff --git a/linux/lloader/ariane.dtb b/linux/lloader/ariane.dtb
new file mode 100755
index 0000000..e69de29
diff --git a/linux/lloader/loader_rv64.ld b/linux/lloader/loader_rv64.ld
new file mode 100755
index 0000000..4f26dd9
--- /dev/null
+++ b/linux/lloader/loader_rv64.ld
@@ -0,0 +1,20 @@
+ENTRY(_start)
+
+SECTIONS
+{   
+    .nloader : {
+        KEEP(*(.nloader))
+    }
+ 
+    .linux : ALIGN(0x200000) { 
+        __linux_start = .;
+        KEEP(*(.linux)) 
+        __linux_end = .;
+    }  
+    
+    .dtb : ALIGN(0x200000) { 
+        __dtb_start = ABSOLUTE(.);
+        KEEP(*(.dtb)) 
+        __dtb_end = .;
+    }  
+}
diff --git a/linux/lloader/rv64.S b/linux/lloader/rv64.S
new file mode 100755
index 0000000..69fec40
--- /dev/null
+++ b/linux/lloader/rv64.S
@@ -0,0 +1,22 @@
+#define STRINGIFY2(X) #X
+#define STRINGIFY(X) STRINGIFY2(X)
+
+.section .nloader, "a"
+.global _start
+_start:
+
+    /* boot protocol */
+    /* We are expecting hartid in a0 */
+    la a1, __dtb_start
+    
+    /* jump to linux */
+    la t0, __linux_start
+    jalr t0
+    j  .
+
+.section .linux, "a"
+    .incbin STRINGIFY(IMAGE)
+
+.section .dtb, "a"
+    .incbin STRINGIFY(DTB)
+ 
diff --git a/linux/occamy.dtb b/linux/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1y-9sfMzq-dI<3<-R_EFDJMi~Z3X6abCn-J8^}WLp82mF=;1V(a5ded2Xn
z>57=jRyMH4^BQ?l_SSUP_)Sv5Z!Oedt!_Pz*NEC?LXlMO6v%^&Ze@;q;7nKkXeu<~
E9ioXPQvd(}

literal 0
HcmV?d00001

diff --git a/linux/occamy.dts b/linux/occamy.dts
new file mode 100755
index 0000000..3d1df7b
--- /dev/null
+++ b/linux/occamy.dts
@@ -0,0 +1,84 @@
+// Copyright 2021 ETH Zurich and University of Bologna.
+// Licensed under the Apache License, Version 2.0, see LICENSE for details.
+// SPDX-License-Identifier: Apache-2.0
+
+// TODO(niwis) auto generate
+/dts-v1/;
+/ {
+  #address-cells = <2>;
+  #size-cells = <2>;
+  compatible = "eth,occamy-dev";
+  model = "eth,occamy";
+  chosen {
+    stdout-path = "/soc/uart@40000000:115200";
+  };
+  memory@80200000 {
+    device_type = "memory";
+    reg = <0x0 0x80200000 0x0 0x1EE00000>;
+  };
+  cpus {
+    #address-cells = <1>;
+    #size-cells = <0>;
+    timebase-frequency = <25000000>;
+    CPU0: cpu@0 {
+      device_type = "cpu";
+      status = "okay";
+      compatible = "eth,ariane", "riscv";
+      clock-frequency = <50000000>;
+      riscv,isa = "rv64fimadch";
+      mmu-type = "riscv,sv39";
+      tlb-split;
+      reg = <0>;
+      CPU0_intc: interrupt-controller {
+        #interrupt-cells = <1>;
+        interrupt-controller;
+        compatible = "riscv,cpu-intc";
+      };
+    };
+  };
+  soc: soc {
+    #address-cells = <2>;
+    #size-cells = <2>;
+    compatible = "eth,ariane-bare-soc", "simple-bus";
+    ranges;
+    clint@2000000 {
+      compatible = "riscv,clint0";
+      interrupts-extended = <&CPU0_intc 3 &CPU0_intc 7>;
+      reg = <0x0 0x2000000 0x0 0xc0000>;
+      reg-names = "control";
+    };
+    PLIC0: interrupt-controller@c000000 {
+      #address-cells = <0>;
+      #interrupt-cells = <1>;
+      compatible = "sifive,plic-1.0.0","riscv,plic0";
+      interrupt-controller;
+      interrupts-extended = <&CPU0_intc 11 &CPU0_intc 9>;
+      reg = <0x0 0xc000000 0x0 0x4000000>;
+      riscv,max-priority = <7>;
+      riscv,ndev = <10>;
+    };
+    debug-controller@0 {
+      compatible = "riscv,debug-013";
+      interrupts-extended = <&CPU0_intc 65535>;
+      reg = <0x0 0x0 0x0 0x1000>;
+      reg-names = "control";
+    };
+    uart@40000000 {
+      compatible = "ns16550";
+      reg = <0x0 0x40000000 0x0 0x1000>;
+      clock-frequency = <50000000>;
+      current-speed = <115200>;
+      interrupt-parent = <&PLIC0>;
+      interrupts = <2>;
+      reg-shift = <2>; // regs are spaced on 32 bit boundary
+      reg-io-width = <4>; // only 32-bit access are supported
+    };
+    timer@18000000 {
+      compatible = "pulp,apb_timer";
+      interrupts = <0x00000004 0x00000005 0x00000006 0x00000007>;
+      reg = <0x00000000 0x18000000 0x00000000 0x00001000>;
+      interrupt-parent = <&PLIC0>;
+      reg-names = "control";
+    };
+  };
+};
\ No newline at end of file
diff --git a/linux/occamy_bao.dtb b/linux/occamy_bao.dtb
new file mode 100755
index 0000000000000000000000000000000000000000..cc055d9e5de2f45dd2906cb8bccac6d720e97a2b
GIT binary patch
literal 1593
zcmZuxOKTKC5blZb5g(`rK@4ahAR^nzt|oEyG=c~JgNM-5)0=HFFS~oztSIE-*}veQ
z@F<A*13Y^4E`lc!58_un)3dX|g4(Y7x@zj#`{mN#AB>%O$QT<lw)z|A9q?7~6)-4z
z4E&=Pmw%#GJ%w|%l~-^E{W9dBlf16nbWlnu@;Oh{%zKdS1@P^~oyQ|NEv+g#n;Vb@
z+qRV3wJ<K;88-B2G}^s49C|Y!E6P<~nt41P0tV3y#W)KdH+KYijOu$r%JByMqTp}-
zpqwLF)z)i^dPt?3`}GkP^rzA5qZm5*#%)gFZVW8go`&$OJQQ;RKx9Mx_Wcn?i$XD@
zt!z59_<pkT=jU;2e-WoKv%Q^(&P6JxQ2lqPm#@6@z|QW|R2!VmH?2&w@^#~kbm5dS
zb>+A$3unqKQwBIu$o(zkP&eW4z;x$l+QdS29AA<^7k=*{lOOdnaD)*;?Y>QN*b&OB
zzcaU>_j<w;VH78StMe*TJZUFHxe$E-|F@o4HrwK@mSYn{{uH}k=S}GAR!{Uy4XR8_
zKH3^?4V$repf_Kbc0Hk;`V6MJX%=*@fhk6}Z!|n23JMDGze1)x4f=P;=X*N!v+Lv1
zGr$Fi{LX>b3p?7|-SrtR#f@><5T(+^>F*V#^ovEGdiN1wy%|N<PUssa^t;f5Pvms2
zOgtL*CO|p)-KpxV8i*>{_eMaQoRFN4LEoUaat0jw()I8<z=ry@Eai$`L=W1nCezS6
zI@dNuni^#-mnzFF+qC+nYGqmGm2f)A6wAw0Wz4#?tQ`k9W%%RLQti8Wg-5Cm7^R*F
ztN6sI=d~*29OlAdHDy-H!yeqc6m12|^P2k)xGdoo>*d&H?;ZMtdivsBR#Q==NXv-g
zKv~w=SgwwoDpHlU8=8wFUKw2)?dC0n+ZmI!F{*F~s$kpsqcnmSfTh~Fo$876k}mlR
MouYh#3y~xEKUAy)VgLXD

literal 0
HcmV?d00001

diff --git a/linux/occamy_bao.dts b/linux/occamy_bao.dts
new file mode 100755
index 0000000..3fae785
--- /dev/null
+++ b/linux/occamy_bao.dts
@@ -0,0 +1,73 @@
+// Copyright 2021 ETH Zurich and University of Bologna.
+// Licensed under the Apache License, Version 2.0, see LICENSE for details.
+// SPDX-License-Identifier: Apache-2.0
+
+// TODO(niwis) auto generate
+/dts-v1/;
+/ {
+  #address-cells = <2>;
+  #size-cells = <2>;
+  compatible = "eth,occamy-dev";
+  model = "eth,occamy";
+  chosen {
+     stdout-path = "/soc/uart@40000000:115200";
+  };
+
+  memory@80200000 {
+    device_type = "memory";
+    reg = <0x0 0x80200000 0x0 0x10E00000>;
+  };
+  cpus {
+    #address-cells = <1>;
+    #size-cells = <0>;
+    timebase-frequency = <25000000>;
+    CPU0: cpu@0 {
+      device_type = "cpu";
+      status = "okay";
+      compatible = "eth,ariane", "riscv";
+      clock-frequency = <50000000>;
+      riscv,isa = "rv64fimadch";
+      mmu-type = "riscv,sv39";
+      tlb-split;
+      reg = <0>;
+      CPU0_intc: interrupt-controller {
+        #interrupt-cells = <1>;
+        interrupt-controller;
+        compatible = "riscv,cpu-intc";
+      };
+    };
+  };
+  soc: soc {
+    #address-cells = <2>;
+    #size-cells = <2>;
+    compatible = "eth,ariane-bare-soc", "simple-bus";
+    ranges;
+    PLIC0: interrupt-controller@c000000 {
+      #address-cells = <0>;
+      #interrupt-cells = <1>;
+      compatible = "sifive,plic-1.0.0","riscv,plic0";
+      interrupt-controller;
+      interrupts-extended = <&CPU0_intc 11 &CPU0_intc 9>;
+      reg = <0x0 0xc000000 0x0 0x4000000>;
+      riscv,max-priority = <7>;
+      riscv,ndev = <10>;
+    };
+    uart@40000000 {
+      compatible = "ns16550";
+      reg = <0x0 0x40000000 0x0 0x1000>;
+      clock-frequency = <50000000>;
+      current-speed = <115200>;
+      interrupt-parent = <&PLIC0>;
+      interrupts = <2>;
+      reg-shift = <2>; // regs are spaced on 32 bit boundary
+      reg-io-width = <4>; // only 32-bit access are supported
+    };
+    timer@18000000 {
+      compatible = "pulp,apb_timer";
+      interrupts = <0x00000004 0x00000005 0x00000006 0x00000007>;
+      reg = <0x00000000 0x18000000 0x00000000 0x00001000>;
+      interrupt-parent = <&PLIC0>;
+      reg-names = "control";
+    };
+  };
+};
\ No newline at end of file