blob: f5740978b9465b619b2bdb072532d5517003b224 [file] [log] [blame]
Nico Huber3a9939b2016-04-27 15:56:14 +02001/*
2 * This file is part of the flashrom project.
3 *
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)
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.
Nico Huber3a9939b2016-04-27 15:56:14 +020019 */
20
21#ifndef __LAYOUT_H__
22#define __LAYOUT_H__ 1
23
24#include <stddef.h>
25#include <stdint.h>
Nico Huberae24b8b2019-01-20 11:33:07 +010026#include <stdbool.h>
Nico Huber3a9939b2016-04-27 15:56:14 +020027
28/* Types and macros regarding the maximum flash space size supported by generic code. */
29typedef uint32_t chipoff_t; /* Able to store any addressable offset within a supported flash memory. */
30typedef 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
Patrick Rudolph2d7ab692019-07-03 17:58:24 +020036#define MAX_ROMLAYOUT 128
Nico Huber3a9939b2016-04-27 15:56:14 +020037
38struct romentry {
39 chipoff_t start;
40 chipoff_t end;
41 bool included;
Nico Huber70461a92019-06-15 14:56:19 +020042 char *name;
Daniel Campello45d50a12021-04-13 10:47:25 -060043 char *file;
Nico Huber3a9939b2016-04-27 15:56:14 +020044};
45
46struct 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
53struct single_layout {
54 struct flashrom_layout base;
55 struct romentry entry;
56};
57
Arthur Heymansb04fef92019-02-05 17:35:05 +010058struct layout_include_args {
59 char *name;
Daniel Campello45d50a12021-04-13 10:47:25 -060060 char *file;
Arthur Heymansb04fef92019-02-05 17:35:05 +010061 struct layout_include_args *next;
62};
63
Nico Huber305f4172013-06-14 11:55:26 +020064struct flashrom_layout *get_global_layout(void);
dhendrixbeaefe02017-09-03 18:06:53 -070065struct flashrom_flashctx;
66const struct flashrom_layout *get_layout(const struct flashrom_flashctx *const flashctx);
Nico Huber305f4172013-06-14 11:55:26 +020067
Daniel Campello7367f772021-04-19 18:43:09 -060068int get_region_range(struct flashrom_layout *const l, const char *name,
69 unsigned int *start, unsigned int *len);
Arthur Heymansb04fef92019-02-05 17:35:05 +010070int process_include_args(struct flashrom_layout *l, const struct layout_include_args *const args);
Nico Huber3d7b1e32018-12-22 00:53:14 +010071const struct romentry *layout_next_included_region(const struct flashrom_layout *, chipoff_t);
Nico Huber5ca55232019-06-15 22:29:08 +020072const struct romentry *layout_next_included(const struct flashrom_layout *, const struct romentry *);
Daniel Campello45d50a12021-04-13 10:47:25 -060073int included_regions_overlap(const struct flashrom_layout *const flashrom_layout);
Daniel Campelloce983bc2021-04-16 15:26:42 -060074void prepare_layout_for_extraction(struct flashrom_flashctx *flash);
Nico Huber3a9939b2016-04-27 15:56:14 +020075
Edward O'Callaghan358a3502020-12-19 11:21:49 +110076#endif /* !__LAYOUT_H__ */