the following patch was just integrated into master:
commit 0e53931fee0178c4f4ac4e2e6b355b103b5e8c42
Author: Sol Boucher <solb(a)chromium.org>
Date: Thu Mar 5 15:38:03 2015 -0800
cbfstool: Clean up in preparation for adding new files
This enables more warnings on the cbfstool codebase and fixes the
issues that surface as a result. A memory leak that used to occur
when compressing files with lzma is also found and fixed.
Finally, there are several fixes for the Makefile:
- Its autodependencies used to be broken because the target for
the .dependencies file was misnamed; this meant that Make
didn't know how to rebuild the file, and so would silently
skip the step of updating it before including it.
- The ability to build to a custom output directory by defining
the obj variable had bitrotted.
- The default value of the obj variable was causing implicit
rules not to apply when specifying a file as a target without
providing a custom value for obj.
- Add a distclean target for removing the .dependencies file.
BUG=chromium:461875
TEST=Build an image with cbfstool both before and after.
BRANCH=None
Change-Id: I951919d63443f2b053c2e67c1ac9872abc0a43ca
Signed-off-by: Sol Boucher <solb(a)chromium.org>
Original-Commit-Id: 49293443b4e565ca48d284e9a66f80c9c213975d
Original-Change-Id: Ia7350c2c3306905984cfa711d5fc4631f0b43d5b
Original-Signed-off-by: Sol Boucher <solb(a)chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/257340
Original-Reviewed-by: Julius Werner <jwerner(a)chromium.org>
Original-Reviewed-by: Stefan Reinauer <reinauer(a)chromium.org>
Reviewed-on: http://review.coreboot.org/9937
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi(a)google.com>
See http://review.coreboot.org/9937 for details.
-gerrit
Leroy P Leahy (leroy.p.leahy(a)intel.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/9974
-gerrit
commit 2da0c310a4d22ff317d434ce2fa5e731549b02d6
Author: Lee Leahy <leroy.p.leahy(a)intel.com>
Date: Mon Apr 20 15:08:28 2015 -0700
vendorcode/intel: Add FSP 1.1 header files
The second step in adding support for FSP 1.1 is to add the header
files.
Updates may be done manually to these files but only to support FSP 1.1.
An FSPx_y tree should be added in the future as FSP binaries migrate
to new FSP specifications.
The files are provided in an EDK2 style tree to allow direct comparison
with the EDK2 tree.
BRANCH=none
BUG=None
TEST=Build for Braswell or Skylake boards using FSP 1.1.
Change-Id: If0e2fbe3cf9d39b18009552af5c861eff24043a0
Signed-off-by: Lee Leahy <leroy.p.leahy(a)intel.com>
---
.../intel/fsp/fsp1_1/IntelFspPkg/Include/FspApi.h | 308 +++++++++++++++++++++
.../fsp/fsp1_1/IntelFspPkg/Include/FspInfoHeader.h | 157 +++++++++++
2 files changed, 465 insertions(+)
diff --git a/src/vendorcode/intel/fsp/fsp1_1/IntelFspPkg/Include/FspApi.h b/src/vendorcode/intel/fsp/fsp1_1/IntelFspPkg/Include/FspApi.h
new file mode 100644
index 0000000..6a621d6
--- /dev/null
+++ b/src/vendorcode/intel/fsp/fsp1_1/IntelFspPkg/Include/FspApi.h
@@ -0,0 +1,308 @@
+/** @file
+ Intel FSP API definition from Intel Firmware Support Package External
+ Architecture Specification, April 2014, revision 001.
+
+ Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef _FSP_API_H_
+#define _FSP_API_H_
+
+#define FSP_STATUS EFI_STATUS
+#define FSPAPI EFIAPI
+
+/**
+ FSP Init continuation function prototype.
+ Control will be returned to this callback function after FspInit API call.
+
+ @param[in] Status Status of the FSP INIT API.
+ @param[in] HobBufferPtr Pointer to the HOB data structure defined in the PI specification.
+**/
+typedef
+VOID
+(* CONTINUATION_PROC) (
+ IN EFI_STATUS Status,
+ IN VOID *HobListPtr
+ );
+
+#pragma pack(1)
+
+typedef struct {
+ ///
+ /// Base address of the microcode region.
+ ///
+ UINT32 MicrocodeRegionBase;
+ ///
+ /// Length of the microcode region.
+ ///
+ UINT32 MicrocodeRegionLength;
+ ///
+ /// Base address of the cacheable flash region.
+ ///
+ UINT32 CodeRegionBase;
+ ///
+ /// Length of the cacheable flash region.
+ ///
+ UINT32 CodeRegionLength;
+} FSP_TEMP_RAM_INIT_PARAMS;
+
+typedef struct {
+ ///
+ /// Non-volatile storage buffer pointer.
+ ///
+ VOID *NvsBufferPtr;
+ ///
+ /// Runtime buffer pointer
+ ///
+ VOID *RtBufferPtr;
+ ///
+ /// Continuation function address
+ ///
+ CONTINUATION_PROC ContinuationFunc;
+} FSP_INIT_PARAMS;
+
+typedef struct {
+ ///
+ /// Stack top pointer used by the bootloader.
+ /// The new stack frame will be set up at this location after FspInit API call.
+ ///
+ UINT32 *StackTop;
+ ///
+ /// Current system boot mode.
+ ///
+ UINT32 BootMode;
+ ///
+ /// User platform configuraiton data region pointer.
+ ///
+ VOID *UpdDataRgnPtr;
+ ///
+ /// The size of memory to be reserved below the top of low usable memory (TOLUM)
+ /// for BootLoader usage. This is optional and value can be zero. If non-zero, the
+ /// size must be a multiple of 4KB. FSP EAS v1.1
+ ///
+ UINT32 BootLoaderTolumSize;
+ ///
+ /// Reserved
+ ///
+ UINT32 Reserved[6];
+} FSP_INIT_RT_COMMON_BUFFER;
+
+typedef enum {
+ ///
+ /// Notification code for post PCI enuermation
+ ///
+ EnumInitPhaseAfterPciEnumeration = 0x20,
+ ///
+ /// Notification code before transfering control to the payload
+ ///
+ EnumInitPhaseReadyToBoot = 0x40
+} FSP_INIT_PHASE;
+
+typedef struct {
+ ///
+ /// Notification phase used for NotifyPhase API
+ ///
+ FSP_INIT_PHASE Phase;
+} NOTIFY_PHASE_PARAMS;
+
+typedef struct {
+ ///
+ /// Non-volatile storage buffer pointer.
+ ///
+ VOID *NvsBufferPtr;
+ ///
+ /// Runtime buffer pointer
+ ///
+ VOID *RtBufferPtr;
+ ///
+ /// Pointer to the HOB data structure defined in the PI specification
+ ///
+ VOID **HobListPtr;
+} FSP_MEMORY_INIT_PARAMS;
+
+#pragma pack()
+
+/**
+ This FSP API is called soon after coming out of reset and before memory and stack is
+ available. This FSP API will load the microcode update, enable code caching for the
+ region specified by the boot loader and also setup a temporary stack to be used until
+ main memory is initialized.
+
+ A hardcoded stack can be set up with the following values, and the "esp" register
+ initialized to point to this hardcoded stack.
+ 1. The return address where the FSP will return control after setting up a temporary
+ stack.
+ 2. A pointer to the input parameter structure
+
+ However, since the stack is in ROM and not writeable, this FSP API cannot be called
+ using the "call" instruction, but needs to be jumped to.
+
+ @param[in] TempRaminitParamPtr Address pointer to the FSP_TEMP_RAM_INIT_PARAMS structure.
+
+ @retval EFI_SUCCESS Temp RAM was initialized successfully.
+ @retval EFI_INVALID_PARAMETER Input parameters are invalid..
+ @retval EFI_NOT_FOUND No valid microcode was found in the microcode region.
+ @retval EFI_UNSUPPORTED The FSP calling conditions were not met.
+ @retval EFI_DEVICE_ERROR Temp RAM initialization failed.
+
+ If this function is successful, the FSP initializes the ECX and EDX registers to point to
+ a temporary but writeable memory range available to the boot loader and returns with
+ FSP_SUCCESS in register EAX. Register ECX points to the start of this temporary
+ memory range and EDX points to the end of the range. Boot loader is free to use the
+ whole range described. Typically the boot loader can reload the ESP register to point
+ to the end of this returned range so that it can be used as a standard stack.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *FSP_TEMP_RAM_INIT) (
+ IN FSP_TEMP_RAM_INIT_PARAMS *FspTempRamInitPtr
+ );
+
+/**
+ This FSP API is called after TempRamInitEntry. This FSP API initializes the memory,
+ the CPU and the chipset to enable normal operation of these devices. This FSP API
+ accepts a pointer to a data structure that will be platform dependent and defined for
+ each FSP binary. This will be documented in the Integration Guide for each FSP
+ release.
+ The boot loader provides a continuation function as a parameter when calling FspInit.
+ After FspInit completes its execution, it does not return to the boot loader from where
+ it was called but instead returns control to the boot loader by calling the continuation
+ function which is passed to FspInit as an argument.
+
+ @param[in] FspInitParamPtr Address pointer to the FSP_INIT_PARAMS structure.
+
+ @retval EFI_SUCCESS FSP execution environment was initialized successfully.
+ @retval EFI_INVALID_PARAMETER Input parameters are invalid.
+ @retval EFI_UNSUPPORTED The FSP calling conditions were not met.
+ @retval EFI_DEVICE_ERROR FSP initialization failed.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *FSP_INIT) (
+ IN OUT FSP_INIT_PARAMS *FspInitParamPtr
+ );
+
+#define FSP_FSP_INIT FSP_INIT
+
+/**
+ This FSP API is used to notify the FSP about the different phases in the boot process.
+ This allows the FSP to take appropriate actions as needed during different initialization
+ phases. The phases will be platform dependent and will be documented with the FSP
+ release. The current FSP supports two notify phases:
+ Post PCI enumeration
+ Ready To Boot
+
+ @param[in] NotifyPhaseParamPtr Address pointer to the NOTIFY_PHASE_PRAMS
+
+ @retval EFI_SUCCESS The notification was handled successfully.
+ @retval EFI_UNSUPPORTED The notification was not called in the proper order.
+ @retval EFI_INVALID_PARAMETER The notification code is invalid.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *FSP_NOTIFY_PHASE) (
+ IN NOTIFY_PHASE_PARAMS *NotifyPhaseParamPtr
+ );
+
+/**
+ This FSP API is called after TempRamInit and initializes the memory.
+ This FSP API accepts a pointer to a data structure that will be platform dependent
+ and defined for each FSP binary. This will be documented in Integration guide with
+ each FSP release.
+ After FspMemInit completes its execution, it passes the pointer to the HobList and
+ returns to the boot loader from where it was called. Bootloader is responsible to
+ migrate it's stack and data to Memory.
+ FspMemoryInit, TempRamExit and FspSiliconInit APIs provide an alternate method to
+ complete the silicon initialization and provides bootloader an opportunity to get
+ control after system memory is available and before the temporary RAM is torn down.
+ These APIs are mutually exclusive to the FspInit API.
+
+ @param[in][out] FspMemoryInitParamPtr Address pointer to the FSP_MEMORY_INIT_PARAMS
+ structure.
+
+ @retval EFI_SUCCESS FSP execution environment was initialized successfully.
+ @retval EFI_INVALID_PARAMETER Input parameters are invalid.
+ @retval EFI_UNSUPPORTED The FSP calling conditions were not met.
+ @retval EFI_DEVICE_ERROR FSP initialization failed.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *FSP_MEMORY_INIT) (
+ IN OUT FSP_MEMORY_INIT_PARAMS *FspMemoryInitParamPtr
+ );
+
+
+/**
+ This FSP API is called after FspMemoryInit API. This FSP API tears down the temporary
+ memory setup by TempRamInit API. This FSP API accepts a pointer to a data structure
+ that will be platform dependent and defined for each FSP binary. This will be
+ documented in Integration Guide.
+ FspMemoryInit, TempRamExit and FspSiliconInit APIs provide an alternate method to
+ complete the silicon initialization and provides bootloader an opportunity to get
+ control after system memory is available and before the temporary RAM is torn down.
+ These APIs are mutually exclusive to the FspInit API.
+
+ @param[in][out] TempRamExitParamPtr Pointer to the Temp Ram Exit parameters structure.
+ This structure is normally defined in the Integration Guide.
+ And if it is not defined in the Integration Guide, pass NULL.
+
+ @retval EFI_SUCCESS FSP execution environment was initialized successfully.
+ @retval EFI_INVALID_PARAMETER Input parameters are invalid.
+ @retval EFI_UNSUPPORTED The FSP calling conditions were not met.
+ @retval EFI_DEVICE_ERROR FSP initialization failed.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *FSP_TEMP_RAM_EXIT) (
+ IN OUT VOID *TempRamExitParamPtr
+ );
+
+
+/**
+ This FSP API is called after TempRamExit API.
+ FspMemoryInit, TempRamExit and FspSiliconInit APIs provide an alternate method to complete the
+ silicon initialization.
+ These APIs are mutually exclusive to the FspInit API.
+
+ @param[in][out] FspSiliconInitParamPtr Pointer to the Silicon Init parameters structure.
+ This structure is normally defined in the Integration Guide.
+ And if it is not defined in the Integration Guide, pass NULL.
+
+ @retval EFI_SUCCESS FSP execution environment was initialized successfully.
+ @retval EFI_INVALID_PARAMETER Input parameters are invalid.
+ @retval EFI_UNSUPPORTED The FSP calling conditions were not met.
+ @retval EFI_DEVICE_ERROR FSP initialization failed.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *FSP_SILICON_INIT) (
+ IN OUT VOID *FspSiliconInitParamPtr
+ );
+
+///
+/// FSP API Return Status Code for backward compatibility with v1.0
+///@{
+#define FSP_SUCCESS EFI_SUCCESS
+#define FSP_INVALID_PARAMETER EFI_INVALID_PARAMETER
+#define FSP_UNSUPPORTED EFI_UNSUPPORTED
+#define FSP_NOT_READY EFI_NOT_READY
+#define FSP_DEVICE_ERROR EFI_DEVICE_ERROR
+#define FSP_OUT_OF_RESOURCES EFI_OUT_OF_RESOURCES
+#define FSP_VOLUME_CORRUPTED EFI_VOLUME_CORRUPTED
+#define FSP_NOT_FOUND EFI_NOT_FOUND
+#define FSP_TIMEOUT EFI_TIMEOUT
+#define FSP_ABORTED EFI_ABORTED
+#define FSP_INCOMPATIBLE_VERSION EFI_INCOMPATIBLE_VERSION
+#define FSP_SECURITY_VIOLATION EFI_SECURITY_VIOLATION
+#define FSP_CRC_ERROR EFI_CRC_ERROR
+///@}
+
+#endif
diff --git a/src/vendorcode/intel/fsp/fsp1_1/IntelFspPkg/Include/FspInfoHeader.h b/src/vendorcode/intel/fsp/fsp1_1/IntelFspPkg/Include/FspInfoHeader.h
new file mode 100644
index 0000000..47d463c
--- /dev/null
+++ b/src/vendorcode/intel/fsp/fsp1_1/IntelFspPkg/Include/FspInfoHeader.h
@@ -0,0 +1,157 @@
+/** @file
+ Intel FSP Info Header definition from Intel Firmware Support Package External
+ Architecture Specification, April 2014, revision 001.
+
+ Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef _FSP_INFO_HEADER_H_
+#define _FSP_INFO_HEADER_H_
+
+#define FSP_HEADER_REVISION_1 1
+#define FSP_HEADER_REVISION_2 2
+
+#define FSPE_HEADER_REVISION_1 1
+#define FSPP_HEADER_REVISION_1 1
+
+///
+/// Fixed FSP header offset in the FSP image
+///
+#define FSP_INFO_HEADER_OFF 0x94
+
+#define OFFSET_IN_FSP_INFO_HEADER(x) (UINT32)&((FSP_INFO_HEADER *)(UINTN)0)->x
+
+#pragma pack(1)
+
+typedef struct {
+ ///
+ /// Byte 0x00: Signature ('FSPH') for the FSP Information Header
+ ///
+ UINT32 Signature;
+ ///
+ /// Byte 0x04: Length of the FSP Information Header
+ ///
+ UINT32 HeaderLength;
+ ///
+ /// Byte 0x08: Reserved
+ ///
+ UINT8 Reserved1[3];
+ ///
+ /// Byte 0x0B: Revision of the FSP Information Header
+ ///
+ UINT8 HeaderRevision;
+ ///
+ /// Byte 0x0C: Revision of the FSP binary
+ ///
+ UINT32 ImageRevision;
+
+
+ ///
+ /// Byte 0x10: Signature string that will help match the FSP Binary to a supported
+ /// hardware configuration.
+ ///
+ CHAR8 ImageId[8];
+ ///
+ /// Byte 0x18: Size of the entire FSP binary
+ ///
+ UINT32 ImageSize;
+ ///
+ /// Byte 0x1C: FSP binary preferred base address
+ ///
+ UINT32 ImageBase;
+
+
+ ///
+ /// Byte 0x20: Attribute for the FSP binary
+ ///
+ UINT32 ImageAttribute;
+ ///
+ /// Byte 0x24: Offset of the FSP configuration region
+ ///
+ UINT32 CfgRegionOffset;
+ ///
+ /// Byte 0x28: Size of the FSP configuration region
+ ///
+ UINT32 CfgRegionSize;
+ ///
+ /// Byte 0x2C: Number of API entries this FSP supports
+ ///
+ UINT32 ApiEntryNum;
+
+
+ ///
+ /// Byte 0x30: The offset for the API to setup a temporary stack till the memory
+ /// is initialized.
+ ///
+ UINT32 TempRamInitEntryOffset;
+ ///
+ /// Byte 0x34: The offset for the API to initialize the CPU and the chipset (SOC)
+ ///
+ UINT32 FspInitEntryOffset;
+ ///
+ /// Byte 0x38: The offset for the API to inform the FSP about the different stages
+ /// in the boot process
+ ///
+ UINT32 NotifyPhaseEntryOffset;
+
+ ///
+ /// Below fields are added in FSP Revision 2
+ ///
+
+ ///
+ /// Byte 0x3C: The offset for the API to initialize the memory
+ ///
+ UINT32 FspMemoryInitEntryOffset;
+ ///
+ /// Byte 0x40: The offset for the API to tear down temporary RAM
+ ///
+ UINT32 TempRamExitEntryOffset;
+ ///
+ /// Byte 0x44: The offset for the API to initialize the CPU and chipset
+ ///
+ UINT32 FspSiliconInitEntryOffset;
+
+} FSP_INFO_HEADER;
+
+///
+/// Below structure is added in FSP version 2
+///
+typedef struct {
+ ///
+ /// Byte 0x00: Signature ('FSPE') for the FSP Extended Information Header
+ ///
+ UINT32 Signature;
+ ///
+ /// Byte 0x04: Length of the FSP Extended Header
+ ///
+ UINT32 HeaderLength;
+ ///
+ /// Byte 0x08: Revision of the FSP Extended Header
+ ///
+ UINT8 Revision;
+ ///
+ /// Byte 0x09: Reserved for future use.
+ ///
+ UINT8 Reserved;
+ ///
+ /// Byte 0x0A: An OEM-supplied string that defines the OEM
+ ///
+ CHAR8 OemId[6];
+ ///
+ /// Byte 0x10: An OEM-supplied revision number. Larger numbers are assumed to be newer revisions.
+ ///
+ UINT32 OemRevision;
+
+} FSP_EXTENTED_HEADER;
+
+#pragma pack()
+
+#endif
Aaron Durbin (adurbin(a)chromium.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/9171
-gerrit
commit 7c2eb65a148e536f8057e5ef0131cc6388561ccd
Author: Aaron Durbin <adurbin(a)chromium.org>
Date: Sun Mar 29 00:05:18 2015 -0500
fmap: add region based fmap API
Instead of being pointer based use the region infrastrucutre.
Additionally, this removes the need for arch-specific compilation
paths.
Change-Id: I436533a4f4a272837794ee00c90280602745edac
Signed-off-by: Aaron Durbin <adurbin(a)chromium.org>
---
src/Kconfig | 9 +++
src/include/fmap.h | 35 ++++++++++
src/lib/Makefile.inc | 4 ++
src/lib/fmap.c | 121 +++++++++++++++++++++++++++++++++
src/vendorcode/google/chromeos/Kconfig | 9 ---
5 files changed, 169 insertions(+), 9 deletions(-)
diff --git a/src/Kconfig b/src/Kconfig
index f531f07..28f821a 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -234,6 +234,15 @@ config CACHE_RELOCATED_RAMSTAGE_OUTSIDE_CBMEM
The relocated ramstage is saved in an area specified by the
by the board and/or chipset.
+config FLASHMAP_OFFSET
+ hex "Flash Map Offset"
+ default 0x00670000 if NORTHBRIDGE_INTEL_SANDYBRIDGE
+ default 0x00610000 if NORTHBRIDGE_INTEL_IVYBRIDGE
+ default CBFS_SIZE if !ARCH_X86
+ default 0
+ help
+ Offset of flash map in firmware image
+
choice
prompt "Bootblock behaviour"
default BOOTBLOCK_SIMPLE
diff --git a/src/include/fmap.h b/src/include/fmap.h
new file mode 100644
index 0000000..e575bbf
--- /dev/null
+++ b/src/include/fmap.h
@@ -0,0 +1,35 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2015 Google 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; version 2 of the License.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc.
+ */
+
+#ifndef _FMAP_H_
+#define _FMAP_H_
+
+#include <region.h>
+
+/* Locate the named area in the fmap and fill in a region device representing
+ * that area. The region is a sub-region of the readonly boot media. Return
+ * 0 on success, < 0 on error. */
+int fmap_locate_area_as_rdev(const char *name, struct region_device *area);
+
+/* Locate the named area in the fmap and fill in a region with the
+ * offset and size of that area within the boot media. Return 0 on success,
+ * < 0 on error. */
+int fmap_locate_area(const char *name, struct region *r);
+
+#endif
diff --git a/src/lib/Makefile.inc b/src/lib/Makefile.inc
index 90e8830..1c69c95 100644
--- a/src/lib/Makefile.inc
+++ b/src/lib/Makefile.inc
@@ -31,11 +31,13 @@ bootblock-y += memchr.c
bootblock-y += memcmp.c
bootblock-y += mem_pool.c
bootblock-y += region.c
+bootblock-y += fmap.c
verstage-y += prog_ops.c
verstage-y += delay.c
verstage-y += cbfs.c
verstage-y += cbfs_boot_props.c
+verstage-y += fmap.c
verstage-y += memcmp.c
verstage-y += region.c
verstage-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
@@ -52,6 +54,7 @@ $(foreach arch,$(ARCH_SUPPORTED),\
$(eval rmodules_$(arch)-y += memcmp.c) \
$(eval rmodules_$(arch)-y += rmodule.ld))
+romstage-y += fmap.c
romstage-$(CONFIG_I2C_TPM) += delay.c
romstage-y += cbfs.c
romstage-y += cbfs_boot_props.c
@@ -80,6 +83,7 @@ ramstage-y += hardwaremain.c
ramstage-y += selfboot.c
ramstage-y += coreboot_table.c
ramstage-y += bootmem.c
+ramstage-y += fmap.c
ramstage-y += memchr.c
ramstage-y += memcmp.c
ramstage-y += malloc.c
diff --git a/src/lib/fmap.c b/src/lib/fmap.c
new file mode 100644
index 0000000..c0cbca1
--- /dev/null
+++ b/src/lib/fmap.c
@@ -0,0 +1,121 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2012-2015 Google 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; version 2 of the License.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc.
+ */
+
+#include <boot_device.h>
+#include <console/console.h>
+#include <fmap.h>
+#include <fmap_serialized.h>
+#include <stddef.h>
+#include <string.h>
+
+/*
+ * See http://code.google.com/p/flashmap/ for more information on FMAP.
+ */
+
+static int find_fmap_directory(struct region_device *fmrd)
+{
+ const struct region_device *boot;
+ struct fmap *fmap;
+ size_t fmap_size;
+ size_t offset = CONFIG_FLASHMAP_OFFSET;
+
+ boot = boot_device_ro();
+
+ if (boot == NULL)
+ return -1;
+
+ fmap_size = sizeof(struct fmap);
+
+ fmap = rdev_mmap(boot, offset, fmap_size);
+
+ if (fmap == NULL)
+ return -1;
+
+ if (memcmp(fmap->signature, FMAP_SIGNATURE, sizeof(fmap->signature))) {
+ printk(BIOS_DEBUG, "No FMAP found at %zx offset.\n", offset);
+ rdev_munmap(boot, fmap);
+ return -1;
+ }
+
+ printk(BIOS_DEBUG, "FMAP: Found \"%s\" version %d.%d at %zx.\n",
+ fmap->name, fmap->ver_major, fmap->ver_minor, offset);
+ printk(BIOS_DEBUG, "FMAP: base = %llx size = %x #areas = %d\n",
+ (long long)fmap->base, fmap->size, fmap->nareas);
+
+ fmap_size += fmap->nareas * sizeof(struct fmap_area);
+
+ rdev_munmap(boot, fmap);
+
+ return rdev_chain(fmrd, boot, offset, fmap_size);
+}
+
+int fmap_locate_area_as_rdev(const char *name, struct region_device *area)
+{
+ const struct region_device *boot;
+ struct region ar;
+
+ boot = boot_device_ro();
+
+ if (fmap_locate_area(name, &ar))
+ return -1;
+
+ return rdev_chain(area, boot, ar.offset, ar.size);
+}
+
+int fmap_locate_area(const char *name, struct region *ar)
+{
+ struct region_device fmrd;
+ size_t offset;
+
+ if (find_fmap_directory(&fmrd))
+ return -1;
+
+ /* Start reading the areas just after fmap header. */
+ offset = sizeof(struct fmap);
+
+ while (1) {
+ struct fmap_area *area;
+
+ area = rdev_mmap(&fmrd, offset, sizeof(*area));
+
+ if (area == NULL)
+ return -1;
+
+ if (strcmp((const char *)area->name, name)) {
+ rdev_munmap(&fmrd, area);
+ offset += sizeof(struct fmap_area);
+ continue;
+ }
+
+ printk(BIOS_DEBUG, "FMAP: area %s found\n", name);
+ printk(BIOS_DEBUG, "FMAP: offset: %x\n", area->offset);
+ printk(BIOS_DEBUG, "FMAP: size: %d bytes\n", area->size);
+
+ ar->offset = area->offset;
+ ar->size = area->size;
+
+ rdev_munmap(&fmrd, area);
+
+ return 0;
+ }
+
+ printk(BIOS_DEBUG, "FMAP: area %s not found\n", name);
+
+ return -1;
+}
diff --git a/src/vendorcode/google/chromeos/Kconfig b/src/vendorcode/google/chromeos/Kconfig
index 9a45efa..a0cac92 100644
--- a/src/vendorcode/google/chromeos/Kconfig
+++ b/src/vendorcode/google/chromeos/Kconfig
@@ -92,15 +92,6 @@ config CHROMEOS_RAMOOPS_RAM_SIZE
default 0x00100000
depends on CHROMEOS_RAMOOPS
-config FLASHMAP_OFFSET
- hex "Flash Map Offset"
- default 0x00670000 if NORTHBRIDGE_INTEL_SANDYBRIDGE
- default 0x00610000 if NORTHBRIDGE_INTEL_IVYBRIDGE
- default CBFS_SIZE if !ARCH_X86
- default 0
- help
- Offset of flash map in firmware image
-
config EC_SOFTWARE_SYNC
bool "Enable EC software sync"
default n
Aaron Durbin (adurbin(a)chromium.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/9170
-gerrit
commit 467eae6910cef29995e7e4721612a983938137a9
Author: Aaron Durbin <adurbin(a)chromium.org>
Date: Sat Mar 28 23:56:22 2015 -0500
fmap: create fmap_serialized.h header
Create a header for the fmap serialized data
layout to allow for easier use from non-chromeos
code.
Change-Id: Ie36e9ff9cb554234ec394b921f029eeed6845aee
Signed-off-by: Aaron Durbin <adurbin(a)chromium.org>
---
src/include/fmap_serialized.h | 73 +++++++++++++++++++++++++++++++++++
src/vendorcode/google/chromeos/fmap.h | 35 +----------------
2 files changed, 74 insertions(+), 34 deletions(-)
diff --git a/src/include/fmap_serialized.h b/src/include/fmap_serialized.h
new file mode 100644
index 0000000..3585f0b
--- /dev/null
+++ b/src/include/fmap_serialized.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
+ * OWNER 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.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ */
+
+#ifndef FLASHMAP_SERIALIZED_H__
+#define FLASHMAP_SERIALIZED_H__
+
+#include <stdint.h>
+
+#define FMAP_SIGNATURE "__FMAP__"
+#define FMAP_VER_MAJOR 1 /* this header's FMAP minor version */
+#define FMAP_VER_MINOR 1 /* this header's FMAP minor version */
+#define FMAP_STRLEN 32 /* maximum length for strings, */
+ /* including null-terminator */
+
+enum fmap_flags {
+ FMAP_AREA_STATIC = 1 << 0,
+ FMAP_AREA_COMPRESSED = 1 << 1,
+ FMAP_AREA_RO = 1 << 2,
+};
+
+/* Mapping of volatile and static regions in firmware binary */
+struct fmap_area {
+ uint32_t offset; /* offset relative to base */
+ uint32_t size; /* size in bytes */
+ uint8_t name[FMAP_STRLEN]; /* descriptive name */
+ uint16_t flags; /* flags for this area */
+} __attribute__((packed));
+
+struct fmap {
+ uint8_t signature[8]; /* "__FMAP__" (0x5F5F464D41505F5F) */
+ uint8_t ver_major; /* major version */
+ uint8_t ver_minor; /* minor version */
+ uint64_t base; /* address of the firmware binary */
+ uint32_t size; /* size of firmware binary in bytes */
+ uint8_t name[FMAP_STRLEN]; /* name of this firmware binary */
+ uint16_t nareas; /* number of areas described by
+ fmap_areas[] below */
+ struct fmap_area areas[];
+} __attribute__((packed));
+
+#endif /* FLASHMAP_SERIALIZED_H__ */
diff --git a/src/vendorcode/google/chromeos/fmap.h b/src/vendorcode/google/chromeos/fmap.h
index 05d3fb6..fc84f15 100644
--- a/src/vendorcode/google/chromeos/fmap.h
+++ b/src/vendorcode/google/chromeos/fmap.h
@@ -36,40 +36,7 @@
#ifndef FLASHMAP_LIB_FMAP_H__
#define FLASHMAP_LIB_FMAP_H__
-#include <stdint.h>
-
-#define FMAP_REVERSED_SIGNATURE "__PAMF__" /* avoid magic number in .rodata */
-#define FMAP_VER_MAJOR 1 /* this header's FMAP minor version */
-#define FMAP_VER_MINOR 1 /* this header's FMAP minor version */
-#define FMAP_STRLEN 32 /* maximum length for strings, */
- /* including null-terminator */
-
-enum fmap_flags {
- FMAP_AREA_STATIC = 1 << 0,
- FMAP_AREA_COMPRESSED = 1 << 1,
- FMAP_AREA_RO = 1 << 2,
-};
-
-/* Mapping of volatile and static regions in firmware binary */
-struct fmap_area {
- uint32_t offset; /* offset relative to base */
- uint32_t size; /* size in bytes */
- uint8_t name[FMAP_STRLEN]; /* descriptive name */
- uint16_t flags; /* flags for this area */
-} __attribute__((packed));
-
-struct fmap {
- uint8_t signature[8]; /* "__FMAP__" (0x5F5F464D41505F5F) */
- uint8_t ver_major; /* major version */
- uint8_t ver_minor; /* minor version */
- uint64_t base; /* address of the firmware binary */
- uint32_t size; /* size of firmware binary in bytes */
- uint8_t name[FMAP_STRLEN]; /* name of this firmware binary */
- uint16_t nareas; /* number of areas described by
- fmap_areas[] below */
- struct fmap_area areas[];
-} __attribute__((packed));
-
+#include <fmap_serialized.h>
/* coreboot specific function prototypes */
const struct fmap *fmap_find(void);
Aaron Durbin (adurbin(a)chromium.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/9171
-gerrit
commit 5b9033a5e640046feeeadb7674f53e3ff00bc792
Author: Aaron Durbin <adurbin(a)chromium.org>
Date: Sun Mar 29 00:05:18 2015 -0500
fmap: add region based fmap API
Instead of being pointer based use the region infrastrucutre.
Additionally, this removes the need for arch-specific compilation
paths.
Change-Id: I436533a4f4a272837794ee00c90280602745edac
Signed-off-by: Aaron Durbin <adurbin(a)chromium.org>
---
src/Kconfig | 9 +++
src/include/fmap.h | 35 ++++++++++
src/lib/Makefile.inc | 4 ++
src/lib/fmap.c | 121 +++++++++++++++++++++++++++++++++
src/vendorcode/google/chromeos/Kconfig | 9 ---
5 files changed, 169 insertions(+), 9 deletions(-)
diff --git a/src/Kconfig b/src/Kconfig
index f531f07..28f821a 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -234,6 +234,15 @@ config CACHE_RELOCATED_RAMSTAGE_OUTSIDE_CBMEM
The relocated ramstage is saved in an area specified by the
by the board and/or chipset.
+config FLASHMAP_OFFSET
+ hex "Flash Map Offset"
+ default 0x00670000 if NORTHBRIDGE_INTEL_SANDYBRIDGE
+ default 0x00610000 if NORTHBRIDGE_INTEL_IVYBRIDGE
+ default CBFS_SIZE if !ARCH_X86
+ default 0
+ help
+ Offset of flash map in firmware image
+
choice
prompt "Bootblock behaviour"
default BOOTBLOCK_SIMPLE
diff --git a/src/include/fmap.h b/src/include/fmap.h
new file mode 100644
index 0000000..e575bbf
--- /dev/null
+++ b/src/include/fmap.h
@@ -0,0 +1,35 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2015 Google 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; version 2 of the License.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc.
+ */
+
+#ifndef _FMAP_H_
+#define _FMAP_H_
+
+#include <region.h>
+
+/* Locate the named area in the fmap and fill in a region device representing
+ * that area. The region is a sub-region of the readonly boot media. Return
+ * 0 on success, < 0 on error. */
+int fmap_locate_area_as_rdev(const char *name, struct region_device *area);
+
+/* Locate the named area in the fmap and fill in a region with the
+ * offset and size of that area within the boot media. Return 0 on success,
+ * < 0 on error. */
+int fmap_locate_area(const char *name, struct region *r);
+
+#endif
diff --git a/src/lib/Makefile.inc b/src/lib/Makefile.inc
index 90e8830..1c69c95 100644
--- a/src/lib/Makefile.inc
+++ b/src/lib/Makefile.inc
@@ -31,11 +31,13 @@ bootblock-y += memchr.c
bootblock-y += memcmp.c
bootblock-y += mem_pool.c
bootblock-y += region.c
+bootblock-y += fmap.c
verstage-y += prog_ops.c
verstage-y += delay.c
verstage-y += cbfs.c
verstage-y += cbfs_boot_props.c
+verstage-y += fmap.c
verstage-y += memcmp.c
verstage-y += region.c
verstage-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
@@ -52,6 +54,7 @@ $(foreach arch,$(ARCH_SUPPORTED),\
$(eval rmodules_$(arch)-y += memcmp.c) \
$(eval rmodules_$(arch)-y += rmodule.ld))
+romstage-y += fmap.c
romstage-$(CONFIG_I2C_TPM) += delay.c
romstage-y += cbfs.c
romstage-y += cbfs_boot_props.c
@@ -80,6 +83,7 @@ ramstage-y += hardwaremain.c
ramstage-y += selfboot.c
ramstage-y += coreboot_table.c
ramstage-y += bootmem.c
+ramstage-y += fmap.c
ramstage-y += memchr.c
ramstage-y += memcmp.c
ramstage-y += malloc.c
diff --git a/src/lib/fmap.c b/src/lib/fmap.c
new file mode 100644
index 0000000..c0cbca1
--- /dev/null
+++ b/src/lib/fmap.c
@@ -0,0 +1,121 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2012-2015 Google 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; version 2 of the License.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc.
+ */
+
+#include <boot_device.h>
+#include <console/console.h>
+#include <fmap.h>
+#include <fmap_serialized.h>
+#include <stddef.h>
+#include <string.h>
+
+/*
+ * See http://code.google.com/p/flashmap/ for more information on FMAP.
+ */
+
+static int find_fmap_directory(struct region_device *fmrd)
+{
+ const struct region_device *boot;
+ struct fmap *fmap;
+ size_t fmap_size;
+ size_t offset = CONFIG_FLASHMAP_OFFSET;
+
+ boot = boot_device_ro();
+
+ if (boot == NULL)
+ return -1;
+
+ fmap_size = sizeof(struct fmap);
+
+ fmap = rdev_mmap(boot, offset, fmap_size);
+
+ if (fmap == NULL)
+ return -1;
+
+ if (memcmp(fmap->signature, FMAP_SIGNATURE, sizeof(fmap->signature))) {
+ printk(BIOS_DEBUG, "No FMAP found at %zx offset.\n", offset);
+ rdev_munmap(boot, fmap);
+ return -1;
+ }
+
+ printk(BIOS_DEBUG, "FMAP: Found \"%s\" version %d.%d at %zx.\n",
+ fmap->name, fmap->ver_major, fmap->ver_minor, offset);
+ printk(BIOS_DEBUG, "FMAP: base = %llx size = %x #areas = %d\n",
+ (long long)fmap->base, fmap->size, fmap->nareas);
+
+ fmap_size += fmap->nareas * sizeof(struct fmap_area);
+
+ rdev_munmap(boot, fmap);
+
+ return rdev_chain(fmrd, boot, offset, fmap_size);
+}
+
+int fmap_locate_area_as_rdev(const char *name, struct region_device *area)
+{
+ const struct region_device *boot;
+ struct region ar;
+
+ boot = boot_device_ro();
+
+ if (fmap_locate_area(name, &ar))
+ return -1;
+
+ return rdev_chain(area, boot, ar.offset, ar.size);
+}
+
+int fmap_locate_area(const char *name, struct region *ar)
+{
+ struct region_device fmrd;
+ size_t offset;
+
+ if (find_fmap_directory(&fmrd))
+ return -1;
+
+ /* Start reading the areas just after fmap header. */
+ offset = sizeof(struct fmap);
+
+ while (1) {
+ struct fmap_area *area;
+
+ area = rdev_mmap(&fmrd, offset, sizeof(*area));
+
+ if (area == NULL)
+ return -1;
+
+ if (strcmp((const char *)area->name, name)) {
+ rdev_munmap(&fmrd, area);
+ offset += sizeof(struct fmap_area);
+ continue;
+ }
+
+ printk(BIOS_DEBUG, "FMAP: area %s found\n", name);
+ printk(BIOS_DEBUG, "FMAP: offset: %x\n", area->offset);
+ printk(BIOS_DEBUG, "FMAP: size: %d bytes\n", area->size);
+
+ ar->offset = area->offset;
+ ar->size = area->size;
+
+ rdev_munmap(&fmrd, area);
+
+ return 0;
+ }
+
+ printk(BIOS_DEBUG, "FMAP: area %s not found\n", name);
+
+ return -1;
+}
diff --git a/src/vendorcode/google/chromeos/Kconfig b/src/vendorcode/google/chromeos/Kconfig
index 9a45efa..a0cac92 100644
--- a/src/vendorcode/google/chromeos/Kconfig
+++ b/src/vendorcode/google/chromeos/Kconfig
@@ -92,15 +92,6 @@ config CHROMEOS_RAMOOPS_RAM_SIZE
default 0x00100000
depends on CHROMEOS_RAMOOPS
-config FLASHMAP_OFFSET
- hex "Flash Map Offset"
- default 0x00670000 if NORTHBRIDGE_INTEL_SANDYBRIDGE
- default 0x00610000 if NORTHBRIDGE_INTEL_IVYBRIDGE
- default CBFS_SIZE if !ARCH_X86
- default 0
- help
- Offset of flash map in firmware image
-
config EC_SOFTWARE_SYNC
bool "Enable EC software sync"
default n
Aaron Durbin (adurbin(a)chromium.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/9170
-gerrit
commit 49673aa35869f3188d291b38499180a0562524bb
Author: Aaron Durbin <adurbin(a)chromium.org>
Date: Sat Mar 28 23:56:22 2015 -0500
fmap: create fmap_serialized.h header
Create a header for the fmap serialized data
layout to allow for easier use from non-chromeos
code.
Change-Id: Ie36e9ff9cb554234ec394b921f029eeed6845aee
Signed-off-by: Aaron Durbin <adurbin(a)chromium.org>
---
src/include/fmap_serialized.h | 73 +++++++++++++++++++++++++++++++++++
src/vendorcode/google/chromeos/fmap.h | 35 +----------------
2 files changed, 74 insertions(+), 34 deletions(-)
diff --git a/src/include/fmap_serialized.h b/src/include/fmap_serialized.h
new file mode 100644
index 0000000..3585f0b
--- /dev/null
+++ b/src/include/fmap_serialized.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
+ * OWNER 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.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ */
+
+#ifndef FLASHMAP_SERIALIZED_H__
+#define FLASHMAP_SERIALIZED_H__
+
+#include <stdint.h>
+
+#define FMAP_SIGNATURE "__FMAP__"
+#define FMAP_VER_MAJOR 1 /* this header's FMAP minor version */
+#define FMAP_VER_MINOR 1 /* this header's FMAP minor version */
+#define FMAP_STRLEN 32 /* maximum length for strings, */
+ /* including null-terminator */
+
+enum fmap_flags {
+ FMAP_AREA_STATIC = 1 << 0,
+ FMAP_AREA_COMPRESSED = 1 << 1,
+ FMAP_AREA_RO = 1 << 2,
+};
+
+/* Mapping of volatile and static regions in firmware binary */
+struct fmap_area {
+ uint32_t offset; /* offset relative to base */
+ uint32_t size; /* size in bytes */
+ uint8_t name[FMAP_STRLEN]; /* descriptive name */
+ uint16_t flags; /* flags for this area */
+} __attribute__((packed));
+
+struct fmap {
+ uint8_t signature[8]; /* "__FMAP__" (0x5F5F464D41505F5F) */
+ uint8_t ver_major; /* major version */
+ uint8_t ver_minor; /* minor version */
+ uint64_t base; /* address of the firmware binary */
+ uint32_t size; /* size of firmware binary in bytes */
+ uint8_t name[FMAP_STRLEN]; /* name of this firmware binary */
+ uint16_t nareas; /* number of areas described by
+ fmap_areas[] below */
+ struct fmap_area areas[];
+} __attribute__((packed));
+
+#endif /* FLASHMAP_SERIALIZED_H__ */
diff --git a/src/vendorcode/google/chromeos/fmap.h b/src/vendorcode/google/chromeos/fmap.h
index 05d3fb6..fc84f15 100644
--- a/src/vendorcode/google/chromeos/fmap.h
+++ b/src/vendorcode/google/chromeos/fmap.h
@@ -36,40 +36,7 @@
#ifndef FLASHMAP_LIB_FMAP_H__
#define FLASHMAP_LIB_FMAP_H__
-#include <stdint.h>
-
-#define FMAP_REVERSED_SIGNATURE "__PAMF__" /* avoid magic number in .rodata */
-#define FMAP_VER_MAJOR 1 /* this header's FMAP minor version */
-#define FMAP_VER_MINOR 1 /* this header's FMAP minor version */
-#define FMAP_STRLEN 32 /* maximum length for strings, */
- /* including null-terminator */
-
-enum fmap_flags {
- FMAP_AREA_STATIC = 1 << 0,
- FMAP_AREA_COMPRESSED = 1 << 1,
- FMAP_AREA_RO = 1 << 2,
-};
-
-/* Mapping of volatile and static regions in firmware binary */
-struct fmap_area {
- uint32_t offset; /* offset relative to base */
- uint32_t size; /* size in bytes */
- uint8_t name[FMAP_STRLEN]; /* descriptive name */
- uint16_t flags; /* flags for this area */
-} __attribute__((packed));
-
-struct fmap {
- uint8_t signature[8]; /* "__FMAP__" (0x5F5F464D41505F5F) */
- uint8_t ver_major; /* major version */
- uint8_t ver_minor; /* minor version */
- uint64_t base; /* address of the firmware binary */
- uint32_t size; /* size of firmware binary in bytes */
- uint8_t name[FMAP_STRLEN]; /* name of this firmware binary */
- uint16_t nareas; /* number of areas described by
- fmap_areas[] below */
- struct fmap_area areas[];
-} __attribute__((packed));
-
+#include <fmap_serialized.h>
/* coreboot specific function prototypes */
const struct fmap *fmap_find(void);
Aaron Durbin (adurbin(a)chromium.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/9128
-gerrit
commit 306c876e2ed432e94d3ca35614f6292a3c95c706
Author: Aaron Durbin <adurbin(a)chromium.org>
Date: Thu Mar 26 14:39:07 2015 -0500
coreboot: add region infrastructure
The region infrastructure provides a means of abstracting
access to different types of storage such as SPI flash, MMC,
or just plain memory. The regions are represented by
region devices which can be chained together forming subregions
of the larger region. This allows the call sites to be agnostic
about the implementations behind the regions. Additionally, this
prepares for a cleaner API for CBFS accesses.
Change-Id: I803f97567ef0505691a69975c282fde1215ea6da
Signed-off-by: Aaron Durbin <adurbin(a)chromium.org>
---
src/include/region.h | 100 ++++++++++++++++++++++++++++++++++++++++++
src/lib/Makefile.inc | 4 ++
src/lib/region.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 225 insertions(+)
diff --git a/src/include/region.h b/src/include/region.h
new file mode 100644
index 0000000..cb91102
--- /dev/null
+++ b/src/include/region.h
@@ -0,0 +1,100 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2015 Google 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; version 2 of the License.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc.
+ */
+
+#ifndef _REGION_H_
+#define _REGION_H_
+
+#include <stdint.h>
+#include <stddef.h>
+
+/*
+ * Region support.
+ *
+ * Regions are intended to abstract away the access mechanisms for blocks of
+ * data. This could be SPI, eMMC, or a memory region as the backing store.
+ * They are accessed through a region_device. Subregions can be made by
+ * chaining together multiple region_devices.
+ */
+
+struct region_device;
+
+/*
+ * Returns NULL on error otherwise a buffer is returned with the conents of
+ * the requested data at offset of size.
+ */
+void *rdev_mmap(const struct region_device *rd, size_t offset, size_t size);
+
+/* Unmap a previously mapped area. Returns 0 on success, < 0 on error. */
+int rdev_munmap(const struct region_device *rd, void *mapping);
+
+/*
+ * Returns < 0 on error otherwise returns size of data read at provided
+ * offset filling in the buffer passed.
+ */
+ssize_t rdev_readat(const struct region_device *rd, void *b, size_t offset,
+ size_t size);
+
+
+/****************************************
+ * Implementation of a region device *
+ ****************************************/
+
+/*
+ * Create a child region of the parent provided the sub-region is within
+ * the parent's region. Returns < 0 on error otherwise 0 on success. Note
+ * that the child device only calls through the parent's operations.
+ */
+int rdev_chain(struct region_device *child, const struct region_device *parent,
+ size_t offset, size_t size);
+
+
+/* A region_device operations. */
+struct region_device_ops {
+ void *(*mmap)(const struct region_device *, size_t, size_t);
+ int (*munmap)(const struct region_device *, void *);
+ ssize_t (*readat)(const struct region_device *, void *, size_t, size_t);
+};
+
+struct region {
+ size_t offset;
+ size_t size;
+};
+
+struct region_device {
+ const struct region_device *root;
+ const struct region_device_ops *ops;
+ struct region region;
+};
+
+#define REGION_DEV_INIT(ops_, offset_, size_) \
+ { \
+ .root = NULL, \
+ .ops = (ops_), \
+ .region = { \
+ .offset = (offset_), \
+ .size = (size_), \
+ }, \
+ }
+
+static inline size_t region_sz(const struct region *r)
+{
+ return r->size;
+}
+
+#endif /* _REGION_H_ */
diff --git a/src/lib/Makefile.inc b/src/lib/Makefile.inc
index f0fb02874..1a1b981 100644
--- a/src/lib/Makefile.inc
+++ b/src/lib/Makefile.inc
@@ -28,11 +28,13 @@ bootblock-$(CONFIG_GENERIC_UDELAY) += timer.c
bootblock-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
bootblock-y += memchr.c
bootblock-y += memcmp.c
+bootblock-y += region.c
verstage-y += prog_ops.c
verstage-y += delay.c
verstage-y += cbfs.c
verstage-y += memcmp.c
+verstage-y += region.c
verstage-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
verstage-$(CONFIG_COMMON_CBFS_SPI_WRAPPER) += cbfs_spi.c
verstage-y += tlcl.c
@@ -122,6 +124,8 @@ ramstage-$(CONFIG_RELOCATABLE_RAMSTAGE) += cbmem_stage_cache.c
romstage-$(CONFIG_RELOCATABLE_RAMSTAGE) += cbmem_stage_cache.c
endif
+romstage-y += region.c
+ramstage-y += region.c
smm-y += cbfs.c cbfs_core.c memcmp.c
smm-$(CONFIG_COMPILER_GCC) += gcc.c
diff --git a/src/lib/region.c b/src/lib/region.c
new file mode 100644
index 0000000..948addd
--- /dev/null
+++ b/src/lib/region.c
@@ -0,0 +1,121 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2015 Google 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; version 2 of the License.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc.
+ */
+
+#include <region.h>
+#include <string.h>
+
+static inline size_t region_offset(const struct region *r)
+{
+ return r->offset;
+}
+
+static inline size_t region_end(const struct region *r)
+{
+ return region_sz(r) + region_offset(r);
+}
+
+static int is_subregion(const struct region *p, const struct region *c)
+{
+ if (region_offset(c) < region_offset(p))
+ return 0;
+
+ if (region_sz(c) > region_sz(p))
+ return 0;
+
+ if (region_end(c) > region_end(p))
+ return 0;
+
+ return 1;
+}
+
+static int normalize_and_ok(const struct region *outer, struct region *inner)
+{
+ inner->offset += region_offset(outer);
+ return is_subregion(outer, inner);
+}
+
+static const struct region_device *rdev_root(const struct region_device *rdev)
+{
+ if (rdev->root == NULL)
+ return rdev;
+ return rdev->root;
+}
+
+void *rdev_mmap(const struct region_device *rd, size_t offset, size_t size)
+{
+ const struct region_device *rdev;
+ struct region req = {
+ .offset = offset,
+ .size = size,
+ };
+
+ if (!normalize_and_ok(&rd->region, &req))
+ return NULL;
+
+ rdev = rdev_root(rd);
+
+ return rdev->ops->mmap(rdev, req.offset, req.size);
+}
+
+int rdev_munmap(const struct region_device *rd, void *mapping)
+{
+ const struct region_device *rdev;
+
+ rdev = rdev_root(rd);
+
+ return rdev->ops->munmap(rdev, mapping);
+}
+
+ssize_t rdev_readat(const struct region_device *rd, void *b, size_t offset,
+ size_t size)
+{
+ const struct region_device *rdev;
+ struct region req = {
+ .offset = offset,
+ .size = size,
+ };
+
+ if (!normalize_and_ok(&rd->region, &req))
+ return -1;
+
+ rdev = rdev_root(rd);
+
+ return rdev->ops->readat(rdev, b, req.offset, req.size);
+}
+
+int rdev_chain(struct region_device *child, const struct region_device *parent,
+ size_t offset, size_t size)
+{
+ struct region req = {
+ .offset = offset,
+ .size = size,
+ };
+
+ if (!normalize_and_ok(&parent->region, &req))
+ return -1;
+
+ /* Keep track of root region device. Note the offsets are relative
+ * to the root device. */
+ child->root = rdev_root(parent);
+ child->ops = NULL;
+ child->region.offset = req.offset;
+ child->region.size = req.size;
+
+ return 0;
+}
Aaron Durbin (adurbin(a)chromium.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/9129
-gerrit
commit b020b47430a4539c16e7a1f0c272cdd447cb4eb0
Author: Aaron Durbin <adurbin(a)chromium.org>
Date: Thu Mar 26 12:29:12 2015 -0500
coreboot: add memory pool infrastructure
The memory pool infrastructure provides an allocator with
very simple free()ing semantics: only the most recent allocation
can be freed from the pool. However, it can be reset and when
not used any longer providing the entire region for future
allocations.
Change-Id: I5ae9ab35bb769d78bbc2866c5ae3b5ce2cdce5fa
Signed-off-by: Aaron Durbin <adurbin(a)chromium.org>
---
src/include/mem_pool.h | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/lib/Makefile.inc | 5 ++++
src/lib/mem_pool.c | 51 +++++++++++++++++++++++++++++++++++
3 files changed, 129 insertions(+)
diff --git a/src/include/mem_pool.h b/src/include/mem_pool.h
new file mode 100644
index 0000000..c57b707
--- /dev/null
+++ b/src/include/mem_pool.h
@@ -0,0 +1,73 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2015 Google 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; version 2 of the License.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc.
+ */
+
+#ifndef _MEM_POOL_H_
+#define _MEM_POOL_H_
+
+#include <stddef.h>
+#include <stdint.h>
+
+/*
+ * The memory pool allows one to allocate memory from a fixed size buffer
+ * that also allows freeing semantics for reuse. However, the current
+ * limitation is that the most recent allocation is the only one that
+ * can be freed. If one tries to free any allocation that isn't the
+ * most recently allocated it will result in a leak within the memory pool.
+ *
+ * The memory returned by allocations are at least 8 byte aligned. Note
+ * that this requires the backing buffer to start on at least an 8 byte
+ * alignment.
+ */
+
+struct mem_pool {
+ uint8_t *buf;
+ size_t size;
+ uint8_t *last_alloc;
+ size_t free_offset;
+};
+
+#define MEM_POOL_INIT(buf_, size_) \
+ { \
+ .buf = (buf_), \
+ .size = (size_), \
+ .last_alloc = NULL, \
+ .free_offset = 0, \
+ }
+
+static inline void mem_pool_reset(struct mem_pool *mp)
+{
+ mp->last_alloc = NULL;
+ mp->free_offset = 0;
+}
+
+/* Initialize a memory pool. */
+static inline void mem_pool_init(struct mem_pool *mp, void *buf, size_t sz)
+{
+ mp->buf = buf;
+ mp->size = sz;
+ mem_pool_reset(mp);
+}
+
+/* Allocate requested size from the memory pool. NULL returned on error. */
+void *mem_pool_alloc(struct mem_pool *mp, size_t sz);
+
+/* Free allocation from memory pool. */
+void mem_pool_free(struct mem_pool *mp, void *alloc);
+
+#endif /* _MEM_POOL_H_ */
diff --git a/src/lib/Makefile.inc b/src/lib/Makefile.inc
index 1a1b981..b861079 100644
--- a/src/lib/Makefile.inc
+++ b/src/lib/Makefile.inc
@@ -28,6 +28,7 @@ bootblock-$(CONFIG_GENERIC_UDELAY) += timer.c
bootblock-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
bootblock-y += memchr.c
bootblock-y += memcmp.c
+bootblock-y += mem_pool.c
bootblock-y += region.c
verstage-y += prog_ops.c
@@ -40,6 +41,7 @@ verstage-$(CONFIG_COMMON_CBFS_SPI_WRAPPER) += cbfs_spi.c
verstage-y += tlcl.c
verstage-$(CONFIG_GENERIC_UDELAY) += timer.c
verstage-$(CONFIG_GENERIC_GPIO_LIB) += gpio.c
+verstage-y += mem_pool.c
romstage-y += prog_ops.c
romstage-y += memchr.c
@@ -124,6 +126,9 @@ ramstage-$(CONFIG_RELOCATABLE_RAMSTAGE) += cbmem_stage_cache.c
romstage-$(CONFIG_RELOCATABLE_RAMSTAGE) += cbmem_stage_cache.c
endif
+romstage-y += mem_pool.c
+ramstage-y += mem_pool.c
+
romstage-y += region.c
ramstage-y += region.c
diff --git a/src/lib/mem_pool.c b/src/lib/mem_pool.c
new file mode 100644
index 0000000..4bd0668
--- /dev/null
+++ b/src/lib/mem_pool.c
@@ -0,0 +1,51 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2015 Google 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; version 2 of the License.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc.
+ */
+
+#include <mem_pool.h>
+#include <stdlib.h>
+
+void *mem_pool_alloc(struct mem_pool *mp, size_t sz)
+{
+ void *p;
+
+ /* Make all allocations be at least 8 byte aligned. */
+ sz = ALIGN_UP(sz, 8);
+
+ /* Determine if any space available. */
+ if ((mp->size - mp->free_offset) < sz)
+ return NULL;
+
+ p = &mp->buf[mp->free_offset];
+
+ mp->free_offset += sz;
+ mp->last_alloc = p;
+
+ return p;
+}
+
+void mem_pool_free(struct mem_pool *mp, void *p)
+{
+ /* Determine if p was the most recent allocation. */
+ if (p == NULL || mp->last_alloc != p)
+ return;
+
+ mp->free_offset = mp->last_alloc - mp->buf;
+ /* No way to track allocation before this one. */
+ mp->last_alloc = NULL;
+}