From 0b94184a9e32d24c8c0f0e41243ab29b24a19e99 Mon Sep 17 00:00:00 2001
From: Yang Hamo Bai <hamo.by@gmail.com>
Date: Wed, 29 Jun 2011 20:58:44 +0800
Subject: [PATCH 03/12] CBFS: added architecture to CBFS master header

We want to support both X86 and ARM for CBFS, so
we need to know the architecture of a rom file.
Bump CBFS version to 0x31313132.

Signed-off-by: Yang Hamo Bai <hamo.by@gmail.com>
---
 documentation/cbfs.txt          |   22 ++++++++++++++++------
 payloads/coreinfo/cbfs_module.c |    3 ++-
 src/include/cbfs.h              |   18 +++++++++++++++---
 util/cbfstool/cbfs.h            |    9 ++++++---
 4 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/documentation/cbfs.txt b/documentation/cbfs.txt
index 61f9f79..aa9dc53 100644
--- a/documentation/cbfs.txt
+++ b/documentation/cbfs.txt
@@ -144,11 +144,15 @@ need to read the pointer and do the appropriate math to locate the header.
 The following is the structure of the master header:
 
 struct cbfs_header {
-	unsigned int magic;
-	unsigned int size;
-	unsigned int align;
-	unsigned int offset;
-};
+       u32 magic;
+       u32 version;
+       u32 romsize;
+       u32 bootblocksize;
+       u32 align;
+       u32 offset;
+       u32 architecture;
+       u32 pad[1];
+} __attribute__((packed));
 
 The meaning of each member is as follows:
 
@@ -156,9 +160,13 @@ The meaning of each member is as follows:
 magic
 number is 0x4F524243, which is 'ORBC' in ASCII.
 
-'size' is the size of the ROM in bytes.  Coreboot will subtract 'size' from
+'version' is TODO
+
+'romsize' is the size of the ROM in bytes.  Coreboot will subtract 'size' from
 0xFFFFFFFF to locate the beginning of the ROM in memory.
 
+'bootblocksize' is TODO
+
 'align' is the number of bytes that each component is aligned to within the
 ROM.  This is used to make sure that each component is aligned correctly
 with
@@ -169,6 +177,8 @@ component at runtime without disturbing the others.
 the ROM).  This is to allow for arbitrary space to be left at the beginning
 of the ROM for things like embedded controller firmware.
 
+'architecture' is TODO
+
 = Bootblock =
 The bootblock is a mandatory component in the ROM.  It is located in the
 last
diff --git a/payloads/coreinfo/cbfs_module.c b/payloads/coreinfo/cbfs_module.c
index 274356d..e2083ad 100644
--- a/payloads/coreinfo/cbfs_module.c
+++ b/payloads/coreinfo/cbfs_module.c
@@ -41,7 +41,8 @@ struct cbheader {
 	u32 bootblocksize;
 	u32 align;
 	u32 offset;
-	u32 pad[2];
+	u32 architecture;
+	u32 pad[1];
 } __attribute__ ((packed));
 
 struct cbfile {
diff --git a/src/include/cbfs.h b/src/include/cbfs.h
index c1c1e33..177d878 100644
--- a/src/include/cbfs.h
+++ b/src/include/cbfs.h
@@ -79,11 +79,19 @@
     located somewhere in the bootblock.  Where it
     actually lives is up to coreboot. A pointer to
     this header will live at 0xFFFFFFFc, so we can
-    easily find it. */
+    easily find it. 
+    For ARM, we don't need the pointer to this header
+    since we put the master header at 0x20. */
 
 #define CBFS_HEADER_MAGIC  0x4F524243
+#if CONFIG_ARCH_X86
 #define CBFS_HEADPTR_ADDR 0xFFFFFFFc
-#define VERSION1 0x31313131
+#elif CONFIG_ARCH_ARM
+#define CBFS_HEADPTR_ADDR
+#else
+#error "No CBFS_HEADPTR_ADDR."
+#endif
+#define VERSION1 0x31313132
 
 struct cbfs_header {
 	u32 magic;
@@ -92,9 +100,13 @@ struct cbfs_header {
         u32 bootblocksize;
 	u32 align;
 	u32 offset;
-	u32 pad[2];
+	u32 architecture;
+	u32 pad[1];
 } __attribute__((packed));
 
+#define CBFS_ARCHITECTURE_ARM      0x10
+#define CBFS_ARCHITECTURE_X86      0x20
+
 /** This is a component header - every entry in the CBFS
     will have this header.
 
diff --git a/util/cbfstool/cbfs.h b/util/cbfstool/cbfs.h
index 5c93838..9b95aaf 100644
--- a/util/cbfstool/cbfs.h
+++ b/util/cbfstool/cbfs.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 coresystems GmbH
- *                 written by Patrick Georgi <patrick.georgi@coresystems.de>
+ * written by Patrick Georgi <patrick.georgi@coresystems.de>
  *
  * 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
@@ -25,9 +25,13 @@ struct cbfs_header {
 	uint32_t bootblocksize;
 	uint32_t align;
 	uint32_t offset;
-	uint32_t pad[2];
+	uint32_t architecture;
+	uint32_t pad[1];
 } __attribute__ ((packed));
 
+#define CBFS_ARCHITECTURE_ARM      0x10
+#define CBFS_ARCHITECTURE_X86      0x20
+
 struct cbfs_file {
 	char magic[8];
 	uint32_t len;
@@ -92,4 +96,3 @@ struct cbfs_payload {
 #define CBFS_COMPONENT_NULL 0xFFFFFFFF
 
 int cbfs_file_header(uint32_t physaddr);
-struct cbfs_file *cbfs_create_empty_file(uint32_t physaddr, uint32_t size);
-- 
1.7.6

