xref: /aosp_15_r20/external/flashrom/include/layout.h (revision 0d6140be3aa665ecc836e8907834fcd3e3b018fc)
1 /*
2  * This file is part of the flashrom project.
3  *
4  * Copyright (C) 2005-2008 coresystems GmbH
5  * (Written by Stefan Reinauer <[email protected]> for coresystems GmbH)
6  * Copyright (C) 2011-2013 Stefan Tauner
7  * Copyright (C) 2016 secunet Security Networks AG
8  * (Written by Nico Huber <[email protected]> for secunet)
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
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
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.
19  */
20 
21 #ifndef __LAYOUT_H__
22 #define __LAYOUT_H__ 1
23 
24 #include <stddef.h>
25 #include <stdint.h>
26 #include <stdbool.h>
27 
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 
36 #define MAX_ROMLAYOUT	128
37 
38 struct flash_region {
39 	char *name;
40 	/*
41 	 * Note that because start and end are chipoff_t, end is an inclusive upper
42 	 * bound: the length of a region is (end - start + 1) bytes and it is
43 	 * impossible to represent a region with zero length.
44 	 */
45 	chipoff_t start;
46 	chipoff_t end;
47 	bool read_prot;
48 	bool write_prot;
49 };
50 
51 struct romentry {
52 	struct romentry *next;
53 
54 	bool included;
55 	char *file;
56 
57 	struct flash_region region;
58 };
59 
60 struct flashrom_layout;
61 
62 struct layout_include_args;
63 
64 struct flashrom_flashctx;
65 const struct flashrom_layout *get_default_layout(const struct flashrom_flashctx *);
66 const struct flashrom_layout *get_layout(const struct flashrom_flashctx *);
67 
68 int layout_from_file(struct flashrom_layout **, const char *name);
69 
70 int register_include_arg(struct layout_include_args **, const char *arg);
71 int process_include_args(struct flashrom_layout *, const struct layout_include_args *);
72 int check_include_args_filename(const struct layout_include_args *);
73 void cleanup_include_args(struct layout_include_args **);
74 
75 const struct romentry *layout_next_included_region(const struct flashrom_layout *, chipoff_t);
76 const struct romentry *layout_next_included(const struct flashrom_layout *, const struct romentry *);
77 const struct romentry *layout_next(const struct flashrom_layout *, const struct romentry *);
78 int included_regions_overlap(const struct flashrom_layout *);
79 void prepare_layout_for_extraction(struct flashrom_flashctx *);
80 int layout_sanity_checks(const struct flashrom_flashctx *);
81 int check_for_unwritable_regions(const struct flashrom_flashctx *flash, unsigned int start, unsigned int len);
82 void get_flash_region(const struct flashrom_flashctx *flash, int addr, struct flash_region *region);
83 
84 #endif /* !__LAYOUT_H__ */
85