Skip to contentSkip to conversation

Add code to read in the coreboot tables and fill in memory info.

PATCH Superseded Gabe Black 4 participants 14 messages Nov 30, 2011 – Jan 8, 2012 x86

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Gabe Black

author
#0 lore raw

cover Add code to read in the coreboot tables and fill in memory info.

These changes add code which reads in the coreboot tables exported by coreboot and puts the info into a single structure for easy access. It also adds some code which uses that info to fill in an e820 table.

Gabe Black (4):
x86: Import code from coreboot's libpayload to parse the coreboot
table
x86: Determine the ram size using the coreboot tables
x86: Force the lib_sysinfo structure to be in the .data section
x86: Add infrastructure to extract an e820 table from the coreboot
tables

 arch/x86/cpu/coreboot/Makefile                |    3 +
 arch/x86/cpu/coreboot/ipchecksum.c            |   54 ++++++
 arch/x86/cpu/coreboot/sdram.c                 |   38 ++++-
 arch/x86/cpu/coreboot/sysinfo.c               |   39 ++++
 arch/x86/cpu/coreboot/tables.c                |  183 +++++++++++++++++++
 arch/x86/include/asm/ic/coreboot/ipchecksum.h |   37 ++++
 arch/x86/include/asm/ic/coreboot/sysinfo.h    |   64 +++++++
 arch/x86/include/asm/ic/coreboot/tables.h     |  241 +++++++++++++++++++++++++
 arch/x86/include/asm/zimage.h                 |    5 +
 arch/x86/lib/zimage.c                         |   10 +
 board/chromebook-x86/coreboot/coreboot.c      |   10 +
 11 files changed, 683 insertions(+), 1 deletions(-)
 create mode 100644 arch/x86/cpu/coreboot/ipchecksum.c
 create mode 100644 arch/x86/cpu/coreboot/sysinfo.c
 create mode 100644 arch/x86/cpu/coreboot/tables.c
 create mode 100644 arch/x86/include/asm/ic/coreboot/ipchecksum.h
 create mode 100644 arch/x86/include/asm/ic/coreboot/sysinfo.h
 create mode 100644 arch/x86/include/asm/ic/coreboot/tables.h
Signature · 1 line
1.7.3.1
author
#1 lore raw

PATCH 1/4 x86: Import code from coreboot's libpayload to parse the coreboot table

---
 arch/x86/cpu/coreboot/Makefile                |    3 +
 arch/x86/cpu/coreboot/ipchecksum.c            |   54 ++++++
 arch/x86/cpu/coreboot/sysinfo.c               |   33 ++++
 arch/x86/cpu/coreboot/tables.c                |  183 +++++++++++++++++++
 arch/x86/include/asm/ic/coreboot/ipchecksum.h |   37 ++++
 arch/x86/include/asm/ic/coreboot/sysinfo.h    |   64 +++++++
 arch/x86/include/asm/ic/coreboot/tables.h     |  241 +++++++++++++++++++++++++
 board/chromebook-x86/coreboot/coreboot.c      |   10 +
 8 files changed, 625 insertions(+), 0 deletions(-)
 create mode 100644 arch/x86/cpu/coreboot/ipchecksum.c
 create mode 100644 arch/x86/cpu/coreboot/sysinfo.c
 create mode 100644 arch/x86/cpu/coreboot/tables.c
 create mode 100644 arch/x86/include/asm/ic/coreboot/ipchecksum.h
 create mode 100644 arch/x86/include/asm/ic/coreboot/sysinfo.h
 create mode 100644 arch/x86/include/asm/ic/coreboot/tables.h
arch/x86/cpu/coreboot/Makefile +3 -0
index 0444399..13f5f8a 100644
@@ -33,7 +33,10 @@ include $(TOPDIR)/config.mk
 
 LIB	:= $(obj)lib$(SOC).o
 
+COBJS-$(CONFIG_SYS_COREBOOT) += tables.o
+COBJS-$(CONFIG_SYS_COREBOOT) += ipchecksum.o
 COBJS-$(CONFIG_SYS_COREBOOT) += sdram.o
+COBJS-$(CONFIG_SYS_COREBOOT) += sysinfo.o
 
 SOBJS-$(CONFIG_SYS_COREBOOT) += coreboot_car.o
 
arch/x86/cpu/coreboot/ipchecksum.c new file +54 -0

54 lines not on this page · raw message

