Commit 6c9e00eebfd7244d74068832a1bb7f8679d1861a
Committed by
Tom Rini
1 parent
a5d1e04a53
Exists in
v2017.01-smarct4x
and in
30 other branches
fastboot: Implement flashing session counter
The fastboot flash command that writes an image to a partition works in several steps: 1 - Retrieve the maximum size the device can download through the "max-download-size" variable 2 - Retrieve the partition type through the "partition-type:%s" variable, that indicates whether or not the partition needs to be erased (even though the fastboot client has minimal support for that) 3a - If the image is smaller than what the device can handle, send the image and flash it. 3b - If the image is larger than what the device can handle, create a sparse image, and split it in several chunks that would fit. Send the chunk, flash it, repeat until we have no more data to send. However, in the 3b case, the subsequent transfers have no particular identifiers, the protocol just assumes that you would resume the writes where you left it. While doing so works well, it also means that flashing two subsequent images on the same partition (for example because the user made a mistake) would not work withouth flashing another partition or rebooting the board, which is not really intuitive. Since we have always the same pattern, we can however maintain a counter that will be reset every time the client will retrieve max-download-size, and incremented after each buffer will be flashed, that will allow us to tell whether we should simply resume the flashing where we were, or start back at the beginning of the partition. Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> Reviewed-by: Tom Rini <trini@konsulko.com>
Showing 5 changed files with 24 additions and 9 deletions Side-by-side Diff
common/aboot.c
... | ... | @@ -264,8 +264,8 @@ |
264 | 264 | free(buffer); |
265 | 265 | } |
266 | 266 | |
267 | -int store_sparse_image(sparse_storage_t *storage, | |
268 | - void *storage_priv, void *data) | |
267 | +int store_sparse_image(sparse_storage_t *storage, void *storage_priv, | |
268 | + unsigned int session_id, void *data) | |
269 | 269 | { |
270 | 270 | unsigned int chunk, offset; |
271 | 271 | sparse_header_t *sparse_header; |
common/fb_mmc.c
... | ... | @@ -96,8 +96,9 @@ |
96 | 96 | fastboot_okay(response_str, ""); |
97 | 97 | } |
98 | 98 | |
99 | -void fb_mmc_flash_write(const char *cmd, void *download_buffer, | |
100 | - unsigned int download_bytes, char *response) | |
99 | +void fb_mmc_flash_write(const char *cmd, unsigned int session_id, | |
100 | + void *download_buffer, unsigned int download_bytes, | |
101 | + char *response) | |
101 | 102 | { |
102 | 103 | block_dev_desc_t *dev_desc; |
103 | 104 | disk_partition_t info; |
... | ... | @@ -151,7 +152,8 @@ |
151 | 152 | printf("Flashing sparse image at offset " LBAFU "\n", |
152 | 153 | info.start); |
153 | 154 | |
154 | - store_sparse_image(&sparse, &sparse_priv, download_buffer); | |
155 | + store_sparse_image(&sparse, &sparse_priv, session_id, | |
156 | + download_buffer); | |
155 | 157 | } else { |
156 | 158 | write_raw_image(dev_desc, &info, cmd, download_buffer, |
157 | 159 | download_bytes); |
drivers/usb/gadget/f_fastboot.c
... | ... | @@ -51,6 +51,7 @@ |
51 | 51 | } |
52 | 52 | |
53 | 53 | static struct f_fastboot *fastboot_func; |
54 | +static unsigned int fastboot_flash_session_id; | |
54 | 55 | static unsigned int download_size; |
55 | 56 | static unsigned int download_bytes; |
56 | 57 | static bool is_high_speed; |
... | ... | @@ -393,6 +394,15 @@ |
393 | 394 | |
394 | 395 | sprintf(str_num, "0x%08x", CONFIG_FASTBOOT_BUF_SIZE); |
395 | 396 | strncat(response, str_num, chars_left); |
397 | + | |
398 | + /* | |
399 | + * This also indicates the start of a new flashing | |
400 | + * "session", in which we could have 1-N buffers to | |
401 | + * write to a partition. | |
402 | + * | |
403 | + * Reset our session counter. | |
404 | + */ | |
405 | + fastboot_flash_session_id = 0; | |
396 | 406 | } else if (!strcmp_l1("serialno", cmd)) { |
397 | 407 | s = getenv("serial#"); |
398 | 408 | if (s) |
399 | 409 | |
... | ... | @@ -555,9 +565,11 @@ |
555 | 565 | |
556 | 566 | strcpy(response, "FAILno flash device defined"); |
557 | 567 | #ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV |
558 | - fb_mmc_flash_write(cmd, (void *)CONFIG_FASTBOOT_BUF_ADDR, | |
568 | + fb_mmc_flash_write(cmd, fastboot_flash_session_id, | |
569 | + (void *)CONFIG_FASTBOOT_BUF_ADDR, | |
559 | 570 | download_bytes, response); |
560 | 571 | #endif |
572 | + fastboot_flash_session_id++; | |
561 | 573 | fastboot_tx_write_str(response); |
562 | 574 | } |
563 | 575 | #endif |
include/aboot.h
include/fb_mmc.h
... | ... | @@ -4,7 +4,8 @@ |
4 | 4 | * SPDX-License-Identifier: GPL-2.0+ |
5 | 5 | */ |
6 | 6 | |
7 | -void fb_mmc_flash_write(const char *cmd, void *download_buffer, | |
8 | - unsigned int download_bytes, char *response); | |
7 | +void fb_mmc_flash_write(const char *cmd, unsigned int session_id, | |
8 | + void *download_buffer, unsigned int download_bytes, | |
9 | + char *response); | |
9 | 10 | void fb_mmc_erase(const char *cmd, char *response); |