@@ -318,6 +318,13 @@ static void getvar(char *cmd_parameter, char *response)
fastboot_getvar(cmd_parameter, response);
}
+void fastboot_download_reset(void)
+{
+ image_size = 0;
+ fastboot_bytes_received = 0;
+ fastboot_bytes_expected = 0;
+}
+
/**
* fastboot_download() - Start a download transfer from the client
*
@@ -328,11 +335,11 @@ static void download(char *cmd_parameter, char *response)
{
char *tmp;
+ fastboot_download_reset();
if (!cmd_parameter) {
fastboot_fail("Expected command parameter", response);
return;
}
- fastboot_bytes_received = 0;
fastboot_bytes_expected = hextoul(cmd_parameter, &tmp);
if (fastboot_bytes_expected == 0) {
fastboot_fail("Expected nonzero image size", response);
@@ -436,6 +443,11 @@ void fastboot_data_download(const void *fastboot_data,
*/
void fastboot_data_complete(char *response)
{
+ if (!fastboot_bytes_expected || fastboot_data_remaining()) {
+ fastboot_fail("Incomplete download", response);
+ return;
+ }
+
/* Download complete. Respond with "OKAY" */
fastboot_okay(NULL, response);
printf("\ndownloading of %d bytes finished\n", fastboot_bytes_received);
@@ -15,6 +15,7 @@
#include <cpu_func.h>
#include <env.h>
#include <fastboot.h>
+#include <fastboot-internal.h>
#include <net.h>
#include <vsprintf.h>
@@ -261,5 +262,5 @@ void fastboot_init(void *buf_addr, u32 buf_size)
(void *)CONFIG_FASTBOOT_BUF_ADDR;
fastboot_buf_size = buf_size ? buf_size : CONFIG_FASTBOOT_BUF_SIZE;
fastboot_set_progress_callback(NULL);
-
+ fastboot_download_reset();
}
@@ -13,6 +13,9 @@ extern void *fastboot_buf_addr;
*/
extern u32 fastboot_buf_size;
+/* Invalidate downloaded data when starting a new session or download. */
+void fastboot_download_reset(void);
+
/**
* fastboot_progress_callback - callback executed during long operations
*/