Naresh Solanki (naresh.solanki(a)intel.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/17246
-gerrit
commit 2b32198badb3bbdb69622bee02420410c2884163
Author: Naresh G Solanki <naresh.solanki(a)intel.com>
Date: Sun Nov 6 12:51:14 2016 +0530
vboot: No vboot verification when Chrome EC disabled
When Chrome EC is disabled, vboot hash is not available during S3 resume.
Hence disable vboot verification when Chrome EC is not available.
Change-Id: I665f5f0e2e53da7b735de30443d323572d8a1a9c
Signed-off-by: Naresh G Solanki <naresh.solanki(a)intel.com>
---
src/vboot/vboot_logic.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/vboot/vboot_logic.c b/src/vboot/vboot_logic.c
index bc6ab48..41896e1 100644
--- a/src/vboot/vboot_logic.c
+++ b/src/vboot/vboot_logic.c
@@ -119,6 +119,13 @@ static int handle_digest_result(void *slot_hash, size_t slot_hash_sz)
int is_resume;
/*
+ * Chrome EC is the only support for vboot_save_hash()/vboot_retrieve_hash(), if Chrome EC
+ * is not enabled then return.
+ */
+ if (!IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC))
+ return 0;
+
+ /*
* Nothing to do since resuming on the platform doesn't require
* vboot verification again.
*/
Ronald G. Minnich (rminnich(a)gmail.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/17233
-gerrit
commit 051344c46114ce4906edff89e6b5dc6930b91f17
Author: Ronald G. Minnich <rminnich(a)gmail.com>
Date: Fri Nov 4 11:27:25 2016 -0700
riscv: map first 2GiB of physical memory at the top of virtual address space
We were mapping physical to virtual 1:1, which makes no sense;
most kernels want to start at high negative address space.
Doing it this way ensures that we're following the intent
of the RISCV designers, i.e that virtual addresses are
correct at the start; and that the kernel does not have to
unmap the low physical addresses once it starts.
Change-Id: I8c577ad885891b4c33c20077995abbd90f355f1c
Signed-off-by: Ronald G. Minnich <rminnich(a)gmail.com>
---
src/arch/riscv/virtual_memory.c | 43 ++++++++++++++++++++++++++++++++++++-----
1 file changed, 38 insertions(+), 5 deletions(-)
diff --git a/src/arch/riscv/virtual_memory.c b/src/arch/riscv/virtual_memory.c
index 999d73c..7091f02 100644
--- a/src/arch/riscv/virtual_memory.c
+++ b/src/arch/riscv/virtual_memory.c
@@ -168,12 +168,40 @@ void init_vm(uintptr_t virtMemStart, uintptr_t physMemStart, pte_t *sbi_pt)
// IO space.
root_pt[0] = pte_create(0, PTE_W|PTE_R, 0);
- root_pt[1] = pte_create(0x40000000>>RISCV_PGSHIFT,
+ root_pt[1] = pte_create(0x40000000 >> RISCV_PGSHIFT,
PTE_W|PTE_R, 0);
// Start of RAM
- root_pt[2] = pte_create(0x80000000>>RISCV_PGSHIFT,
- PTE_W|PTE_R, 0);
+ //
+ // A RISCV goal is that Machine or Hypervisor modes be able
+ // start a Supervisor (kernel) at the C entry point. The
+ // intent is that firmware creates the virtual memory maps for
+ // the kernel to use.
+ //
+ // Question: what is the virtual address of physical memory
+ // for a kernel? Hey, glad you asked! In most kernels out
+ // there, physical memory is mapped at the top of the virtual
+ // address space. The express intent of the RISCV designers
+ // (I asked them) is that we be able to enter a kernel at
+ // main() in C, with no assembly needed.
+ //
+ // This is a neat idea that may not quite work out. For
+ // example: where's the stack go? Once you start in
+ // Supervisor mode, you are using virtual addresses set up by
+ // coreboot. So you can't use the coreboot stack, it's mapped
+ // to low physical addresses. You *should* not use the
+ // coreboot stack, your kernel may need it in a different
+ // place. So the kernel needs to change the stack, in ... a
+ // bit of startup assembly code, what else? Oh well. Map
+ // physical to high virtual. It's the most common way to
+ // go. Kernels that want to put kernel virtual addresses based
+ // at 0 will need to fixup page tables in ... a bit of startup
+ // assembly code :-)
+ //
+ // TODO: use a constant for the number of PTEs per page, when
+ // (hopefully) newer RISCV toolchains define that constant.
+ root_pt[0x1ff] = pte_create(0x80000000 >> RISCV_PGSHIFT,
+ PTE_R | PTE_W | PTE_X, 0);
mb();
root_page_table = root_pt;
uintptr_t ptbr = ((uintptr_t) root_pt) >> RISCV_PGSHIFT;
@@ -198,9 +226,14 @@ void initVirtualMemory(void) {
}
// TODO: Figure out how to grab this from cbfs
+ // N.B. We used to map phsyical from 0x81000000,
+ // but since kernels need to be able to see the page tables
+ // created by firmware, we're going to map from start of RAM.
+ // All this is subject to change as we learn more. Much
+ // about RISCV is still in flux.
printk(BIOS_DEBUG, "Initializing virtual memory...\n");
- uintptr_t physicalStart = 0x81000000;
- uintptr_t virtualStart = 0xffffffff81000000;
+ uintptr_t physicalStart = 0x80000000;
+ uintptr_t virtualStart = 0xffffffff80000000;
init_vm(virtualStart, physicalStart, (pte_t *)_pagetables);
mb();
flush_tlb();
Ronald G. Minnich (rminnich(a)gmail.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/17255
-gerrit
commit cf30fad5069648e8bb7f7e5b313b98f39c9d5956
Author: Ronald G. Minnich <rminnich(a)gmail.com>
Date: Sun Nov 6 20:51:18 2016 -0800
riscv: bring in the configstring parsing functions from UCB
I've tested this with commits to come later.
This is from the lowrisc bbl distribution, 87588c4,
with fixes so it builds.
Change-Id: I87893638872259c94d6972e1971578b633155e7e
Signed-off-by: Ronald G. Minnich <rminnich(a)gmail.com>
---
src/commonlib/configstring.c | 54 +++++++
src/commonlib/include/commonlib/configstring.h | 209 +++++++++++++++++++++++++
2 files changed, 263 insertions(+)
diff --git a/src/commonlib/configstring.c b/src/commonlib/configstring.c
new file mode 100644
index 0000000..40beb16
--- /dev/null
+++ b/src/commonlib/configstring.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2013-2016, The Regents of the University of California
+ *(Regents).
+ * All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Regents nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+ * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+ * ARISING
+ * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
+ * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
+ * HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
+ * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ */
+
+#include <config.h>
+#include <assert.h>
+#include <string.h>
+#include <commonlib/configstring.h>
+
+void query_mem(const char *config_string, uintptr_t *base, size_t *size)
+{
+ query_result res = query_config_string(config_string, "ram{0{addr");
+ *base = get_uint(res);
+ res = query_config_string(config_string, "ram{0{size");
+ *size = get_uint(res);
+}
+
+/* query_rtc returns the physical address of the rtc. */
+void query_rtc(const char *config_string, uintptr_t *mtime)
+{
+ query_result res = query_config_string(config_string, "rtc{addr");
+ *mtime = (uintptr_t)get_uint(res);
+}
+
+const char *configstring(void)
+{
+ uint32_t addr = *(uint32_t *)CONFIG_ARCH_CONFIGSTRING_RISCV;
+ return (const char *)(uintptr_t)addr;
+}
diff --git a/src/commonlib/include/commonlib/configstring.h b/src/commonlib/include/commonlib/configstring.h
new file mode 100644
index 0000000..8aacbda
--- /dev/null
+++ b/src/commonlib/include/commonlib/configstring.h
@@ -0,0 +1,209 @@
+/*
+ * Copyright (c) 2013-2016, The Regents of the University of California
+ *(Regents).
+ * All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Regents nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+ * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+ * ARISING
+ * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
+ * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
+ * HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
+ * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ */
+
+#ifndef RISCV_CONFIG_STRING_H
+#define RISCV_CONFIG_STRING_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+static const char *skip_whitespace(const char *str)
+{
+ while (*str && *str <= ' ')
+ str++;
+ return str;
+}
+
+static const char *skip_string(const char *str)
+{
+ while (*str && *str++ != '"')
+ ;
+ return str;
+}
+
+static int is_hex(char ch)
+{
+ return (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') ||
+ (ch >= 'A' && ch <= 'F');
+}
+
+static int parse_hex(char ch)
+{
+ return (ch >= '0' && ch <= '9') ? ch - '0' : (ch >= 'a' && ch <= 'f')
+ ? ch - 'a' + 10
+ : ch - 'A' + 10;
+}
+
+static const char *skip_key(const char *str)
+{
+ while (*str >= 35 && *str <= 122 && *str != ';')
+ str++;
+ return str;
+}
+
+typedef struct {
+ const char *start;
+ const char *end;
+} query_result;
+
+static inline query_result query_config_string(const char *str, const char *k)
+{
+ size_t ksize = 0;
+ while (k[ksize] && k[ksize] != '{')
+ ksize++;
+ int last = !k[ksize];
+
+ query_result res = {0, 0};
+ while (1) {
+ const char *key_start = str = skip_whitespace(str);
+ const char *key_end = str = skip_key(str);
+ int match = (size_t)(key_end - key_start) == ksize;
+ if (match)
+ for (size_t i = 0; i < ksize; i++)
+ if (key_start[i] != k[i])
+ match = 0;
+ const char *value_start = str = skip_whitespace(str);
+ while (*str != ';') {
+ if (!*str) {
+ return res;
+ } else if (*str == '"') {
+ str = skip_string(str + 1);
+ } else if (*str == '{') {
+ const char *search_key =
+ match && !last ? k + ksize + 1 : "";
+ query_result inner_res =
+ query_config_string(str + 1, search_key);
+ if (inner_res.start)
+ return inner_res;
+ str = inner_res.end + 1;
+ } else {
+ str = skip_key(str);
+ }
+ str = skip_whitespace(str);
+ }
+ res.end = str;
+ if (match && last) {
+ res.start = value_start;
+ return res;
+ }
+ str = skip_whitespace(str + 1);
+ if (*str == '}') {
+ res.end = str;
+ return res;
+ }
+ }
+}
+
+static void parse_string(query_result r, char *buf)
+{
+ if (r.start < r.end) {
+ if (*r.start == '"') {
+ for (const char *p = r.start + 1;
+ p < r.end && *p != '"'; p++) {
+ char ch = p[0];
+ if (ch == '\\' && p[1] == 'x' && is_hex(p[2])) {
+ ch = parse_hex(p[2]);
+ if (is_hex(p[3])) {
+ ch =
+ (ch << 4) + parse_hex(p[3]);
+ p++;
+ }
+ p += 2;
+ }
+ *buf++ = ch;
+ }
+ } else {
+ for (const char *p = r.start; p < r.end && *p > ' ';
+ p++)
+ *buf++ = *p;
+ }
+ }
+ *buf = 0;
+}
+
+static uint64_t __get_uint_hex(const char *s)
+{
+ uint64_t res = 0;
+ while (*s) {
+ if (is_hex(*s))
+ res = (res << 4) + parse_hex(*s);
+ else if (*s != '_')
+ break;
+ s++;
+ }
+ return res;
+}
+
+static uint64_t __get_uint_dec(const char *s)
+{
+ uint64_t res = 0;
+ while (*s) {
+ if (*s >= '0' && *s <= '9')
+ res = res * 10 + (*s - '0');
+ else
+ break;
+ s++;
+ }
+ return res;
+}
+
+static uint64_t __get_uint(const char *s)
+{
+ if (s[0] == '0' && s[1] == 'x')
+ return __get_uint_hex(s + 2);
+ return __get_uint_dec(s);
+}
+
+// This is nasty. But the original code used a much nastier thing,
+// an array declared as an automatic, which triggered gcc warnings
+// as it was sized by the res.end - res.start. We'll need a better
+// solution, long term. Malloc is probably not it.
+static char name[1024];
+static inline uint64_t get_uint(query_result res)
+{
+ uint64_t v;
+ parse_string(res, name);
+ v = __get_uint(name);
+ return v;
+}
+
+static inline int64_t get_sint(query_result res)
+{
+ int64_t v;
+ parse_string(res, name);
+ if (name[0] == '-')
+ return -__get_uint(name + 1);
+ v = __get_uint(name);
+ return v;
+}
+
+const char *configstring(void);
+void query_mem(const char *config_string, uintptr_t *base, size_t *size);
+void query_rtc(const char *config_string, uintptr_t *mtime);
+#endif
Ronald G. Minnich (rminnich(a)gmail.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/17254
-gerrit
commit 7fade81566bc26c920ee8ca86028e5657ddfe9de
Author: Ronald G. Minnich <rminnich(a)gmail.com>
Date: Sun Nov 6 16:13:52 2016 -0800
riscv: change payload() to pass the config string pointer as arg0
The riscv 1.9 standard defines a textual config string to be passed
to kernels and hypervisors. A pointer to this string is available
at a platform-dependent location, default 0x100c on all extant platforms.
Define a new config variable, ARCH_CONFIGSTRING_RISCV, to contain
this location and change payload() arguments so arg0 is this pointer
and arg1 is the pointer to the payload.
Change-Id: I3be7f1712accf2d726704e4c970f22749d3c3f36
Signed-off-by: Ronald G. Minnich <rminnich(a)gmail.com>
---
src/arch/riscv/Kconfig | 5 +++++
src/arch/riscv/boot.c | 7 +++++--
src/arch/riscv/payload.S | 4 +++-
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/arch/riscv/Kconfig b/src/arch/riscv/Kconfig
index a30cb70..7c43da4 100644
--- a/src/arch/riscv/Kconfig
+++ b/src/arch/riscv/Kconfig
@@ -19,3 +19,8 @@ config ARCH_ROMSTAGE_RISCV
config ARCH_RAMSTAGE_RISCV
bool
default n
+
+config ARCH_CONFIGSTRING_RISCV
+ hex "Location of pointer to RISCV config string"
+ default 0x100c
+ depends on ARCH_RISCV
diff --git a/src/arch/riscv/boot.c b/src/arch/riscv/boot.c
index ff1844e..0fa4d5f 100644
--- a/src/arch/riscv/boot.c
+++ b/src/arch/riscv/boot.c
@@ -22,12 +22,15 @@
void arch_prog_run(struct prog *prog)
{
void (*doit)(void *) = prog_entry(prog);
- void riscvpayload(void *);
+ void riscvpayload(const char *configstring, void *payload);
+ uint32_t addr = *(uint32_t *)CONFIG_ARCH_CONFIGSTRING_RISCV;
+ const char *configstring = (const char *)(uintptr_t)addr;
if (ENV_RAMSTAGE && prog_type(prog) == PROG_PAYLOAD) {
+ printk(BIOS_SPEW, "Config string: '%s'\n", configstring);
initVirtualMemory();
printk(BIOS_SPEW, "OK, let's go\n");
- riscvpayload(doit);
+ riscvpayload(configstring, doit);
}
doit(prog_entry_arg(prog));
diff --git a/src/arch/riscv/payload.S b/src/arch/riscv/payload.S
index 3261a80..e50a589 100644
--- a/src/arch/riscv/payload.S
+++ b/src/arch/riscv/payload.S
@@ -11,10 +11,12 @@
* GNU General Public License for more details.
*/
+// "return" to a payload pointed to by a1 with
+// a pointer to the config string in a0.
.global riscvpayload
riscvpayload:
/* Jump to a0 in S-mode */
- mv t0,a0
+ mv t0,a1
csrw mepc, t0
csrr t0, mstatus
li t1, ~(3<<11)
the following patch was just integrated into master:
commit 99f2f113ec397dd042dcaa23c47123f3def19ebc
Author: Jonathan Neuschäfer <j.neuschaefer(a)gmx.net>
Date: Fri Oct 28 00:25:02 2016 +0200
riscv: Unify SBI call implementations under arch/riscv/
Note that currently, traps are only handled by the trap handler
installed in the bootblock. The romstage and ramstage don't override it.
TEST=Booted emulation/spike-qemu and lowrisc/nexys4ddr with a linux
payload. It worked as much as before (Linux didn't boot, but it
made some successful SBI calls)
Change-Id: Icce96ab3f41ae0f34bd86e30f9ff17c30317854e
Signed-off-by: Jonathan Neuschäfer <j.neuschaefer(a)gmx.net>
Reviewed-on: https://review.coreboot.org/17057
Tested-by: build bot (Jenkins)
Reviewed-by: Martin Roth <martinroth(a)google.com>
Reviewed-by: Ronald G. Minnich <rminnich(a)gmail.com>
See https://review.coreboot.org/17057 for details.
-gerrit