blob: bc1d00cbad3f28d0484f8d8fb6f4e1c780a59332 [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);
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 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 *);
Daniel Campellodf477722021-04-05 16:53:33 -060083int included_regions_overlap(const struct flashrom_layout *const layout);
Daniel Campello6b0f1fc2021-04-09 21:28:12 -060084int write_content_to_image_files(struct flashrom_flashctx *flashctx, uint8_t *buf);
85int get_required_erase_size(struct flashrom_flashctx *flash);
86int round_to_erasable_block_boundary(const int required_erase_size,
87 const struct romentry *entry,
88 chipoff_t *rounded_start,
89 chipsize_t* rounded_len);
David Hendricksc36685a2016-09-12 20:41:05 -070090
Vadim Bendebury2b4dcef2018-05-21 10:47:18 -070091/*
92 * In case user specified sections to program (using the -i command line
93 * option), prepare new contents such that only the required sections are
94 * re-programmed.
95 *
96 * If no -i command line option was used - do nothing.
97 *
98 * All areas outside of sections included in -i command line options are set
99 * to the same value as old contents (modulo lowest erase block size). This
100 * would make sure that those areas remain unchanged.
101 *
102 * If flashrom was invoked for writing the chip, fill the sections to be
103 * written from the user provided image file.
104 *
105 * If flashrom was invoked for erasing - leave the sections in question
106 * untouched, they have been set to flash erase value already.
107 */
Edward O'Callaghana2f3e2a2020-07-26 16:49:30 +1000108int build_new_image(const struct flashctx *flash, uint8_t *oldcontents,
Vadim Bendebury2b4dcef2018-05-21 10:47:18 -0700109 uint8_t *newcontents, int erase_mode);
110
Edward O'Callaghan85edc312021-02-16 00:08:49 +1100111#endif /* !__LAYOUT_H__ */