eliminate "magic numbers", support 8mbyte single-image flash chips
Prior to this commit, ownerboot had quite a lot of "magic addresses" and flash chip layouts. This commit eliminates all of them. All flash chip geometry is now computed from first principles and two parameters: 1. The flash chip size 2. The number of images per chip (two means NORMAL/FALLBACK) If (flash-chip-size / num-images) is too small, coreboot's build process will notice this and fail. It should be possible to build a single-image (i.e. no FALLBACK) ownerboot for use on 8mbyte flash chips, which lets people try this out without having to buy a new flash chip or (in the case of the rk3399-gru-kevin laptop) doing any soldering.master
parent
c72e1a55be
commit
9dd5bdf298
@ -0,0 +1,212 @@
|
|||||||
|
From db4da17916cbeed002e4fa8422ed2cdd82b3b26f Mon Sep 17 00:00:00 2001
|
||||||
|
From: Your Name <you@example.com>
|
||||||
|
Date: Thu, 2 Dec 2021 23:39:00 -0800
|
||||||
|
Subject: [PATCH] use_fallback(): platform-independent part
|
||||||
|
|
||||||
|
This commit implements the platform-independent part of a two-image
|
||||||
|
fallback system.
|
||||||
|
|
||||||
|
The images are stored as separate FMAP regions, with each region
|
||||||
|
containing a complete CBFS structure. The names of the two FMAP
|
||||||
|
regions, NORMAL and FALLBACK, are hardcoded in
|
||||||
|
src/include/bootblock_common.h.
|
||||||
|
|
||||||
|
There is only one copy of the bootblock. Where it is kept is a
|
||||||
|
platform-specific matter.
|
||||||
|
|
||||||
|
The bootblock will call use_fallback(); if this function returns 0
|
||||||
|
then the NORMAL FMAP region is used for CBFS lookups. If it returns
|
||||||
|
1 then the FALLBACK FMAP region is used for CBFS lookups. The default
|
||||||
|
__weak implementation always returns 1.
|
||||||
|
|
||||||
|
Any CBFS accesses from romcc stages will always use the FALLBACK copy,
|
||||||
|
since the romcc version of the CBFS-walking routine does not
|
||||||
|
understand FMAP partitions. This means that the `cmos.layout` from
|
||||||
|
the FALLBACK region is used for the majority of the boot process.
|
||||||
|
---
|
||||||
|
Makefile.inc | 5 +++--
|
||||||
|
src/drivers/pc80/rtc/mc146818rtc.c | 9 +++++++--
|
||||||
|
src/include/bootblock_common.h | 4 ++++
|
||||||
|
src/lib/bootblock.c | 1 +
|
||||||
|
src/lib/cbfs.c | 9 +++++++--
|
||||||
|
src/lib/prog_loaders.c | 6 +++++-
|
||||||
|
util/cbfstool/cbfs_sections.h | 2 +-
|
||||||
|
util/scripts/dts-to-fmd.sh | 6 +++---
|
||||||
|
8 files changed, 31 insertions(+), 11 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/Makefile.inc b/Makefile.inc
|
||||||
|
index 44c58be5b78..fde7511ee82 100644
|
||||||
|
--- a/Makefile.inc
|
||||||
|
+++ b/Makefile.inc
|
||||||
|
@@ -727,7 +727,7 @@ extract_nth=$(subst *,$(spc),$(patsubst -%-,%,$(word $(1), $(subst |,- -,-$(2)-)
|
||||||
|
#
|
||||||
|
# This is the default implementation. When using a boot strategy employing
|
||||||
|
# multiple CBFSes in fmap regions, override it.
|
||||||
|
-regions-for-file ?= COREBOOT
|
||||||
|
+regions-for-file ?= FALLBACK
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_CBFS_AUTOGEN_ATTRIBUTES),y)
|
||||||
|
cbfs-autogen-attributes=-g
|
||||||
|
@@ -999,7 +999,7 @@ else # ifeq ($(CONFIG_ARCH_X86),y)
|
||||||
|
-b -4
|
||||||
|
rm -f $@.tmp.2
|
||||||
|
endif # ifeq ($(CONFIG_ARCH_X86),y)
|
||||||
|
- $(CBFSTOOL) $@.tmp add-master-header $(TS_OPTIONS)
|
||||||
|
+ $(CBFSTOOL) $@.tmp add-master-header -rFALLBACK $(TS_OPTIONS)
|
||||||
|
$(prebuild-files) true
|
||||||
|
mv $@.tmp $@
|
||||||
|
else # ifneq ($(CONFIG_UPDATE_IMAGE),y)
|
||||||
|
diff --git a/src/drivers/pc80/rtc/mc146818rtc.c b/src/drivers/pc80/rtc/mc146818rtc.c
|
||||||
|
index 3b22a46298b..ef1ef7a275b 100644
|
||||||
|
--- a/src/drivers/pc80/rtc/mc146818rtc.c
|
||||||
|
+++ b/src/drivers/pc80/rtc/mc146818rtc.c
|
||||||
|
@@ -250,9 +250,14 @@ static enum cb_err locate_cmos_layout(struct region_device *rdev)
|
||||||
|
* we have multiple CMOS layout files and to locate them we'd need to
|
||||||
|
* include VBOOT into SMM...
|
||||||
|
*
|
||||||
|
- * Support only one CMOS layout in the 'COREBOOT' region for now.
|
||||||
|
+ * Support only one CMOS layout in the 'NORMAL' region for now.
|
||||||
|
*/
|
||||||
|
- if (cbfs_locate_file_in_region(&fh, "COREBOOT", "cmos_layout.bin",
|
||||||
|
+ if (cbfs_locate_file_in_region(&fh,
|
||||||
|
+ // always use FALLBACK because we can't yet access the
|
||||||
|
+ // nvram in order to figure out which mode (normal/fallback)
|
||||||
|
+ // we are in.
|
||||||
|
+ "FALLBACK",
|
||||||
|
+ "cmos_layout.bin",
|
||||||
|
&cbfs_type)) {
|
||||||
|
printk(BIOS_ERR, "RTC: cmos_layout.bin could not be found. "
|
||||||
|
"Options are disabled\n");
|
||||||
|
diff --git a/src/include/bootblock_common.h b/src/include/bootblock_common.h
|
||||||
|
index 7af0cebe633..21a5efee901 100644
|
||||||
|
--- a/src/include/bootblock_common.h
|
||||||
|
+++ b/src/include/bootblock_common.h
|
||||||
|
@@ -21,6 +21,9 @@
|
||||||
|
#include <timestamp.h>
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
+#define FMAP_REGION_FALLBACK "FALLBACK"
|
||||||
|
+#define FMAP_REGION_NORMAL "FALLBACK"
|
||||||
|
+
|
||||||
|
/*
|
||||||
|
* These are defined as weak no-ops that can be overridden by mainboard/SoC.
|
||||||
|
* The 'early' variants are called prior to console initialization. Also, the
|
||||||
|
@@ -31,6 +34,7 @@ void bootblock_mainboard_early_init(void);
|
||||||
|
void bootblock_mainboard_init(void);
|
||||||
|
void bootblock_soc_early_init(void);
|
||||||
|
void bootblock_soc_init(void);
|
||||||
|
+int use_fallback(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* C code entry point for the boot block.
|
||||||
|
diff --git a/src/lib/bootblock.c b/src/lib/bootblock.c
|
||||||
|
index f2ada522eb5..890c19f3160 100644
|
||||||
|
--- a/src/lib/bootblock.c
|
||||||
|
+++ b/src/lib/bootblock.c
|
||||||
|
@@ -28,6 +28,7 @@ __weak void bootblock_mainboard_early_init(void) { /* no-op */ }
|
||||||
|
__weak void bootblock_soc_early_init(void) { /* do nothing */ }
|
||||||
|
__weak void bootblock_soc_init(void) { /* do nothing */ }
|
||||||
|
__weak void bootblock_mainboard_init(void) { /* do nothing */ }
|
||||||
|
+__weak int use_fallback(void) { /* always */ return 1; }
|
||||||
|
|
||||||
|
asmlinkage void bootblock_main_with_timestamp(uint64_t base_timestamp,
|
||||||
|
struct timestamp_entry *timestamps, size_t num_timestamps)
|
||||||
|
diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c
|
||||||
|
index a5c9f852386..076ff1a8a97 100644
|
||||||
|
--- a/src/lib/cbfs.c
|
||||||
|
+++ b/src/lib/cbfs.c
|
||||||
|
@@ -26,6 +26,7 @@
|
||||||
|
#include <timestamp.h>
|
||||||
|
#include <fmap.h>
|
||||||
|
#include "fmap_config.h"
|
||||||
|
+#include "bootblock_common.h"
|
||||||
|
|
||||||
|
#define ERROR(x...) printk(BIOS_ERR, "CBFS: " x)
|
||||||
|
#define LOG(x...) printk(BIOS_INFO, "CBFS: " x)
|
||||||
|
@@ -273,7 +274,7 @@ out:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
-/* This only supports the "COREBOOT" fmap region. */
|
||||||
|
+/* This now supports both the "NORMAL" and "FALLBACK" fmap regions. */
|
||||||
|
static int cbfs_master_header_props(struct cbfs_props *props)
|
||||||
|
{
|
||||||
|
struct cbfs_header header;
|
||||||
|
@@ -286,7 +287,11 @@ static int cbfs_master_header_props(struct cbfs_props *props)
|
||||||
|
if (bdev == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
- size_t fmap_top = ___FMAP__COREBOOT_BASE + ___FMAP__COREBOOT_SIZE;
|
||||||
|
+ size_t fmap_top =
|
||||||
|
+ use_fallback()
|
||||||
|
+ ? (___FMAP__FALLBACK_BASE + ___FMAP__FALLBACK_SIZE)
|
||||||
|
+ : (___FMAP__FALLBACK_BASE + ___FMAP__FALLBACK_SIZE)
|
||||||
|
+ ;
|
||||||
|
|
||||||
|
/* Find location of header using signed 32-bit offset from
|
||||||
|
* end of CBFS region. */
|
||||||
|
diff --git a/src/lib/prog_loaders.c b/src/lib/prog_loaders.c
|
||||||
|
index a9c9addbc60..10b5746e384 100644
|
||||||
|
--- a/src/lib/prog_loaders.c
|
||||||
|
+++ b/src/lib/prog_loaders.c
|
||||||
|
@@ -30,6 +30,7 @@
|
||||||
|
#include <symbols.h>
|
||||||
|
#include <timestamp.h>
|
||||||
|
#include <fit_payload.h>
|
||||||
|
+#include <bootblock_common.h>
|
||||||
|
|
||||||
|
/* Only can represent up to 1 byte less than size_t. */
|
||||||
|
const struct mem_region_device addrspace_32bit =
|
||||||
|
@@ -41,7 +42,10 @@ int prog_locate(struct prog *prog)
|
||||||
|
|
||||||
|
cbfs_prepare_program_locate();
|
||||||
|
|
||||||
|
- if (cbfs_boot_locate(&file, prog_name(prog), NULL))
|
||||||
|
+ if (cbfs_locate_file_in_region(&file,
|
||||||
|
+ use_fallback() ? FMAP_REGION_FALLBACK : FMAP_REGION_NORMAL,
|
||||||
|
+ prog_name(prog),
|
||||||
|
+ NULL))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
cbfsf_file_type(&file, &prog->cbfs_type);
|
||||||
|
diff --git a/util/cbfstool/cbfs_sections.h b/util/cbfstool/cbfs_sections.h
|
||||||
|
index 3526f8d94c3..fe2011cbb34 100644
|
||||||
|
--- a/util/cbfstool/cbfs_sections.h
|
||||||
|
+++ b/util/cbfstool/cbfs_sections.h
|
||||||
|
@@ -21,7 +21,7 @@
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#define SECTION_NAME_FMAP "FMAP"
|
||||||
|
-#define SECTION_NAME_PRIMARY_CBFS "COREBOOT"
|
||||||
|
+#define SECTION_NAME_PRIMARY_CBFS "FALLBACK"
|
||||||
|
|
||||||
|
#define SECTION_ANNOTATION_CBFS "CBFS"
|
||||||
|
|
||||||
|
diff --git a/util/scripts/dts-to-fmd.sh b/util/scripts/dts-to-fmd.sh
|
||||||
|
index b468b35bcd7..6a022933022 100755
|
||||||
|
--- a/util/scripts/dts-to-fmd.sh
|
||||||
|
+++ b/util/scripts/dts-to-fmd.sh
|
||||||
|
@@ -91,9 +91,9 @@ for region in $FMAP_REGIONS; do
|
||||||
|
|
||||||
|
# special handling: rename BOOT_STUB to COREBOOT, mark them as CBFS
|
||||||
|
if [ "${REGION_NAME}" = "BOOT_STUB" ]; then
|
||||||
|
- REGION_NAME="COREBOOT"
|
||||||
|
+ REGION_NAME="NORMAL"
|
||||||
|
fi
|
||||||
|
- if [ "${REGION_NAME}" = "COREBOOT" ]; then
|
||||||
|
+ if [ "${REGION_NAME}" = "NORMAL" ]; then
|
||||||
|
IS_CBFS="(CBFS)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
@@ -105,7 +105,7 @@ for region in $FMAP_REGIONS; do
|
||||||
|
# special handling: COREBOOT region at 0, inject a 128K bootblock
|
||||||
|
# The size may need changes to accommodate the chipsets,
|
||||||
|
# but should work for now.
|
||||||
|
- if [ "${REGION_NAME}" = "COREBOOT" -a \
|
||||||
|
+ if [ "${REGION_NAME}" = "NORMAL" -a \
|
||||||
|
$(( ${REGION_START} )) -eq 0 ]; then
|
||||||
|
printf "\n${PREFIX}BOOTBLOCK@0 128K"
|
||||||
|
LOCAL_REGION_START=$(( ${LOCAL_REGION_START} + 128*1024 ))
|
||||||
|
--
|
||||||
|
2.39.1
|
||||||
|
|
Loading…
Reference in New Issue