blob: bf6a4a9c28ed520aa1e956bc7ff58e5151649a0c [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;
60 struct layout_include_args *next;
61};
Edward O'Callaghan13e8ed82020-06-01 13:22:19 +100062
Jack Rosenthal14f24e52021-04-16 23:22:04 +000063struct flashrom_flashctx;
64#define flashctx flashrom_flashctx /* TODO: Agree on a name and convert all occurences. */
Edward O'Callaghan8bc8b092020-12-04 15:31:56 +110065
Simon Glass9ad06c12013-07-03 22:08:17 +090066/**
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 */
Jack Rosenthal14f24e52021-04-16 23:22:04 +000072int extract_regions(struct flashctx *flash);
Simon Glass9ad06c12013-07-03 22:08:17 +090073
Edward O'Callaghan53ff4ad2020-12-16 20:36:28 +110074struct flashrom_layout *get_global_layout(void);
Jack Rosenthal14f24e52021-04-16 23:22:04 +000075const struct flashrom_layout *get_layout(const struct flashctx *const flashctx);
Edward O'Callaghan53ff4ad2020-12-16 20:36:28 +110076
Jack Rosenthal14f24e52021-04-16 23:22:04 +000077int find_romentry(struct flashrom_layout *const l, char *name);
Daniel Campellodf477722021-04-05 16:53:33 -060078int fill_romentry(struct flashrom_layout *const l, struct romentry *entry, int n);
Edward O'Callaghan10bb9ae2020-12-17 13:06:10 +110079int process_include_args(struct flashrom_layout *l, const struct layout_include_args *const args);
Edward O'Callaghan4a288872020-12-18 10:26:04 +110080const struct romentry *layout_next_included_region(const struct flashrom_layout *, chipoff_t);
81const struct romentry *layout_next_included(const struct flashrom_layout *, const struct romentry *);
Jack Rosenthal14f24e52021-04-16 23:22:04 +000082int included_regions_overlap(const struct flashrom_layout *const layout);
Daniel Campello6b0f1fc2021-04-09 21:28:12 -060083int get_required_erase_size(struct flashrom_flashctx *flash);
84int round_to_erasable_block_boundary(const int required_erase_size,
85 const struct romentry *entry,
86 chipoff_t *rounded_start,
87 chipsize_t* rounded_len);
David Hendricksc36685a2016-09-12 20:41:05 -070088
Edward O'Callaghan85edc312021-02-16 00:08:49 +110089#endif /* !__LAYOUT_H__ */