blob: ef3959450ab07309f1d763dd68b9e2041dffbabc [file] [log] [blame]
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +00001/*
Patrick Georgib7b56dd82009-09-14 13:29:27 +00002 * Copyright (C) 2009 coresystems GmbH
3 * written by Patrick Georgi <patrick.georgi@coresystems.de>
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +00004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
17 */
18
Stefan Reinauer63217582012-10-29 16:52:36 -070019#ifndef __CBFS_H
20#define __CBFS_H
21
Patrick Georgib7b56dd82009-09-14 13:29:27 +000022#include <stdint.h>
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -080023
24/* create a magic number in host-byte order.
25 * b3 is the high order byte.
26 * in the coreboot tools, we go with the 32-bit
27 * magic number convention.
28 * This was an inline func but that breaks anything
29 * that uses it in a case statement.
30 */
31
32#define makemagic(b3, b2, b1, b0)\
33 (((b3)<<24) | ((b2) << 16) | ((b1) << 8) | (b0))
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +000034
Sol Boucher67a0a862015-03-18 12:36:27 -070035// Alignment (in bytes) to be used when no master header is present
36#define CBFS_ENTRY_ALIGNMENT 64
37
David Hendricks90ca3b62012-11-16 14:48:22 -080038#define CBFS_HEADER_MAGIC 0x4F524243
39#define CBFS_HEADPTR_ADDR_X86 0xFFFFFFFC
Hung-Te Lin086842a2013-01-04 12:33:03 +080040#define CBFS_HEADER_VERSION1 0x31313131
41#define CBFS_HEADER_VERSION2 0x31313132
42#define CBFS_HEADER_VERSION CBFS_HEADER_VERSION2
David Hendricks90ca3b62012-11-16 14:48:22 -080043
Patrick Georgib7b56dd82009-09-14 13:29:27 +000044struct cbfs_header {
45 uint32_t magic;
46 uint32_t version;
47 uint32_t romsize;
48 uint32_t bootblocksize;
49 uint32_t align;
50 uint32_t offset;
David Hendricks90ca3b62012-11-16 14:48:22 -080051 uint32_t architecture; /* Version 2 */
52 uint32_t pad[1];
Patrick Georgib7b56dd82009-09-14 13:29:27 +000053} __attribute__ ((packed));
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +000054
David Hendricks90ca3b62012-11-16 14:48:22 -080055#define CBFS_ARCHITECTURE_UNKNOWN 0xFFFFFFFF
56#define CBFS_ARCHITECTURE_X86 0x00000001
Gabe Black51edd542013-09-30 23:00:33 -070057#define CBFS_ARCHITECTURE_ARM 0x00000010
Ronald G. Minnich5f431842013-11-12 09:03:33 -080058#define CBFS_ARCHITECTURE_AARCH64 0x0000aa64
Paul Burton33186922014-06-13 23:56:45 +010059#define CBFS_ARCHITECTURE_MIPS 0x00000100
Ronald G. Minnich833bf202014-10-16 10:55:39 +000060#define CBFS_ARCHITECTURE_RISCV 0xc001d0de
David Hendricks90ca3b62012-11-16 14:48:22 -080061
Hung-Te Lineab2c812013-01-29 01:56:17 +080062#define CBFS_FILE_MAGIC "LARCHIVE"
63
Patrick Georgib7b56dd82009-09-14 13:29:27 +000064struct cbfs_file {
Stefan Reinauera1e48242011-10-21 14:24:57 -070065 uint8_t magic[8];
Patrick Georgib7b56dd82009-09-14 13:29:27 +000066 uint32_t len;
67 uint32_t type;
68 uint32_t checksum;
69 uint32_t offset;
70} __attribute__ ((packed));
71
72struct cbfs_stage {
Stefan Reinauera1e48242011-10-21 14:24:57 -070073 uint32_t compression;
74 uint64_t entry;
75 uint64_t load;
76 uint32_t len;
77 uint32_t memlen;
Patrick Georgib7b56dd82009-09-14 13:29:27 +000078} __attribute__ ((packed));
79
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -080080#define PAYLOAD_SEGMENT_CODE makemagic('C', 'O', 'D', 'E')
81#define PAYLOAD_SEGMENT_DATA makemagic('D', 'A', 'T', 'A')
Wei Hu2ad6ee92014-04-16 22:52:59 -070082#define PAYLOAD_SEGMENT_BSS makemagic('B', 'S', 'S', ' ')
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -080083#define PAYLOAD_SEGMENT_PARAMS makemagic('P', 'A', 'R', 'A')
84#define PAYLOAD_SEGMENT_ENTRY makemagic('E', 'N', 'T', 'R')
Patrick Georgib7b56dd82009-09-14 13:29:27 +000085
86struct cbfs_payload_segment {
Stefan Reinauera1e48242011-10-21 14:24:57 -070087 uint32_t type;
88 uint32_t compression;
89 uint32_t offset;
90 uint64_t load_addr;
91 uint32_t len;
92 uint32_t mem_len;
Patrick Georgib7b56dd82009-09-14 13:29:27 +000093} __attribute__ ((packed));
94
95struct cbfs_payload {
96 struct cbfs_payload_segment segments;
97} __attribute__ ((packed));
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +000098
99/** These are standard component types for well known
100 components (i.e - those that coreboot needs to consume.
101 Users are welcome to use any other value for their
102 components */
103
Stefan Reinauer800379f2010-03-01 08:34:19 +0000104#define CBFS_COMPONENT_STAGE 0x10
105#define CBFS_COMPONENT_PAYLOAD 0x20
106#define CBFS_COMPONENT_OPTIONROM 0x30
107#define CBFS_COMPONENT_BOOTSPLASH 0x40
108#define CBFS_COMPONENT_RAW 0x50
109#define CBFS_COMPONENT_VSA 0x51
110#define CBFS_COMPONENT_MBI 0x52
111#define CBFS_COMPONENT_MICROCODE 0x53
Martin Rothdde307c2015-03-24 15:54:20 -0600112#define CBFS_COMPONENT_FSP 0x60
113#define CBFS_COMPONENT_MRC 0x61
Patrick Georgia865b172011-01-14 07:40:24 +0000114#define CBFS_COMPONENT_CMOS_DEFAULT 0xaa
Martin Rothdde307c2015-03-24 15:54:20 -0600115#define CBFS_COMPONENT_SPD 0xab
116#define CBFS_COMPONENT_MRC_CACHE 0xac
Patrick Georgi24479372011-01-18 13:56:36 +0000117#define CBFS_COMPONENT_CMOS_LAYOUT 0x01aa
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +0000118
Ronald G. Minnich83b8f0c2009-05-08 19:23:00 +0000119/* The deleted type is chosen to be a value
120 * that can be written in a FLASH from all other
Stefan Reinauer14e22772010-04-27 06:56:47 +0000121 * values.
Ronald G. Minnich83b8f0c2009-05-08 19:23:00 +0000122 */
123#define CBFS_COMPONENT_DELETED 0
124
Stefan Reinauer14e22772010-04-27 06:56:47 +0000125/* for all known FLASH, this value can be changed
126 * to all other values. This allows NULL files to be
Ronald G. Minnich83b8f0c2009-05-08 19:23:00 +0000127 * changed without a block erase
128 */
Peter Stuge1d862de2009-04-14 00:08:34 +0000129#define CBFS_COMPONENT_NULL 0xFFFFFFFF
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +0000130
Hung-Te Lin3bb035b2013-01-29 02:15:49 +0800131#define CBFS_NAME(_c) (((char *) (_c)) + sizeof(struct cbfs_file))
Stefan Reinauerdb5b8932013-01-18 15:53:22 -0800132#define CBFS_SUBHEADER(_p) ( (void *) ((((uint8_t *) (_p)) + ntohl((_p)->offset))) )
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -0800133/* cbfs_image.c */
134uint32_t get_cbfs_entry_type(const char *name, uint32_t default_value);
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -0800135uint32_t get_cbfs_compression(const char *name, uint32_t unknown);
Stefan Reinauerdb5b8932013-01-18 15:53:22 -0800136
Ronald G. Minnich3fcde222014-02-04 17:35:44 -0800137/* common.c */
138void cbfs_file_get_header(struct buffer *buf, struct cbfs_file *file);
139
Ronald G. Minnich818f3692014-02-04 08:29:35 -0800140/* cbfs-mkpayload.c */
141void xdr_segs(struct buffer *output,
142 struct cbfs_payload_segment *segs, int nseg);
Aaron Durbinca630272014-08-05 10:48:20 -0500143void xdr_get_seg(struct cbfs_payload_segment *out,
144 struct cbfs_payload_segment *in);
Ronald G. Minnich818f3692014-02-04 08:29:35 -0800145
Stefan Reinauer63217582012-10-29 16:52:36 -0700146#endif