<p>Jonathan Neuschäfer has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/25789">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">src/sifive: Add the SiFive Freedom Unleashed 540 SoC<br><br>The FU540 is the first RISC-V SoC with the necessary resources to run<br>Linux (an external memory interface, MMU, etc).<br><br>More information is available on SiFive's website:<br>https://www.sifive.com/products/hifive-unleashed/<br><br>Change-Id: Ic2a3c7b1dfa56b67cc0571969cc9cf67a770ae43<br>Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net><br>---<br>A src/soc/sifive/Kconfig<br>A src/soc/sifive/fu540/Kconfig<br>A src/soc/sifive/fu540/Makefile.inc<br>A src/soc/sifive/fu540/bootblock.c<br>A src/soc/sifive/fu540/cbmem.c<br>A src/soc/sifive/fu540/include/soc/addressmap.h<br>A src/soc/sifive/fu540/include/soc/memlayout.ld<br>A src/soc/sifive/fu540/media.c<br>A src/soc/sifive/fu540/uart.c<br>A util/riscv/sifive-gpt.py<br>10 files changed, 407 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/89/25789/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/soc/sifive/Kconfig b/src/soc/sifive/Kconfig</span><br><span>new file mode 100644</span><br><span>index 0000000..14900be</span><br><span>--- /dev/null</span><br><span>+++ b/src/soc/sifive/Kconfig</span><br><span>@@ -0,0 +1,2 @@</span><br><span style="color: hsl(120, 100%, 40%);">+# Load all chipsets</span><br><span style="color: hsl(120, 100%, 40%);">+source "src/soc/sifive/*/Kconfig"</span><br><span>diff --git a/src/soc/sifive/fu540/Kconfig b/src/soc/sifive/fu540/Kconfig</span><br><span>new file mode 100644</span><br><span>index 0000000..d247c28</span><br><span>--- /dev/null</span><br><span>+++ b/src/soc/sifive/fu540/Kconfig</span><br><span>@@ -0,0 +1,26 @@</span><br><span style="color: hsl(120, 100%, 40%);">+# This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# Copyright (C) 2018 Jonathan Neuschäfer</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+# it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+# the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+# but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+# GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+config SOC_SIFIVE_FU540</span><br><span style="color: hsl(120, 100%, 40%);">+      bool</span><br><span style="color: hsl(120, 100%, 40%);">+  select ARCH_RISCV</span><br><span style="color: hsl(120, 100%, 40%);">+     select ARCH_BOOTBLOCK_RISCV</span><br><span style="color: hsl(120, 100%, 40%);">+   select ARCH_VERSTAGE_RISCV</span><br><span style="color: hsl(120, 100%, 40%);">+    select ARCH_ROMSTAGE_RISCV</span><br><span style="color: hsl(120, 100%, 40%);">+    select ARCH_RAMSTAGE_RISCV</span><br><span style="color: hsl(120, 100%, 40%);">+    select BOOTBLOCK_CONSOLE</span><br><span style="color: hsl(120, 100%, 40%);">+      select DRIVERS_UART_SIFIVE</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+if SOC_SIFIVE_FU540</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+endif</span><br><span>diff --git a/src/soc/sifive/fu540/Makefile.inc b/src/soc/sifive/fu540/Makefile.inc</span><br><span>new file mode 100644</span><br><span>index 0000000..8a2f3a6</span><br><span>--- /dev/null</span><br><span>+++ b/src/soc/sifive/fu540/Makefile.inc</span><br><span>@@ -0,0 +1,33 @@</span><br><span style="color: hsl(120, 100%, 40%);">+# This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# Copyright (C) 2018 Jonathan Neuschäfer</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+# it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+# the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+# but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+# GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ifeq ($(CONFIG_SOC_SIFIVE_FU540),y)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+bootblock-y += uart.c</span><br><span style="color: hsl(120, 100%, 40%);">+bootblock-y += media.c</span><br><span style="color: hsl(120, 100%, 40%);">+bootblock-y += bootblock.c</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+romstage-y += uart.c</span><br><span style="color: hsl(120, 100%, 40%);">+romstage-y += media.c</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ramstage-y += uart.c</span><br><span style="color: hsl(120, 100%, 40%);">+ramstage-y += media.c</span><br><span style="color: hsl(120, 100%, 40%);">+ramstage-y += cbmem.c</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+CPPFLAGS_common += -Isrc/soc/sifive/fu540/include</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+$(objcbfs)/bootblock.bin: $(objcbfs)/bootblock.raw.bin</span><br><span style="color: hsl(120, 100%, 40%);">+       @printf "    GPT        $(notdir $(@))\n"</span><br><span style="color: hsl(120, 100%, 40%);">+   @util/riscv/sifive-gpt.py $< $@</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+endif</span><br><span>diff --git a/src/soc/sifive/fu540/bootblock.c b/src/soc/sifive/fu540/bootblock.c</span><br><span>new file mode 100644</span><br><span>index 0000000..203081c</span><br><span>--- /dev/null</span><br><span>+++ b/src/soc/sifive/fu540/bootblock.c</span><br><span>@@ -0,0 +1,24 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2018 Jonathan Neuschäfer</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <arch/io.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <bootblock_common.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <console/console.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <soc/addressmap.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void bootblock_soc_init(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      printk(BIOS_INFO, "Boot mode: %d\n", read32((uint32_t *)FU540_MSEL));</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/src/soc/sifive/fu540/cbmem.c b/src/soc/sifive/fu540/cbmem.c</span><br><span>new file mode 100644</span><br><span>index 0000000..8648370</span><br><span>--- /dev/null</span><br><span>+++ b/src/soc/sifive/fu540/cbmem.c</span><br><span>@@ -0,0 +1,22 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2018 Jonathan Neuschäfer</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <cbmem.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void *cbmem_top(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ /* dummy value */</span><br><span style="color: hsl(120, 100%, 40%);">+     return (void *)(4ULL * GiB);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/src/soc/sifive/fu540/include/soc/addressmap.h b/src/soc/sifive/fu540/include/soc/addressmap.h</span><br><span>new file mode 100644</span><br><span>index 0000000..904c8b6</span><br><span>--- /dev/null</span><br><span>+++ b/src/soc/sifive/fu540/include/soc/addressmap.h</span><br><span>@@ -0,0 +1,34 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2018 Jonathan Neuschäfer</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#define FU540_MSEL             0x00001000</span><br><span style="color: hsl(120, 100%, 40%);">+#define FU540_DTIM          0x01000000</span><br><span style="color: hsl(120, 100%, 40%);">+#define FU540_L2LIM         0x08000000</span><br><span style="color: hsl(120, 100%, 40%);">+#define FU540_UART0         0x10010000</span><br><span style="color: hsl(120, 100%, 40%);">+#define FU540_UART(x)               (FU540_UART0 + 0x1000 * (x))</span><br><span style="color: hsl(120, 100%, 40%);">+#define FU540_PRCI                0x10000000</span><br><span style="color: hsl(120, 100%, 40%);">+#define FU540_QSPI0         0x10040000</span><br><span style="color: hsl(120, 100%, 40%);">+#define FU540_QSPI1         0x10041000</span><br><span style="color: hsl(120, 100%, 40%);">+#define FU540_QSPI2         0x10050000</span><br><span style="color: hsl(120, 100%, 40%);">+#define FU540_GPIO          0x10060000</span><br><span style="color: hsl(120, 100%, 40%);">+#define FU540_OTP           0x10070000</span><br><span style="color: hsl(120, 100%, 40%);">+#define FU540_PINCTRL               0x10080000</span><br><span style="color: hsl(120, 100%, 40%);">+#define FU540_ETHMAC                0x10090000</span><br><span style="color: hsl(120, 100%, 40%);">+#define FU540_ETHMGMT               0x100a0000</span><br><span style="color: hsl(120, 100%, 40%);">+#define FU540_DDRCTRL               0x100b0000</span><br><span style="color: hsl(120, 100%, 40%);">+#define FU540_DDRMGMT               0x100c0000</span><br><span style="color: hsl(120, 100%, 40%);">+#define FU540_QSPI0FLASH    0x20000000</span><br><span style="color: hsl(120, 100%, 40%);">+#define FU540_QSPI1FLASH    0x30000000</span><br><span style="color: hsl(120, 100%, 40%);">+#define FU540_DRAM          0x80000000</span><br><span>diff --git a/src/soc/sifive/fu540/include/soc/memlayout.ld b/src/soc/sifive/fu540/include/soc/memlayout.ld</span><br><span>new file mode 100644</span><br><span>index 0000000..a03c03d</span><br><span>--- /dev/null</span><br><span>+++ b/src/soc/sifive/fu540/include/soc/memlayout.ld</span><br><span>@@ -0,0 +1,35 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2018 Jonathan Neuschäfer</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <memlayout.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <soc/addressmap.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <arch/header.ld></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#define L2LIM_START(addr) SYMBOL(l2lim, addr)</span><br><span style="color: hsl(120, 100%, 40%);">+#define L2LIM_END(addr) SYMBOL(el2lim, addr)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+SECTIONS</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  L2LIM_START(FU540_L2LIM)</span><br><span style="color: hsl(120, 100%, 40%);">+      BOOTBLOCK(FU540_L2LIM, 64K)</span><br><span style="color: hsl(120, 100%, 40%);">+   STACK(FU540_L2LIM + 64K, 4K)</span><br><span style="color: hsl(120, 100%, 40%);">+  PRERAM_CBMEM_CONSOLE(FU540_L2LIM + 68K, 8K)</span><br><span style="color: hsl(120, 100%, 40%);">+   ROMSTAGE(FU540_L2LIM + 128K, 128K)</span><br><span style="color: hsl(120, 100%, 40%);">+    L2LIM_END(FU540_L2LIM + 2M)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ DRAM_START(FU540_DRAM)</span><br><span style="color: hsl(120, 100%, 40%);">+        RAMSTAGE(FU540_DRAM, 256K)</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/src/soc/sifive/fu540/media.c b/src/soc/sifive/fu540/media.c</span><br><span>new file mode 100644</span><br><span>index 0000000..7b9ccb0</span><br><span>--- /dev/null</span><br><span>+++ b/src/soc/sifive/fu540/media.c</span><br><span>@@ -0,0 +1,25 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2018 Jonathan Neuschäfer</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <boot_device.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* At 0x20000000: A 256MiB long memory-mapped view of the flash at QSPI0 */</span><br><span style="color: hsl(120, 100%, 40%);">+static struct mem_region_device mdev =</span><br><span style="color: hsl(120, 100%, 40%);">+     MEM_REGION_DEV_RO_INIT((void *)0x20000000, CONFIG_ROM_SIZE);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+const struct region_device *boot_device_ro(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+   return &mdev.rdev;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/src/soc/sifive/fu540/uart.c b/src/soc/sifive/fu540/uart.c</span><br><span>new file mode 100644</span><br><span>index 0000000..940dc97</span><br><span>--- /dev/null</span><br><span>+++ b/src/soc/sifive/fu540/uart.c</span><br><span>@@ -0,0 +1,25 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2018 Jonathan Neuschäfer</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <console/uart.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <soc/addressmap.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+uintptr_t uart_platform_base(int idx)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+   if (idx < 2)</span><br><span style="color: hsl(120, 100%, 40%);">+               return FU540_UART(idx);</span><br><span style="color: hsl(120, 100%, 40%);">+       else</span><br><span style="color: hsl(120, 100%, 40%);">+          return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/util/riscv/sifive-gpt.py b/util/riscv/sifive-gpt.py</span><br><span>new file mode 100755</span><br><span>index 0000000..cb77302</span><br><span>--- /dev/null</span><br><span>+++ b/util/riscv/sifive-gpt.py</span><br><span>@@ -0,0 +1,181 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#!/usr/bin/python3</span><br><span style="color: hsl(120, 100%, 40%);">+# This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# Copyright (C) 2018 Jonathan Neuschäfer</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+# it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+# the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+# but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+# GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+import sys, os, struct, uuid, zlib, io</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# This script wraps the bootblock in a GPT partition, because that's what</span><br><span style="color: hsl(120, 100%, 40%);">+# SiFive's bootrom will load.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# Size of a GPT disk block, in bytes</span><br><span style="color: hsl(120, 100%, 40%);">+BLOCK_SIZE = 512</span><br><span style="color: hsl(120, 100%, 40%);">+BLOCK_MASK = BLOCK_SIZE - 1</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# Size of the bootcode part of the MBR</span><br><span style="color: hsl(120, 100%, 40%);">+MBR_BOOTCODE_SIZE = 0x1be</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# A protecive MBR, without the bootcode part</span><br><span style="color: hsl(120, 100%, 40%);">+PROTECTIVE_MBR_FOOTER = bytes([</span><br><span style="color: hsl(120, 100%, 40%);">+    0x00, 0x00, 0x02, 0x00, 0xee, 0xff, 0xff, 0xff,</span><br><span style="color: hsl(120, 100%, 40%);">+    0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,</span><br><span style="color: hsl(120, 100%, 40%);">+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,</span><br><span style="color: hsl(120, 100%, 40%);">+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,</span><br><span style="color: hsl(120, 100%, 40%);">+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,</span><br><span style="color: hsl(120, 100%, 40%);">+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,</span><br><span style="color: hsl(120, 100%, 40%);">+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,</span><br><span style="color: hsl(120, 100%, 40%);">+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,</span><br><span style="color: hsl(120, 100%, 40%);">+    0x55, 0xaa</span><br><span style="color: hsl(120, 100%, 40%);">+])</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# A "protective MBR"[1], which may also contain some boot code.</span><br><span style="color: hsl(120, 100%, 40%);">+# [1]: https://en.wikipedia.org/wiki/GUID_Partition_Table#PROTECTIVE-MBR</span><br><span style="color: hsl(120, 100%, 40%);">+class ProtectiveMBR:</span><br><span style="color: hsl(120, 100%, 40%);">+    def __init__(self):</span><br><span style="color: hsl(120, 100%, 40%);">+        self.bootcode = bytes(MBR_BOOTCODE_SIZE)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    def generate(self, stream):</span><br><span style="color: hsl(120, 100%, 40%);">+        assert len(self.bootcode) == MBR_BOOTCODE_SIZE</span><br><span style="color: hsl(120, 100%, 40%);">+        mbr = self.bootcode + PROTECTIVE_MBR_FOOTER</span><br><span style="color: hsl(120, 100%, 40%);">+        assert len(mbr) == BLOCK_SIZE</span><br><span style="color: hsl(120, 100%, 40%);">+        stream.write(mbr)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# Generate a GUID from a string</span><br><span style="color: hsl(120, 100%, 40%);">+class GUID(uuid.UUID):</span><br><span style="color: hsl(120, 100%, 40%);">+    def __init__(self, string):</span><br><span style="color: hsl(120, 100%, 40%);">+        super().__init__(string)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    def get_bytes(self):</span><br><span style="color: hsl(120, 100%, 40%);">+        return self.bytes_le</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+DUMMY_GUID_DISK_UNIQUE = GUID('17145242-abaa-441d-916a-3f26c970aba2')</span><br><span style="color: hsl(120, 100%, 40%);">+DUMMY_GUID_PART_UNIQUE = GUID('7552133d-c8de-4a20-924c-0e85f5ea81f2')</span><br><span style="color: hsl(120, 100%, 40%);">+GUID_TYPE_FSBL = GUID('5B193300-FC78-40CD-8002-E86C45580B47')</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# A GPT disk header</span><br><span style="color: hsl(120, 100%, 40%);">+# https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_table_header_(LBA_1)</span><br><span style="color: hsl(120, 100%, 40%);">+class GPTHeader:</span><br><span style="color: hsl(120, 100%, 40%);">+    def __init__(self):</span><br><span style="color: hsl(120, 100%, 40%);">+        self.current_lba = 1</span><br><span style="color: hsl(120, 100%, 40%);">+        self.backup_lba = 1</span><br><span style="color: hsl(120, 100%, 40%);">+        self.first_usable_lba = 2</span><br><span style="color: hsl(120, 100%, 40%);">+        self.last_usable_lba = 0xff     # dummy value</span><br><span style="color: hsl(120, 100%, 40%);">+        self.uniq = DUMMY_GUID_DISK_UNIQUE</span><br><span style="color: hsl(120, 100%, 40%);">+        self.part_entries_lba = 2</span><br><span style="color: hsl(120, 100%, 40%);">+        self.part_entries_number = 0</span><br><span style="color: hsl(120, 100%, 40%);">+        self.part_entries_crc32 = 0</span><br><span style="color: hsl(120, 100%, 40%);">+        self.part_entry_size = 128</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    def pack_with_crc(self, crc):</span><br><span style="color: hsl(120, 100%, 40%);">+        header_size = 92</span><br><span style="color: hsl(120, 100%, 40%);">+        header = struct.pack('<8sIIIIQQQQ16sQIII',</span><br><span style="color: hsl(120, 100%, 40%);">+                b'EFI PART', 0x100, header_size, crc, 0,</span><br><span style="color: hsl(120, 100%, 40%);">+                self.current_lba, self.backup_lba, self.first_usable_lba,</span><br><span style="color: hsl(120, 100%, 40%);">+                self.last_usable_lba, self.uniq.get_bytes(),</span><br><span style="color: hsl(120, 100%, 40%);">+                self.part_entries_lba, self.part_entries_number,</span><br><span style="color: hsl(120, 100%, 40%);">+                self.part_entry_size, self.part_entries_crc32)</span><br><span style="color: hsl(120, 100%, 40%);">+        assert len(header) == header_size</span><br><span style="color: hsl(120, 100%, 40%);">+        return header</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    def generate(self, stream):</span><br><span style="color: hsl(120, 100%, 40%);">+        crc = zlib.crc32(self.pack_with_crc(0))</span><br><span style="color: hsl(120, 100%, 40%);">+        header = self.pack_with_crc(crc)</span><br><span style="color: hsl(120, 100%, 40%);">+        stream.write(header.ljust(BLOCK_SIZE, b'\0'))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# A GPT partition entry.</span><br><span style="color: hsl(120, 100%, 40%);">+# https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_entries_(LBA_2-33)</span><br><span style="color: hsl(120, 100%, 40%);">+class GPTPartition:</span><br><span style="color: hsl(120, 100%, 40%);">+    def __init__(self):</span><br><span style="color: hsl(120, 100%, 40%);">+        self.type = GUID('00000000-0000-0000-0000-000000000000')</span><br><span style="color: hsl(120, 100%, 40%);">+        self.uniq = GUID('00000000-0000-0000-0000-000000000000')</span><br><span style="color: hsl(120, 100%, 40%);">+        self.first_lba = 0</span><br><span style="color: hsl(120, 100%, 40%);">+        self.last_lba = 0</span><br><span style="color: hsl(120, 100%, 40%);">+        self.attr = 0</span><br><span style="color: hsl(120, 100%, 40%);">+        self.name = ''</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    def generate(self, stream):</span><br><span style="color: hsl(120, 100%, 40%);">+        name_utf16 = self.name.encode('UTF-16LE')</span><br><span style="color: hsl(120, 100%, 40%);">+        part = struct.pack('<16s16sQQQ72s',</span><br><span style="color: hsl(120, 100%, 40%);">+                self.type.get_bytes(), self.uniq.get_bytes(),</span><br><span style="color: hsl(120, 100%, 40%);">+                self.first_lba, self.last_lba, self.attr,</span><br><span style="color: hsl(120, 100%, 40%);">+                name_utf16.ljust(72, b'\0'))</span><br><span style="color: hsl(120, 100%, 40%);">+        assert len(part) == 128</span><br><span style="color: hsl(120, 100%, 40%);">+        stream.write(part)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+class GPTImage:</span><br><span style="color: hsl(120, 100%, 40%);">+    # The final image consists of:</span><br><span style="color: hsl(120, 100%, 40%);">+    # - A protective MBR</span><br><span style="color: hsl(120, 100%, 40%);">+    # - A GPT header</span><br><span style="color: hsl(120, 100%, 40%);">+    # - A few GPT partition entries</span><br><span style="color: hsl(120, 100%, 40%);">+    # - The content of the bootblock</span><br><span style="color: hsl(120, 100%, 40%);">+    def __init__(self):</span><br><span style="color: hsl(120, 100%, 40%);">+        self.mbr = ProtectiveMBR()</span><br><span style="color: hsl(120, 100%, 40%);">+        self.header = GPTHeader()</span><br><span style="color: hsl(120, 100%, 40%);">+        self.partitions = [ GPTPartition() for i in range(8) ]</span><br><span style="color: hsl(120, 100%, 40%);">+        self.bootblock = b''</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # Fix up a few numbers to ensure consistency between the different</span><br><span style="color: hsl(120, 100%, 40%);">+    # components.</span><br><span style="color: hsl(120, 100%, 40%);">+    def fixup(self):</span><br><span style="color: hsl(120, 100%, 40%);">+        # Align the bootblock to a whole number to LBA blocks</span><br><span style="color: hsl(120, 100%, 40%);">+        bootblock_size = (len(self.bootblock) + BLOCK_SIZE - 1) & ~BLOCK_MASK</span><br><span style="color: hsl(120, 100%, 40%);">+        self.bootblock = self.bootblock.ljust(bootblock_size)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        # Propagate the number of partition entries</span><br><span style="color: hsl(120, 100%, 40%);">+        self.header.part_entries_number = len(self.partitions)</span><br><span style="color: hsl(120, 100%, 40%);">+        self.header.first_usable_lba = 2 + self.header.part_entries_number // 4</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        # Create a partition entry for the bootblock</span><br><span style="color: hsl(120, 100%, 40%);">+        self.partitions[0].type = GUID_TYPE_FSBL</span><br><span style="color: hsl(120, 100%, 40%);">+        self.partitions[0].uniq = DUMMY_GUID_PART_UNIQUE</span><br><span style="color: hsl(120, 100%, 40%);">+        self.partitions[0].first_lba = self.header.first_usable_lba</span><br><span style="color: hsl(120, 100%, 40%);">+        self.partitions[0].last_lba = \</span><br><span style="color: hsl(120, 100%, 40%);">+            self.header.first_usable_lba + bootblock_size // BLOCK_SIZE</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        # Calculate the CRC32 checksum of the partitions array</span><br><span style="color: hsl(120, 100%, 40%);">+        partition_array = io.BytesIO()</span><br><span style="color: hsl(120, 100%, 40%);">+        for part in self.partitions:</span><br><span style="color: hsl(120, 100%, 40%);">+            part.generate(partition_array)</span><br><span style="color: hsl(120, 100%, 40%);">+        self.header.part_entries_crc32 = zlib.crc32(partition_array.getvalue())</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    def generate(self, stream):</span><br><span style="color: hsl(120, 100%, 40%);">+        self.mbr.generate(stream)</span><br><span style="color: hsl(120, 100%, 40%);">+        self.header.generate(stream)</span><br><span style="color: hsl(120, 100%, 40%);">+        for part in self.partitions:</span><br><span style="color: hsl(120, 100%, 40%);">+            part.generate(stream)</span><br><span style="color: hsl(120, 100%, 40%);">+        stream.write(self.bootblock)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+if __name__ == '__main__':</span><br><span style="color: hsl(120, 100%, 40%);">+    if len(sys.argv) != 3:</span><br><span style="color: hsl(120, 100%, 40%);">+        print('Usage:', file=sys.stderr)</span><br><span style="color: hsl(120, 100%, 40%);">+        print('    %s bootblock.raw.bin bootblock.bin' % sys.argv[0],</span><br><span style="color: hsl(120, 100%, 40%);">+                file=sys.stderr)</span><br><span style="color: hsl(120, 100%, 40%);">+        sys.exit(1)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    image = GPTImage()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    with open(sys.argv[1], 'rb') as f:</span><br><span style="color: hsl(120, 100%, 40%);">+        image.bootblock = f.read()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    image.fixup()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    with open(sys.argv[2], 'wb') as f:</span><br><span style="color: hsl(120, 100%, 40%);">+        image.generate(f)</span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/25789">change 25789</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/25789"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ic2a3c7b1dfa56b67cc0571969cc9cf67a770ae43 </div>
<div style="display:none"> Gerrit-Change-Number: 25789 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Jonathan Neuschäfer <j.neuschaefer@gmx.net> </div>