fastboot: Refactor fastboot_okay/fail to take response

Add the response string as a parameter to fastboot_okay/fail, instead
of modifying a global, to match the contract expected by the AOSP
U-Boot code.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>
lime2-spi
Alex Kiernan 6 years ago committed by Marek Vasut
parent 312a10f16b
commit c4ded03ef6
  1. 2
      cmd/mmc.c
  2. 32
      common/image-sparse.c
  3. 83
      drivers/fastboot/fb_mmc.c
  4. 34
      drivers/fastboot/fb_nand.c
  5. 35
      drivers/usb/gadget/f_fastboot.c
  6. 4
      include/fastboot.h
  7. 4
      include/fb_mmc.h
  8. 4
      include/fb_nand.h
  9. 4
      include/image-sparse.h

@ -367,7 +367,7 @@ static int do_mmc_sparse_write(cmd_tbl_t *cmdtp, int flag,
sparse.mssg = NULL; sparse.mssg = NULL;
sprintf(dest, "0x" LBAF, sparse.start * sparse.blksz); sprintf(dest, "0x" LBAF, sparse.start * sparse.blksz);
if (write_sparse_image(&sparse, dest, addr)) if (write_sparse_image(&sparse, dest, addr, NULL))
return CMD_RET_FAILURE; return CMD_RET_FAILURE;
else else
return CMD_RET_SUCCESS; return CMD_RET_SUCCESS;

@ -48,10 +48,10 @@
#define CONFIG_FASTBOOT_FLASH_FILLBUF_SIZE (1024 * 512) #define CONFIG_FASTBOOT_FLASH_FILLBUF_SIZE (1024 * 512)
#endif #endif
static void default_log(const char *ignored) {} static void default_log(const char *ignored, char *response) {}
int write_sparse_image(struct sparse_storage *info, int write_sparse_image(struct sparse_storage *info,
const char *part_name, void *data) const char *part_name, void *data, char *response)
{ {
lbaint_t blk; lbaint_t blk;
lbaint_t blkcnt; lbaint_t blkcnt;
@ -104,7 +104,7 @@ int write_sparse_image(struct sparse_storage *info,
if (offset) { if (offset) {
printf("%s: Sparse image block size issue [%u]\n", printf("%s: Sparse image block size issue [%u]\n",
__func__, sparse_header->blk_sz); __func__, sparse_header->blk_sz);
info->mssg("sparse image block size issue"); info->mssg("sparse image block size issue", response);
return -1; return -1;
} }
@ -139,7 +139,8 @@ int write_sparse_image(struct sparse_storage *info,
case CHUNK_TYPE_RAW: case CHUNK_TYPE_RAW:
if (chunk_header->total_sz != if (chunk_header->total_sz !=
(sparse_header->chunk_hdr_sz + chunk_data_sz)) { (sparse_header->chunk_hdr_sz + chunk_data_sz)) {
info->mssg("Bogus chunk size for chunk type Raw"); info->mssg("Bogus chunk size for chunk type Raw",
response);
return -1; return -1;
} }
@ -147,7 +148,8 @@ int write_sparse_image(struct sparse_storage *info,
printf( printf(
"%s: Request would exceed partition size!\n", "%s: Request would exceed partition size!\n",
__func__); __func__);
info->mssg("Request would exceed partition size!"); info->mssg("Request would exceed partition size!",
response);
return -1; return -1;
} }
@ -157,7 +159,7 @@ int write_sparse_image(struct sparse_storage *info,
printf("%s: %s" LBAFU " [" LBAFU "]\n", printf("%s: %s" LBAFU " [" LBAFU "]\n",
__func__, "Write failed, block #", __func__, "Write failed, block #",
blk, blks); blk, blks);
info->mssg("flash write failure"); info->mssg("flash write failure", response);
return -1; return -1;
} }
blk += blks; blk += blks;
@ -169,7 +171,7 @@ int write_sparse_image(struct sparse_storage *info,
case CHUNK_TYPE_FILL: case CHUNK_TYPE_FILL:
if (chunk_header->total_sz != if (chunk_header->total_sz !=
(sparse_header->chunk_hdr_sz + sizeof(uint32_t))) { (sparse_header->chunk_hdr_sz + sizeof(uint32_t))) {
info->mssg("Bogus chunk size for chunk type FILL"); info->mssg("Bogus chunk size for chunk type FILL", response);
return -1; return -1;
} }
@ -179,7 +181,8 @@ int write_sparse_image(struct sparse_storage *info,
info->blksz * fill_buf_num_blks, info->blksz * fill_buf_num_blks,
ARCH_DMA_MINALIGN)); ARCH_DMA_MINALIGN));
if (!fill_buf) { if (!fill_buf) {
info->mssg("Malloc failed for: CHUNK_TYPE_FILL"); info->mssg("Malloc failed for: CHUNK_TYPE_FILL",
response);
return -1; return -1;
} }
@ -196,7 +199,8 @@ int write_sparse_image(struct sparse_storage *info,
printf( printf(
"%s: Request would exceed partition size!\n", "%s: Request would exceed partition size!\n",
__func__); __func__);
info->mssg("Request would exceed partition size!"); info->mssg("Request would exceed partition size!",
response);
return -1; return -1;
} }
@ -211,7 +215,8 @@ int write_sparse_image(struct sparse_storage *info,
__func__, __func__,
"Write failed, block #", "Write failed, block #",
blk, j); blk, j);
info->mssg("flash write failure"); info->mssg("flash write failure",
response);
free(fill_buf); free(fill_buf);
return -1; return -1;
} }
@ -231,7 +236,8 @@ int write_sparse_image(struct sparse_storage *info,
case CHUNK_TYPE_CRC32: case CHUNK_TYPE_CRC32:
if (chunk_header->total_sz != if (chunk_header->total_sz !=
sparse_header->chunk_hdr_sz) { sparse_header->chunk_hdr_sz) {
info->mssg("Bogus chunk size for chunk type Dont Care"); info->mssg("Bogus chunk size for chunk type Dont Care",
response);
return -1; return -1;
} }
total_blocks += chunk_header->chunk_sz; total_blocks += chunk_header->chunk_sz;
@ -241,7 +247,7 @@ int write_sparse_image(struct sparse_storage *info,
default: default:
printf("%s: Unknown chunk type: %x\n", __func__, printf("%s: Unknown chunk type: %x\n", __func__,
chunk_header->chunk_type); chunk_header->chunk_type);
info->mssg("Unknown chunk type"); info->mssg("Unknown chunk type", response);
return -1; return -1;
} }
} }
@ -251,7 +257,7 @@ int write_sparse_image(struct sparse_storage *info,
printf("........ wrote %u bytes to '%s'\n", bytes_written, part_name); printf("........ wrote %u bytes to '%s'\n", bytes_written, part_name);
if (total_blocks != sparse_header->total_blks) { if (total_blocks != sparse_header->total_blks) {
info->mssg("sparse image write failure"); info->mssg("sparse image write failure", response);
return -1; return -1;
} }

@ -73,7 +73,7 @@ static lbaint_t fb_mmc_sparse_reserve(struct sparse_storage *info,
static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info, static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info,
const char *part_name, void *buffer, const char *part_name, void *buffer,
unsigned int download_bytes) unsigned int download_bytes, char *response)
{ {
lbaint_t blkcnt; lbaint_t blkcnt;
lbaint_t blks; lbaint_t blks;
@ -84,7 +84,7 @@ static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info,
if (blkcnt > info->size) { if (blkcnt > info->size) {
pr_err("too large for partition: '%s'\n", part_name); pr_err("too large for partition: '%s'\n", part_name);
fastboot_fail("too large for partition"); fastboot_fail("too large for partition", response);
return; return;
} }
@ -93,13 +93,13 @@ static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info,
blks = blk_dwrite(dev_desc, info->start, blkcnt, buffer); blks = blk_dwrite(dev_desc, info->start, blkcnt, buffer);
if (blks != blkcnt) { if (blks != blkcnt) {
pr_err("failed writing to device %d\n", dev_desc->devnum); pr_err("failed writing to device %d\n", dev_desc->devnum);
fastboot_fail("failed writing to device"); fastboot_fail("failed writing to device", response);
return; return;
} }
printf("........ wrote " LBAFU " bytes to '%s'\n", blkcnt * info->blksz, printf("........ wrote " LBAFU " bytes to '%s'\n", blkcnt * info->blksz,
part_name); part_name);
fastboot_okay(""); fastboot_okay(NULL, response);
} }
#ifdef CONFIG_ANDROID_BOOT_IMAGE #ifdef CONFIG_ANDROID_BOOT_IMAGE
@ -114,7 +114,8 @@ static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info,
*/ */
static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc, static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
disk_partition_t *info, disk_partition_t *info,
struct andr_img_hdr *hdr) struct andr_img_hdr *hdr,
char *response)
{ {
ulong sector_size; /* boot partition sector size */ ulong sector_size; /* boot partition sector size */
lbaint_t hdr_sectors; /* boot image header sectors count */ lbaint_t hdr_sectors; /* boot image header sectors count */
@ -125,7 +126,7 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
hdr_sectors = DIV_ROUND_UP(sizeof(struct andr_img_hdr), sector_size); hdr_sectors = DIV_ROUND_UP(sizeof(struct andr_img_hdr), sector_size);
if (hdr_sectors == 0) { if (hdr_sectors == 0) {
pr_err("invalid number of boot sectors: 0"); pr_err("invalid number of boot sectors: 0");
fastboot_fail("invalid number of boot sectors: 0"); fastboot_fail("invalid number of boot sectors: 0", response);
return 0; return 0;
} }
@ -133,7 +134,8 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
res = blk_dread(dev_desc, info->start, hdr_sectors, (void *)hdr); res = blk_dread(dev_desc, info->start, hdr_sectors, (void *)hdr);
if (res != hdr_sectors) { if (res != hdr_sectors) {
pr_err("cannot read header from boot partition"); pr_err("cannot read header from boot partition");
fastboot_fail("cannot read header from boot partition"); fastboot_fail("cannot read header from boot partition",
response);
return 0; return 0;
} }
@ -141,7 +143,7 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
res = android_image_check_header(hdr); res = android_image_check_header(hdr);
if (res != 0) { if (res != 0) {
pr_err("bad boot image magic"); pr_err("bad boot image magic");
fastboot_fail("boot partition not initialized"); fastboot_fail("boot partition not initialized", response);
return 0; return 0;
} }
@ -159,7 +161,8 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
*/ */
static int fb_mmc_update_zimage(struct blk_desc *dev_desc, static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
void *download_buffer, void *download_buffer,
unsigned int download_bytes) unsigned int download_bytes,
char *response)
{ {
uintptr_t hdr_addr; /* boot image header address */ uintptr_t hdr_addr; /* boot image header address */
struct andr_img_hdr *hdr; /* boot image header */ struct andr_img_hdr *hdr; /* boot image header */
@ -179,7 +182,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
res = part_get_info_by_name(dev_desc, BOOT_PARTITION_NAME, &info); res = part_get_info_by_name(dev_desc, BOOT_PARTITION_NAME, &info);
if (res < 0) { if (res < 0) {
pr_err("cannot find boot partition"); pr_err("cannot find boot partition");
fastboot_fail("cannot find boot partition"); fastboot_fail("cannot find boot partition", response);
return -1; return -1;
} }
@ -188,17 +191,18 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
hdr = (struct andr_img_hdr *)hdr_addr; hdr = (struct andr_img_hdr *)hdr_addr;
/* Read boot image header */ /* Read boot image header */
hdr_sectors = fb_mmc_get_boot_header(dev_desc, &info, hdr); hdr_sectors = fb_mmc_get_boot_header(dev_desc, &info, hdr, response);
if (hdr_sectors == 0) { if (hdr_sectors == 0) {
pr_err("unable to read boot image header"); pr_err("unable to read boot image header");
fastboot_fail("unable to read boot image header"); fastboot_fail("unable to read boot image header", response);
return -1; return -1;
} }
/* Check if boot image has second stage in it (we don't support it) */ /* Check if boot image has second stage in it (we don't support it) */
if (hdr->second_size > 0) { if (hdr->second_size > 0) {
pr_err("moving second stage is not supported yet"); pr_err("moving second stage is not supported yet");
fastboot_fail("moving second stage is not supported yet"); fastboot_fail("moving second stage is not supported yet",
response);
return -1; return -1;
} }
@ -216,7 +220,8 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
ramdisk_buffer); ramdisk_buffer);
if (res != ramdisk_sectors) { if (res != ramdisk_sectors) {
pr_err("cannot read ramdisk from boot partition"); pr_err("cannot read ramdisk from boot partition");
fastboot_fail("cannot read ramdisk from boot partition"); fastboot_fail("cannot read ramdisk from boot partition",
response);
return -1; return -1;
} }
@ -225,7 +230,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
res = blk_dwrite(dev_desc, info.start, hdr_sectors, (void *)hdr); res = blk_dwrite(dev_desc, info.start, hdr_sectors, (void *)hdr);
if (res == 0) { if (res == 0) {
pr_err("cannot writeback boot image header"); pr_err("cannot writeback boot image header");
fastboot_fail("cannot write back boot image header"); fastboot_fail("cannot write back boot image header", response);
return -1; return -1;
} }
@ -237,7 +242,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
download_buffer); download_buffer);
if (res == 0) { if (res == 0) {
pr_err("cannot write new kernel"); pr_err("cannot write new kernel");
fastboot_fail("cannot write new kernel"); fastboot_fail("cannot write new kernel", response);
return -1; return -1;
} }
@ -249,18 +254,18 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
ramdisk_buffer); ramdisk_buffer);
if (res == 0) { if (res == 0) {
pr_err("cannot write back original ramdisk"); pr_err("cannot write back original ramdisk");
fastboot_fail("cannot write back original ramdisk"); fastboot_fail("cannot write back original ramdisk", response);
return -1; return -1;
} }
puts("........ zImage was updated in boot partition\n"); puts("........ zImage was updated in boot partition\n");
fastboot_okay(""); fastboot_okay(NULL, response);
return 0; return 0;
} }
#endif #endif
void fb_mmc_flash_write(const char *cmd, void *download_buffer, void fb_mmc_flash_write(const char *cmd, void *download_buffer,
unsigned int download_bytes) unsigned int download_bytes, char *response)
{ {
struct blk_desc *dev_desc; struct blk_desc *dev_desc;
disk_partition_t info; disk_partition_t info;
@ -268,7 +273,7 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV); dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) { if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
pr_err("invalid mmc device\n"); pr_err("invalid mmc device\n");
fastboot_fail("invalid mmc device"); fastboot_fail("invalid mmc device", response);
return; return;
} }
@ -279,16 +284,17 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
if (is_valid_gpt_buf(dev_desc, download_buffer)) { if (is_valid_gpt_buf(dev_desc, download_buffer)) {
printf("%s: invalid GPT - refusing to write to flash\n", printf("%s: invalid GPT - refusing to write to flash\n",
__func__); __func__);
fastboot_fail("invalid GPT partition"); fastboot_fail("invalid GPT partition", response);
return; return;
} }
if (write_mbr_and_gpt_partitions(dev_desc, download_buffer)) { if (write_mbr_and_gpt_partitions(dev_desc, download_buffer)) {
printf("%s: writing GPT partitions failed\n", __func__); printf("%s: writing GPT partitions failed\n", __func__);
fastboot_fail("writing GPT partitions failed"); fastboot_fail("writing GPT partitions failed",
response);
return; return;
} }
printf("........ success\n"); printf("........ success\n");
fastboot_okay(""); fastboot_okay(NULL, response);
return; return;
} }
#endif #endif
@ -299,30 +305,32 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
if (is_valid_dos_buf(download_buffer)) { if (is_valid_dos_buf(download_buffer)) {
printf("%s: invalid MBR - refusing to write to flash\n", printf("%s: invalid MBR - refusing to write to flash\n",
__func__); __func__);
fastboot_fail("invalid MBR partition"); fastboot_fail("invalid MBR partition", response);
return; return;
} }
if (write_mbr_partition(dev_desc, download_buffer)) { if (write_mbr_partition(dev_desc, download_buffer)) {
printf("%s: writing MBR partition failed\n", __func__); printf("%s: writing MBR partition failed\n", __func__);
fastboot_fail("writing MBR partition failed"); fastboot_fail("writing MBR partition failed",
response);
return; return;
} }
printf("........ success\n"); printf("........ success\n");
fastboot_okay(""); fastboot_okay(NULL, response);
return; return;
} }
#endif #endif
#ifdef CONFIG_ANDROID_BOOT_IMAGE #ifdef CONFIG_ANDROID_BOOT_IMAGE
if (strncasecmp(cmd, "zimage", 6) == 0) { if (strncasecmp(cmd, "zimage", 6) == 0) {
fb_mmc_update_zimage(dev_desc, download_buffer, download_bytes); fb_mmc_update_zimage(dev_desc, download_buffer,
download_bytes, response);
return; return;
} }
#endif #endif
if (part_get_info_by_name_or_alias(dev_desc, cmd, &info) < 0) { if (part_get_info_by_name_or_alias(dev_desc, cmd, &info) < 0) {
pr_err("cannot find partition: '%s'\n", cmd); pr_err("cannot find partition: '%s'\n", cmd);
fastboot_fail("cannot find partition"); fastboot_fail("cannot find partition", response);
return; return;
} }
@ -344,16 +352,17 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
sparse.start); sparse.start);
sparse.priv = &sparse_priv; sparse.priv = &sparse_priv;
err = write_sparse_image(&sparse, cmd, download_buffer); err = write_sparse_image(&sparse, cmd, download_buffer,
response);
if (!err) if (!err)
fastboot_okay(""); fastboot_okay(NULL, response);
} else { } else {
write_raw_image(dev_desc, &info, cmd, download_buffer, write_raw_image(dev_desc, &info, cmd, download_buffer,
download_bytes); download_bytes, response);
} }
} }
void fb_mmc_erase(const char *cmd) void fb_mmc_erase(const char *cmd, char *response)
{ {
int ret; int ret;
struct blk_desc *dev_desc; struct blk_desc *dev_desc;
@ -363,21 +372,21 @@ void fb_mmc_erase(const char *cmd)
if (mmc == NULL) { if (mmc == NULL) {
pr_err("invalid mmc device"); pr_err("invalid mmc device");
fastboot_fail("invalid mmc device"); fastboot_fail("invalid mmc device", response);
return; return;
} }
dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV); dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) { if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
pr_err("invalid mmc device"); pr_err("invalid mmc device");
fastboot_fail("invalid mmc device"); fastboot_fail("invalid mmc device", response);
return; return;
} }
ret = part_get_info_by_name_or_alias(dev_desc, cmd, &info); ret = part_get_info_by_name_or_alias(dev_desc, cmd, &info);
if (ret < 0) { if (ret < 0) {
pr_err("cannot find partition: '%s'", cmd); pr_err("cannot find partition: '%s'", cmd);
fastboot_fail("cannot find partition"); fastboot_fail("cannot find partition", response);
return; return;
} }
@ -396,11 +405,11 @@ void fb_mmc_erase(const char *cmd)
blks = blk_derase(dev_desc, blks_start, blks_size); blks = blk_derase(dev_desc, blks_start, blks_size);
if (blks != blks_size) { if (blks != blks_size) {
pr_err("failed erasing from device %d", dev_desc->devnum); pr_err("failed erasing from device %d", dev_desc->devnum);
fastboot_fail("failed erasing from device"); fastboot_fail("failed erasing from device", response);
return; return;
} }
printf("........ erased " LBAFU " bytes from '%s'\n", printf("........ erased " LBAFU " bytes from '%s'\n",
blks_size * info.blksz, cmd); blks_size * info.blksz, cmd);
fastboot_okay(""); fastboot_okay(NULL, response);
} }

