Philipp Hug has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/31215
Change subject: WIP: riscv: Implement FIT for RISC-V
......................................................................
WIP: riscv: Implement FIT for RISC-V
Change-Id: Ic50f14a4f483d904db590ecd53bb1fc5bdeb06d6
---
M payloads/Kconfig
M src/arch/riscv/Makefile.inc
A src/arch/riscv/fit_payload.c
M src/soc/sifive/fu540/Kconfig
4 files changed, 171 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/15/31215/1
diff --git a/payloads/Kconfig b/payloads/Kconfig
index c7a7ba6..0c5ce8f 100644
--- a/payloads/Kconfig
+++ b/payloads/Kconfig
@@ -30,7 +30,7 @@
config PAYLOAD_FIT
bool "A FIT payload"
- depends on ARCH_ARM64
+ depends on ARCH_ARM64 || ARCH_RISCV
select PAYLOAD_FIT_SUPPORT
help
Select this option if you have a payload image (a FIT file) which
diff --git a/src/arch/riscv/Makefile.inc b/src/arch/riscv/Makefile.inc
index e4c8468..12609d4 100644
--- a/src/arch/riscv/Makefile.inc
+++ b/src/arch/riscv/Makefile.inc
@@ -139,6 +139,7 @@
ramstage-y += tables.c
ramstage-y += payload.S
ramstage-$(ARCH_RISCV_PMP) += pmp.c
+ramstage-$(CONFIG_PAYLOAD_FIT_SUPPORT) += fit_payload.c
ramstage-y += \
$(top)/src/lib/memchr.c \
$(top)/src/lib/memcmp.c \
diff --git a/src/arch/riscv/fit_payload.c b/src/arch/riscv/fit_payload.c
new file mode 100644
index 0000000..2176095
--- /dev/null
+++ b/src/arch/riscv/fit_payload.c
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2013 Google Inc.
+ * Copyright 2018 Facebook, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <console/console.h>
+#include <bootmem.h>
+#include <stdlib.h>
+#include <program_loading.h>
+#include <string.h>
+#include <commonlib/compression.h>
+#include <commonlib/cbfs_serialized.h>
+#include <lib.h>
+#include <fit.h>
+#include <endian.h>
+
+#define MAX_KERNEL_SIZE (64*MiB)
+
+static bool fit_place_kernel(const struct range_entry *r, void *arg)
+{
+ struct region *region = arg;
+ resource_t start;
+
+ if (range_entry_tag(r) != BM_MEM_RAM)
+ return true;
+
+ /**
+ * The Image must be placed text_offset bytes from a 2MB aligned base
+ * address anywhere in usable system RAM and called there. The region
+ * between the 2 MB aligned base address and the start of the image has
+ * no special significance to the kernel, and may be used for other
+ * purposes.
+ *
+ * If the reserved memory (BL31 for example) is smaller than text_offset
+ * we can use the 2 MiB base address, otherwise use the next 2 MiB page.
+ * It's not mandatory, but wastes less memory below the kernel.
+ */
+ start = ALIGN_DOWN(range_entry_base(r), 2 * MiB);
+
+ if (start < range_entry_base(r))
+ start += 2 * MiB;
+ /**
+ * At least image_size bytes from the start of the image must be free
+ * for use by the kernel.
+ */
+ if (start + region->size < range_entry_end(r)) {
+ region->offset = (size_t)start;
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ * Place the region in free memory range.
+ *
+ * The caller has to set region->offset to the minimum allowed address.
+ * The region->offset is usually 0 on kernel >v4.6 and kernel_base + kernel_size
+ * on kernel <v4.6.
+ */
+static bool fit_place_mem(const struct range_entry *r, void *arg)
+{
+ struct region *region = arg;
+ resource_t start;
+
+ if (range_entry_tag(r) != BM_MEM_RAM)
+ return true;
+
+ /* Linux 4.15 doesn't like 4KiB alignment. Align to 1 MiB for now. */
+ start = ALIGN_UP(MAX(region->offset, range_entry_base(r)), 1 * MiB);
+
+ if (start + region->size < range_entry_end(r)) {
+ region->offset = (size_t)start;
+ return false;
+ }
+
+ return true;
+}
+
+bool fit_payload_arch(struct prog *payload, struct fit_config_node *config,
+ struct region *kernel,
+ struct region *fdt,
+ struct region *initrd)
+{
+ bool place_anywhere;
+ void *arg = NULL;
+
+ if (!config->fdt || !fdt) {
+ printk(BIOS_CRIT, "CRIT: Providing a valid FDT is mandatory to "
+ "boot an RISCV kernel!\n");
+ return false;
+ }
+
+ /* Update kernel size from image header, if possible */
+ kernel->size = 0x2000000; //get_kernel_size(config->kernel_node);
+ printk(BIOS_DEBUG, "FIT: Using kernel size of 0x%zx bytes\n",
+ kernel->size);
+
+
+ /**
+ * The code assumes that bootmem_walk provides a sorted list of memory
+ * regions, starting from the lowest address.
+ * The order of the calls here doesn't matter, as the placement is
+ * enforced in the called functions.
+ * For details check code on top.
+ */
+
+ if (!bootmem_walk(fit_place_kernel, kernel))
+ return false;
+
+ /* Mark as reserved for future allocations. */
+ bootmem_add_range(kernel->offset, kernel->size, BM_MEM_PAYLOAD);
+
+ /**
+ * NOTE: versions prior to v4.6 cannot make use of memory below the
+ * physical offset of the Image so it is recommended that the Image be
+ * placed as close as possible to the start of system RAM.
+ *
+ * For kernel <v4.6 the INITRD and FDT can't be placed below the kernel.
+ * In that case set region offset to an address on top of kernel.
+ */
+
+ place_anywhere = false;
+ printk(BIOS_DEBUG, "FIT: Placing FDT and INITRD %s\n",
+ place_anywhere ? "anywhere" : "on top of kernel");
+
+ /* Place INITRD */
+ if (config->ramdisk) {
+ initrd->offset = 0;
+
+ if (!bootmem_walk(fit_place_mem, initrd))
+ return false;
+ /* Mark as reserved for future allocations. */
+ bootmem_add_range(initrd->offset, initrd->size, BM_MEM_PAYLOAD);
+ }
+
+ /* Place FDT */
+ if (place_anywhere)
+ fdt->offset = 0;
+ else
+ fdt->offset = kernel->offset + kernel->size;
+
+ if (!bootmem_walk(fit_place_mem, fdt))
+ return false;
+ /* Mark as reserved for future allocations. */
+ bootmem_add_range(fdt->offset, fdt->size, BM_MEM_PAYLOAD);
+
+ /* Kernel expects FDT as argument */
+ arg = (void *)fdt->offset;
+
+ prog_set_entry(payload, (void *)kernel->offset, arg);
+
+ bootmem_dump_ranges();
+
+ return true;
+}
diff --git a/src/soc/sifive/fu540/Kconfig b/src/soc/sifive/fu540/Kconfig
index 6ebde33..20645da 100644
--- a/src/soc/sifive/fu540/Kconfig
+++ b/src/soc/sifive/fu540/Kconfig
@@ -49,4 +49,7 @@
int
default 0
+config HEAP_SIZE
+ default 0x10000
+
endif
--
To view, visit https://review.coreboot.org/c/coreboot/+/31215
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: Ic50f14a4f483d904db590ecd53bb1fc5bdeb06d6
Gerrit-Change-Number: 31215
Gerrit-PatchSet: 1
Gerrit-Owner: Philipp Hug <philipp(a)hug.cx>
Gerrit-MessageType: newchange
Xiang Wang has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/32394
Change subject: riscv: add support to boot linux kernel binary using opensbi
......................................................................
riscv: add support to boot linux kernel binary using opensbi
Change-Id: I2a178595bd2aa2e1f114cbc69e8eadd46955b54d
Signed-off-by: Xiang Wang <wxjstz(a)126.com>
---
M payloads/Kconfig
M payloads/external/Makefile.inc
M src/arch/riscv/Makefile.inc
M src/arch/riscv/boot.c
M src/soc/sifive/fu540/Kconfig
5 files changed, 49 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/94/32394/1
diff --git a/payloads/Kconfig b/payloads/Kconfig
index d0f8a44..4cf9d1e 100644
--- a/payloads/Kconfig
+++ b/payloads/Kconfig
@@ -28,6 +28,18 @@
You will be able to specify the location and file name of the
payload image later.
+config PAYLOAD_RISCV_LINUX_BINARY
+ bool "An linux binary payload"
+ depends on ARCH_RISCV
+ help
+ Select this option if you have a payload image (an binary file)
+ which coreboot should run as soon as the basic hardware
+ initialization is completed. This image will be used as the
+ payload of opensbi and will be started by coreboot.
+
+ You will be able to specify the location and file name of the
+ payload image later.
+
config PAYLOAD_FIT
bool "A FIT payload"
depends on ARCH_ARM64
@@ -57,9 +69,10 @@
config PAYLOAD_FILE
string "Payload path and filename"
- depends on PAYLOAD_ELF || PAYLOAD_FIT
+ depends on PAYLOAD_ELF || PAYLOAD_FIT || PAYLOAD_RISCV_LINUX_BINARY
default "payload.elf" if PAYLOAD_ELF
default "uImage" if PAYLOAD_FIT
+ default "payload.bin" if PAYLOAD_RISCV_LINUX_BINARY
help
The path and filename of the ELF executable file to use as payload.
diff --git a/payloads/external/Makefile.inc b/payloads/external/Makefile.inc
index 5f9d800..3b29b41 100644
--- a/payloads/external/Makefile.inc
+++ b/payloads/external/Makefile.inc
@@ -48,7 +48,11 @@
endif
cbfs-files-y += $(CONFIG_CBFS_PREFIX)/payload
+ifeq ($(CONFIG_PAYLOAD_RISCV_LINUX_BINARY),y)
+$(CONFIG_CBFS_PREFIX)/payload-file := $(obj)/opensbi.elf
+else
$(CONFIG_CBFS_PREFIX)/payload-file := $(CONFIG_PAYLOAD_FILE)
+endif
ifeq ($(CONFIG_PAYLOAD_IS_FLAT_BINARY),y)
$(CONFIG_CBFS_PREFIX)/payload-type := flat-binary
else
diff --git a/src/arch/riscv/Makefile.inc b/src/arch/riscv/Makefile.inc
index d5f6295..d4d362b 100644
--- a/src/arch/riscv/Makefile.inc
+++ b/src/arch/riscv/Makefile.inc
@@ -174,4 +174,27 @@
endif #CONFIG_ARCH_RISCV_RV32
endif #CONFIG_ARCH_RAMSTAGE_RISCV
+
+ifeq ($(CONFIG_PAYLOAD_RISCV_LINUX_BINARY),y)
+
+OPENSBI := $(obj)/opensbi.elf
+OPENSBI_SOURCE := $(top)/payloads/external/opensbi
+OPENSBI_BUILD := $(abspath $(obj)/payloads/external/opensbi)
+OPENSBI_TARGET := $(OPENSBI_BUILD)/platform/$(CONFIG_OPENSBI_PLATFORM)/firmware/fw_payload.elf
+
+$(OPENSBI):$(obj)/build.h
+ printf " MAKE $(subst $(obj)/,,$(@))\n"
+ mkdir -p $(OPENSBI_BUILD)
+ $(MAKE) \
+ -C $(OPENSBI_SOURCE) \
+ CROSS_COMPILE=riscv64-elf- \
+ PLATFORM=$(CONFIG_OPENSBI_PLATFORM) \
+ O=$(OPENSBI_BUILD) \
+ FW_PAYLOAD_PATH=$(abspath $(CONFIG_PAYLOAD_FILE))
+ cp $(OPENSBI_TARGET) $(abspath $@)
+
+.PHONY: $(OPENSBI)
+
+endif #CONFIG_PAYLOAD_RISCV_LINUX_BINARY
+
endif #CONFIG_ARCH_RISCV
diff --git a/src/arch/riscv/boot.c b/src/arch/riscv/boot.c
index 535067e..9998255 100644
--- a/src/arch/riscv/boot.c
+++ b/src/arch/riscv/boot.c
@@ -49,7 +49,11 @@
fdt = HLS()->fdt;
if (ENV_RAMSTAGE && prog_type(prog) == PROG_PAYLOAD) {
+#if CONFIG(PAYLOAD_RISCV_LINUX_BINARY)
+ run_payload(prog, fdt, RISCV_PAYLOAD_MODE_M);
+#else
run_payload(prog, fdt, RISCV_PAYLOAD_MODE_S);
+#endif
return;
}
diff --git a/src/soc/sifive/fu540/Kconfig b/src/soc/sifive/fu540/Kconfig
index 6ebde33..2e88150 100644
--- a/src/soc/sifive/fu540/Kconfig
+++ b/src/soc/sifive/fu540/Kconfig
@@ -49,4 +49,8 @@
int
default 0
+config OPENSBI_PLATFORM
+ string
+ default "sifive/fu540"
+
endif
--
To view, visit https://review.coreboot.org/c/coreboot/+/32394
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I2a178595bd2aa2e1f114cbc69e8eadd46955b54d
Gerrit-Change-Number: 32394
Gerrit-PatchSet: 1
Gerrit-Owner: Xiang Wang <wxjstz(a)126.com>
Gerrit-MessageType: newchange
Hello nsekar(a)codeaurora.org,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/coreboot/+/32271
to review the following change.
Change subject: TEMP: NOT FOR REVIEW: Mistral: Add board id detection using TPM
......................................................................
TEMP: NOT FOR REVIEW: Mistral: Add board id detection using TPM
This patch adds support to select the board id
based on the TPM availability.
Change-Id: Ib75d51a21a6129e3650e2af24ff85f37a462591b
Signed-off-by: Nitheesh Sekar <nsekar(a)codeaurora.org>
---
M src/mainboard/google/mistral/boardid.c
1 file changed, 16 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/71/32271/1
diff --git a/src/mainboard/google/mistral/boardid.c b/src/mainboard/google/mistral/boardid.c
index 8258ac3..9a0d309 100644
--- a/src/mainboard/google/mistral/boardid.c
+++ b/src/mainboard/google/mistral/boardid.c
@@ -32,7 +32,22 @@
[1] = GPIO(106),
[0] = GPIO(105)};
- bid = gpio_binary_first_base3_value(pins, ARRAY_SIZE(pins));
+ if (is_tpm_detected() == 0) {
+ bid = 25; /* Assign 25 for EVB boards */
+ printk(BIOS_DEBUG, "EVB Board ID: %d\n", bid);
+ } else {
+ bid = 0; /* Assign 0 for Proto boards */
+
+ /* The board id assigned for Proto boards is 0.
+ * Since gpios are not wired in the initial phase,
+ * we will get 0 whihch is a coincidence.
+ * To make sure it starts working, after gpios are
+ * wired, reassign the value read from gpios to id.
+ */
+ bid = gpio_binary_first_base3_value(pins, ARRAY_SIZE(pins));
+
+ printk(BIOS_DEBUG, "Proto Board ID: %d\n", bid);
+ }
return bid;
}
--
To view, visit https://review.coreboot.org/c/coreboot/+/32271
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: Ib75d51a21a6129e3650e2af24ff85f37a462591b
Gerrit-Change-Number: 32271
Gerrit-PatchSet: 1
Gerrit-Owner: Patrick Georgi <pgeorgi(a)google.com>
Gerrit-Reviewer: nsekar(a)codeaurora.org
Gerrit-MessageType: newchange