arch/x86/cpu/coreboot/sysinfo.c new file +33 -0
new file mode 100644
index 0000000..464f8a1
@@ -0,0 +1,33 @@
+/*
+ * This file is part of the libpayload project.
+ *
+ * Copyright (C) 2008 Advanced Micro Devices, Inc.
+ * Copyright (C) 2009 coresystems GmbH
+ *
+ * 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. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <asm/ic/coreboot/sysinfo.h>
+
+struct sysinfo_t lib_sysinfo;
arch/x86/cpu/coreboot/tables.c new file +183 -0

183 lines not on this page · raw message

arch/x86/include/asm/ic/coreboot/ipchecksum.h new file +37 -0
new file mode 100644
index 0000000..1d73b4d
@@ -0,0 +1,37 @@
+/*
+ * This file is part of the libpayload project.
+ *
+ * It has originally been taken from the FreeBSD project.
+ *
+ * Copyright (c) 2001 Charles Mott <[email protected]>
+ * Copyright (c) 2008 coresystems GmbH
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _COREBOOT_IPCHECKSUM_H
+#define _COREBOOT_IPCHECKSUM_H
+
+unsigned short ipchksum(const void *vptr, unsigned long nbytes);
+
+#endif
arch/x86/include/asm/ic/coreboot/sysinfo.h new file +64 -0

64 lines not on this page · raw message

arch/x86/include/asm/ic/coreboot/tables.h new file +241 -0

241 lines not on this page · raw message

board/chromebook-x86/coreboot/coreboot.c +10 -0
index 44c6f15..a2d6ef5 100644
@@ -26,6 +26,8 @@
 #include <asm/u-boot-x86.h>
 #include <flash.h>
 #include <netdev.h>
+#include <asm/ic/coreboot/tables.h>
+#include <asm/ic/coreboot/sysinfo.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -34,6 +36,14 @@ unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN;
 /*
  * Miscellaneous platform dependent initializations
  */
+int cpu_init_f(void)
+{
+	int ret = get_coreboot_info(&lib_sysinfo);
+	if (ret != 0)
+		printf("Failed to parse coreboot tables.\n");
+	return ret;
+}
+
 int board_early_init_f(void)
 {
 	return 0;
Signature · 1 line
1.7.3.1
#2 lore raw

PATCH 1/4 x86: Import code from coreboot's libpayload to parse the coreboot table

Hi Gabe,

Quoted 9 lines · Gabe Black
---
 arch/x86/cpu/coreboot/Makefile                |    3 +
 arch/x86/cpu/coreboot/ipchecksum.c            |   54 ++++++
 arch/x86/cpu/coreboot/sysinfo.c               |   33 ++++
 arch/x86/cpu/coreboot/tables.c                |  183 +++++++++++++++++++
 arch/x86/include/asm/ic/coreboot/ipchecksum.h |   37 ++++
 arch/x86/include/asm/ic/coreboot/sysinfo.h    |   64 +++++++
 arch/x86/include/asm/ic/coreboot/tables.h     |  241 +++++++++++++++++++++++++

Please move these to arch/x86/include/asm/arch-coreboot/

Quoted 9 lines
 board/chromebook-x86/coreboot/coreboot.c      |   10 +
 8 files changed, 625 insertions(+), 0 deletions(-)
 create mode 100644 arch/x86/cpu/coreboot/ipchecksum.c
 create mode 100644 arch/x86/cpu/coreboot/sysinfo.c
 create mode 100644 arch/x86/cpu/coreboot/tables.c
 create mode 100644 arch/x86/include/asm/ic/coreboot/ipchecksum.h
 create mode 100644 arch/x86/include/asm/ic/coreboot/sysinfo.h
 create mode 100644 arch/x86/include/asm/ic/coreboot/tables.h

Regards,

Graeme

author
#3 lore raw

PATCH 2/4 x86: Determine the ram size using the coreboot tables

In reply to Gabe Black

This is really only an approximation using the largest RAM address available in the tables. There may be areas which are marked as reserved which are actually at the end of RAM.

---
 arch/x86/cpu/coreboot/sdram.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)
arch/x86/cpu/coreboot/sdram.c +17 -1
index b56085a..b5b086b 100644
@@ -24,12 +24,28 @@
 
 #include <common.h>
 #include <asm/u-boot-x86.h>
+#include <asm/global_data.h>
+#include <asm/ic/coreboot/sysinfo.h>
+#include <asm/ic/coreboot/tables.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
 int dram_init_f(void)
 {
-	gd->ram_size = 64*1024*1024;
+	int i;
+	phys_size_t ram_size = 0;
+	for (i = 0; i < lib_sysinfo.n_memranges; i++) {
+		unsigned long long end = \
+			lib_sysinfo.memrange[i].base +
+			lib_sysinfo.memrange[i].size;
+		if (lib_sysinfo.memrange[i].type == CB_MEM_RAM &&
+			end > ram_size) {
+			ram_size = end;
+		}
+	}
+	gd->ram_size = ram_size;
+	if (ram_size == 0)
+		return -1;
 	return 0;
 }
 
Signature · 1 line
1.7.3.1
author
#4 lore raw

PATCH 3/4 x86: Force the lib_sysinfo structure to be in the .data section

In reply to Gabe Black

Otherwise it ends up in the .bss section. U-boot assumes that it doesn't need to copy it over during relocation, and instead fills that whole section with zeroes. If we really were booting from ROM that would be appropriate, but we need some information from the coreboot tables (memory size) before then and have to fill that structure before relocation. We skirt u-boot's assumption by putting this in .data where it assumes there is still read only but non-zero data.

