Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 1 | /* |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 2 | * Copyright (C) 2009 coresystems GmbH |
| 3 | * written by Patrick Georgi <patrick.georgi@coresystems.de> |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 4 | * |
| 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 Reinauer | 6321758 | 2012-10-29 16:52:36 -0700 | [diff] [blame] | 19 | #ifndef __CBFS_H |
| 20 | #define __CBFS_H |
| 21 | |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 22 | #include <stdint.h> |
Ronald G. Minnich | a8a133d | 2013-12-30 13:16:18 -0800 | [diff] [blame] | 23 | #include "elf.h" |
| 24 | |
| 25 | /* create a magic number in host-byte order. |
| 26 | * b3 is the high order byte. |
| 27 | * in the coreboot tools, we go with the 32-bit |
| 28 | * magic number convention. |
| 29 | * This was an inline func but that breaks anything |
| 30 | * that uses it in a case statement. |
| 31 | */ |
| 32 | |
| 33 | #define makemagic(b3, b2, b1, b0)\ |
| 34 | (((b3)<<24) | ((b2) << 16) | ((b1) << 8) | (b0)) |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 35 | |
David Hendricks | 90ca3b6 | 2012-11-16 14:48:22 -0800 | [diff] [blame] | 36 | #define CBFS_HEADER_MAGIC 0x4F524243 |
| 37 | #define CBFS_HEADPTR_ADDR_X86 0xFFFFFFFC |
Hung-Te Lin | 086842a | 2013-01-04 12:33:03 +0800 | [diff] [blame] | 38 | #define CBFS_HEADER_VERSION1 0x31313131 |
| 39 | #define CBFS_HEADER_VERSION2 0x31313132 |
| 40 | #define CBFS_HEADER_VERSION CBFS_HEADER_VERSION2 |
David Hendricks | 90ca3b6 | 2012-11-16 14:48:22 -0800 | [diff] [blame] | 41 | |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 42 | struct cbfs_header { |
| 43 | uint32_t magic; |
| 44 | uint32_t version; |
| 45 | uint32_t romsize; |
| 46 | uint32_t bootblocksize; |
| 47 | uint32_t align; |
| 48 | uint32_t offset; |
David Hendricks | 90ca3b6 | 2012-11-16 14:48:22 -0800 | [diff] [blame] | 49 | uint32_t architecture; /* Version 2 */ |
| 50 | uint32_t pad[1]; |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 51 | } __attribute__ ((packed)); |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 52 | |
David Hendricks | 90ca3b6 | 2012-11-16 14:48:22 -0800 | [diff] [blame] | 53 | #define CBFS_ARCHITECTURE_UNKNOWN 0xFFFFFFFF |
| 54 | #define CBFS_ARCHITECTURE_X86 0x00000001 |
| 55 | #define CBFS_ARCHITECTURE_ARMV7 0x00000010 |
| 56 | |
Hung-Te Lin | eab2c81 | 2013-01-29 01:56:17 +0800 | [diff] [blame] | 57 | #define CBFS_FILE_MAGIC "LARCHIVE" |
| 58 | |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 59 | struct cbfs_file { |
Stefan Reinauer | a1e4824 | 2011-10-21 14:24:57 -0700 | [diff] [blame] | 60 | uint8_t magic[8]; |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 61 | uint32_t len; |
| 62 | uint32_t type; |
| 63 | uint32_t checksum; |
| 64 | uint32_t offset; |
| 65 | } __attribute__ ((packed)); |
| 66 | |
| 67 | struct cbfs_stage { |
Stefan Reinauer | a1e4824 | 2011-10-21 14:24:57 -0700 | [diff] [blame] | 68 | uint32_t compression; |
| 69 | uint64_t entry; |
| 70 | uint64_t load; |
| 71 | uint32_t len; |
| 72 | uint32_t memlen; |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 73 | } __attribute__ ((packed)); |
| 74 | |
Ronald G. Minnich | a8a133d | 2013-12-30 13:16:18 -0800 | [diff] [blame] | 75 | #define PAYLOAD_SEGMENT_CODE makemagic('C', 'O', 'D', 'E') |
| 76 | #define PAYLOAD_SEGMENT_DATA makemagic('D', 'A', 'T', 'A') |
| 77 | #define PAYLOAD_SEGMENT_BSS makemagic(' ', 'B', 'S', 'S') |
| 78 | #define PAYLOAD_SEGMENT_PARAMS makemagic('P', 'A', 'R', 'A') |
| 79 | #define PAYLOAD_SEGMENT_ENTRY makemagic('E', 'N', 'T', 'R') |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 80 | |
| 81 | struct cbfs_payload_segment { |
Stefan Reinauer | a1e4824 | 2011-10-21 14:24:57 -0700 | [diff] [blame] | 82 | uint32_t type; |
| 83 | uint32_t compression; |
| 84 | uint32_t offset; |
| 85 | uint64_t load_addr; |
| 86 | uint32_t len; |
| 87 | uint32_t mem_len; |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 88 | } __attribute__ ((packed)); |
| 89 | |
| 90 | struct cbfs_payload { |
| 91 | struct cbfs_payload_segment segments; |
| 92 | } __attribute__ ((packed)); |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 93 | |
| 94 | /** These are standard component types for well known |
| 95 | components (i.e - those that coreboot needs to consume. |
| 96 | Users are welcome to use any other value for their |
| 97 | components */ |
| 98 | |
Stefan Reinauer | 800379f | 2010-03-01 08:34:19 +0000 | [diff] [blame] | 99 | #define CBFS_COMPONENT_STAGE 0x10 |
| 100 | #define CBFS_COMPONENT_PAYLOAD 0x20 |
| 101 | #define CBFS_COMPONENT_OPTIONROM 0x30 |
| 102 | #define CBFS_COMPONENT_BOOTSPLASH 0x40 |
| 103 | #define CBFS_COMPONENT_RAW 0x50 |
| 104 | #define CBFS_COMPONENT_VSA 0x51 |
| 105 | #define CBFS_COMPONENT_MBI 0x52 |
| 106 | #define CBFS_COMPONENT_MICROCODE 0x53 |
Patrick Georgi | a865b17 | 2011-01-14 07:40:24 +0000 | [diff] [blame] | 107 | #define CBFS_COMPONENT_CMOS_DEFAULT 0xaa |
Patrick Georgi | 2447937 | 2011-01-18 13:56:36 +0000 | [diff] [blame] | 108 | #define CBFS_COMPONENT_CMOS_LAYOUT 0x01aa |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 109 | |
Ronald G. Minnich | 83b8f0c | 2009-05-08 19:23:00 +0000 | [diff] [blame] | 110 | /* The deleted type is chosen to be a value |
| 111 | * that can be written in a FLASH from all other |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 112 | * values. |
Ronald G. Minnich | 83b8f0c | 2009-05-08 19:23:00 +0000 | [diff] [blame] | 113 | */ |
| 114 | #define CBFS_COMPONENT_DELETED 0 |
| 115 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 116 | /* for all known FLASH, this value can be changed |
| 117 | * to all other values. This allows NULL files to be |
Ronald G. Minnich | 83b8f0c | 2009-05-08 19:23:00 +0000 | [diff] [blame] | 118 | * changed without a block erase |
| 119 | */ |
Peter Stuge | 1d862de | 2009-04-14 00:08:34 +0000 | [diff] [blame] | 120 | #define CBFS_COMPONENT_NULL 0xFFFFFFFF |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 121 | |
Hung-Te Lin | 3bb035b | 2013-01-29 02:15:49 +0800 | [diff] [blame] | 122 | #define CBFS_NAME(_c) (((char *) (_c)) + sizeof(struct cbfs_file)) |
Stefan Reinauer | db5b893 | 2013-01-18 15:53:22 -0800 | [diff] [blame] | 123 | #define CBFS_SUBHEADER(_p) ( (void *) ((((uint8_t *) (_p)) + ntohl((_p)->offset))) ) |
Ronald G. Minnich | a8a133d | 2013-12-30 13:16:18 -0800 | [diff] [blame] | 124 | /* cbfs_image.c */ |
| 125 | uint32_t get_cbfs_entry_type(const char *name, uint32_t default_value); |
| 126 | const char *get_cbfs_entry_type_name(uint32_t type); |
| 127 | uint32_t get_cbfs_compression(const char *name, uint32_t unknown); |
Stefan Reinauer | db5b893 | 2013-01-18 15:53:22 -0800 | [diff] [blame] | 128 | |
Ronald G. Minnich | a8a133d | 2013-12-30 13:16:18 -0800 | [diff] [blame] | 129 | /* elfheaders.c */ |
| 130 | int |
| 131 | elf_headers(const struct buffer *pinput, |
Alexandru Gagniuc | 35850ae | 2014-02-02 22:37:28 -0600 | [diff] [blame] | 132 | uint32_t arch, |
Ronald G. Minnich | a8a133d | 2013-12-30 13:16:18 -0800 | [diff] [blame] | 133 | Elf64_Ehdr *ehdr, |
| 134 | Elf64_Phdr **pphdr, |
| 135 | Elf64_Shdr **pshdr); |
Stefan Reinauer | 6321758 | 2012-10-29 16:52:36 -0700 | [diff] [blame] | 136 | |
Ronald G. Minnich | 818f369 | 2014-02-04 08:29:35 -0800 | [diff] [blame] | 137 | /* cbfs-mkpayload.c */ |
| 138 | void xdr_segs(struct buffer *output, |
| 139 | struct cbfs_payload_segment *segs, int nseg); |
| 140 | |
Stefan Reinauer | 6321758 | 2012-10-29 16:52:36 -0700 | [diff] [blame] | 141 | #endif |