diff --git a/common/Kconfig b/common/Kconfig index ac282d8..0c342d8 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -1026,18 +1026,6 @@ images that are bigger than the available memory. If unsure, say yes here. -config FASTBOOT_BUF - bool - prompt "Download files to temporary buffer instead of file" - help - With this option enabled the fastboot code will download files to a - temporary buffer instead of a temporary file. Normally you want to - use a file as this also works when your memory is fragmented. However, - in some special cases, when the file consumer also better copes with - a buffer, then using a buffer might be better. - - Say no here unless you know what you are doing. - config FASTBOOT_CMD_OEM bool prompt "Enable OEM commands" diff --git a/common/fastboot.c b/common/fastboot.c index c32b0a0..302720c 100644 --- a/common/fastboot.c +++ b/common/fastboot.c @@ -53,14 +53,6 @@ struct list_head list; }; -static inline bool fastboot_download_to_buf(struct fastboot *fb) -{ - if (IS_ENABLED(CONFIG_FASTBOOT_BUF)) - return true; - else - return false; -} - static void fb_setvar(struct fb_variable *var, const char *fmt, ...) { va_list ap; @@ -331,13 +323,9 @@ { int ret; - if (fastboot_download_to_buf(fb)) { - memcpy(fb->buf + fb->download_bytes, buffer, len); - } else { - ret = write(fb->download_fd, buffer, len); - if (ret < 0) - return ret; - } + ret = write(fb->download_fd, buffer, len); + if (ret < 0) + return ret; fb->download_bytes += len; show_progress(fb->download_bytes); @@ -346,8 +334,7 @@ void fastboot_download_finished(struct fastboot *fb) { - if (!fastboot_download_to_buf(fb)) - close(fb->download_fd); + close(fb->download_fd); printf("\n"); @@ -367,21 +354,10 @@ init_progression_bar(fb->download_size); - if (fastboot_download_to_buf(fb)) { - free(fb->buf); - fb->buf = malloc(fb->download_size); - if (!fb->buf) { - fastboot_tx_print(fb, FASTBOOT_MSG_FAIL, - "not enough memory"); + fb->download_fd = open(fb->tempname, O_WRONLY | O_CREAT | O_TRUNC); + if (fb->download_fd < 0) { + fastboot_tx_print(fb, FASTBOOT_MSG_FAIL, "internal error"); return; - } - } else { - fb->download_fd = open(fb->tempname, O_WRONLY | O_CREAT | O_TRUNC); - if (fb->download_fd < 0) { - fastboot_tx_print(fb, FASTBOOT_MSG_FAIL, - "internal error"); - return; - } } if (!fb->download_size) @@ -440,12 +416,11 @@ } static int do_ubiformat(struct fastboot *fb, struct mtd_info *mtd, - const char *file, const void *buf, size_t len) + const char *file, size_t len) { struct ubiformat_args args = { .yes = 1, .image = file, - .image_buf = buf, .image_size = len, }; @@ -588,7 +563,7 @@ } if (pos == 0) { - ret = do_ubiformat(fb, mtd, NULL, NULL, 0); + ret = do_ubiformat(fb, mtd, NULL, 0); if (ret) goto out; } @@ -626,16 +601,10 @@ { struct file_list_entry *fentry; int ret; - const char *filename = NULL, *sourcefile; + const char *filename = NULL; enum filetype filetype; - if (fastboot_download_to_buf(fb)) { - sourcefile = NULL; - filetype = file_detect_type(fb->buf, fb->download_bytes); - } else { - sourcefile = fb->tempname; - filetype = file_name_detect_type(fb->tempname); - } + filetype = file_name_detect_type(fb->tempname); fastboot_tx_print(fb, FASTBOOT_MSG_INFO, "Copying file to %s...", cmd); @@ -650,8 +619,7 @@ } if (fb->cmd_flash) { - ret = fb->cmd_flash(fb, fentry, sourcefile, fb->buf, - fb->download_size); + ret = fb->cmd_flash(fb, fentry, fb->tempname, fb->download_size); if (ret != FASTBOOT_CMD_FALLTHROUGH) goto out; } @@ -659,8 +627,7 @@ filename = fentry->filename; if (filetype == filetype_android_sparse) { - if (!IS_ENABLED(CONFIG_FASTBOOT_SPARSE) || - fastboot_download_to_buf(fb)) { + if (!IS_ENABLED(CONFIG_FASTBOOT_SPARSE)) { fastboot_tx_print(fb, FASTBOOT_MSG_FAIL, "sparse image not supported"); ret = -EOPNOTSUPP; @@ -685,8 +652,7 @@ mtd = get_mtd(fb, fentry->filename); - ret = do_ubiformat(fb, mtd, sourcefile, fb->buf, - fb->download_size); + ret = do_ubiformat(fb, mtd, fb->tempname, fb->download_size); if (ret) { fastboot_tx_print(fb, FASTBOOT_MSG_FAIL, "write partition: %s", @@ -698,6 +664,7 @@ } if (IS_ENABLED(CONFIG_BAREBOX_UPDATE) && filetype_is_barebox_image(filetype)) { + void *buf; struct bbu_handler *handler; struct bbu_data data = { .devicefile = filename, @@ -711,20 +678,16 @@ fastboot_tx_print(fb, FASTBOOT_MSG_INFO, "This is a barebox image..."); - if (fastboot_download_to_buf(fb)) { - data.len = fb->download_size; - } else { - ret = read_file_2(sourcefile, &data.len, &fb->buf, - fb->download_size); - if (ret) { - fastboot_tx_print(fb, FASTBOOT_MSG_FAIL, - "reading barebox"); - goto out; - } + ret = read_file_2(fb->tempname, &data.len, &buf, + fb->download_size); + if (ret) { + fastboot_tx_print(fb, FASTBOOT_MSG_FAIL, + "reading barebox"); + goto out; } - data.image = fb->buf; - data.imagefile = sourcefile; + data.image = buf; + data.imagefile = fb->tempname; ret = barebox_update(&data, handler); @@ -732,15 +695,13 @@ fastboot_tx_print(fb, FASTBOOT_MSG_FAIL, "update barebox: %s", strerror(-ret)); + free(buf); + goto out; } copy: - if (fastboot_download_to_buf(fb)) - ret = write_file(filename, fb->buf, fb->download_size); - else - ret = copy_file(fb->tempname, filename, 1); - + ret = copy_file(fb->tempname, filename, 1); if (ret) fastboot_tx_print(fb, FASTBOOT_MSG_FAIL, "write partition: %s", strerror(-ret)); @@ -749,11 +710,7 @@ if (!ret) fastboot_tx_print(fb, FASTBOOT_MSG_OKAY, ""); - free(fb->buf); - fb->buf = NULL; - - if (!fastboot_download_to_buf(fb)) - unlink(fb->tempname); + unlink(fb->tempname); } static void cb_erase(struct fastboot *fb, const char *cmd) diff --git a/include/fastboot.h b/include/fastboot.h index b3e7155..d33f9d1 100644 --- a/include/fastboot.h +++ b/include/fastboot.h @@ -22,9 +22,8 @@ struct file_list *files; int (*cmd_exec)(struct fastboot *fb, const char *cmd); int (*cmd_flash)(struct fastboot *fb, struct file_list_entry *entry, - const char *filename, const void *buf, size_t len); + const char *filename, size_t len); int download_fd; - void *buf; char *tempname; bool active; @@ -44,7 +43,7 @@ bool export_bbu; int (*cmd_exec)(struct fastboot *fb, const char *cmd); int (*cmd_flash)(struct fastboot *fb, struct file_list_entry *entry, - const char *filename, const void *buf, size_t len); + const char *filename, size_t len); }; enum fastboot_msg_type {