---
 arch/x86/cpu/coreboot/sysinfo.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
arch/x86/cpu/coreboot/sysinfo.c +7 -1
index 464f8a1..e74fe0a 100644
@@ -30,4 +30,10 @@
 
 #include <asm/ic/coreboot/sysinfo.h>
 
-struct sysinfo_t lib_sysinfo;
+/*
+ * This needs to be in the .data section so that it's copied over during
+ * relocation. By default it's put in the .bss section which is simply filled
+ * with zeroes when transitioning from "ROM", which is really RAM, to other
+ * RAM.
+ */
+struct sysinfo_t lib_sysinfo __attribute__((section(".data")));
Signature · 1 line
1.7.3.1
#5 lore raw

PATCH 3/4 x86: Force the lib_sysinfo structure to be in the .data section

Hi Gabe,

Quoted 19 lines · Gabe Black

Otherwise it ends up in the .bss section. U-boot assumes that it doesn't need to copy it over during relocation, and instead fills that whole section with zeroes. If we really were booting from ROM that would be appropriate, but we need some information from the coreboot tables (memory size) before then and have to fill that structure before relocation. We skirt u-boot's assumption by putting this in .data where it assumes there is still read only but non-zero data.

---
 arch/x86/cpu/coreboot/sysinfo.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
arch/x86/cpu/coreboot/sysinfo.c +0 -0
index 464f8a1..e74fe0a 100644
@@ -30,4 +30,10 @@
 

arch/x86/cpu/coreboot/sysinfo.c line 39

Quoted 10 lines
arch/x86/cpu/coreboot/sysinfo.c +7 -1
 #include <asm/ic/coreboot/sysinfo.h>
 
-struct sysinfo_t lib_sysinfo;
+/*
+ * This needs to be in the .data section so that it's copied over during
+ * relocation. By default it's put in the .bss section which is simply filled
+ * with zeroes when transitioning from "ROM", which is really RAM, to other
+ * RAM.
+ */
+struct sysinfo_t lib_sysinfo __attribute__((section(".data")));

I think this can be logically folded into the first patch

Regards,

Graeme

#6 lore raw

PATCH 3/4 x86: Force the lib_sysinfo structure to be in the .data section

Quoted 37 lines · Graeme Russ

Hi Gabe,

Quoted 4 lines · Gabe Black

Otherwise it ends up in the .bss section. U-boot assumes that it doesn't need to copy it over during relocation, and instead fills that whole section with zeroes. If we really were booting from ROM that would be appropriate, but we need some information from the coreboot tables

(memory

Review

Quoted 10 lines

size) before then and have to fill that structure before relocation. We skirt u-boot's assumption by putting this in .data where it assumes there is still read only but non-zero data.

---
 arch/x86/cpu/coreboot/sysinfo.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
(quoted diff) +0 -0

b/arch/x86/cpu/coreboot/sysinfo.c

arch/x86/cpu/coreboot/sysinfo.c line 35

Quoted 11 lines

index 464f8a1..e74fe0a 100644

arch/x86/cpu/coreboot/sysinfo.c +3 -1
@@ -30,4 +30,10 @@
 
 #include <asm/ic/coreboot/sysinfo.h>
 
-struct sysinfo_t lib_sysinfo;
+/*
+ * This needs to be in the .data section so that it's copied over during
+ * relocation. By default it's put in the .bss section which is simply

filled

arch/x86/cpu/coreboot/sysinfo.c line 36

Quoted 1 line
arch/x86/cpu/coreboot/sysinfo.c +1 -0
+ * with zeroes when transitioning from "ROM", which is really RAM, to

other

arch/x86/cpu/coreboot/sysinfo.c line 39

Quoted 3 lines
arch/x86/cpu/coreboot/sysinfo.c +3 -0
+ * RAM.
+ */
+struct sysinfo_t lib_sysinfo __attribute__((section(".data")));
Quoted 6 lines

I think this can be logically folded into the first patch

Regards,

Graeme

I would rather not do that since the first patch is, modulo checkpatch and build fixes, just importing that code from coreboot's libpayload. This change is making an important, non-obvious change which makes it work properly within u-boot. These are two different things, and one way or the other this one is important enough to be singled out as its own change and not lost in the midst of the other.

Gabe

#7 lore raw

PATCH 3/4 x86: Force the lib_sysinfo structure to be in the .data section

Hi Gabe,

Quoted 50 lines · Gabe Black

