#define CONFIG_FASTBOOT_GPT_NAME GPT_ENTRY_NAME
#endif
-static char *response_str;
-
struct fb_mmc_sparse {
struct blk_desc *dev_desc;
};
if (blkcnt > info->size) {
error("too large for partition: '%s'\n", part_name);
- fastboot_fail(response_str, "too large for partition");
+ fastboot_fail("too large for partition");
return;
}
blks = blk_dwrite(dev_desc, info->start, blkcnt, buffer);
if (blks != blkcnt) {
error("failed writing to device %d\n", dev_desc->devnum);
- fastboot_fail(response_str, "failed writing to device");
+ fastboot_fail("failed writing to device");
return;
}
printf("........ wrote " LBAFU " bytes to '%s'\n", blkcnt * info->blksz,
part_name);
- fastboot_okay(response_str, "");
+ fastboot_okay("");
}
void fb_mmc_flash_write(const char *cmd, void *download_buffer,
- unsigned int download_bytes, char *response)
+ unsigned int download_bytes)
{
struct blk_desc *dev_desc;
disk_partition_t info;
- /* initialize the response buffer */
- response_str = response;
-
dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
error("invalid mmc device\n");
- fastboot_fail(response_str, "invalid mmc device");
+ fastboot_fail("invalid mmc device");
return;
}
if (is_valid_gpt_buf(dev_desc, download_buffer)) {
printf("%s: invalid GPT - refusing to write to flash\n",
__func__);
- fastboot_fail(response_str, "invalid GPT partition");
+ fastboot_fail("invalid GPT partition");
return;
}
if (write_mbr_and_gpt_partitions(dev_desc, download_buffer)) {
printf("%s: writing GPT partitions failed\n", __func__);
- fastboot_fail(response_str,
+ fastboot_fail(
"writing GPT partitions failed");
return;
}
printf("........ success\n");
- fastboot_okay(response_str, "");
+ fastboot_okay("");
return;
} else if (part_get_info_efi_by_name_or_alias(dev_desc, cmd, &info)) {
error("cannot find partition: '%s'\n", cmd);
- fastboot_fail(response_str, "cannot find partition");
+ fastboot_fail("cannot find partition");
return;
}
sparse.priv = &sparse_priv;
write_sparse_image(&sparse, cmd, download_buffer,
- download_bytes, response_str);
+ download_bytes);
} else {
write_raw_image(dev_desc, &info, cmd, download_buffer,
download_bytes);
}
}
-void fb_mmc_erase(const char *cmd, char *response)
+void fb_mmc_erase(const char *cmd)
{
int ret;
struct blk_desc *dev_desc;
if (mmc == NULL) {
error("invalid mmc device");
- fastboot_fail(response_str, "invalid mmc device");
+ fastboot_fail("invalid mmc device");
return;
}
- /* initialize the response buffer */
- response_str = response;
-
dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
error("invalid mmc device");
- fastboot_fail(response_str, "invalid mmc device");
+ fastboot_fail("invalid mmc device");
return;
}
ret = part_get_info_efi_by_name_or_alias(dev_desc, cmd, &info);
if (ret) {
error("cannot find partition: '%s'", cmd);
- fastboot_fail(response_str, "cannot find partition");
+ fastboot_fail("cannot find partition");
return;
}
blks = dev_desc->block_erase(dev_desc, blks_start, blks_size);
if (blks != blks_size) {
error("failed erasing from device %d", dev_desc->devnum);
- fastboot_fail(response_str, "failed erasing from device");
+ fastboot_fail("failed erasing from device");
return;
}
printf("........ erased " LBAFU " bytes from '%s'\n",
blks_size * info.blksz, cmd);
- fastboot_okay(response_str, "");
+ fastboot_okay("");
}
#include <jffs2/jffs2.h>
#include <nand.h>
-static char *response_str;
-
struct fb_nand_sparse {
struct mtd_info *mtd;
struct part_info *part;
return 0;
}
-static int fb_nand_lookup(const char *partname, char *response,
+static int fb_nand_lookup(const char *partname,
struct mtd_info **mtd,
struct part_info **part)
{
ret = mtdparts_init();
if (ret) {
error("Cannot initialize MTD partitions\n");
- fastboot_fail(response_str, "cannot init mtdparts");
+ fastboot_fail("cannot init mtdparts");
return ret;
}
ret = find_dev_and_part(partname, &dev, &pnum, part);
if (ret) {
error("cannot find partition: '%s'", partname);
- fastboot_fail(response_str, "cannot find partition");
+ fastboot_fail("cannot find partition");
return ret;
}
if (dev->id->type != MTD_DEV_TYPE_NAND) {
error("partition '%s' is not stored on a NAND device",
partname);
- fastboot_fail(response_str, "not a NAND device");
+ fastboot_fail("not a NAND device");
return -EINVAL;
}
}
void fb_nand_flash_write(const char *cmd, void *download_buffer,
- unsigned int download_bytes, char *response)
+ unsigned int download_bytes)
{
struct part_info *part;
struct mtd_info *mtd = NULL;
int ret;
- /* initialize the response buffer */
- response_str = response;
-
- ret = fb_nand_lookup(cmd, response, &mtd, &part);
+ ret = fb_nand_lookup(cmd, &mtd, &part);
if (ret) {
error("invalid NAND device");
- fastboot_fail(response_str, "invalid NAND device");
+ fastboot_fail("invalid NAND device");
return;
}
sparse.priv = &sparse_priv;
write_sparse_image(&sparse, cmd, download_buffer,
- download_bytes, response_str);
+ download_bytes);
} else {
printf("Flashing raw image at offset 0x%llx\n",
part->offset);
}
if (ret) {
- fastboot_fail(response_str, "error writing the image");
+ fastboot_fail("error writing the image");
return;
}
- fastboot_okay(response_str, "");
+ fastboot_okay("");
}
-void fb_nand_erase(const char *cmd, char *response)
+void fb_nand_erase(const char *cmd)
{
struct part_info *part;
struct mtd_info *mtd = NULL;
int ret;
- /* initialize the response buffer */
- response_str = response;
-
- ret = fb_nand_lookup(cmd, response, &mtd, &part);
+ ret = fb_nand_lookup(cmd, &mtd, &part);
if (ret) {
error("invalid NAND device");
- fastboot_fail(response_str, "invalid NAND device");
+ fastboot_fail("invalid NAND device");
return;
}
ret = _fb_nand_erase(mtd, part);
if (ret) {
error("failed erasing from device %s", mtd->name);
- fastboot_fail(response_str, "failed erasing from device");
+ fastboot_fail("failed erasing from device");
return;
}
- fastboot_okay(response_str, "");
+ fastboot_okay("");
}
void write_sparse_image(
struct sparse_storage *info, const char *part_name,
- void *data, unsigned sz, char *response_str)
+ void *data, unsigned sz)
{
lbaint_t blk;
lbaint_t blkcnt;
if (offset) {
printf("%s: Sparse image block size issue [%u]\n",
__func__, sparse_header->blk_sz);
- fastboot_fail(response_str, "sparse image block size issue");
+ fastboot_fail("sparse image block size issue");
return;
}
case CHUNK_TYPE_RAW:
if (chunk_header->total_sz !=
(sparse_header->chunk_hdr_sz + chunk_data_sz)) {
- fastboot_fail(response_str,
+ fastboot_fail(
"Bogus chunk size for chunk type Raw");
return;
}
printf(
"%s: Request would exceed partition size!\n",
__func__);
- fastboot_fail(response_str,
+ fastboot_fail(
"Request would exceed partition size!");
return;
}
printf("%s: %s" LBAFU " [" LBAFU "]\n",
__func__, "Write failed, block #",
blk, blks);
- fastboot_fail(response_str,
+ fastboot_fail(
"flash write failure");
return;
}
case CHUNK_TYPE_FILL:
if (chunk_header->total_sz !=
(sparse_header->chunk_hdr_sz + sizeof(uint32_t))) {
- fastboot_fail(response_str,
+ fastboot_fail(
"Bogus chunk size for chunk type FILL");
return;
}
ROUNDUP(info->blksz,
ARCH_DMA_MINALIGN));
if (!fill_buf) {
- fastboot_fail(response_str,
+ fastboot_fail(
"Malloc failed for: CHUNK_TYPE_FILL");
return;
}
printf(
"%s: Request would exceed partition size!\n",
__func__);
- fastboot_fail(response_str,
+ fastboot_fail(
"Request would exceed partition size!");
return;
}
if (blks < 1) {
printf("%s: %s, block # " LBAFU "\n",
__func__, "Write failed", blk);
- fastboot_fail(response_str,
+ fastboot_fail(
"flash write failure");
free(fill_buf);
return;
case CHUNK_TYPE_CRC32:
if (chunk_header->total_sz !=
sparse_header->chunk_hdr_sz) {
- fastboot_fail(response_str,
+ fastboot_fail(
"Bogus chunk size for chunk type Dont Care");
return;
}
default:
printf("%s: Unknown chunk type: %x\n", __func__,
chunk_header->chunk_type);
- fastboot_fail(response_str, "Unknown chunk type");
+ fastboot_fail("Unknown chunk type");
return;
}
}
printf("........ wrote %u bytes to '%s'\n", bytes_written, part_name);
if (total_blocks != sparse_header->total_blks)
- fastboot_fail(response_str, "sparse image write failure");
+ fastboot_fail("sparse image write failure");
else
- fastboot_okay(response_str, "");
+ fastboot_okay("");
return;
}
static int strcmp_l1(const char *s1, const char *s2);
-void fastboot_fail(char *response, const char *reason)
+static char *fb_response_str;
+
+void fastboot_fail(const char *reason)
{
- strncpy(response, "FAIL\0", 5);
- strncat(response, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
+ strncpy(fb_response_str, "FAIL\0", 5);
+ strncat(fb_response_str, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
}
-void fastboot_okay(char *response, const char *reason)
+void fastboot_okay(const char *reason)
{
- strncpy(response, "OKAY\0", 5);
- strncat(response, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
+ strncpy(fb_response_str, "OKAY\0", 5);
+ strncat(fb_response_str, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
}
static void fastboot_complete(struct usb_ep *ep, struct usb_request *req)
return;
}
- strcpy(response, "FAILno flash device defined");
+ /* initialize the response buffer */
+ fb_response_str = response;
+
+ fastboot_fail("no flash device defined");
#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
fb_mmc_flash_write(cmd, (void *)CONFIG_FASTBOOT_BUF_ADDR,
- download_bytes, response);
+ download_bytes);
#endif
#ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV
fb_nand_flash_write(cmd,
(void *)CONFIG_FASTBOOT_BUF_ADDR,
- download_bytes, response);
+ download_bytes);
#endif
fastboot_tx_write_str(response);
}
return;
}
- strcpy(response, "FAILno flash device defined");
+ /* initialize the response buffer */
+ fb_response_str = response;
+ fastboot_fail("no flash device defined");
#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
- fb_mmc_erase(cmd, response);
+ fb_mmc_erase(cmd);
#endif
#ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV
- fb_nand_erase(cmd, response);
+ fb_nand_erase(cmd);
#endif
fastboot_tx_write_str(response);
}
/* The 64 defined bytes plus \0 */
#define FASTBOOT_RESPONSE_LEN (64 + 1)
-void fastboot_fail(char *response, const char *reason);
-void fastboot_okay(char *response, const char *reason);
+void fastboot_fail(const char *reason);
+void fastboot_okay(const char *reason);
#endif /* _FASTBOOT_H_ */
*/
void fb_mmc_flash_write(const char *cmd, void *download_buffer,
- unsigned int download_bytes, char *response);
-void fb_mmc_erase(const char *cmd, char *response);
+ unsigned int download_bytes);
+void fb_mmc_erase(const char *cmd);
*/
void fb_nand_flash_write(const char *cmd, void *download_buffer,
- unsigned int download_bytes, char *response);
-void fb_nand_erase(const char *cmd, char *response);
+ unsigned int download_bytes);
+void fb_nand_erase(const char *cmd);
}
void write_sparse_image(struct sparse_storage *info, const char *part_name,
- void *data, unsigned sz, char *response_str);
+ void *data, unsigned sz);