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; |
| 60 | struct layout_include_args *next; |
| 61 | }; |
Edward O'Callaghan | 13e8ed8 | 2020-06-01 13:22:19 +1000 | [diff] [blame] | 62 | |
Edward O'Callaghan | 8bc8b09 | 2020-12-04 15:31:56 +1100 | [diff] [blame] | 63 | struct flashrom_flashctx; |
| 64 | #define flashctx flashrom_flashctx /* TODO: Agree on a name and convert all occurences. */ |
| 65 | |
Simon Glass | 9ad06c1 | 2013-07-03 22:08:17 +0900 | [diff] [blame] | 66 | /** |
| 67 | * Extract regions to current directory |
| 68 | * |
| 69 | * @flash: Information about flash chip to access |
| 70 | * @return 0 if OK, non-zero on error |
| 71 | */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 72 | int extract_regions(struct flashctx *flash); |
Simon Glass | 9ad06c1 | 2013-07-03 22:08:17 +0900 | [diff] [blame] | 73 | |
Edward O'Callaghan | 53ff4ad | 2020-12-16 20:36:28 +1100 | [diff] [blame] | 74 | struct flashrom_layout *get_global_layout(void); |
Edward O'Callaghan | 743904d | 2020-12-17 13:06:56 +1100 | [diff] [blame] | 75 | const struct flashrom_layout *get_layout(const struct flashctx *const flashctx); |
Edward O'Callaghan | 53ff4ad | 2020-12-16 20:36:28 +1100 | [diff] [blame] | 76 | |
Edward O'Callaghan | 13e8ed8 | 2020-06-01 13:22:19 +1000 | [diff] [blame] | 77 | int find_romentry(struct flashrom_layout *const l, char *name); |
Edward O'Callaghan | 50755cc | 2019-06-24 18:35:50 +1000 | [diff] [blame] | 78 | int fill_romentry(struct romentry *entry, int n); |
Edward O'Callaghan | 10bb9ae | 2020-12-17 13:06:10 +1100 | [diff] [blame] | 79 | int get_num_include_args(const struct flashrom_layout *const l); |
| 80 | 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] | 81 | const struct romentry *layout_next_included_region(const struct flashrom_layout *, chipoff_t); |
| 82 | const struct romentry *layout_next_included(const struct flashrom_layout *, const struct romentry *); |
David Hendricks | a98dfd0 | 2016-09-12 20:45:45 -0700 | [diff] [blame] | 83 | int included_regions_overlap(void); |
David Hendricks | a98dfd0 | 2016-09-12 20:45:45 -0700 | [diff] [blame] | 84 | int handle_partial_read( |
| 85 | struct flashctx *flash, |
| 86 | uint8_t *buf, |
| 87 | int (*read) (struct flashctx *flash, uint8_t *buf, |
| 88 | unsigned int start, unsigned int len), |
| 89 | int write_to_file); |
| 90 | /* RETURN: the number of partitions that have beenpartial read. |
| 91 | * ==0 means no partition is specified. |
| 92 | * < 0 means writing file error. */ |
David Hendricks | c36685a | 2016-09-12 20:41:05 -0700 | [diff] [blame] | 93 | |
Vadim Bendebury | 2b4dcef | 2018-05-21 10:47:18 -0700 | [diff] [blame] | 94 | /* |
| 95 | * In case user specified sections to program (using the -i command line |
| 96 | * option), prepare new contents such that only the required sections are |
| 97 | * re-programmed. |
| 98 | * |
| 99 | * If no -i command line option was used - do nothing. |
| 100 | * |
| 101 | * All areas outside of sections included in -i command line options are set |
| 102 | * to the same value as old contents (modulo lowest erase block size). This |
| 103 | * would make sure that those areas remain unchanged. |
| 104 | * |
| 105 | * If flashrom was invoked for writing the chip, fill the sections to be |
| 106 | * written from the user provided image file. |
| 107 | * |
| 108 | * If flashrom was invoked for erasing - leave the sections in question |
| 109 | * untouched, they have been set to flash erase value already. |
| 110 | */ |
Edward O'Callaghan | a2f3e2a | 2020-07-26 16:49:30 +1000 | [diff] [blame] | 111 | int build_new_image(const struct flashctx *flash, uint8_t *oldcontents, |
Vadim Bendebury | 2b4dcef | 2018-05-21 10:47:18 -0700 | [diff] [blame] | 112 | uint8_t *newcontents, int erase_mode); |
| 113 | |
Edward O'Callaghan | 2520fac | 2019-06-24 19:10:49 +1000 | [diff] [blame] | 114 | #endif /* __LAYOUT_H__ */ |