On Fri, Dec 2, 2011 at 1:10 PM, Graeme Russ <[email protected] <mailto:[email protected]>> wrote:

    Hi Gabe,

    On 30/11/11 17:07, Gabe Black wrote:
    > Otherwise it ends up in the .bss section. U-boot assumes that it doesn't
    > need to copy it over during relocation, and instead fills that whole
    > section with zeroes. If we really were booting from ROM that would be
    > appropriate, but we need some information from the coreboot tables
    (memory
    > size) before then and have to fill that structure before relocation. We
    > skirt u-boot's assumption by putting this in .data where it assumes there
    > is still read only but non-zero data.
    >
    > Signed-off-by: Gabe Black <[email protected]
    <mailto:[email protected]>>
    > ---
    >  arch/x86/cpu/coreboot/sysinfo.c |    8 +++++++-
    >  1 files changed, 7 insertions(+), 1 deletions(-)
    >
    > diff --git a/arch/x86/cpu/coreboot/sysinfo.c
    b/arch/x86/cpu/coreboot/sysinfo.c
    > index 464f8a1..e74fe0a 100644
    > --- a/arch/x86/cpu/coreboot/sysinfo.c
    > +++ b/arch/x86/cpu/coreboot/sysinfo.c
    > @@ -30,4 +30,10 @@
    >
    >  #include <asm/ic/coreboot/sysinfo.h>
    >
    > -struct sysinfo_t lib_sysinfo;
    > +/*
    > + * This needs to be in the .data section so that it's copied over during
    > + * relocation. By default it's put in the .bss section which is
    simply filled
    > + * with zeroes when transitioning from "ROM", which is really RAM,
    to other
    > + * RAM.
    > + */
    > +struct sysinfo_t lib_sysinfo __attribute__((section(".data")));

    I think this can be logically folded into the first patch

    Regards,

    Graeme
Quoted 6 lines

I would rather not do that since the first patch is, modulo checkpatch and build fixes, just importing that code from coreboot's libpayload. This change is making an important, non-obvious change which makes it work properly within u-boot. These are two different things, and one way or the other this one is important enough to be singled out as its own change and not lost in the midst of the other.

I agree that is a logical position to take, however I think that the fact that you introduce a commit which is known to be 'broken' is the overriding factor - Include to fact that the modification is made in the commit message and the comment like:

/*
* Note: U-Boot needs this to be in the .data section so....
* ...
*/

Also, can you supply any specific commit id(s) for the originating source - We typically try to include as much canonical information to identify the source to a particular commit

Regards,

Graeme

author
#8 lore raw

PATCH 3/4 x86: Force the lib_sysinfo structure to be in the .data section

Quoted 79 lines · Graeme Russ

Hi Gabe,

Quoted 9 lines · Gabe Black

On Fri, Dec 2, 2011 at 1:10 PM, Graeme Russ <[email protected] <mailto:[email protected]>> wrote:

Hi Gabe,

On 30/11/11 17:07, Gabe Black wrote:
> Otherwise it ends up in the .bss section. U-boot assumes that it

doesn't

Quoted 1 line
Quoted 1 line

need to copy it over during relocation, and instead fills that

whole

Quoted 1 line
Quoted 1 line

section with zeroes. If we really were booting from ROM that would

be

Quoted 3 lines
Quoted 1 line

appropriate, but we need some information from the coreboot tables

(memory
> size) before then and have to fill that structure before

relocation. We

Quoted 1 line
Quoted 1 line

skirt u-boot's assumption by putting this in .data where it

assumes there

Quoted 12 lines
Quoted 3 lines

is still read only but non-zero data.

    <mailto:[email protected]>>
    > ---
    >  arch/x86/cpu/coreboot/sysinfo.c |    8 +++++++-
    >  1 files changed, 7 insertions(+), 1 deletions(-)
    >
    > diff --git a/arch/x86/cpu/coreboot/sysinfo.c
    b/arch/x86/cpu/coreboot/sysinfo.c
    > index 464f8a1..e74fe0a 100644
    > --- a/arch/x86/cpu/coreboot/sysinfo.c
Quoted 8 lines
    > +++ b/arch/x86/cpu/coreboot/sysinfo.c
    > @@ -30,4 +30,10 @@
    >
    >  #include <asm/ic/coreboot/sysinfo.h>
    >
    > -struct sysinfo_t lib_sysinfo;
    > +/*
    > + * This needs to be in the .data section so that it's copied over

during

Quoted 15 lines
Quoted 1 line

+ * relocation. By default it's put in the .bss section which is

    simply filled
    > + * with zeroes when transitioning from "ROM", which is really RAM,
    to other
    > + * RAM.
    > + */
    > +struct sysinfo_t lib_sysinfo __attribute__((section(".data")));

    I think this can be logically folded into the first patch

    Regards,

    Graeme
Quoted 1 line

I would rather not do that since the first patch is, modulo checkpatch

and

Quoted 3 lines

build fixes, just importing that code from coreboot's libpayload. This change is making an important, non-obvious change which makes it work properly within u-boot. These are two different things, and one way or

the

Quoted 1 line

other this one is important enough to be singled out as its own change

and

Quoted 1 line

not lost in the midst of the other.

I agree that is a logical position to take, however I think that the fact that you introduce a commit which is known to be 'broken' is the overriding factor - Include to fact that the modification is made in the commit message and the comment like:

/*
* Note: U-Boot needs this to be in the .data section so....
* ...
*/