@ -31,7 +31,8 @@ __weak int board_fastboot_write_partition_setup(char *name)
static int fb_nand_lookup(const char *partname, static int fb_nand_lookup(const char *partname,
struct mtd_info **mtd, struct mtd_info **mtd,
struct part_info **part) struct part_info **part,
char *response)
{ {
struct mtd_device *dev; struct mtd_device *dev;
int ret; int ret;
@ -40,21 +41,21 @@ static int fb_nand_lookup(const char *partname,
ret = mtdparts_init(); ret = mtdparts_init();
if (ret) { if (ret) {
pr_err("Cannot initialize MTD partitions\n"); pr_err("Cannot initialize MTD partitions\n");
fastboot_fail("cannot init mtdparts"); fastboot_fail("cannot init mtdparts", response);
return ret; return ret;
} }
ret = find_dev_and_part(partname, &dev, &pnum, part); ret = find_dev_and_part(partname, &dev, &pnum, part);
if (ret) { if (ret) {
pr_err("cannot find partition: '%s'", partname); pr_err("cannot find partition: '%s'", partname);
fastboot_fail("cannot find partition"); fastboot_fail("cannot find partition", response);
return ret; return ret;
} }
if (dev->id->type != MTD_DEV_TYPE_NAND) { if (dev->id->type != MTD_DEV_TYPE_NAND) {
pr_err("partition '%s' is not stored on a NAND device", pr_err("partition '%s' is not stored on a NAND device",
partname); partname);
fastboot_fail("not a NAND device"); fastboot_fail("not a NAND device", response);
return -EINVAL; return -EINVAL;
} }
@ -145,16 +146,16 @@ static lbaint_t fb_nand_sparse_reserve(struct sparse_storage *info,
} }
void fb_nand_flash_write(const char *cmd, void *download_buffer, void fb_nand_flash_write(const char *cmd, void *download_buffer,
unsigned int download_bytes) unsigned int download_bytes, char *response)
{ {
struct part_info *part; struct part_info *part;
struct mtd_info *mtd = NULL; struct mtd_info *mtd = NULL;
int ret; int ret;
ret = fb_nand_lookup(cmd, &mtd, &part); ret = fb_nand_lookup(cmd, &mtd, &part, response);
if (ret) { if (ret) {
pr_err("invalid NAND device"); pr_err("invalid NAND device");
fastboot_fail("invalid NAND device"); fastboot_fail("invalid NAND device", response);
return; return;
} }
@ -180,9 +181,10 @@ void fb_nand_flash_write(const char *cmd, void *download_buffer,
sparse.start); sparse.start);
sparse.priv = &sparse_priv; sparse.priv = &sparse_priv;
ret = write_sparse_image(&sparse, cmd, download_buffer); ret = write_sparse_image(&sparse, cmd, download_buffer,
response);
if (!ret) if (!ret)
fastboot_okay(""); fastboot_okay(NULL, response);
} else { } else {
printf("Flashing raw image at offset 0x%llx\n", printf("Flashing raw image at offset 0x%llx\n",
part->offset); part->offset);
@ -195,23 +197,23 @@ void fb_nand_flash_write(const char *cmd, void *download_buffer,
} }
if (ret) { if (ret) {
fastboot_fail("error writing the image"); fastboot_fail("error writing the image", response);
return; return;
} }
fastboot_okay(""); fastboot_okay(NULL, response);
} }
void fb_nand_erase(const char *cmd) void fb_nand_erase(const char *cmd, char *response)
{ {
struct part_info *part; struct part_info *part;
struct mtd_info *mtd = NULL; struct mtd_info *mtd = NULL;
int ret; int ret;
ret = fb_nand_lookup(cmd, &mtd, &part); ret = fb_nand_lookup(cmd, &mtd, &part, response);
if (ret) { if (ret) {
pr_err("invalid NAND device"); pr_err("invalid NAND device");
fastboot_fail("invalid NAND device"); fastboot_fail("invalid NAND device", response);
return; return;
} }
@ -222,9 +224,9 @@ void fb_nand_erase(const char *cmd)
ret = _fb_nand_erase(mtd, part); ret = _fb_nand_erase(mtd, part);
if (ret) { if (ret) {
pr_err("failed erasing from device %s", mtd->name); pr_err("failed erasing from device %s", mtd->name);
fastboot_fail("failed erasing from device"); fastboot_fail("failed erasing from device", response);
return; return;
} }
fastboot_okay(""); fastboot_okay(NULL, response);
} }

