blob: f5740978b9465b619b2bdb072532d5517003b224 [file] [log] [blame]
Simon Glassc53fc492013-02-10 17:00:38 -08001/*
2 * This file is part of the flashrom project.
3 *
Edward O'Callaghan10bb9ae2020-12-17 13:06:10 +11004 * 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 Glassc53fc492013-02-10 17:00:38 -08009 *
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'Callaghan10bb9ae2020-12-17 13:06:10 +110012 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
Simon Glassc53fc492013-02-10 17:00:38 -080014 *
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 Glassc53fc492013-02-10 17:00:38 -080019 */
20
Edward O'Callaghan2520fac2019-06-24 19:10:49 +100021#ifndef __LAYOUT_H__
22#define __LAYOUT_H__ 1
23
24#include <stddef.h>
25#include <stdint.h>
Nico Huber7bb12612019-01-20 11:33:07 +010026#include <stdbool.h>
Edward O'Callaghan2520fac2019-06-24 19:10:49 +100027
Edward O'Callaghana2f3e2a2020-07-26 16:49:30 +100028/* 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
Edward O'Callaghan10bb9ae2020-12-17 13:06:10 +110036#define MAX_ROMLAYOUT 128
Simon Glassc53fc492013-02-10 17:00:38 -080037
Edward O'Callaghan50755cc2019-06-24 18:35:50 +100038struct romentry {
Edward O'Callaghana2f3e2a2020-07-26 16:49:30 +100039 chipoff_t start;
40 chipoff_t end;
Edward O'Callaghana44e6ac2020-12-19 11:19:32 +110041 bool included;
Edward O'Callaghan9494cba2020-07-24 22:35:22 +100042 char *name;
Edward O'Callaghan8b0f1772020-12-16 20:19:08 +110043 char *file;
Edward O'Callaghan50755cc2019-06-24 18:35:50 +100044};
Simon Glassc53fc492013-02-10 17:00:38 -080045
Edward O'Callaghan2520fac2019-06-24 19:10:49 +100046struct 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
Edward O'Callaghan53ff4ad2020-12-16 20:36:28 +110058struct layout_include_args {
59 char *name;
Daniel Campello2fdc8372021-04-16 17:52:51 -060060 char *file;
Edward O'Callaghan53ff4ad2020-12-16 20:36:28 +110061 struct layout_include_args *next;
62};
Edward O'Callaghan13e8ed82020-06-01 13:22:19 +100063
Edward O'Callaghan53ff4ad2020-12-16 20:36:28 +110064struct flashrom_layout *get_global_layout(void);
Daniel Campello2fdc8372021-04-16 17:52:51 -060065struct flashrom_flashctx;
66const struct flashrom_layout *get_layout(const struct flashrom_flashctx *const flashctx);
Edward O'Callaghan53ff4ad2020-12-16 20:36:28 +110067
Daniel Campello2fdc8372021-04-16 17:52:51 -060068int get_region_range(struct flashrom_layout *const l, const char *name,
69 unsigned int *start, unsigned int *len);
Edward O'Callaghan10bb9ae2020-12-17 13:06:10 +110070int process_include_args(struct flashrom_layout *l, const struct layout_include_args *const args);
Edward O'Callaghan4a288872020-12-18 10:26:04 +110071const struct romentry *layout_next_included_region(const struct flashrom_layout *, chipoff_t);
72const struct romentry *layout_next_included(const struct flashrom_layout *, const struct romentry *);
Daniel Campello2fdc8372021-04-16 17:52:51 -060073int included_regions_overlap(const struct flashrom_layout *const flashrom_layout);
Daniel Campello83752f82021-04-16 14:54:27 -060074void prepare_layout_for_extraction(struct flashrom_flashctx *flash);
David Hendricksc36685a2016-09-12 20:41:05 -070075
Edward O'Callaghan85edc312021-02-16 00:08:49 +110076#endif /* !__LAYOUT_H__ */