blob: d87c72745cb37e51ad947b527d86b540a38dd5e7 [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
Edward O'Callaghan8bc8b092020-12-04 15:31:56 +110063struct flashrom_flashctx;
64#define flashctx flashrom_flashctx /* TODO: Agree on a name and convert all occurences. */
65
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 */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070072int 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);
Edward O'Callaghan743904d2020-12-17 13:06:56 +110075const struct flashrom_layout *get_layout(const struct flashctx *const flashctx);
Edward O'Callaghan53ff4ad2020-12-16 20:36:28 +110076
Edward O'Callaghan13e8ed82020-06-01 13:22:19 +100077int find_romentry(struct flashrom_layout *const l, char *name);
Edward O'Callaghan50755cc2019-06-24 18:35:50 +100078int fill_romentry(struct romentry *entry, int n);
Edward O'Callaghan10bb9ae2020-12-17 13:06:10 +110079int get_num_include_args(const struct flashrom_layout *const l);
80int process_include_args(struct flashrom_layout *l, const struct layout_include_args *const args);
Edward O'Callaghan4a288872020-12-18 10:26:04 +110081const struct romentry *layout_next_included_region(const struct flashrom_layout *, chipoff_t);
82const struct romentry *layout_next_included(const struct flashrom_layout *, const struct romentry *);
David Hendricksa98dfd02016-09-12 20:45:45 -070083int included_regions_overlap(void);
David Hendricksa98dfd02016-09-12 20:45:45 -070084int handle_partial_read(
85 struct flashctx *flash,
86 uint8_t *buf,
87 int (*read) (struct flashctx *flash, uint8_t *buf,
88 unsigned int start, unsigned int len),
89 int write_to_file);
90 /* RETURN: the number of partitions that have beenpartial read.
91 * ==0 means no partition is specified.
92 * < 0 means writing file error. */
David Hendricksc36685a2016-09-12 20:41:05 -070093
Vadim Bendebury2b4dcef2018-05-21 10:47:18 -070094/*
95 * In case user specified sections to program (using the -i command line
96 * option), prepare new contents such that only the required sections are
97 * re-programmed.
98 *
99 * If no -i command line option was used - do nothing.
100 *
101 * All areas outside of sections included in -i command line options are set
102 * to the same value as old contents (modulo lowest erase block size). This
103 * would make sure that those areas remain unchanged.
104 *
105 * If flashrom was invoked for writing the chip, fill the sections to be
106 * written from the user provided image file.
107 *
108 * If flashrom was invoked for erasing - leave the sections in question
109 * untouched, they have been set to flash erase value already.
110 */
Edward O'Callaghana2f3e2a2020-07-26 16:49:30 +1000111int build_new_image(const struct flashctx *flash, uint8_t *oldcontents,
Vadim Bendebury2b4dcef2018-05-21 10:47:18 -0700112 uint8_t *newcontents, int erase_mode);
113
Edward O'Callaghan2520fac2019-06-24 19:10:49 +1000114#endif /* __LAYOUT_H__ */