|
@@ -6,6 +6,7 @@
|
|
|
|
|
|
#include <config.h>
|
|
|
#include <common.h>
|
|
|
+#include <fastboot.h>
|
|
|
#include <fb_mmc.h>
|
|
|
#include <part.h>
|
|
|
#include <aboot.h>
|
|
@@ -16,23 +17,8 @@
|
|
|
#define CONFIG_FASTBOOT_GPT_NAME GPT_ENTRY_NAME
|
|
|
#endif
|
|
|
|
|
|
-/* The 64 defined bytes plus the '\0' */
|
|
|
-#define RESPONSE_LEN (64 + 1)
|
|
|
-
|
|
|
static char *response_str;
|
|
|
|
|
|
-void fastboot_fail(const char *s)
|
|
|
-{
|
|
|
- strncpy(response_str, "FAIL\0", 5);
|
|
|
- strncat(response_str, s, RESPONSE_LEN - 4 - 1);
|
|
|
-}
|
|
|
-
|
|
|
-void fastboot_okay(const char *s)
|
|
|
-{
|
|
|
- strncpy(response_str, "OKAY\0", 5);
|
|
|
- strncat(response_str, s, RESPONSE_LEN - 4 - 1);
|
|
|
-}
|
|
|
-
|
|
|
static int get_partition_info_efi_by_name_or_alias(block_dev_desc_t *dev_desc,
|
|
|
const char *name, disk_partition_t *info)
|
|
|
{
|
|
@@ -68,7 +54,7 @@ static void write_raw_image(block_dev_desc_t *dev_desc, disk_partition_t *info,
|
|
|
|
|
|
if (blkcnt > info->size) {
|
|
|
error("too large for partition: '%s'\n", part_name);
|
|
|
- fastboot_fail("too large for partition");
|
|
|
+ fastboot_fail(response_str, "too large for partition");
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -78,13 +64,13 @@ static void write_raw_image(block_dev_desc_t *dev_desc, disk_partition_t *info,
|
|
|
buffer);
|
|
|
if (blks != blkcnt) {
|
|
|
error("failed writing to device %d\n", dev_desc->dev);
|
|
|
- fastboot_fail("failed writing to device");
|
|
|
+ fastboot_fail(response_str, "failed writing to device");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
printf("........ wrote " LBAFU " bytes to '%s'\n", blkcnt * info->blksz,
|
|
|
part_name);
|
|
|
- fastboot_okay("");
|
|
|
+ fastboot_okay(response_str, "");
|
|
|
}
|
|
|
|
|
|
void fb_mmc_flash_write(const char *cmd, void *download_buffer,
|
|
@@ -99,7 +85,7 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
|
|
|
dev_desc = get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
|
|
|
if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
|
|
|
error("invalid mmc device\n");
|
|
|
- fastboot_fail("invalid mmc device");
|
|
|
+ fastboot_fail(response_str, "invalid mmc device");
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -109,20 +95,21 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
|
|
|
if (is_valid_gpt_buf(dev_desc, download_buffer)) {
|
|
|
printf("%s: invalid GPT - refusing to write to flash\n",
|
|
|
__func__);
|
|
|
- fastboot_fail("invalid GPT partition");
|
|
|
+ fastboot_fail(response_str, "invalid GPT partition");
|
|
|
return;
|
|
|
}
|
|
|
if (write_mbr_and_gpt_partitions(dev_desc, download_buffer)) {
|
|
|
printf("%s: writing GPT partitions failed\n", __func__);
|
|
|
- fastboot_fail("writing GPT partitions failed");
|
|
|
+ fastboot_fail(response_str,
|
|
|
+ "writing GPT partitions failed");
|
|
|
return;
|
|
|
}
|
|
|
printf("........ success\n");
|
|
|
- fastboot_okay("");
|
|
|
+ fastboot_okay(response_str, "");
|
|
|
return;
|
|
|
} else if (get_partition_info_efi_by_name_or_alias(dev_desc, cmd, &info)) {
|
|
|
error("cannot find partition: '%s'\n", cmd);
|
|
|
- fastboot_fail("cannot find partition");
|
|
|
+ fastboot_fail(response_str, "cannot find partition");
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -132,6 +119,8 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
|
|
|
else
|
|
|
write_raw_image(dev_desc, &info, cmd, download_buffer,
|
|
|
download_bytes);
|
|
|
+
|
|
|
+ fastboot_okay(response_str, "");
|
|
|
}
|
|
|
|
|
|
void fb_mmc_erase(const char *cmd, char *response)
|
|
@@ -144,7 +133,7 @@ void fb_mmc_erase(const char *cmd, char *response)
|
|
|
|
|
|
if (mmc == NULL) {
|
|
|
error("invalid mmc device");
|
|
|
- fastboot_fail("invalid mmc device");
|
|
|
+ fastboot_fail(response_str, "invalid mmc device");
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -154,14 +143,14 @@ void fb_mmc_erase(const char *cmd, char *response)
|
|
|
dev_desc = get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
|
|
|
if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
|
|
|
error("invalid mmc device");
|
|
|
- fastboot_fail("invalid mmc device");
|
|
|
+ fastboot_fail(response_str, "invalid mmc device");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
ret = get_partition_info_efi_by_name_or_alias(dev_desc, cmd, &info);
|
|
|
if (ret) {
|
|
|
error("cannot find partition: '%s'", cmd);
|
|
|
- fastboot_fail("cannot find partition");
|
|
|
+ fastboot_fail(response_str, "cannot find partition");
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -180,11 +169,11 @@ void fb_mmc_erase(const char *cmd, char *response)
|
|
|
blks = dev_desc->block_erase(dev_desc->dev, blks_start, blks_size);
|
|
|
if (blks != blks_size) {
|
|
|
error("failed erasing from device %d", dev_desc->dev);
|
|
|
- fastboot_fail("failed erasing from device");
|
|
|
+ fastboot_fail(response_str, "failed erasing from device");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
printf("........ erased " LBAFU " bytes from '%s'\n",
|
|
|
blks_size * info.blksz, cmd);
|
|
|
- fastboot_okay("");
|
|
|
+ fastboot_okay(response_str, "");
|
|
|
}
|