@ -150,18 +150,16 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req);
static int strcmp_l1(const char *s1, const char *s2); static int strcmp_l1(const char *s1, const char *s2);
static char *fb_response_str; void fastboot_fail(const char *reason, char *response)
void fastboot_fail(const char *reason)
{ {
strncpy(fb_response_str, "FAIL\0", 5); strncpy(response, "FAIL\0", 5);
strncat(fb_response_str, reason, FASTBOOT_RESPONSE_LEN - 4 - 1); strncat(response, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
} }
void fastboot_okay(const char *reason) void fastboot_okay(const char *reason, char *response)
{ {
strncpy(fb_response_str, "OKAY\0", 5); strncpy(response, "OKAY\0", 5);
strncat(fb_response_str, reason, FASTBOOT_RESPONSE_LEN - 4 - 1); strncat(response, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
} }
static void fastboot_complete(struct usb_ep *ep, struct usb_request *req) static void fastboot_complete(struct usb_ep *ep, struct usb_request *req)
@ -597,18 +595,14 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req)
return; return;
} }
/* initialize the response buffer */ fastboot_fail("no flash device defined", response);
fb_response_str = response;
fastboot_fail("no flash device defined");
#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV #ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
fb_mmc_flash_write(cmd, (void *)CONFIG_FASTBOOT_BUF_ADDR, fb_mmc_flash_write(cmd, (void *)CONFIG_FASTBOOT_BUF_ADDR,
download_bytes); download_bytes, response);
#endif #endif
#ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV #ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV
fb_nand_flash_write(cmd, fb_nand_flash_write(cmd, (void *)CONFIG_FASTBOOT_BUF_ADDR,
(void *)CONFIG_FASTBOOT_BUF_ADDR, download_bytes, response);
download_bytes);
#endif #endif
fastboot_tx_write_str(response); fastboot_tx_write_str(response);
} }
@ -649,15 +643,12 @@ static void cb_erase(struct usb_ep *ep, struct usb_request *req)
return; return;
} }
/* initialize the response buffer */ fastboot_fail("no flash device defined", response);
fb_response_str = response;
fastboot_fail("no flash device defined");
#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV #ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
fb_mmc_erase(cmd); fb_mmc_erase(cmd, response);
#endif #endif
#ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV #ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV
fb_nand_erase(cmd); fb_nand_erase(cmd, response);
#endif #endif
fastboot_tx_write_str(response); fastboot_tx_write_str(response);
} }

