xref: /aosp_15_r20/external/flashrom/action_descriptor.h (revision 0d6140be3aa665ecc836e8907834fcd3e3b018fc)
1 /* Copyright 2018 The Chromium OS Authors. All rights reserved.
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  */
5 #ifndef __FLASHROM_ACTION_DESCRIPTOR_H
6 #define __FLASHROM_ACTION_DESCRIPTOR_H
7 
8 #include <stddef.h>
9 #include <stdint.h>
10 #include <stdbool.h>
11 
12 /*
13  * Structure containing information about the processing flashrom is supposed
14  * to perform on the current run.
15  *
16  * The variable size 'processing_units' array contains description of
17  * processing to the flash block granularity.
18  */
19 struct action_descriptor {
20 	void *oldcontents;
21 	void *newcontents;
22 	struct processing_unit {
23 		size_t block_size;  /* Block size granularity of this unit. */
24 		size_t offset;	    /* Offset of the first block. */
25 		size_t num_blocks;  /* Number of consecutive blocks. Value of
26 				     * zero indicates the last entry in the
27 				     * processing_units array. */
28 		int block_eraser_index;  /* Index into 'block_erasers'. */
29 		int block_region_index;  /* Index into 'eraseblocks'. */
30 	} processing_units[0];
31 };
32 
33 /* Forward reference for the flash descriptor structure defined in flash.h. */
34 struct flashrom_flashctx;
35 #define flashctx flashrom_flashctx /* TODO: Agree on a name and convert all occurences. */
36 
37 /*
38  * Function to create an action descriptor based on the 'before' and 'after'
39  * flash contents.
40  */
41 struct action_descriptor *prepare_action_descriptor(struct flashctx *flash,
42 						    void *oldcontents,
43 						    void *newcontents);
44 
45 /*
46  * Returns if the op should be consider a dry-run and return early or not.
47  *
48  * This function is set to indicate that the invoked flash programming
49  * command should not be executed, but just verified for validity.
50  *
51  * This is useful when one needs to determine if a certain flash erase command
52  * supported by the chip is allowed by the Intel controller on the device.
53  */
54 bool is_dry_run(void);
55 
56 /*
57  * A function to test action descriptor implementation, returns number of
58  * failures.
59  */
60 int test_action_descriptor(void);
61 
62 #endif  /* ! __FLASHROM_ACTION_DESCRIPTOR_H */
63