blob: 81beee420d7deedbd8ab5d299831b0d031aa6386 [file] [log] [blame]
Simon Glassc53fc492013-02-10 17:00:38 -08001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2013 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
Simon Glassc53fc492013-02-10 17:00:38 -080015 */
16
Edward O'Callaghan2520fac2019-06-24 19:10:49 +100017#ifndef __LAYOUT_H__
18#define __LAYOUT_H__ 1
19
20#include <stddef.h>
21#include <stdint.h>
Nico Huber7bb12612019-01-20 11:33:07 +010022#include <stdbool.h>
Edward O'Callaghan2520fac2019-06-24 19:10:49 +100023
Edward O'Callaghana2f3e2a2020-07-26 16:49:30 +100024/* Types and macros regarding the maximum flash space size supported by generic code. */
25typedef uint32_t chipoff_t; /* Able to store any addressable offset within a supported flash memory. */
26typedef uint32_t chipsize_t; /* Able to store the number of bytes of any supported flash memory. */
27#define FL_MAX_CHIPOFF_BITS (24)
28#define FL_MAX_CHIPOFF ((chipoff_t)(1ULL<<FL_MAX_CHIPOFF_BITS)-1)
29#define PRIxCHIPOFF "06"PRIx32
30#define PRIuCHIPSIZE PRIu32
31
Edward O'Callaghan2520fac2019-06-24 19:10:49 +100032#define MAX_ROMLAYOUT 64
Simon Glassc53fc492013-02-10 17:00:38 -080033
Edward O'Callaghan50755cc2019-06-24 18:35:50 +100034struct romentry {
Edward O'Callaghana2f3e2a2020-07-26 16:49:30 +100035 chipoff_t start;
36 chipoff_t end;
Simon Glassc53fc492013-02-10 17:00:38 -080037 unsigned int included;
Edward O'Callaghan9494cba2020-07-24 22:35:22 +100038 char *name;
Simon Glassc53fc492013-02-10 17:00:38 -080039 char file[256]; /* file[0]=='\0' means not specified. */
Edward O'Callaghan50755cc2019-06-24 18:35:50 +100040};
Simon Glassc53fc492013-02-10 17:00:38 -080041
Edward O'Callaghan2520fac2019-06-24 19:10:49 +100042struct flashrom_layout {
43 /* entries store the entries specified in a layout file and associated run-time data */
44 struct romentry *entries;
45 /* the number of successfully parsed entries */
46 size_t num_entries;
47};
48
49struct single_layout {
50 struct flashrom_layout base;
51 struct romentry entry;
52};
53
Edward O'Callaghan13e8ed82020-06-01 13:22:19 +100054struct flashrom_layout *get_global_layout(void);
55
Simon Glass9ad06c12013-07-03 22:08:17 +090056/**
57 * Extract regions to current directory
58 *
59 * @flash: Information about flash chip to access
60 * @return 0 if OK, non-zero on error
61 */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070062int extract_regions(struct flashctx *flash);
Simon Glass9ad06c12013-07-03 22:08:17 +090063
Edward O'Callaghan9494cba2020-07-24 22:35:22 +100064int read_romlayout(const char *name);
Edward O'Callaghan13e8ed82020-06-01 13:22:19 +100065int find_romentry(struct flashrom_layout *const l, char *name);
Edward O'Callaghan50755cc2019-06-24 18:35:50 +100066int fill_romentry(struct romentry *entry, int n);
David Hendricksa98dfd02016-09-12 20:45:45 -070067int get_num_include_args(void);
68int register_include_arg(char *name);
69int process_include_args(void);
70int num_include_files(void);
71int included_regions_overlap(void);
David Hendricksa98dfd02016-09-12 20:45:45 -070072int handle_partial_read(
73 struct flashctx *flash,
74 uint8_t *buf,
75 int (*read) (struct flashctx *flash, uint8_t *buf,
76 unsigned int start, unsigned int len),
77 int write_to_file);
78 /* RETURN: the number of partitions that have beenpartial read.
79 * ==0 means no partition is specified.
80 * < 0 means writing file error. */
David Hendricksc36685a2016-09-12 20:41:05 -070081
Edward O'Callaghana2f3e2a2020-07-26 16:49:30 +100082int normalize_romentries(const struct flashctx *flash);
Vadim Bendebury2b4dcef2018-05-21 10:47:18 -070083/*
84 * In case user specified sections to program (using the -i command line
85 * option), prepare new contents such that only the required sections are
86 * re-programmed.
87 *
88 * If no -i command line option was used - do nothing.
89 *
90 * All areas outside of sections included in -i command line options are set
91 * to the same value as old contents (modulo lowest erase block size). This
92 * would make sure that those areas remain unchanged.
93 *
94 * If flashrom was invoked for writing the chip, fill the sections to be
95 * written from the user provided image file.
96 *
97 * If flashrom was invoked for erasing - leave the sections in question
98 * untouched, they have been set to flash erase value already.
99 */
Edward O'Callaghana2f3e2a2020-07-26 16:49:30 +1000100int build_new_image(const struct flashctx *flash, uint8_t *oldcontents,
Vadim Bendebury2b4dcef2018-05-21 10:47:18 -0700101 uint8_t *newcontents, int erase_mode);
Edward O'Callaghan627ca372019-09-07 18:52:30 +1000102void layout_cleanup(void);
Vadim Bendebury2b4dcef2018-05-21 10:47:18 -0700103
Edward O'Callaghan2520fac2019-06-24 19:10:49 +1000104#endif /* __LAYOUT_H__ */