Skip to content

Commit

Permalink
Reduce the number of open() and close() to improve performance
Browse files Browse the repository at this point in the history
VELAPLATFO-25330

Change-Id: Ica2e8186d6f7018c476d729e1f33bd044ee4573a
Signed-off-by: wangjianyu3 <[email protected]>
  • Loading branch information
JianyuWang0623 committed Sep 10, 2024
1 parent de7ac5c commit 43cd401
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions system/fastboot/fastboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 43cd401

Please sign in to comment.