Simon Glass | c53fc49 | 2013-02-10 17:00:38 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
Edward O'Callaghan | 10bb9ae | 2020-12-17 13:06:10 +1100 | [diff] [blame] | 4 | * Copyright (C) 2005-2008 coresystems GmbH |
| 5 | * (Written by Stefan Reinauer <stepan@coresystems.de> for coresystems GmbH) |
| 6 | * Copyright (C) 2011-2013 Stefan Tauner |
| 7 | * Copyright (C) 2016 secunet Security Networks AG |
| 8 | * (Written by Nico Huber <nico.huber@secunet.com> for secunet) |
Simon Glass | c53fc49 | 2013-02-10 17:00:38 -0800 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
Edward O'Callaghan | 10bb9ae | 2020-12-17 13:06:10 +1100 | [diff] [blame] | 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
Simon Glass | c53fc49 | 2013-02-10 17:00:38 -0800 | [diff] [blame] | 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
Simon Glass | c53fc49 | 2013-02-10 17:00:38 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
Edward O'Callaghan | 2520fac | 2019-06-24 19:10:49 +1000 | [diff] [blame] | 21 | #ifndef __LAYOUT_H__ |
| 22 | #define __LAYOUT_H__ 1 |
| 23 | |
| 24 | #include <stddef.h> |
| 25 | #include <stdint.h> |
Nico Huber | 7bb1261 | 2019-01-20 11:33:07 +0100 | [diff] [blame] | 26 | #include <stdbool.h> |
Edward O'Callaghan | 2520fac | 2019-06-24 19:10:49 +1000 | [diff] [blame] | 27 | |
Edward O'Callaghan | a2f3e2a | 2020-07-26 16:49:30 +1000 | [diff] [blame] | 28 | /* Types and macros regarding the maximum flash space size supported by generic code. */ |
| 29 | typedef uint32_t chipoff_t; /* Able to store any addressable offset within a supported flash memory. */ |
| 30 | typedef uint32_t chipsize_t; /* Able to store the number of bytes of any supported flash memory. */ |
| 31 | #define FL_MAX_CHIPOFF_BITS (24) |
| 32 | #define FL_MAX_CHIPOFF ((chipoff_t)(1ULL<<FL_MAX_CHIPOFF_BITS)-1) |
| 33 | #define PRIxCHIPOFF "06"PRIx32 |
| 34 | #define PRIuCHIPSIZE PRIu32 |
| 35 | |
Edward O'Callaghan | 10bb9ae | 2020-12-17 13:06:10 +1100 | [diff] [blame] | 36 | #define MAX_ROMLAYOUT 128 |
Simon Glass | c53fc49 | 2013-02-10 17:00:38 -0800 | [diff] [blame] | 37 | |
Edward O'Callaghan | 50755cc | 2019-06-24 18:35:50 +1000 | [diff] [blame] | 38 | struct romentry { |
Edward O'Callaghan | a2f3e2a | 2020-07-26 16:49:30 +1000 | [diff] [blame] | 39 | chipoff_t start; |
| 40 | chipoff_t end; |
Edward O'Callaghan | a44e6ac | 2020-12-19 11:19:32 +1100 | [diff] [blame] | 41 | bool included; |
Edward O'Callaghan | 9494cba | 2020-07-24 22:35:22 +1000 | [diff] [blame] | 42 | char *name; |
Edward O'Callaghan | 8b0f177 | 2020-12-16 20:19:08 +1100 | [diff] [blame] | 43 | char *file; |
Edward O'Callaghan | 50755cc | 2019-06-24 18:35:50 +1000 | [diff] [blame] | 44 | }; |
Simon Glass | c53fc49 | 2013-02-10 17:00:38 -0800 | [diff] [blame] | 45 | |
Edward O'Callaghan | 2520fac | 2019-06-24 19:10:49 +1000 | [diff] [blame] | 46 | struct flashrom_layout { |
| 47 | /* entries store the entries specified in a layout file and associated run-time data */ |
| 48 | struct romentry *entries; |
| 49 | /* the number of successfully parsed entries */ |
| 50 | size_t num_entries; |
| 51 | }; |
| 52 | |
| 53 | struct single_layout { |
| 54 | struct flashrom_layout base; |
| 55 | struct romentry entry; |
| 56 | }; |
| 57 | |
Edward O'Callaghan | 53ff4ad | 2020-12-16 20:36:28 +1100 | [diff] [blame] | 58 | struct layout_include_args { |
| 59 | char *name; |
Daniel Campello | 2fdc837 | 2021-04-16 17:52:51 -0600 | [diff] [blame] | 60 | char *file; |
Edward O'Callaghan | 53ff4ad | 2020-12-16 20:36:28 +1100 | [diff] [blame] | 61 | struct layout_include_args *next; |
| 62 | }; |
Edward O'Callaghan | 13e8ed8 | 2020-06-01 13:22:19 +1000 | [diff] [blame] | 63 | |
Edward O'Callaghan | 53ff4ad | 2020-12-16 20:36:28 +1100 | [diff] [blame] | 64 | struct flashrom_layout *get_global_layout(void); |
Daniel Campello | 2fdc837 | 2021-04-16 17:52:51 -0600 | [diff] [blame] | 65 | struct flashrom_flashctx; |
| 66 | const struct flashrom_layout *get_layout(const struct flashrom_flashctx *const flashctx); |
Edward O'Callaghan | 53ff4ad | 2020-12-16 20:36:28 +1100 | [diff] [blame] | 67 | |
Daniel Campello | 2fdc837 | 2021-04-16 17:52:51 -0600 | [diff] [blame] | 68 | int get_region_range(struct flashrom_layout *const l, const char *name, |
| 69 | unsigned int *start, unsigned int *len); |
Edward O'Callaghan | 10bb9ae | 2020-12-17 13:06:10 +1100 | [diff] [blame] | 70 | int process_include_args(struct flashrom_layout *l, const struct layout_include_args *const args); |
Edward O'Callaghan | 4a28887 | 2020-12-18 10:26:04 +1100 | [diff] [blame] | 71 | const struct romentry *layout_next_included_region(const struct flashrom_layout *, chipoff_t); |
| 72 | const struct romentry *layout_next_included(const struct flashrom_layout *, const struct romentry *); |
Daniel Campello | 2fdc837 | 2021-04-16 17:52:51 -0600 | [diff] [blame] | 73 | int included_regions_overlap(const struct flashrom_layout *const flashrom_layout); |
Daniel Campello | 83752f8 | 2021-04-16 14:54:27 -0600 | [diff] [blame] | 74 | void prepare_layout_for_extraction(struct flashrom_flashctx *flash); |
David Hendricks | c36685a | 2016-09-12 20:41:05 -0700 | [diff] [blame] | 75 | |
Edward O'Callaghan | 85edc31 | 2021-02-16 00:08:49 +1100 | [diff] [blame] | 76 | #endif /* !__LAYOUT_H__ */ |