From patchwork Tue Jun 7 18:19:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Rae X-Patchwork-Id: 631756 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3rPKd74n0vz9t3t for ; Wed, 8 Jun 2016 04:20:59 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=broadcom.com header.i=@broadcom.com header.b=RGF7hoN2; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4A3BDB3812; Tue, 7 Jun 2016 20:20:58 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id g3S4MXthhMmX; Tue, 7 Jun 2016 20:20:58 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B54CDB3802; Tue, 7 Jun 2016 20:20:57 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B3D37B3802 for ; Tue, 7 Jun 2016 20:20:52 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fElfZ_8zSkWX for ; Tue, 7 Jun 2016 20:20:52 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pa0-f49.google.com (mail-pa0-f49.google.com [209.85.220.49]) by theia.denx.de (Postfix) with ESMTPS id 0A2A9B3801 for ; Tue, 7 Jun 2016 20:20:47 +0200 (CEST) Received: by mail-pa0-f49.google.com with SMTP id ec8so42338331pac.0 for ; Tue, 07 Jun 2016 11:20:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=b0fet3R9bIkuvjJ4jGvtKziWNRneUmW/S5ryYpvxWks=; b=RGF7hoN2ZgBXfgSkXHR4F22cGIG5Iv/14lQubxR7H3DTBRi+jV9jk2ba8n3nZsO++J PpLLQEZXGXjbIqB0gESJUUqfP+dfku0zc+2UAsFRT33QIzXjgiH9d2lxhClWgREQiiRa rvzna1U5A5xQ/FgNpxaTIyESwS8UiC9pBqYW4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=b0fet3R9bIkuvjJ4jGvtKziWNRneUmW/S5ryYpvxWks=; b=RRV8aM1DMjOmL11UU0iF45gEnrzrMm5nzvfIUu4oQzHqyaJQ6/0PAtyx6Am0wZGYxk S0dBejKjzlBFFgrLRthSfL15G3F8e44CQdWn07Ocki7QK/o5kM8/IADl+MF0vNauET92 O04Q/mOzpJZ+Fwh8GmzWRAc+8/5fGh1Eku3uHYTV7ZgRhq4QkiD24/ZZVewROhPwPPVm yvHFnXeGlVR2a5AtAmH+Y7VdlFQN6hEcbWlNBRxbHgAy/p1RxA5r5uREvwYsZgYMnDR2 mlLJ1dj3A8iqRG7DsCaKoUEGCe1ei4X3BVbDD/uRlbNdjBW/iiA3AbZ7ZMaQZFhYiFTv uAqg== X-Gm-Message-State: ALyK8tKXMb8BSaP3MA0Ed4no62QYZvXbGOR4q5OtyKNHk9ele3HaBnuR7A/hHT8bn8X4Wo70 X-Received: by 10.66.4.129 with SMTP id k1mr764836pak.45.1465323645696; Tue, 07 Jun 2016 11:20:45 -0700 (PDT) Received: from VM-host64-64-A1.ric.broadcom.com ([216.31.219.19]) by smtp.gmail.com with ESMTPSA id u65sm36917222pfa.9.2016.06.07.11.20.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Jun 2016 11:20:45 -0700 (PDT) From: Steve Rae To: u-boot@lists.denx.de Date: Tue, 7 Jun 2016 11:19:37 -0700 Message-Id: <1465323579-18928-4-git-send-email-srae@broadcom.com> X-Mailer: git-send-email 1.8.5 In-Reply-To: <1465323579-18928-1-git-send-email-srae@broadcom.com> References: <1465323579-18928-1-git-send-email-srae@broadcom.com> Cc: Steve Rae , Tom Rini , Stephen Warren Subject: [U-Boot] [PATCH v2 3/5] fastboot: sparse: resync common/image-sparse.c (part 2) X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" - update fastboot_okay() and fastboot_fail() This file originally came from upstream code. While retaining the storage abstraction feature, this is the second set of the changes required to resync with the cmd_flash_mmc_sparse_img() in the file aboot.c from https://us.codeaurora.org/cgit/quic/la/kernel/lk/plain/app/aboot/aboot.c?h=LE.BR.1.2.1 Signed-off-by: Steve Rae --- Changes in v2: None common/fb_mmc.c | 40 ++++++++++++++++------------------------ common/fb_nand.c | 38 +++++++++++++++----------------------- common/image-sparse.c | 26 +++++++++++++------------- drivers/usb/gadget/f_fastboot.c | 31 +++++++++++++++++++------------ include/fastboot.h | 4 ++-- include/fb_mmc.h | 4 ++-- include/fb_nand.h | 4 ++-- include/image-sparse.h | 2 +- 8 files changed, 70 insertions(+), 79 deletions(-) diff --git a/common/fb_mmc.c b/common/fb_mmc.c index 3dad0ea..6bafbc6 100644 --- a/common/fb_mmc.c +++ b/common/fb_mmc.c @@ -18,8 +18,6 @@ #define CONFIG_FASTBOOT_GPT_NAME GPT_ENTRY_NAME #endif -static char *response_str; - struct fb_mmc_sparse { struct blk_desc *dev_desc; }; @@ -68,7 +66,7 @@ static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info, 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; } @@ -77,28 +75,25 @@ static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info, 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; } @@ -108,21 +103,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(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; } @@ -142,14 +137,14 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer, 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; @@ -159,24 +154,21 @@ void fb_mmc_erase(const char *cmd, char *response) 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; } @@ -195,11 +187,11 @@ void fb_mmc_erase(const char *cmd, char *response) 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(""); } diff --git a/common/fb_nand.c b/common/fb_nand.c index bdfad17..77ca55d 100644 --- a/common/fb_nand.c +++ b/common/fb_nand.c @@ -15,8 +15,6 @@ #include #include -static char *response_str; - struct fb_nand_sparse { struct mtd_info *mtd; struct part_info *part; @@ -32,7 +30,7 @@ __weak int board_fastboot_write_partition_setup(char *name) 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) { @@ -43,21 +41,21 @@ static int fb_nand_lookup(const char *partname, char *response, 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; } @@ -129,19 +127,16 @@ static lbaint_t fb_nand_sparse_write(struct sparse_storage *info, } 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; } @@ -166,7 +161,7 @@ void fb_nand_flash_write(const char *cmd, void *download_buffer, 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); @@ -179,26 +174,23 @@ void fb_nand_flash_write(const char *cmd, void *download_buffer, } 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; } @@ -209,9 +201,9 @@ void fb_nand_erase(const char *cmd, char *response) 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(""); } diff --git a/common/image-sparse.c b/common/image-sparse.c index 924cc63..b36703b 100644 --- a/common/image-sparse.c +++ b/common/image-sparse.c @@ -47,7 +47,7 @@ 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; @@ -93,7 +93,7 @@ void write_sparse_image( 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; } @@ -128,7 +128,7 @@ void write_sparse_image( 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; } @@ -137,7 +137,7 @@ void write_sparse_image( printf( "%s: Request would exceed partition size!\n", __func__); - fastboot_fail(response_str, + fastboot_fail( "Request would exceed partition size!"); return; } @@ -148,7 +148,7 @@ void write_sparse_image( printf("%s: %s" LBAFU " [" LBAFU "]\n", __func__, "Write failed, block #", blk, blks); - fastboot_fail(response_str, + fastboot_fail( "flash write failure"); return; } @@ -161,7 +161,7 @@ void write_sparse_image( 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; } @@ -171,7 +171,7 @@ void write_sparse_image( ROUNDUP(info->blksz, ARCH_DMA_MINALIGN)); if (!fill_buf) { - fastboot_fail(response_str, + fastboot_fail( "Malloc failed for: CHUNK_TYPE_FILL"); return; } @@ -186,7 +186,7 @@ void write_sparse_image( printf( "%s: Request would exceed partition size!\n", __func__); - fastboot_fail(response_str, + fastboot_fail( "Request would exceed partition size!"); return; } @@ -197,7 +197,7 @@ void write_sparse_image( 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; @@ -219,7 +219,7 @@ void write_sparse_image( 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; } @@ -230,7 +230,7 @@ void write_sparse_image( 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; } } @@ -240,9 +240,9 @@ void write_sparse_image( 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; } diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index ddf989c..2160b1c 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -151,16 +151,18 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req); 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) @@ -588,15 +590,18 @@ static void cb_flash(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); } @@ -637,13 +642,15 @@ static void cb_erase(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_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); } diff --git a/include/fastboot.h b/include/fastboot.h index db826d2..616631e 100644 --- a/include/fastboot.h +++ b/include/fastboot.h @@ -16,7 +16,7 @@ /* 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_ */ diff --git a/include/fb_mmc.h b/include/fb_mmc.h index 402ba9b..12b99cb 100644 --- a/include/fb_mmc.h +++ b/include/fb_mmc.h @@ -5,5 +5,5 @@ */ 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); diff --git a/include/fb_nand.h b/include/fb_nand.h index 88bdf36..aaf7cf7 100644 --- a/include/fb_nand.h +++ b/include/fb_nand.h @@ -6,5 +6,5 @@ */ 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); diff --git a/include/image-sparse.h b/include/image-sparse.h index 4e9e784..f6869d6 100644 --- a/include/image-sparse.h +++ b/include/image-sparse.h @@ -33,4 +33,4 @@ static inline int is_sparse_image(void *buf) } void write_sparse_image(struct sparse_storage *info, const char *part_name, - void *data, unsigned sz, char *response_str); + void *data, unsigned sz);