diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | futility/flashrom_wp_drv.c | 50 | ||||
-rw-r--r-- | futility/updater_utils.h | 7 | ||||
-rw-r--r-- | host/lib/flashrom_drv.c (renamed from futility/flashrom_drv.c) | 43 | ||||
-rw-r--r-- | host/lib/include/flashrom.h | 6 |
5 files changed, 62 insertions, 48 deletions
@@ -436,6 +436,7 @@ ALL_OBJS += ${FWLIB_OBJS} ${TLCL_OBJS} COMMONLIB_SRCS = \ host/lib/fmap.c \ host/lib/flashrom.c \ + host/lib/flashrom_drv.c \ host/lib/subprocess.c # Intermediate library for the vboot_reference utilities to link against. @@ -664,7 +665,8 @@ USE_FLASHROM ?= 1 ifneq ($(filter-out 0,${USE_FLASHROM}),) $(info building with libflashrom support) FLASHROM_LIBS := $(shell ${PKG_CONFIG} --libs flashrom) -FUTIL_SRCS += futility/flashrom_drv.c \ +FUTIL_SRCS += host/lib/flashrom_drv.c \ + futility/flashrom_wp_drv.c \ futility/updater_archive.c \ futility/updater_quirks.c \ futility/updater_utils.c \ diff --git a/futility/flashrom_wp_drv.c b/futility/flashrom_wp_drv.c new file mode 100644 index 00000000..ff7a8214 --- /dev/null +++ b/futility/flashrom_wp_drv.c @@ -0,0 +1,50 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * The utility functions for firmware updater. + */ + +#include <libflashrom.h> + +#include "updater.h" + +#define FLASHROM_OUTPUT_WP_PATTERN "write protect is " + +/* System environment values. */ +static const char * const FLASHROM_OUTPUT_WP_ENABLED = + FLASHROM_OUTPUT_WP_PATTERN "enabled", + * const FLASHROM_OUTPUT_WP_DISABLED = + FLASHROM_OUTPUT_WP_PATTERN "disabled"; + + +/* Helper function to return write protection status via given programmer. */ +enum wp_state flashrom_get_wp(const char *programmer) +{ + char *command, *result; + const char *postfix; + int r; + + /* grep is needed because host_shell only returns 1 line. */ + postfix = " 2>/dev/null | grep \"" FLASHROM_OUTPUT_WP_PATTERN "\""; + + + /* TODO(b/203715651): link with flashrom directly. */ + ASPRINTF(&command, "flashrom --wp-status -p %s %s", programmer, postfix); + + /* invokes flashrom(8) with non-zero result if error. */ + result = host_shell(command); + strip_string(result, NULL); + free(command); + VB2_DEBUG("wp-status: %s\n", result); + + if (strstr(result, FLASHROM_OUTPUT_WP_ENABLED)) + r = WP_ENABLED; + else if (strstr(result, FLASHROM_OUTPUT_WP_DISABLED)) + r = WP_DISABLED; + else + r = WP_ERROR; + free(result); + + return r; +} diff --git a/futility/updater_utils.h b/futility/updater_utils.h index e2c8b961..4ab61c93 100644 --- a/futility/updater_utils.h +++ b/futility/updater_utils.h @@ -225,11 +225,4 @@ void init_system_properties(struct system_property *props, int num); */ const char *get_firmware_rootkey_hash(const struct firmware_image *image); -int flashrom_read_image(struct firmware_image *image, const char *region, - int verbosity); -int flashrom_write_image(const struct firmware_image *image, - const char *region, - const struct firmware_image *diff_image, - int do_verify, int verbosity); - #endif /* VBOOT_REFERENCE_FUTILITY_UPDATER_UTILS_H_ */ diff --git a/futility/flashrom_drv.c b/host/lib/flashrom_drv.c index 8630b8f3..02250472 100644 --- a/futility/flashrom_drv.c +++ b/host/lib/flashrom_drv.c @@ -11,15 +11,9 @@ #include "crossystem.h" #include "host_misc.h" #include "util_misc.h" -#include "updater.h" - -#define FLASHROM_OUTPUT_WP_PATTERN "write protect is " - -/* System environment values. */ -static const char * const FLASHROM_OUTPUT_WP_ENABLED = - FLASHROM_OUTPUT_WP_PATTERN "enabled", - * const FLASHROM_OUTPUT_WP_DISABLED = - FLASHROM_OUTPUT_WP_PATTERN "disabled"; +//#include "updater.h" +#include "../../futility/futility.h" +#include "flashrom.h" // global to allow verbosity level to be injected into callback. static enum flashrom_log_level g_verbose_screen = FLASHROM_MSG_INFO; @@ -194,34 +188,3 @@ err_cleanup: return r; } - -/* Helper function to return write protection status via given programmer. */ -enum wp_state flashrom_get_wp(const char *programmer) -{ - char *command, *result; - const char *postfix; - int r; - - /* grep is needed because host_shell only returns 1 line. */ - postfix = " 2>/dev/null | grep \"" FLASHROM_OUTPUT_WP_PATTERN "\""; - - - /* TODO(b/203715651): link with flashrom directly. */ - ASPRINTF(&command, "flashrom --wp-status -p %s %s", programmer, postfix); - - /* invokes flashrom(8) with non-zero result if error. */ - result = host_shell(command); - strip_string(result, NULL); - free(command); - VB2_DEBUG("wp-status: %s\n", result); - - if (strstr(result, FLASHROM_OUTPUT_WP_ENABLED)) - r = WP_ENABLED; - else if (strstr(result, FLASHROM_OUTPUT_WP_DISABLED)) - r = WP_DISABLED; - else - r = WP_ERROR; - free(result); - - return r; -} diff --git a/host/lib/include/flashrom.h b/host/lib/include/flashrom.h index 0a4f885b..eb6d5313 100644 --- a/host/lib/include/flashrom.h +++ b/host/lib/include/flashrom.h @@ -40,6 +40,8 @@ struct firmware_image { * @return VB2_SUCCESS on success, or a relevant error. */ vb2_error_t flashrom_read(struct firmware_image *image, const char *region); +int flashrom_read_image(struct firmware_image *image, const char *region, + int verbosity); /** * Write using flashrom from a buffer. @@ -52,3 +54,7 @@ vb2_error_t flashrom_read(struct firmware_image *image, const char *region); * @return VB2_SUCCESS on success, or a relevant error. */ vb2_error_t flashrom_write(struct firmware_image *image, const char *region); +int flashrom_write_image(const struct firmware_image *image, + const char *region, + const struct firmware_image *diff_image, + int do_verify, int verbosity); |