| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#ifndef VBOOT_REFERENCE_FUTILITY_UPDATER_UTILS_H_ |
| 9 |
#define VBOOT_REFERENCE_FUTILITY_UPDATER_UTILS_H_ |
| 10 |
|
| 11 |
#include <stdbool.h> |
| 12 |
#include <stdio.h> |
| 13 |
#include "fmap.h" |
| 14 |
|
| 15 |
#define ASPRINTF(strp, ...) do { if (asprintf(strp, __VA_ARGS__) >= 0) break; \ |
| 16 |
ERROR("Failed to allocate memory, abort.\n"); exit(1); } while (0) |
| 17 |
|
| 18 |
|
| 19 |
struct u_archive; |
| 20 |
|
| 21 |
|
| 22 |
static const char * const FWACT_A = "A", |
| 23 |
* const FWACT_B = "B"; |
| 24 |
|
| 25 |
enum active_slot { |
| 26 |
SLOT_UNKNOWN = -1, |
| 27 |
SLOT_A = 0, |
| 28 |
SLOT_B, |
| 29 |
}; |
| 30 |
|
| 31 |
|
| 32 |
struct tempfile { |
| 33 |
char *filepath; |
| 34 |
struct tempfile *next; |
| 35 |
}; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
const char *create_temp_file(struct tempfile *head); |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
void remove_all_temp_files(struct tempfile *head); |
| 52 |
|
| 53 |
|
| 54 |
#include "flashrom.h" |
| 55 |
|
| 56 |
enum { |
| 57 |
IMAGE_LOAD_SUCCESS = 0, |
| 58 |
IMAGE_READ_FAILURE = -1, |
| 59 |
IMAGE_PARSE_FAILURE = -2, |
| 60 |
}; |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
int load_firmware_image(struct firmware_image *image, const char *file_name, |
| 70 |
struct u_archive *archive); |
| 71 |
|
| 72 |
|
| 73 |
struct updater_config; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
int load_system_firmware(struct updater_config *cfg, |
| 81 |
struct firmware_image *image); |
| 82 |
|
| 83 |
|
| 84 |
void free_firmware_image(struct firmware_image *image); |
| 85 |
|
| 86 |
|
| 87 |
int reload_firmware_image(const char *file_path, struct firmware_image *image); |
| 88 |
|
| 89 |
|
| 90 |
void check_firmware_versions(const struct firmware_image *image); |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
const char *get_firmware_image_temp_file(const struct firmware_image *image, |
| 98 |
struct tempfile *tempfiles); |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
int write_system_firmware(struct updater_config *cfg, |
| 107 |
const struct firmware_image *image, |
| 108 |
const char *const regions[], size_t regions_len); |
| 109 |
|
| 110 |
struct firmware_section { |
| 111 |
uint8_t *data; |
| 112 |
size_t size; |
| 113 |
}; |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
int firmware_section_exists(const struct firmware_image *image, |
| 119 |
const char *section_name); |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
int find_firmware_section(struct firmware_section *section, |
| 127 |
const struct firmware_image *image, |
| 128 |
const char *section_name); |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
int preserve_firmware_section(const struct firmware_image *image_from, |
| 139 |
struct firmware_image *image_to, |
| 140 |
const char *section_name); |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
int overwrite_section(struct firmware_image *image, |
| 148 |
const char *fmap_section, size_t offset, |
| 149 |
size_t size, const uint8_t *new_values); |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
const char *get_firmware_rootkey_hash(const struct firmware_image *image); |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
struct vb2_gbb_header; |
| 161 |
const struct vb2_gbb_header *find_gbb(const struct firmware_image *image); |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
void strip_string(char *s, const char *pattern); |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
int save_file_from_stdin(const char *output); |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
bool is_ap_write_protection_enabled(struct updater_config *cfg); |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
bool is_ec_write_protection_enabled(struct updater_config *cfg); |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
char *host_shell(const char *command); |
| 192 |
|
| 193 |
|
| 194 |
#define ENV_SERVOD_PORT "SERVOD_PORT" |
| 195 |
|
| 196 |
|
| 197 |
#define ENV_SERVOD_NAME "SERVOD_NAME" |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
char *host_detect_servo(const char **prepare_ctrl_name); |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
void prepare_servo_control(const char *control_name, bool on); |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
struct dut_property { |
| 215 |
int (*getter)(struct updater_config *cfg); |
| 216 |
int value; |
| 217 |
int initialized; |
| 218 |
}; |
| 219 |
|
| 220 |
enum dut_property_type { |
| 221 |
DUT_PROP_MAINFW_ACT, |
| 222 |
DUT_PROP_TPM_FWVER, |
| 223 |
DUT_PROP_PLATFORM_VER, |
| 224 |
DUT_PROP_WP_HW, |
| 225 |
DUT_PROP_WP_SW_AP, |
| 226 |
DUT_PROP_WP_SW_EC, |
| 227 |
DUT_PROP_MAX |
| 228 |
}; |
| 229 |
|
| 230 |
|
| 231 |
void dut_init_properties(struct dut_property *props, int num); |
| 232 |
|
| 233 |
|
| 234 |
int dut_get_property(enum dut_property_type property_type, |
| 235 |
struct updater_config *cfg); |
| 236 |
|
| 237 |
int dut_set_property_string(const char *key, const char *value, |
| 238 |
struct updater_config *cfg); |
| 239 |
int dut_get_property_string(const char *key, char *dest, size_t size, |
| 240 |
struct updater_config *cfg); |
| 241 |
int dut_set_property_int(const char *key, const int value, |
| 242 |
struct updater_config *cfg); |
| 243 |
int dut_get_property_int(const char *key, struct updater_config *cfg); |
| 244 |
|
| 245 |
|
| 246 |
int dut_get_manifest_key(char **manifest_key_out, struct updater_config *cfg); |
| 247 |
|
| 248 |
#endif |