blob: 924e11f6b970e5ec0213465632dc84ee0c2d3f4b [file] [log] [blame]
David Hendricks6d62d752011-03-07 21:20:22 -08001/*
Daniel Campello241c6bf2021-04-19 09:58:47 -06002 * Copyright 2010, Google LLC.
Edward O'Callaghancba2d4d2020-07-24 16:10:42 +10003 * Copyright 2018-present, Facebook Inc.
David Hendricks6d62d752011-03-07 21:20:22 -08004 * 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.
David Hendricks6d62d752011-03-07 21:20:22 -080035 */
36
Edward O'Callaghan12c7e032019-09-09 00:45:03 +100037#ifndef __FMAP_H__
38#define __FMAP_H__ 1
David Hendricks6d62d752011-03-07 21:20:22 -080039
40#include <inttypes.h>
Edward O'Callaghancba2d4d2020-07-24 16:10:42 +100041#include <stdbool.h>
David Hendricks6d62d752011-03-07 21:20:22 -080042
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 */
Edward O'Callaghana7082592020-08-18 14:16:13 +100046#define FMAP_STRLEN 32 /* maximum length for strings */
David Hendricks6d62d752011-03-07 21:20:22 -080047
David Hendricks6d62d752011-03-07 21:20:22 -080048struct 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));
Daniel Campello241c6bf2021-04-19 09:58:47 -060054
David Hendricks6d62d752011-03-07 21:20:22 -080055struct fmap {
Daniel Campello241c6bf2021-04-19 09:58:47 -060056 uint8_t signature[8]; /* "__FMAP__" */
David Hendricks6d62d752011-03-07 21:20:22 -080057 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[];
Edward O'Callaghana7082592020-08-18 14:16:13 +100065} __attribute__((packed));
Simon Glass1d2e26a2013-03-04 15:34:46 -080066
Edward O'Callaghana02ec342020-07-24 20:14:31 +100067int fmap_read_from_buffer(struct fmap **fmap_out, const uint8_t *buf, size_t len);
Edward O'Callaghan20a36512020-08-18 14:14:31 +100068int fmap_read_from_rom(struct fmap **fmap_out, struct flashctx *const flashctx, size_t rom_offset, size_t len);
Edward O'Callaghana02ec342020-07-24 20:14:31 +100069
Edward O'Callaghanf0a3b3d2020-11-01 18:27:36 +110070
Edward O'Callaghan12c7e032019-09-09 00:45:03 +100071#endif /* __FMAP_H__*/