@ -15,7 +15,7 @@
/* The 64 defined bytes plus \0 */ /* The 64 defined bytes plus \0 */
#define FASTBOOT_RESPONSE_LEN (64 + 1) #define FASTBOOT_RESPONSE_LEN (64 + 1)
void fastboot_fail(const char *reason); void fastboot_fail(const char *reason, char *response);
void fastboot_okay(const char *reason); void fastboot_okay(const char *reason, char *response);
#endif /* _FASTBOOT_H_ */ #endif /* _FASTBOOT_H_ */

@ -4,5 +4,5 @@
*/ */
void fb_mmc_flash_write(const char *cmd, void *download_buffer, void fb_mmc_flash_write(const char *cmd, void *download_buffer,
unsigned int download_bytes); unsigned int download_bytes, char *response);
void fb_mmc_erase(const char *cmd); void fb_mmc_erase(const char *cmd, char *response);

@ -5,5 +5,5 @@
*/ */
void fb_nand_flash_write(const char *cmd, void *download_buffer, void fb_nand_flash_write(const char *cmd, void *download_buffer,
unsigned int download_bytes); unsigned int download_bytes, char *response);
void fb_nand_erase(const char *cmd); void fb_nand_erase(const char *cmd, char *response);

@ -23,7 +23,7 @@ struct sparse_storage {
lbaint_t blk, lbaint_t blk,
lbaint_t blkcnt); lbaint_t blkcnt);
void (*mssg)(const char *str); void (*mssg)(const char *str, char *response);
}; };
static inline int is_sparse_image(void *buf) static inline int is_sparse_image(void *buf)
@ -38,4 +38,4 @@ static inline int is_sparse_image(void *buf)
} }
int write_sparse_image(struct sparse_storage *info, const char *part_name, int write_sparse_image(struct sparse_storage *info, const char *part_name,
void *data); void *data, char *response);

Loading…
Cancel
Save