blob: 52a4a5097bc487927f34836802f0335172838d26 [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
David Hendricks90ca3b62012-11-16 14:48:22 -080035#define CBFS_HEADER_MAGIC 0x4F524243
36#define CBFS_HEADPTR_ADDR_X86 0xFFFFFFFC
Hung-Te Lin086842a2013-01-04 12:33:03 +080037#define CBFS_HEADER_VERSION1 0x31313131
38#define CBFS_HEADER_VERSION2 0x31313132
39#define CBFS_HEADER_VERSION CBFS_HEADER_VERSION2
David Hendricks90ca3b62012-11-16 14:48:22 -080040
Patrick Georgib7b56dd82009-09-14 13:29:27 +000041struct cbfs_header {
42 uint32_t magic;
43 uint32_t version;
44 uint32_t romsize;
45 uint32_t bootblocksize;
46 uint32_t align;
47 uint32_t offset;
David Hendricks90ca3b62012-11-16 14:48:22 -080048 uint32_t architecture; /* Version 2 */
49 uint32_t pad[1];
Patrick Georgib7b56dd82009-09-14 13:29:27 +000050} __attribute__ ((packed));
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +000051
David Hendricks90ca3b62012-11-16 14:48:22 -080052#define CBFS_ARCHITECTURE_UNKNOWN 0xFFFFFFFF
53#define CBFS_ARCHITECTURE_X86 0x00000001
54#define CBFS_ARCHITECTURE_ARMV7 0x00000010
55
Hung-Te Lineab2c812013-01-29 01:56:17 +080056#define CBFS_FILE_MAGIC "LARCHIVE"
57
Patrick Georgib7b56dd82009-09-14 13:29:27 +000058struct cbfs_file {
Stefan Reinauera1e48242011-10-21 14:24:57 -070059 uint8_t magic[8];
Patrick Georgib7b56dd82009-09-14 13:29:27 +000060 uint32_t len;
61 uint32_t type;
62 uint32_t checksum;
63 uint32_t offset;
64} __attribute__ ((packed));
65
66struct cbfs_stage {
Stefan Reinauera1e48242011-10-21 14:24:57 -070067 uint32_t compression;
68 uint64_t entry;
69 uint64_t load;
70 uint32_t len;
71 uint32_t memlen;
Patrick Georgib7b56dd82009-09-14 13:29:27 +000072} __attribute__ ((packed));
73
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -080074#define PAYLOAD_SEGMENT_CODE makemagic('C', 'O', 'D', 'E')
75#define PAYLOAD_SEGMENT_DATA makemagic('D', 'A', 'T', 'A')
Wei Hu2ad6ee92014-04-16 22:52:59 -070076#define PAYLOAD_SEGMENT_BSS makemagic('B', 'S', 'S', ' ')
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -080077#define PAYLOAD_SEGMENT_PARAMS makemagic('P', 'A', 'R', 'A')
78#define PAYLOAD_SEGMENT_ENTRY makemagic('E', 'N', 'T', 'R')
Patrick Georgib7b56dd82009-09-14 13:29:27 +000079
80struct cbfs_payload_segment {
Stefan Reinauera1e48242011-10-21 14:24:57 -070081 uint32_t type;
82 uint32_t compression;
83 uint32_t offset;
84 uint64_t load_addr;
85 uint32_t len;
86 uint32_t mem_len;
Patrick Georgib7b56dd82009-09-14 13:29:27 +000087} __attribute__ ((packed));
88
89struct cbfs_payload {
90 struct cbfs_payload_segment segments;
91} __attribute__ ((packed));
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +000092
93/** These are standard component types for well known
94 components (i.e - those that coreboot needs to consume.
95 Users are welcome to use any other value for their
96 components */
97
Stefan Reinauer800379f2010-03-01 08:34:19 +000098#define CBFS_COMPONENT_STAGE 0x10
99#define CBFS_COMPONENT_PAYLOAD 0x20
100#define CBFS_COMPONENT_OPTIONROM 0x30
101#define CBFS_COMPONENT_BOOTSPLASH 0x40
102#define CBFS_COMPONENT_RAW 0x50
103#define CBFS_COMPONENT_VSA 0x51
104#define CBFS_COMPONENT_MBI 0x52
105#define CBFS_COMPONENT_MICROCODE 0x53
Patrick Georgia865b172011-01-14 07:40:24 +0000106#define CBFS_COMPONENT_CMOS_DEFAULT 0xaa
Patrick Georgi24479372011-01-18 13:56:36 +0000107#define CBFS_COMPONENT_CMOS_LAYOUT 0x01aa
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +0000108
Ronald G. Minnich83b8f0c2009-05-08 19:23:00 +0000109/* The deleted type is chosen to be a value
110 * that can be written in a FLASH from all other
Stefan Reinauer14e22772010-04-27 06:56:47 +0000111 * values.
Ronald G. Minnich83b8f0c2009-05-08 19:23:00 +0000112 */
113#define CBFS_COMPONENT_DELETED 0
114
Stefan Reinauer14e22772010-04-27 06:56:47 +0000115/* for all known FLASH, this value can be changed
116 * to all other values. This allows NULL files to be
Ronald G. Minnich83b8f0c2009-05-08 19:23:00 +0000117 * changed without a block erase
118 */
Peter Stuge1d862de2009-04-14 00:08:34 +0000119#define CBFS_COMPONENT_NULL 0xFFFFFFFF
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +0000120
Hung-Te Lin3bb035b2013-01-29 02:15:49 +0800121#define CBFS_NAME(_c) (((char *) (_c)) + sizeof(struct cbfs_file))
Stefan Reinauerdb5b8932013-01-18 15:53:22 -0800122#define CBFS_SUBHEADER(_p) ( (void *) ((((uint8_t *) (_p)) + ntohl((_p)->offset))) )
Ronald G. Minnicha8a133d2013-12-30 13:16:18 -0800123/* cbfs_image.c */
124uint32_t get_cbfs_entry_type(const char *name, uint32_t default_value);
125const char *get_cbfs_entry_type_name(uint32_t type);
126uint32_t get_cbfs_compression(const char *name, uint32_t unknown);
Stefan Reinauerdb5b8932013-01-18 15:53:22 -0800127
Ronald G. Minnich3fcde222014-02-04 17:35:44 -0800128/* common.c */
129void cbfs_file_get_header(struct buffer *buf, struct cbfs_file *file);
130
Ronald G. Minnich818f3692014-02-04 08:29:35 -0800131/* cbfs-mkpayload.c */
132void xdr_segs(struct buffer *output,
133 struct cbfs_payload_segment *segs, int nseg);
Aaron Durbinca630272014-08-05 10:48:20 -0500134void xdr_get_seg(struct cbfs_payload_segment *out,
135 struct cbfs_payload_segment *in);
Ronald G. Minnich818f3692014-02-04 08:29:35 -0800136
Stefan Reinauer63217582012-10-29 16:52:36 -0700137#endif