blob: 1eb95528ab1bb22aab7aad75f8b348f6c7edf619 [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
24#define MAX_ROMLAYOUT 64
Simon Glassc53fc492013-02-10 17:00:38 -080025
Edward O'Callaghan50755cc2019-06-24 18:35:50 +100026struct romentry {
Simon Glassc53fc492013-02-10 17:00:38 -080027 unsigned int start;
28 unsigned int end;
29 unsigned int included;
30 char name[256];
31 char file[256]; /* file[0]=='\0' means not specified. */
Edward O'Callaghan50755cc2019-06-24 18:35:50 +100032};
Simon Glassc53fc492013-02-10 17:00:38 -080033
Edward O'Callaghan2520fac2019-06-24 19:10:49 +100034struct flashrom_layout {
35 /* entries store the entries specified in a layout file and associated run-time data */
36 struct romentry *entries;
37 /* the number of successfully parsed entries */
38 size_t num_entries;
39};
40
41struct single_layout {
42 struct flashrom_layout base;
43 struct romentry entry;
44};
45
46const struct flashrom_layout *get_global_layout(void);
47
Simon Glass9ad06c12013-07-03 22:08:17 +090048/**
49 * Extract regions to current directory
50 *
51 * @flash: Information about flash chip to access
52 * @return 0 if OK, non-zero on error
53 */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070054int extract_regions(struct flashctx *flash);
Simon Glass9ad06c12013-07-03 22:08:17 +090055
David Hendricksa98dfd02016-09-12 20:45:45 -070056int read_romlayout(char *name);
57int find_romentry(char *name);
Edward O'Callaghan50755cc2019-06-24 18:35:50 +100058int fill_romentry(struct romentry *entry, int n);
Vadim Bendeburycc9577d2018-05-09 11:52:00 -070059int get_fmap_entries(const char *filename, struct flashctx *flash);
David Hendricksa98dfd02016-09-12 20:45:45 -070060int get_num_include_args(void);
61int register_include_arg(char *name);
62int process_include_args(void);
63int num_include_files(void);
64int included_regions_overlap(void);
David Hendricksa98dfd02016-09-12 20:45:45 -070065int handle_partial_read(
66 struct flashctx *flash,
67 uint8_t *buf,
68 int (*read) (struct flashctx *flash, uint8_t *buf,
69 unsigned int start, unsigned int len),
70 int write_to_file);
71 /* RETURN: the number of partitions that have beenpartial read.
72 * ==0 means no partition is specified.
73 * < 0 means writing file error. */
74int handle_partial_verify(
75 struct flashctx *flash,
76 uint8_t *buf,
77 int (*verify) (struct flashctx *flash, uint8_t *buf, unsigned int start,
78 unsigned int len, const char* message));
79 /* RETURN: ==0 means all identical.
80 !=0 means buf and flash are different. */
David Hendricksc36685a2016-09-12 20:41:05 -070081
Vadim Bendebury2b4dcef2018-05-21 10:47:18 -070082/*
83 * In case layout is used, return the largest offset of the end of all
84 * included sections. If layout is not used, return zero.
85 */
86size_t top_section_offset(void);
87
88/*
89 * In case user specified sections to program (using the -i command line
90 * option), prepare new contents such that only the required sections are
91 * re-programmed.
92 *
93 * If no -i command line option was used - do nothing.
94 *
95 * All areas outside of sections included in -i command line options are set
96 * to the same value as old contents (modulo lowest erase block size). This
97 * would make sure that those areas remain unchanged.
98 *
99 * If flashrom was invoked for writing the chip, fill the sections to be
100 * written from the user provided image file.
101 *
102 * If flashrom was invoked for erasing - leave the sections in question
103 * untouched, they have been set to flash erase value already.
104 */
Edward O'Callaghanf93b3742019-02-24 17:24:27 +1100105int handle_romentries(const struct flashctx *flash, uint8_t *oldcontents,
Vadim Bendebury2b4dcef2018-05-21 10:47:18 -0700106 uint8_t *newcontents, int erase_mode);
Edward O'Callaghan627ca372019-09-07 18:52:30 +1000107void layout_cleanup(void);
Vadim Bendebury2b4dcef2018-05-21 10:47:18 -0700108
Edward O'Callaghan2520fac2019-06-24 19:10:49 +1000109#endif /* __LAYOUT_H__ */