From 43cd401778e70f1a33578dafd43080456d85b2d0 Mon Sep 17 00:00:00 2001 From: wangjianyu3 Date: Wed, 24 Jan 2024 21:09:50 +0800 Subject: [PATCH] Reduce the number of open() and close() to improve performance VELAPLATFO-25330 Change-Id: Ica2e8186d6f7018c476d729e1f33bd044ee4573a Signed-off-by: wangjianyu3 --- system/fastboot/fastboot.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/system/fastboot/fastboot.c b/system/fastboot/fastboot.c index 19120e02a76..37373a0b1d6 100644 --- a/system/fastboot/fastboot.c +++ b/system/fastboot/fastboot.c @@ -108,6 +108,7 @@ struct fastboot_ctx_s { int usbdev_in; int usbdev_out; + int flash_fd; size_t download_max; size_t download_size; size_t download_offset; @@ -400,18 +401,20 @@ static void fastboot_flash(FAR struct fastboot_ctx_s *context, FAR const char *arg) { char blkdev[PATH_MAX]; - int fd; snprintf(blkdev, PATH_MAX, FASTBOOT_BLKDEV, arg); - fd = fastboot_flash_open(blkdev); - if (fd < 0) + if (context->flash_fd < 0) { - fastboot_fail(context, "Flash open failure"); - return; + context->flash_fd = fastboot_flash_open(blkdev); + if (context->flash_fd < 0) + { + fastboot_fail(context, "Flash open failure"); + return; + } } - if (fastboot_flash_program(context, fd) < 0) + if (fastboot_flash_program(context, context->flash_fd) < 0) { fastboot_fail(context, "Image flash failure"); } @@ -420,7 +423,11 @@ static void fastboot_flash(FAR struct fastboot_ctx_s *context, fastboot_okay(context, ""); } - fastboot_flash_close(fd); + if (context->total_imgsize == 0) + { + fastboot_flash_close(context->flash_fd); + context->flash_fd = -1; + } } static void fastboot_erase(FAR struct fastboot_ctx_s *context, @@ -745,6 +752,7 @@ int main(int argc, FAR char **argv) goto err_with_in; } + context.flash_fd = -1; context.download_buffer = buffer; context.download_size = 0; context.download_offset = 0;