Debian Codegraph @

include/writeprotect.h

raw
1 /*
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
21 #include <stdint.h>
22 #include <stdbool.h>
23 #include <stddef.h>
24
25 #include "libflashrom.h"
26
27 #define MAX_BP_BITS 4
28
29 /* Chip protection range: start address and length. */
30 struct wp_range {
31 size_t start, len;
32 };
33
34 /* Generic description of a chip's write protection configuration. */
35 struct flashrom_wp_cfg {
36 enum flashrom_wp_mode mode;
37 struct wp_range range;
38 };
39
40 /* Collection of multiple write protection ranges. */
41 struct flashrom_wp_ranges {
42 struct wp_range *ranges;
43 size_t count;
44 };
45
46 /*
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 */
52 struct 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
78 struct flashrom_flashctx;
79
80 /* Write WP configuration to the chip */
81 enum flashrom_wp_result wp_write_cfg(struct flashrom_flashctx *, const struct flashrom_wp_cfg *);
82
83 /* Read WP configuration from the chip */
84 enum flashrom_wp_result wp_read_cfg(struct flashrom_wp_cfg *, struct flashrom_flashctx *);
85
86 /* Get a list of protection ranges supported by the chip */
87 enum flashrom_wp_result wp_get_available_ranges(struct flashrom_wp_ranges **, struct flashrom_flashctx *);
88
89 /* Checks if writeprotect functions can be used with the current flash/programmer */
90 bool wp_operations_available(struct flashrom_flashctx *);
91
92 /*
93 * Converts a writeprotect config to register values and masks that indicate which register bits affect WP state.
94 * reg_values, bit_masks, and write_masks must all have length of at least MAX_REGISTERS.
95 */
96 enum flashrom_wp_result wp_cfg_to_reg_values(uint8_t *reg_values, uint8_t *bit_masks, uint8_t *write_masks, struct flashrom_flashctx *, const struct flashrom_wp_cfg *);
97
98 #endif /* !__WRITEPROTECT_H__ */