blob: d54befad481ce0a12a66cc6e86407bb487ceb3d4 [file] [log] [blame]
Nikolai Artemiev3e3c5bf2021-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 Artemievb3b2d412021-10-21 01:12:39 +110021#include <stdint.h>
22#include <stdbool.h>
23#include <stddef.h>
24
Nikolai Artemiev539ec8a2021-10-21 00:58:12 +110025#include "libflashrom.h"
26
Nikolai Artemiev3e3c5bf2021-10-20 23:34:15 +110027#define MAX_BP_BITS 4
28
Nikolai Artemiev539ec8a2021-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 Artemievb3b2d412021-10-21 01:12:39 +110040/*
41 * Description of a chip's write protection configuration.
42 *
43 * It allows most WP code to store and manipulate a chip's configuration
44 * without knowing the exact layout of bits in the chip's status registers.
45 */
46struct wp_bits {
47 /* Status register protection bit (SRP) */
48 bool srp_bit_present;
49 uint8_t srp;
50
51 /* Status register lock bit (SRL) */
52 bool srl_bit_present;
53 uint8_t srl;
54
55 /* Complement bit (CMP) */
56 bool cmp_bit_present;
57 uint8_t cmp;
58
59 /* Sector/block protection bit (SEC) */
60 bool sec_bit_present;
61 uint8_t sec;
62
63 /* Top/bottom protection bit (TB) */
64 bool tb_bit_present;
65 uint8_t tb;
66
67 /* Block protection bits (BP) */
68 size_t bp_bit_count;
69 uint8_t bp[MAX_BP_BITS];
70};
71
Nikolai Artemiev539ec8a2021-10-21 00:58:12 +110072struct flashrom_flashctx;
73
74/* Write WP configuration to the chip */
75enum flashrom_wp_result wp_write_cfg(struct flashrom_flashctx *, const struct flashrom_wp_cfg *);
76
77/* Read WP configuration from the chip */
78enum flashrom_wp_result wp_read_cfg(struct flashrom_wp_cfg *, struct flashrom_flashctx *);
79
Nikolai Artemiev3e3c5bf2021-10-20 23:34:15 +110080#endif /* !__WRITEPROTECT_H__ */