Quoted 8 lines

Also, can you supply any specific commit id(s) for the originating source - We typically try to include as much canonical information to identify the source to a particular commit

Regards,

Graeme

These commits were originally put together many months ago, so the exact version of the original source is lost.

#9 lore raw

PATCH 3/4 x86: Force the lib_sysinfo structure to be in the .data section

In reply to Gabe Black
Quoted 1 line · On Wednesday 30 November 2011 01:07:54 Gabe Black wrote:

+struct sysinfo_t lib_sysinfo __attribute__((section(".data")));

seems like it should be .data.lib_sysinfo

or maybe pick a field you always init and set it to something non-zero.

struct sysinfo_t lib_sysinfo = {
	/* force into .data */
	.cpu_khz = 1,
};

-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120108/ab4a754a/attachment.pgp>

author
#10 lore raw

PATCH 4/4 x86: Add infrastructure to extract an e820 table from the coreboot tables

In reply to Gabe Black
---
 arch/x86/cpu/coreboot/sdram.c |   32 ++++++++++++++++++++++++++------
 arch/x86/include/asm/zimage.h |    5 +++++
 arch/x86/lib/zimage.c         |   10 ++++++++++
 3 files changed, 41 insertions(+), 6 deletions(-)
arch/x86/cpu/coreboot/sdram.c +26 -6
index b5b086b..ce73467 100644
@@ -23,6 +23,8 @@
  */
 
 #include <common.h>
+#include <malloc.h>
+#include <asm/e820.h>
 #include <asm/u-boot-x86.h>
 #include <asm/global_data.h>
 #include <asm/ic/coreboot/sysinfo.h>
