summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2019-11-22 08:42:30 +0800
committerCommit Bot <commit-bot@chromium.org>2019-11-27 16:58:19 +0000
commit6ef33b990578a9583a3ac53f2c835d4e16219b25 (patch)
tree56254eea8f613392c6447646bb5966e0a0858c80
parent45facd54087232ef3f354108e8429932e6f0355f (diff)
downloadvboot-6ef33b990578a9583a3ac53f2c835d4e16219b25.tar.gz
futility: updater: refactor: unify getting temp files for firmware images
Unify "create a temp file and write firmware image contents" to the new API get_firmware_image_temp_file with better error messages. BRANCH=none BUG=chromium:1024401 TEST=make clean && make runtests Change-Id: I441f24053a8d94def587cf8270c44a4bdce9a4fe Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1928359 Reviewed-by: Joel Kitching <kitching@chromium.org> Commit-Queue: Hung-Te Lin <hungte@chromium.org> Tested-by: Hung-Te Lin <hungte@chromium.org> Auto-Submit: Hung-Te Lin <hungte@chromium.org>
-rw-r--r--futility/updater.c17
-rw-r--r--futility/updater_quirks.c30
-rw-r--r--futility/updater_utils.c4
3 files changed, 19 insertions, 32 deletions
diff --git a/futility/updater.c b/futility/updater.c
index 21d0910b..0ed52234 100644
--- a/futility/updater.c
+++ b/futility/updater.c
@@ -839,14 +839,13 @@ static int legacy_needs_update(struct updater_config *cfg)
int has_from, has_to;
const char * const tag = "cros_allow_auto_update";
const char *section = FMAP_RW_LEGACY;
- const char *tmp_path = create_temp_file(&cfg->tempfiles);
+ const char *tmp_path;
VB2_DEBUG("Checking %s contents...\n", FMAP_RW_LEGACY);
- if (!tmp_path ||
- vb2_write_file(tmp_path, cfg->image.data, cfg->image.size)) {
- ERROR("Failed to create temporary file for image contents.\n");
+
+ tmp_path = get_firmware_image_temp_file(&cfg->image, &cfg->tempfiles);
+ if (!tmp_path)
return 0;
- }
has_to = cbfs_file_exists(tmp_path, section, tag);
has_from = cbfs_file_exists(tmp_path, section, tag);
@@ -1342,14 +1341,10 @@ static int updater_apply_white_label(struct updater_config *cfg,
assert(model->is_white_label);
if (!signature_id) {
if (cfg->image_current.data) {
- tmp_image = create_temp_file(&cfg->tempfiles);
+ tmp_image = get_firmware_image_temp_file(
+ &cfg->image_current, &cfg->tempfiles);
if (!tmp_image)
return 1;
- if (vb2_write_file(tmp_image, cfg->image_current.data,
- cfg->image_current.size)) {
- ERROR("Failed writing temporary image file.\n");
- return 1;
- }
} else {
INFO("Loading system firmware for white label...\n");
load_system_firmware(&cfg->image_current,
diff --git a/futility/updater_quirks.c b/futility/updater_quirks.c
index 7defd577..ea96a67a 100644
--- a/futility/updater_quirks.c
+++ b/futility/updater_quirks.c
@@ -59,15 +59,6 @@ static const struct quirks_record quirks_records[] = {
{ .match = "Google_Wizpig.", .quirks = "allow_empty_wltag" },
};
-/*
- * Helper function to write a firmware image into file on disk.
- * Returns the result from vb2_write_file.
- */
-static int write_image(const char *file_path, struct firmware_image *image)
-{
- return vb2_write_file(file_path, image->data, image->size);
-}
-
/* Preserves meta data and reload image contents from given file path. */
static int reload_firmware_image(const char *file_path,
struct firmware_image *image)
@@ -107,18 +98,16 @@ static int is_ec_software_sync_enabled(struct updater_config *cfg)
*/
static int ec_ro_software_sync(struct updater_config *cfg)
{
- const char *tmp_path = create_temp_file(&cfg->tempfiles);
const char *ec_ro_path;
uint8_t *ec_ro_data;
uint32_t ec_ro_len;
int is_same_ec_ro;
struct firmware_section ec_ro_sec;
+ const char *tmp_path = get_firmware_image_temp_file(
+ &cfg->image, &cfg->tempfiles);
- if (!tmp_path ||
- vb2_write_file(tmp_path, cfg->image.data, cfg->image.size)) {
- ERROR("Failed to create temporary file for image contents.\n");
+ if (!tmp_path)
return 1;
- }
find_firmware_section(&ec_ro_sec, &cfg->ec_image, "EC_RO");
if (!ec_ro_sec.data || !ec_ro_sec.size) {
ERROR("EC image has invalid section '%s'.\n", "EC_RO");
@@ -182,14 +171,13 @@ static int quirk_enlarge_image(struct updater_config *cfg)
if (image_from->size <= image_to->size)
return 0;
- tmp_path = create_temp_file(&cfg->tempfiles);
+ tmp_path = get_firmware_image_temp_file(image_to, &cfg->tempfiles);
if (!tmp_path)
return -1;
VB2_DEBUG("Resize image from %u to %u.\n",
image_to->size, image_from->size);
to_write = image_from->size - image_to->size;
- write_image(tmp_path, image_to);
fp = fopen(tmp_path, "ab");
if (!fp) {
ERROR("Cannot open temporary file %s.\n", tmp_path);
@@ -377,11 +365,12 @@ static int quirk_daisy_snow_dual_model(struct updater_config *cfg)
static int quirk_eve_smm_store(struct updater_config *cfg)
{
const char *smm_store_name = "smm_store";
- const char *temp_image = create_temp_file(&cfg->tempfiles);
const char *old_store;
char *command;
+ const char *temp_image = get_firmware_image_temp_file(
+ &cfg->image_current, &cfg->tempfiles);
- if (write_image(temp_image, &cfg->image_current) != VB2_SUCCESS)
+ if (!temp_image)
return -1;
old_store = cbfs_extract_file(temp_image, FMAP_RW_LEGACY,
@@ -392,8 +381,9 @@ static int quirk_eve_smm_store(struct updater_config *cfg)
return 0;
}
- /* Reuse temp_image. */
- if (write_image(temp_image, &cfg->image) != VB2_SUCCESS)
+ /* Reuse temp_image */
+ temp_image = get_firmware_image_temp_file(&cfg->image, &cfg->tempfiles);
+ if (!temp_image)
return -1;
/* crosreview.com/1165109: The offset is fixed at 0x1bf000. */
diff --git a/futility/updater_utils.c b/futility/updater_utils.c
index 28d41984..7a8185b1 100644
--- a/futility/updater_utils.c
+++ b/futility/updater_utils.c
@@ -222,7 +222,9 @@ const char *get_firmware_image_temp_file(const struct firmware_image *image,
return NULL;
if (vb2_write_file(tmp_path, image->data, image->size) != VB2_SUCCESS) {
- ERROR("Cannot write temporary file for output: %s\n", tmp_path);
+ ERROR("Failed writing %s firmware image (%u bytes) to %s.\n",
+ image->programmer ? image->programmer : "temp",
+ image->size, tmp_path);
return NULL;
}
return tmp_path;