Simon Glass | c53fc49 | 2013-02-10 17:00:38 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2013 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
Simon Glass | c53fc49 | 2013-02-10 17:00:38 -0800 | [diff] [blame] | 15 | */ |
| 16 | |
Edward O'Callaghan | 2520fac | 2019-06-24 19:10:49 +1000 | [diff] [blame] | 17 | #ifndef __LAYOUT_H__ |
| 18 | #define __LAYOUT_H__ 1 |
| 19 | |
| 20 | #include <stddef.h> |
| 21 | #include <stdint.h> |
Nico Huber | 7bb1261 | 2019-01-20 11:33:07 +0100 | [diff] [blame] | 22 | #include <stdbool.h> |
Edward O'Callaghan | 2520fac | 2019-06-24 19:10:49 +1000 | [diff] [blame] | 23 | |
Edward O'Callaghan | a2f3e2a | 2020-07-26 16:49:30 +1000 | [diff] [blame] | 24 | /* Types and macros regarding the maximum flash space size supported by generic code. */ |
| 25 | typedef uint32_t chipoff_t; /* Able to store any addressable offset within a supported flash memory. */ |
| 26 | typedef uint32_t chipsize_t; /* Able to store the number of bytes of any supported flash memory. */ |
| 27 | #define FL_MAX_CHIPOFF_BITS (24) |
| 28 | #define FL_MAX_CHIPOFF ((chipoff_t)(1ULL<<FL_MAX_CHIPOFF_BITS)-1) |
| 29 | #define PRIxCHIPOFF "06"PRIx32 |
| 30 | #define PRIuCHIPSIZE PRIu32 |
| 31 | |
Edward O'Callaghan | 2520fac | 2019-06-24 19:10:49 +1000 | [diff] [blame] | 32 | #define MAX_ROMLAYOUT 64 |
Simon Glass | c53fc49 | 2013-02-10 17:00:38 -0800 | [diff] [blame] | 33 | |
Edward O'Callaghan | 50755cc | 2019-06-24 18:35:50 +1000 | [diff] [blame] | 34 | struct romentry { |
Edward O'Callaghan | a2f3e2a | 2020-07-26 16:49:30 +1000 | [diff] [blame] | 35 | chipoff_t start; |
| 36 | chipoff_t end; |
Simon Glass | c53fc49 | 2013-02-10 17:00:38 -0800 | [diff] [blame] | 37 | unsigned int included; |
Edward O'Callaghan | 9494cba | 2020-07-24 22:35:22 +1000 | [diff] [blame] | 38 | char *name; |
Simon Glass | c53fc49 | 2013-02-10 17:00:38 -0800 | [diff] [blame] | 39 | char file[256]; /* file[0]=='\0' means not specified. */ |
Edward O'Callaghan | 50755cc | 2019-06-24 18:35:50 +1000 | [diff] [blame] | 40 | }; |
Simon Glass | c53fc49 | 2013-02-10 17:00:38 -0800 | [diff] [blame] | 41 | |
Edward O'Callaghan | 2520fac | 2019-06-24 19:10:49 +1000 | [diff] [blame] | 42 | struct flashrom_layout { |
| 43 | /* entries store the entries specified in a layout file and associated run-time data */ |
| 44 | struct romentry *entries; |
| 45 | /* the number of successfully parsed entries */ |
| 46 | size_t num_entries; |
| 47 | }; |
| 48 | |
| 49 | struct single_layout { |
| 50 | struct flashrom_layout base; |
| 51 | struct romentry entry; |
| 52 | }; |
| 53 | |
Simon Glass | 9ad06c1 | 2013-07-03 22:08:17 +0900 | [diff] [blame] | 54 | /** |
| 55 | * Extract regions to current directory |
| 56 | * |
| 57 | * @flash: Information about flash chip to access |
| 58 | * @return 0 if OK, non-zero on error |
| 59 | */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 60 | int extract_regions(struct flashctx *flash); |
Simon Glass | 9ad06c1 | 2013-07-03 22:08:17 +0900 | [diff] [blame] | 61 | |
Edward O'Callaghan | 9494cba | 2020-07-24 22:35:22 +1000 | [diff] [blame] | 62 | int read_romlayout(const char *name); |
David Hendricks | a98dfd0 | 2016-09-12 20:45:45 -0700 | [diff] [blame] | 63 | int find_romentry(char *name); |
Edward O'Callaghan | 50755cc | 2019-06-24 18:35:50 +1000 | [diff] [blame] | 64 | int fill_romentry(struct romentry *entry, int n); |
Vadim Bendebury | cc9577d | 2018-05-09 11:52:00 -0700 | [diff] [blame] | 65 | int get_fmap_entries(const char *filename, struct flashctx *flash); |
David Hendricks | a98dfd0 | 2016-09-12 20:45:45 -0700 | [diff] [blame] | 66 | int get_num_include_args(void); |
| 67 | int register_include_arg(char *name); |
| 68 | int process_include_args(void); |
| 69 | int num_include_files(void); |
| 70 | int included_regions_overlap(void); |
David Hendricks | a98dfd0 | 2016-09-12 20:45:45 -0700 | [diff] [blame] | 71 | int handle_partial_read( |
| 72 | struct flashctx *flash, |
| 73 | uint8_t *buf, |
| 74 | int (*read) (struct flashctx *flash, uint8_t *buf, |
| 75 | unsigned int start, unsigned int len), |
| 76 | int write_to_file); |
| 77 | /* RETURN: the number of partitions that have beenpartial read. |
| 78 | * ==0 means no partition is specified. |
| 79 | * < 0 means writing file error. */ |
| 80 | int handle_partial_verify( |
| 81 | struct flashctx *flash, |
| 82 | uint8_t *buf, |
| 83 | int (*verify) (struct flashctx *flash, uint8_t *buf, unsigned int start, |
| 84 | unsigned int len, const char* message)); |
| 85 | /* RETURN: ==0 means all identical. |
| 86 | !=0 means buf and flash are different. */ |
David Hendricks | c36685a | 2016-09-12 20:41:05 -0700 | [diff] [blame] | 87 | |
Vadim Bendebury | 2b4dcef | 2018-05-21 10:47:18 -0700 | [diff] [blame] | 88 | /* |
| 89 | * In case layout is used, return the largest offset of the end of all |
| 90 | * included sections. If layout is not used, return zero. |
| 91 | */ |
| 92 | size_t top_section_offset(void); |
| 93 | |
Edward O'Callaghan | a2f3e2a | 2020-07-26 16:49:30 +1000 | [diff] [blame] | 94 | int normalize_romentries(const struct flashctx *flash); |
Vadim Bendebury | 2b4dcef | 2018-05-21 10:47:18 -0700 | [diff] [blame] | 95 | /* |
| 96 | * In case user specified sections to program (using the -i command line |
| 97 | * option), prepare new contents such that only the required sections are |
| 98 | * re-programmed. |
| 99 | * |
| 100 | * If no -i command line option was used - do nothing. |
| 101 | * |
| 102 | * All areas outside of sections included in -i command line options are set |
| 103 | * to the same value as old contents (modulo lowest erase block size). This |
| 104 | * would make sure that those areas remain unchanged. |
| 105 | * |
| 106 | * If flashrom was invoked for writing the chip, fill the sections to be |
| 107 | * written from the user provided image file. |
| 108 | * |
| 109 | * If flashrom was invoked for erasing - leave the sections in question |
| 110 | * untouched, they have been set to flash erase value already. |
| 111 | */ |
Edward O'Callaghan | a2f3e2a | 2020-07-26 16:49:30 +1000 | [diff] [blame] | 112 | int build_new_image(const struct flashctx *flash, uint8_t *oldcontents, |
Vadim Bendebury | 2b4dcef | 2018-05-21 10:47:18 -0700 | [diff] [blame] | 113 | uint8_t *newcontents, int erase_mode); |
Edward O'Callaghan | 627ca37 | 2019-09-07 18:52:30 +1000 | [diff] [blame] | 114 | void layout_cleanup(void); |
Vadim Bendebury | 2b4dcef | 2018-05-21 10:47:18 -0700 | [diff] [blame] | 115 | |
Edward O'Callaghan | 2520fac | 2019-06-24 19:10:49 +1000 | [diff] [blame] | 116 | #endif /* __LAYOUT_H__ */ |