David Hendricks | 6d62d75 | 2011-03-07 21:20:22 -0800 | [diff] [blame] | 1 | /* |
Daniel Campello | 241c6bf | 2021-04-19 09:58:47 -0600 | [diff] [blame] | 2 | * Copyright 2010, Google LLC. |
Edward O'Callaghan | cba2d4d | 2020-07-24 16:10:42 +1000 | [diff] [blame] | 3 | * Copyright 2018-present, Facebook Inc. |
David Hendricks | 6d62d75 | 2011-03-07 21:20:22 -0800 | [diff] [blame] | 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. |
David Hendricks | 6d62d75 | 2011-03-07 21:20:22 -0800 | [diff] [blame] | 35 | */ |
| 36 | |
Edward O'Callaghan | 12c7e03 | 2019-09-09 00:45:03 +1000 | [diff] [blame] | 37 | #ifndef __FMAP_H__ |
| 38 | #define __FMAP_H__ 1 |
David Hendricks | 6d62d75 | 2011-03-07 21:20:22 -0800 | [diff] [blame] | 39 | |
| 40 | #include <inttypes.h> |
Edward O'Callaghan | cba2d4d | 2020-07-24 16:10:42 +1000 | [diff] [blame] | 41 | #include <stdbool.h> |
David Hendricks | 6d62d75 | 2011-03-07 21:20:22 -0800 | [diff] [blame] | 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 */ |
Edward O'Callaghan | a708259 | 2020-08-18 14:16:13 +1000 | [diff] [blame] | 46 | #define FMAP_STRLEN 32 /* maximum length for strings */ |
David Hendricks | 6d62d75 | 2011-03-07 21:20:22 -0800 | [diff] [blame] | 47 | |
David Hendricks | 6d62d75 | 2011-03-07 21:20:22 -0800 | [diff] [blame] | 48 | struct 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 Campello | 241c6bf | 2021-04-19 09:58:47 -0600 | [diff] [blame] | 54 | |
David Hendricks | 6d62d75 | 2011-03-07 21:20:22 -0800 | [diff] [blame] | 55 | struct fmap { |
Daniel Campello | 241c6bf | 2021-04-19 09:58:47 -0600 | [diff] [blame] | 56 | uint8_t signature[8]; /* "__FMAP__" */ |
David Hendricks | 6d62d75 | 2011-03-07 21:20:22 -0800 | [diff] [blame] | 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[]; |
Edward O'Callaghan | a708259 | 2020-08-18 14:16:13 +1000 | [diff] [blame] | 65 | } __attribute__((packed)); |
Simon Glass | 1d2e26a | 2013-03-04 15:34:46 -0800 | [diff] [blame] | 66 | |
Edward O'Callaghan | a02ec34 | 2020-07-24 20:14:31 +1000 | [diff] [blame] | 67 | int fmap_read_from_buffer(struct fmap **fmap_out, const uint8_t *buf, size_t len); |
Edward O'Callaghan | 20a3651 | 2020-08-18 14:14:31 +1000 | [diff] [blame] | 68 | int fmap_read_from_rom(struct fmap **fmap_out, struct flashctx *const flashctx, size_t rom_offset, size_t len); |
Edward O'Callaghan | a02ec34 | 2020-07-24 20:14:31 +1000 | [diff] [blame] | 69 | |
Edward O'Callaghan | f0a3b3d | 2020-11-01 18:27:36 +1100 | [diff] [blame] | 70 | |
Edward O'Callaghan | 12c7e03 | 2019-09-09 00:45:03 +1000 | [diff] [blame] | 71 | #endif /* __FMAP_H__*/ |