@@ -30,18 +32,36 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+unsigned install_e820_map(unsigned max_entries, struct e820entry *entries)
+{
+	int i;
+
+	unsigned num_entries = min(lib_sysinfo.n_memranges, max_entries);
+	if (num_entries < lib_sysinfo.n_memranges) {
+		printf("Warning: Limiting e820 map to %d entries.\n",
+			num_entries);
+	}
+	for (i = 0; i < num_entries; i++) {
+		struct memrange *memrange = &lib_sysinfo.memrange[i];
+
+		entries[i].addr = memrange->base;
+		entries[i].size = memrange->size;
+		entries[i].type = memrange->type;
+	}
+	return num_entries;
+}
+
 int dram_init_f(void)
 {
 	int i;
 	phys_size_t ram_size = 0;
+
 	for (i = 0; i < lib_sysinfo.n_memranges; i++) {
-		unsigned long long end = \
-			lib_sysinfo.memrange[i].base +
-			lib_sysinfo.memrange[i].size;
-		if (lib_sysinfo.memrange[i].type == CB_MEM_RAM &&
-			end > ram_size) {
+		struct memrange *memrange = &lib_sysinfo.memrange[i];
+		unsigned long long end = memrange->base + memrange->size;
+
+		if (memrange->type == CB_MEM_RAM && end > ram_size)
 			ram_size = end;
-		}
 	}
 	gd->ram_size = ram_size;
 	if (ram_size == 0)
arch/x86/include/asm/zimage.h +5 -0
index a02637f..b172048 100644
@@ -24,6 +24,8 @@
 #ifndef _ASM_ZIMAGE_H_
 #define _ASM_ZIMAGE_H_
 
+#include <asm/e820.h>
+
 /* linux i386 zImage/bzImage header. Offsets relative to
  * the start of the image */
 
@@ -65,6 +67,9 @@
 #define BZIMAGE_LOAD_ADDR  0x100000
 #define ZIMAGE_LOAD_ADDR   0x10000
 
+/* Implementation defined function to install an e820 map. */
+unsigned install_e820_map(unsigned max_entries, struct e820entry *);
+
 void *load_zimage(char *image, unsigned long kernel_size,
 		  unsigned long initrd_addr, unsigned long initrd_size,
 		  int auto_boot);
arch/x86/lib/zimage.c +10 -0
index 6843ff6..1fde13f 100644
@@ -51,6 +51,16 @@
 
 #define COMMAND_LINE_SIZE	2048
 
+unsigned generic_install_e820_map(unsigned max_entries,
+				  struct e820entry *entries)
+{
+	return 0;
+}
+
+unsigned install_e820_map(unsigned max_entries,
+			  struct e820entry *entries)
+	__attribute__((weak, alias("generic_install_e820_map")));
+
 static void build_command_line(char *command_line, int auto_boot)
 {
 	char *env_command_line;
Signature · 1 line
1.7.3.1
#11 lore raw

PATCH 4/4 x86: Add infrastructure to extract an e820 table from the coreboot tables

Hi Gabe,

Quoted 53 lines · Gabe Black
---
 arch/x86/cpu/coreboot/sdram.c |   32 ++++++++++++++++++++++++++------
 arch/x86/include/asm/zimage.h |    5 +++++
 arch/x86/lib/zimage.c         |   10 ++++++++++
 3 files changed, 41 insertions(+), 6 deletions(-)
arch/x86/cpu/coreboot/sdram.c +22 -4
index b5b086b..ce73467 100644
@@ -23,6 +23,8 @@
  */
 
 #include <common.h>
+#include <malloc.h>
+#include <asm/e820.h>
 #include <asm/u-boot-x86.h>
 #include <asm/global_data.h>
 #include <asm/ic/coreboot/sysinfo.h>
@@ -30,18 +32,36 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+unsigned install_e820_map(unsigned max_entries, struct e820entry *entries)
+{
+	int i;
+
+	unsigned num_entries = min(lib_sysinfo.n_memranges, max_entries);
+	if (num_entries < lib_sysinfo.n_memranges) {
+		printf("Warning: Limiting e820 map to %d entries.\n",
+			num_entries);
+	}
+	for (i = 0; i < num_entries; i++) {
+		struct memrange *memrange = &lib_sysinfo.memrange[i];
+
+		entries[i].addr = memrange->base;
+		entries[i].size = memrange->size;
+		entries[i].type = memrange->type;
+	}
+	return num_entries;
+}
+
 int dram_init_f(void)
 {
 	int i;
 	phys_size_t ram_size = 0;
+
 	for (i = 0; i < lib_sysinfo.n_memranges; i++) {
-		unsigned long long end = \
-			lib_sysinfo.memrange[i].base +
-			lib_sysinfo.memrange[i].size;
-		if (lib_sysinfo.memrange[i].type == CB_MEM_RAM &&

arch/x86/cpu/coreboot/sdram.c line 67

Quoted 10 lines
arch/x86/cpu/coreboot/sdram.c +4 -2
-			end > ram_size) {
+		struct memrange *memrange = &lib_sysinfo.memrange[i];
+		unsigned long long end = memrange->base + memrange->size;
+
+		if (memrange->type == CB_MEM_RAM && end > ram_size)
 			ram_size = end;
-		}
 	}
 	gd->ram_size = ram_size;
 	if (ram_size == 0)

Please fold these changes to dram_init_f() into the second patch

Quoted 34 lines
arch/x86/include/asm/zimage.h +5 -0
index a02637f..b172048 100644
@@ -24,6 +24,8 @@
 #ifndef _ASM_ZIMAGE_H_
 #define _ASM_ZIMAGE_H_
 
+#include <asm/e820.h>
+
 /* linux i386 zImage/bzImage header. Offsets relative to
  * the start of the image */
 
@@ -65,6 +67,9 @@
 #define BZIMAGE_LOAD_ADDR  0x100000
 #define ZIMAGE_LOAD_ADDR   0x10000
 
+/* Implementation defined function to install an e820 map. */
+unsigned install_e820_map(unsigned max_entries, struct e820entry *);
+
 void *load_zimage(char *image, unsigned long kernel_size,
 		  unsigned long initrd_addr, unsigned long initrd_size,
 		  int auto_boot);
arch/x86/lib/zimage.c +3 -0
index 6843ff6..1fde13f 100644
@@ -51,6 +51,16 @@
 
 #define COMMAND_LINE_SIZE	2048
 
+unsigned generic_install_e820_map(unsigned max_entries,
+				  struct e820entry *entries)
+{

arch/x86/lib/zimage.c line 66

Quoted 10 lines
arch/x86/lib/zimage.c +7 -0
+	return 0;
+}
+
+unsigned install_e820_map(unsigned max_entries,
+			  struct e820entry *entries)
+	__attribute__((weak, alias("generic_install_e820_map")));
+
 static void build_command_line(char *command_line, int auto_boot)
 {
 	char *env_command_line;

I think all of the e820 code can be moved into your 32-bit boot protocol patch series

Regards,

Graeme

author
#12 lore raw

PATCH 4/4 x86: Add infrastructure to extract an e820 table from the coreboot tables

Quoted 120 lines · Graeme Russ

Hi Gabe,

Review

Quoted 8 lines · Gabe Black
---
 arch/x86/cpu/coreboot/sdram.c |   32 ++++++++++++++++++++++++++------
 arch/x86/include/asm/zimage.h |    5 +++++
 arch/x86/lib/zimage.c         |   10 ++++++++++
 3 files changed, 41 insertions(+), 6 deletions(-)
(quoted diff) +0 -0

b/arch/x86/cpu/coreboot/sdram.c

Quoted 13 lines

index b5b086b..ce73467 100644

arch/x86/cpu/coreboot/sdram.c +2 -0
@@ -23,6 +23,8 @@
  */
 
 #include <common.h>
+#include <malloc.h>
+#include <asm/e820.h>
 #include <asm/u-boot-x86.h>
 #include <asm/global_data.h>
 #include <asm/ic/coreboot/sysinfo.h>

arch/x86/cpu/coreboot/sdram.c line 35

Quoted 4 lines
arch/x86/cpu/coreboot/sdram.c +1 -0
@@ -30,18 +32,36 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+unsigned install_e820_map(unsigned max_entries, struct e820entry

*entries)

Quoted 28 lines
arch/x86/cpu/coreboot/sdram.c +19 -4
+{
+     int i;
+
+     unsigned num_entries = min(lib_sysinfo.n_memranges, max_entries);
+     if (num_entries < lib_sysinfo.n_memranges) {
+             printf("Warning: Limiting e820 map to %d entries.\n",
+                     num_entries);
+     }
+     for (i = 0; i < num_entries; i++) {
+             struct memrange *memrange = &lib_sysinfo.memrange[i];
+
+             entries[i].addr = memrange->base;
+             entries[i].size = memrange->size;
+             entries[i].type = memrange->type;
+     }
+     return num_entries;
+}
+
 int dram_init_f(void)
 {
      int i;
      phys_size_t ram_size = 0;
+
      for (i = 0; i < lib_sysinfo.n_memranges; i++) {
-             unsigned long long end = \
-                     lib_sysinfo.memrange[i].base +
-                     lib_sysinfo.memrange[i].size;
-             if (lib_sysinfo.memrange[i].type == CB_MEM_RAM &&

arch/x86/cpu/coreboot/sdram.c line 67

Quoted 10 lines
arch/x86/cpu/coreboot/sdram.c +4 -2
-                     end > ram_size) {
+             struct memrange *memrange = &lib_sysinfo.memrange[i];
+             unsigned long long end = memrange->base + memrange->size;
+
+             if (memrange->type == CB_MEM_RAM && end > ram_size)
                      ram_size = end;
-             }
      }
      gd->ram_size = ram_size;
      if (ram_size == 0)

Please fold these changes to dram_init_f() into the second patch

Review

Quoted 1 line
(quoted diff) +0 -0

b/arch/x86/include/asm/zimage.h

Quoted 33 lines

index a02637f..b172048 100644

arch/x86/include/asm/zimage.h +5 -0
@@ -24,6 +24,8 @@
 #ifndef _ASM_ZIMAGE_H_
 #define _ASM_ZIMAGE_H_
 
+#include <asm/e820.h>
+
 /* linux i386 zImage/bzImage header. Offsets relative to
  * the start of the image */
 
@@ -65,6 +67,9 @@
 #define BZIMAGE_LOAD_ADDR  0x100000
 #define ZIMAGE_LOAD_ADDR   0x10000
 
+/* Implementation defined function to install an e820 map. */
+unsigned install_e820_map(unsigned max_entries, struct e820entry *);
+
 void *load_zimage(char *image, unsigned long kernel_size,
                unsigned long initrd_addr, unsigned long initrd_size,
                int auto_boot);
arch/x86/lib/zimage.c +3 -0
index 6843ff6..1fde13f 100644
@@ -51,6 +51,16 @@
 
 #define COMMAND_LINE_SIZE    2048
 
+unsigned generic_install_e820_map(unsigned max_entries,
+                               struct e820entry *entries)
+{

arch/x86/lib/zimage.c line 66

Quoted 10 lines
arch/x86/lib/zimage.c +7 -0
+     return 0;
+}
+
+unsigned install_e820_map(unsigned max_entries,
+                       struct e820entry *entries)
+     __attribute__((weak, alias("generic_install_e820_map")));
+
 static void build_command_line(char *command_line, int auto_boot)
 {
      char *env_command_line;

I think all of the e820 code can be moved into your 32-bit boot protocol patch series

Quoted 4 lines

Regards,

Graeme

The changes which gather e820 information from the coreboot tables don't really have anything specifically to do with the zboot command. The e820 information could be gathered another way (or generated on the spot like you're doing) and the e820 info could be consumed by something else like the bootm command. They are not a single logical change and should not be merged.

Gabe

#13 lore raw

PATCH 4/4 x86: Add infrastructure to extract an e820 table from the coreboot tables

Hi Gabe,

Quoted 132 lines · Gabe Black

On Fri, Dec 2, 2011 at 1:14 PM, Graeme Russ <[email protected] <mailto:[email protected]>> wrote:

    Hi Gabe,

    On 30/11/11 17:07, Gabe Black wrote:
    > Signed-off-by: Gabe Black <[email protected]
    <mailto:[email protected]>>
    > ---
    >  arch/x86/cpu/coreboot/sdram.c |   32 ++++++++++++++++++++++++++------
    >  arch/x86/include/asm/zimage.h |    5 +++++
    >  arch/x86/lib/zimage.c         |   10 ++++++++++
    >  3 files changed, 41 insertions(+), 6 deletions(-)
    >
    > diff --git a/arch/x86/cpu/coreboot/sdram.c
    b/arch/x86/cpu/coreboot/sdram.c
    > index b5b086b..ce73467 100644
    > --- a/arch/x86/cpu/coreboot/sdram.c
    > +++ b/arch/x86/cpu/coreboot/sdram.c
    > @@ -23,6 +23,8 @@
    >   */
    >
    >  #include <common.h>
    > +#include <malloc.h>
    > +#include <asm/e820.h>
    >  #include <asm/u-boot-x86.h>
    >  #include <asm/global_data.h>
    >  #include <asm/ic/coreboot/sysinfo.h>
    > @@ -30,18 +32,36 @@
    >
    >  DECLARE_GLOBAL_DATA_PTR;
    >
    > +unsigned install_e820_map(unsigned max_entries, struct e820entry
    *entries)
    > +{
    > +     int i;
    > +
    > +     unsigned num_entries = min(lib_sysinfo.n_memranges, max_entries);
    > +     if (num_entries < lib_sysinfo.n_memranges) {
    > +             printf("Warning: Limiting e820 map to %d entries.\n",
    > +                     num_entries);
    > +     }
    > +     for (i = 0; i < num_entries; i++) {
    > +             struct memrange *memrange = &lib_sysinfo.memrange[i];
    > +
    > +             entries[i].addr = memrange->base;
    > +             entries[i].size = memrange->size;
    > +             entries[i].type = memrange->type;
    > +     }
    > +     return num_entries;
    > +}
    > +
    >  int dram_init_f(void)
    >  {
    >       int i;
    >       phys_size_t ram_size = 0;
    > +
    >       for (i = 0; i < lib_sysinfo.n_memranges; i++) {
    > -             unsigned long long end = \
    > -                     lib_sysinfo.memrange[i].base +
    > -                     lib_sysinfo.memrange[i].size;
    > -             if (lib_sysinfo.memrange[i].type == CB_MEM_RAM &&
    > -                     end > ram_size) {
    > +             struct memrange *memrange = &lib_sysinfo.memrange[i];
    > +             unsigned long long end = memrange->base + memrange->size;
    > +
    > +             if (memrange->type == CB_MEM_RAM && end > ram_size)
    >                       ram_size = end;
    > -             }
    >       }
    >       gd->ram_size = ram_size;
    >       if (ram_size == 0)

    Please fold these changes to dram_init_f() into the second patch

    > diff --git a/arch/x86/include/asm/zimage.h
    b/arch/x86/include/asm/zimage.h
    > index a02637f..b172048 100644
    > --- a/arch/x86/include/asm/zimage.h
    > +++ b/arch/x86/include/asm/zimage.h
    > @@ -24,6 +24,8 @@
    >  #ifndef _ASM_ZIMAGE_H_
    >  #define _ASM_ZIMAGE_H_
    >
    > +#include <asm/e820.h>
    > +
    >  /* linux i386 zImage/bzImage header. Offsets relative to
    >   * the start of the image */
    >
    > @@ -65,6 +67,9 @@
    >  #define BZIMAGE_LOAD_ADDR  0x100000
    >  #define ZIMAGE_LOAD_ADDR   0x10000
    >
    > +/* Implementation defined function to install an e820 map. */
    > +unsigned install_e820_map(unsigned max_entries, struct e820entry *);
    > +
    >  void *load_zimage(char *image, unsigned long kernel_size,
    >                 unsigned long initrd_addr, unsigned long initrd_size,
    >                 int auto_boot);
    > diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
    > index 6843ff6..1fde13f 100644
    > --- a/arch/x86/lib/zimage.c
    > +++ b/arch/x86/lib/zimage.c
    > @@ -51,6 +51,16 @@
    >
    >  #define COMMAND_LINE_SIZE    2048
    >
    > +unsigned generic_install_e820_map(unsigned max_entries,
    > +                               struct e820entry *entries)
    > +{
    > +     return 0;
    > +}
    > +
    > +unsigned install_e820_map(unsigned max_entries,
    > +                       struct e820entry *entries)
    > +     __attribute__((weak, alias("generic_install_e820_map")));
    > +
    >  static void build_command_line(char *command_line, int auto_boot)
    >  {
    >       char *env_command_line;

    I think all of the e820 code can be moved into your 32-bit boot protocol
    patch series

    Regards,

    Graeme
Quoted 6 lines

The changes which gather e820 information from the coreboot tables don't really have anything specifically to do with the zboot command. The e820 information could be gathered another way (or generated on the spot like you're doing) and the e820 info could be consumed by something else like the bootm command. They are not a single logical change and should not be merged.

Well to 32-bit boot protocol requires a function that fills out the e820 map which is what install_e820_map() does so, IMHO, they really belong together. Maybe we fold the two patch series together (git does not care for series of patches) as:

1) x86, coreboot: Import code from coreboot's libpayload to parse the coreboot table
2) x86, coreboot: Determine the ram size using the coreboot tables
3) x86: Clean up the x86 zimage code in preparation to extend it
4) x86: Add support for booting Linux using the 32 bit boot protocol
5) x86, coreboot: Populate e820 tables from coreboot tables
6) x86: Refactor the zboot innards so they can be reused with a vboot image
7) x86: Add support for specifying an initrd with the zboot command

4) would include adding the generic_install_e820_map() function
5) would add the coreboot specific implementation

Regards,

Graeme