blob: e27403dcfb7c6cb1262b7e5ff2594dc81a419441 [file] [log] [blame]
Nikolai Artemievc6c3f282021-10-20 23:34:15 +11001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2010 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; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
18#ifndef __WRITEPROTECT_H__
19#define __WRITEPROTECT_H__ 1
20
Nikolai Artemieve75127a2021-10-21 01:12:39 +110021#include <stdint.h>
22#include <stdbool.h>
23#include <stddef.h>
24
Nikolai Artemievda1c8342021-10-21 00:58:12 +110025#include "libflashrom.h"
26
Nikolai Artemievc6c3f282021-10-20 23:34:15 +110027#define MAX_BP_BITS 4
28
Nikolai Artemievda1c8342021-10-21 00:58:12 +110029/* Chip protection range: start address and length. */
30struct wp_range {
31 size_t start, len;
32};
33
34/* Generic description of a chip's write protection configuration. */
35struct flashrom_wp_cfg {
36 enum flashrom_wp_mode mode;
37 struct wp_range range;
38};
39
Nikolai Artemiev077c0d12021-10-21 01:50:15 +110040/* Collection of multiple write protection ranges. */
41struct flashrom_wp_ranges {
42 struct wp_range *ranges;
43 size_t count;
44};
45
Nikolai Artemieve75127a2021-10-21 01:12:39 +110046/*
47 * Description of a chip's write protection configuration.
48 *
49 * It allows most WP code to store and manipulate a chip's configuration
50 * without knowing the exact layout of bits in the chip's status registers.
51 */
52struct wp_bits {
53 /* Status register protection bit (SRP) */
54 bool srp_bit_present;
55 uint8_t srp;
56
57 /* Status register lock bit (SRL) */
58 bool srl_bit_present;
59 uint8_t srl;
60
61 /* Complement bit (CMP) */
62 bool cmp_bit_present;
63 uint8_t cmp;
64
65 /* Sector/block protection bit (SEC) */
66 bool sec_bit_present;
67 uint8_t sec;
68
69 /* Top/bottom protection bit (TB) */
70 bool tb_bit_present;
71 uint8_t tb;
72
73 /* Block protection bits (BP) */
74 size_t bp_bit_count;
75 uint8_t bp[MAX_BP_BITS];
76};
77
Nikolai Artemievda1c8342021-10-21 00:58:12 +110078struct flashrom_flashctx;
79
80/* Write WP configuration to the chip */
81enum flashrom_wp_result wp_write_cfg(struct flashrom_flashctx *, const struct flashrom_wp_cfg *);
82
83/* Read WP configuration from the chip */
84enum flashrom_wp_result wp_read_cfg(struct flashrom_wp_cfg *, struct flashrom_flashctx *);
85
Nikolai Artemiev077c0d12021-10-21 01:50:15 +110086/* Get a list of protection ranges supported by the chip */
87enum flashrom_wp_result wp_get_available_ranges(struct flashrom_wp_ranges **, struct flashrom_flashctx *);
88
Nikolai Artemievc6c3f282021-10-20 23:34:15 +110089#endif /* !__WRITEPROTECT_H__ */