Debian Codegraph @

3rdparty/vboot/futility/flash_helpers.c

raw symbols SCIP
1 /* Copyright 2023 The ChromiumOS Authors
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
6 #include "flash_helpers.h"
7 #include "futility.h"
8 #include "updater.h"
9
10 int setup_flash(struct updater_config **cfg,
11 struct updater_config_arguments *args)
12 {
13 #ifdef USE_FLASHROM
14 *cfg = updater_new_config();
15 if (!*cfg) {
16 ERROR("Out of memory\n");
17 return 1;
18 }
19 if (args->detect_servo) {
20 char *servo_programmer = host_detect_servo(&(*cfg)->prepare_ctrl_name);
21 if (!servo_programmer) {
22 ERROR("Problem communicating with servo\n");
23 goto errdelete;
24 }
25
26 if (!args->programmer)
27 args->programmer = servo_programmer;
28 else
29 free(servo_programmer);
30 }
31
32 if (updater_setup_config(*cfg, args)) {
33 ERROR("Bad servo options\n");
34 goto errdelete;
35 }
36 prepare_servo_control((*cfg)->prepare_ctrl_name, true);
37 return 0;
38
39 errdelete:
40 updater_delete_config(*cfg);
41 *cfg = NULL;
42 return 1;
43 #else
44 return 1;
45 #endif /* USE_FLASHROM */
46 }
47
48 void teardown_flash(struct updater_config *cfg)
49 {
50 #ifdef USE_FLASHROM
51 prepare_servo_control(cfg->prepare_ctrl_name, false);
52 updater_delete_config(cfg);
53 #endif /* USE_FLASHROM */
54 }