free(buffer);
 }
 
-int store_sparse_image(sparse_storage_t *storage,
-                      void *storage_priv, void *data)
+int store_sparse_image(sparse_storage_t *storage, void *storage_priv,
+                      unsigned int session_id, void *data)
 {
        unsigned int chunk, offset;
        sparse_header_t *sparse_header;
 
        fastboot_okay(response_str, "");
 }
 
-void fb_mmc_flash_write(const char *cmd, void *download_buffer,
-                       unsigned int download_bytes, char *response)
+void fb_mmc_flash_write(const char *cmd, unsigned int session_id,
+                       void *download_buffer, unsigned int download_bytes,
+                       char *response)
 {
        block_dev_desc_t *dev_desc;
        disk_partition_t info;
                printf("Flashing sparse image at offset " LBAFU "\n",
                       info.start);
 
-               store_sparse_image(&sparse, &sparse_priv, download_buffer);
+               store_sparse_image(&sparse, &sparse_priv, session_id,
+                                  download_buffer);
        } else {
                write_raw_image(dev_desc, &info, cmd, download_buffer,
                                download_bytes);
 
 }
 
 static struct f_fastboot *fastboot_func;
+static unsigned int fastboot_flash_session_id;
 static unsigned int download_size;
 static unsigned int download_bytes;
 static bool is_high_speed;
 
                sprintf(str_num, "0x%08x", CONFIG_FASTBOOT_BUF_SIZE);
                strncat(response, str_num, chars_left);
+
+               /*
+                * This also indicates the start of a new flashing
+                * "session", in which we could have 1-N buffers to
+                * write to a partition.
+                *
+                * Reset our session counter.
+                */
+               fastboot_flash_session_id = 0;
        } else if (!strcmp_l1("serialno", cmd)) {
                s = getenv("serial#");
                if (s)
 
        strcpy(response, "FAILno flash device defined");
 #ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
-       fb_mmc_flash_write(cmd, (void *)CONFIG_FASTBOOT_BUF_ADDR,
+       fb_mmc_flash_write(cmd, fastboot_flash_session_id,
+                          (void *)CONFIG_FASTBOOT_BUF_ADDR,
                           download_bytes, response);
 #endif
+       fastboot_flash_session_id++;
        fastboot_tx_write_str(response);
 }
 #endif
 
 }
 
 int store_sparse_image(sparse_storage_t *storage, void *storage_priv,
-                      void *data);
+                      unsigned int session_id, void *data);
 
  * SPDX-License-Identifier:    GPL-2.0+
  */
 
-void fb_mmc_flash_write(const char *cmd, void *download_buffer,
-                       unsigned int download_bytes, char *response);
+void fb_mmc_flash_write(const char *cmd, unsigned int session_id,
+                       void *download_buffer, unsigned int download_bytes,
+                       char *response);
 void fb_mmc_erase(const char *cmd, char *response);