Attention is currently required from: Zheng Bao.
Hello Zheng Bao,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/coreboot/+/78305?usp=email
to review the following change.
Change subject: amdfwtool: Move the function to handle_file.c ......................................................................
amdfwtool: Move the function to handle_file.c
Change-Id: I4cfec13cbc2a86dc352758541cce915a838e0d0f Signed-off-by: Zheng Bao fishbaozi@gmail.com --- M util/amdfwtool/amdfwtool.c M util/amdfwtool/amdfwtool.h M util/amdfwtool/handle_file.c 3 files changed, 54 insertions(+), 52 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/05/78305/1
diff --git a/util/amdfwtool/amdfwtool.c b/util/amdfwtool/amdfwtool.c index b071e6c..ded9acf 100644 --- a/util/amdfwtool/amdfwtool.c +++ b/util/amdfwtool/amdfwtool.c @@ -95,10 +95,6 @@
#define DEFAULT_SOFT_FUSE_CHAIN "0x1"
-#define EFS_FILE_SUFFIX ".efs" -#define TMP_FILE_SUFFIX ".tmp" -#define BODY_FILE_SUFFIX ".body" - static void output_manifest(int manifest_fd, amd_fw_entry *fw_entry);
/* @@ -1814,54 +1810,6 @@ return 0; }
-static ssize_t write_body(char *output, void *body_offset, ssize_t body_size) -{ - char body_name[PATH_MAX], body_tmp_name[PATH_MAX]; - int ret; - int fd; - ssize_t bytes = -1; - - /* Create a tmp file and rename it at the end so that make does not get confused - if amdfwtool is killed for some unexpected reasons. */ - ret = snprintf(body_tmp_name, sizeof(body_tmp_name), "%s%s%s", - output, BODY_FILE_SUFFIX, TMP_FILE_SUFFIX); - if (ret < 0) { - fprintf(stderr, "Error %s forming BODY tmp file name: %d\n", - strerror(errno), ret); - return -1; - } else if ((unsigned int)ret >= sizeof(body_tmp_name)) { - fprintf(stderr, "BODY File name %d > %zu\n", ret, sizeof(body_tmp_name)); - return -1; - } - - fd = open(body_tmp_name, O_RDWR | O_CREAT | O_TRUNC, 0666); - if (fd < 0) { - fprintf(stderr, "Error: Opening %s file: %s\n", body_tmp_name, strerror(errno)); - return -1; - } - - bytes = write_from_buf_to_file(fd, body_offset, body_size); - if (bytes != body_size) { - fprintf(stderr, "Error: Writing to file %s failed\n", body_tmp_name); - return -1; - } - close(fd); - - /* Rename the tmp file */ - ret = snprintf(body_name, sizeof(body_name), "%s%s", output, BODY_FILE_SUFFIX); - if (ret < 0) { - fprintf(stderr, "Error %s forming BODY file name: %d\n", strerror(errno), ret); - return -1; - } - - if (rename(body_tmp_name, body_name)) { - fprintf(stderr, "Error: renaming file %s to %s\n", body_tmp_name, body_name); - return -1; - } - - return bytes; -} - void open_process_config(char *config, amd_cb_config *cb_config, int debug) { FILE *config_handle; diff --git a/util/amdfwtool/amdfwtool.h b/util/amdfwtool/amdfwtool.h index 2044696..e9c158f 100644 --- a/util/amdfwtool/amdfwtool.h +++ b/util/amdfwtool/amdfwtool.h @@ -435,9 +435,15 @@ amd_fw_entry *fw_table, uint64_t signed_start_addr, enum platform soc_id); + +#define EFS_FILE_SUFFIX ".efs" +#define TMP_FILE_SUFFIX ".tmp" +#define BODY_FILE_SUFFIX ".body" + void write_or_fail(int fd, void *ptr, size_t size); ssize_t read_from_file_to_buf(int fd, void *buf, size_t buf_size); ssize_t write_from_buf_to_file(int fd, const void *buf, size_t buf_size); +ssize_t write_body(char *output, void *body_offset, ssize_t body_size); #define OK 0
#define LINE_EOF (1) diff --git a/util/amdfwtool/handle_file.c b/util/amdfwtool/handle_file.c index 884f1ba..2877096 100644 --- a/util/amdfwtool/handle_file.c +++ b/util/amdfwtool/handle_file.c @@ -82,3 +82,51 @@
return buf_size; } + +ssize_t write_body(char *output, void *body_offset, ssize_t body_size) +{ + char body_name[PATH_MAX], body_tmp_name[PATH_MAX]; + int ret; + int fd; + ssize_t bytes = -1; + + /* Create a tmp file and rename it at the end so that make does not get confused + if amdfwtool is killed for some unexpected reasons. */ + ret = snprintf(body_tmp_name, sizeof(body_tmp_name), "%s%s%s", + output, BODY_FILE_SUFFIX, TMP_FILE_SUFFIX); + if (ret < 0) { + fprintf(stderr, "Error %s forming BODY tmp file name: %d\n", + strerror(errno), ret); + return -1; + } else if ((unsigned int)ret >= sizeof(body_tmp_name)) { + fprintf(stderr, "BODY File name %d > %zu\n", ret, sizeof(body_tmp_name)); + return -1; + } + + fd = open(body_tmp_name, O_RDWR | O_CREAT | O_TRUNC, 0666); + if (fd < 0) { + fprintf(stderr, "Error: Opening %s file: %s\n", body_tmp_name, strerror(errno)); + return -1; + } + + bytes = write_from_buf_to_file(fd, body_offset, body_size); + if (bytes != body_size) { + fprintf(stderr, "Error: Writing to file %s failed\n", body_tmp_name); + return -1; + } + close(fd); + + /* Rename the tmp file */ + ret = snprintf(body_name, sizeof(body_name), "%s%s", output, BODY_FILE_SUFFIX); + if (ret < 0) { + fprintf(stderr, "Error %s forming BODY file name: %d\n", strerror(errno), ret); + return -1; + } + + if (rename(body_tmp_name, body_name)) { + fprintf(stderr, "Error: renaming file %s to %s\n", body_tmp_name, body_name); + return -1; + } + + return bytes; +}