blob: be5f8bc25d56bbc3661fa121b0c90e1641d3907f [file] [log] [blame]
Arthur Heymansc82900b2018-01-10 12:48:16 +01001/*
2 * Copyright 2015, Google Inc.
3 * Copyright 2018-present, Facebook Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * Alternatively, this software may be distributed under the terms of the
33 * GNU General Public License ("GPL") version 2 as published by the Free
34 * Software Foundation.
35 */
36
37#ifndef __FMAP_H__
38#define __FMAP_H__ 1
39
40#include <inttypes.h>
41#include <stdbool.h>
42
43#define FMAP_SIGNATURE "__FMAP__"
44#define FMAP_VER_MAJOR 1 /* this header's FMAP minor version */
45#define FMAP_VER_MINOR 1 /* this header's FMAP minor version */
46#define FMAP_STRLEN 32 /* maximum length for strings */
47
48struct fmap_area {
49 uint32_t offset; /* offset relative to base */
50 uint32_t size; /* size in bytes */
51 uint8_t name[FMAP_STRLEN]; /* descriptive name */
52 uint16_t flags; /* flags for this area */
53} __attribute__((packed));
54
55struct fmap {
56 uint8_t signature[8]; /* "__FMAP__" */
57 uint8_t ver_major; /* major version */
58 uint8_t ver_minor; /* minor version */
59 uint64_t base; /* address of the firmware binary */
60 uint32_t size; /* size of firmware binary in bytes */
61 uint8_t name[FMAP_STRLEN]; /* name of this firmware binary */
62 uint16_t nareas; /* number of areas described by
63 fmap_areas[] below */
64 struct fmap_area areas[];
65} __attribute__((packed));
66
67int fmap_read_from_buffer(struct fmap **fmap_out, const uint8_t *buf, size_t len);
68int fmap_read_from_rom(struct fmap **fmap_out, struct flashctx *const flashctx, size_t rom_offset, size_t len);
69
70
71#endif /* __FMAP_H__*/