]> git.sur5r.net Git - u-boot/commitdiff
mmc: Separate "mmc swrite" from fastboot
authorAlex Kiernan <alex.kiernan@gmail.com>
Tue, 29 May 2018 15:30:52 +0000 (15:30 +0000)
committerMarek Vasut <marex@denx.de>
Wed, 30 May 2018 09:59:21 +0000 (11:59 +0200)
Introduce CONFIG_IMAGE_SPARSE and CONFIG_CMD_MMC_SWRITE so the "mmc
swrite" command is separated from the fastboot code.

Move image-sparse from common to lib so it's clear it's library code.

Rename CONFIG_FASTBOOT_FLASH_FILLBUF_SIZE to CONFIG_IMAGE_SPARSE_FILLBUF_SIZE
and migrate it to Kconfig.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Acked-by: Jassi Brar <jaswinder.singh@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
cmd/Kconfig
cmd/mmc.c
common/Makefile
common/image-sparse.c [deleted file]
drivers/fastboot/Kconfig
lib/Kconfig
lib/Makefile
lib/image-sparse.c [new file with mode: 0644]
scripts/config_whitelist.txt

index 9848c067daa96d9c5fcdd07e3c1ae560d9c46544..30cf63f172b44c13aef5739156301ebbfc31157f 100644 (file)
@@ -833,6 +833,14 @@ config CMD_MMC_RPMB
          Enable the commands for reading, writing and programming the
          key for the Replay Protection Memory Block partition in eMMC.
 
+config CMD_MMC_SWRITE
+       bool "mmc swrite"
+       depends on CMD_MMC && MMC_WRITE
+       select IMAGE_SPARSE
+       help
+         Enable support for the "mmc swrite" command to write Android sparse
+         images to eMMC.
+
 config CMD_NAND
        bool "nand"
        default y if NAND_SUNXI
index a5719b81ebb196c31f76f81f376a494e06c591f5..c2ee2d9c0af1d9e77d4339621a2173411e92d07a 100644 (file)
--- a/cmd/mmc.c
+++ b/cmd/mmc.c
@@ -308,8 +308,7 @@ static int do_mmc_read(cmd_tbl_t *cmdtp, int flag,
        return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
 }
 
-#if CONFIG_IS_ENABLED(MMC_WRITE)
-#if defined(CONFIG_FASTBOOT_FLASH)
+#if CONFIG_IS_ENABLED(CMD_MMC_SWRITE)
 static lbaint_t mmc_sparse_write(struct sparse_storage *info, lbaint_t blk,
                                 lbaint_t blkcnt, const void *buffer)
 {
@@ -374,6 +373,7 @@ static int do_mmc_sparse_write(cmd_tbl_t *cmdtp, int flag,
 }
 #endif
 
+#if CONFIG_IS_ENABLED(MMC_WRITE)
 static int do_mmc_write(cmd_tbl_t *cmdtp, int flag,
                        int argc, char * const argv[])
 {
@@ -868,10 +868,10 @@ static cmd_tbl_t cmd_mmc[] = {
        U_BOOT_CMD_MKENT(read, 4, 1, do_mmc_read, "", ""),
 #if CONFIG_IS_ENABLED(MMC_WRITE)
        U_BOOT_CMD_MKENT(write, 4, 0, do_mmc_write, "", ""),
-#if defined(CONFIG_FASTBOOT_FLASH)
-       U_BOOT_CMD_MKENT(swrite, 3, 0, do_mmc_sparse_write, "", ""),
-#endif
        U_BOOT_CMD_MKENT(erase, 3, 0, do_mmc_erase, "", ""),
+#endif
+#if CONFIG_IS_ENABLED(CMD_MMC_SWRITE)
+       U_BOOT_CMD_MKENT(swrite, 3, 0, do_mmc_sparse_write, "", ""),
 #endif
        U_BOOT_CMD_MKENT(rescan, 1, 1, do_mmc_rescan, "", ""),
        U_BOOT_CMD_MKENT(part, 1, 1, do_mmc_part, "", ""),
@@ -927,7 +927,7 @@ U_BOOT_CMD(
        "info - display info of the current MMC device\n"
        "mmc read addr blk# cnt\n"
        "mmc write addr blk# cnt\n"
-#if defined(CONFIG_FASTBOOT_FLASH)
+#if CONFIG_IS_ENABLED(CMD_MMC_SWRITE)
        "mmc swrite addr blk#\n"
 #endif
        "mmc erase blk# cnt\n"
index 9ec40b9d272ce4b2f4a4d3a9a2f14477c5a037f2..b3da72ebb2c94ee3ca23a104cb8d79a1be51f5eb 100644 (file)
@@ -29,7 +29,6 @@ obj-$(CONFIG_CMD_BOOTI) += bootm.o bootm_os.o
 
 obj-$(CONFIG_CMD_BEDBUG) += bedbug.o
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += fdt_support.o
-obj-$(CONFIG_FASTBOOT_FLASH) += image-sparse.o
 obj-$(CONFIG_MII) += miiphyutil.o
 obj-$(CONFIG_CMD_MII) += miiphyutil.o
 obj-$(CONFIG_PHYLIB) += miiphyutil.o
diff --git a/common/image-sparse.c b/common/image-sparse.c
deleted file mode 100644 (file)
index 1ae7a4d..0000000
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- * Copyright (c) 2009, Google Inc.
- * All rights reserved.
- *
- * Copyright (c) 2009-2014, The Linux Foundation. All rights reserved.
- * Portions Copyright 2014 Broadcom Corporation.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in the
- *       documentation and/or other materials provided with the distribution.
- *     * Neither the name of The Linux Foundation nor
- *       the names of its contributors may be used to endorse or promote
- *       products derived from this software without specific prior written
- *       permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * NOTE:
- *   Although it is very similar, this license text is not identical
- *   to the "BSD-3-Clause", therefore, DO NOT MODIFY THIS LICENSE TEXT!
- */
-
-#include <config.h>
-#include <common.h>
-#include <image-sparse.h>
-#include <div64.h>
-#include <malloc.h>
-#include <part.h>
-#include <sparse_format.h>
-
-#include <linux/math64.h>
-
-#ifndef CONFIG_FASTBOOT_FLASH_FILLBUF_SIZE
-#define CONFIG_FASTBOOT_FLASH_FILLBUF_SIZE (1024 * 512)
-#endif
-
-static void default_log(const char *ignored, char *response) {}
-
-int write_sparse_image(struct sparse_storage *info,
-                      const char *part_name, void *data, char *response)
-{
-       lbaint_t blk;
-       lbaint_t blkcnt;
-       lbaint_t blks;
-       uint32_t bytes_written = 0;
-       unsigned int chunk;
-       unsigned int offset;
-       unsigned int chunk_data_sz;
-       uint32_t *fill_buf = NULL;
-       uint32_t fill_val;
-       sparse_header_t *sparse_header;
-       chunk_header_t *chunk_header;
-       uint32_t total_blocks = 0;
-       int fill_buf_num_blks;
-       int i;
-       int j;
-
-       fill_buf_num_blks = CONFIG_FASTBOOT_FLASH_FILLBUF_SIZE / info->blksz;
-
-       /* Read and skip over sparse image header */
-       sparse_header = (sparse_header_t *)data;
-
-       data += sparse_header->file_hdr_sz;
-       if (sparse_header->file_hdr_sz > sizeof(sparse_header_t)) {
-               /*
-                * Skip the remaining bytes in a header that is longer than
-                * we expected.
-                */
-               data += (sparse_header->file_hdr_sz - sizeof(sparse_header_t));
-       }
-
-       if (!info->mssg)
-               info->mssg = default_log;
-
-       debug("=== Sparse Image Header ===\n");
-       debug("magic: 0x%x\n", sparse_header->magic);
-       debug("major_version: 0x%x\n", sparse_header->major_version);
-       debug("minor_version: 0x%x\n", sparse_header->minor_version);
-       debug("file_hdr_sz: %d\n", sparse_header->file_hdr_sz);
-       debug("chunk_hdr_sz: %d\n", sparse_header->chunk_hdr_sz);
-       debug("blk_sz: %d\n", sparse_header->blk_sz);
-       debug("total_blks: %d\n", sparse_header->total_blks);
-       debug("total_chunks: %d\n", sparse_header->total_chunks);
-
-       /*
-        * Verify that the sparse block size is a multiple of our
-        * storage backend block size
-        */
-       div_u64_rem(sparse_header->blk_sz, info->blksz, &offset);
-       if (offset) {
-               printf("%s: Sparse image block size issue [%u]\n",
-                      __func__, sparse_header->blk_sz);
-               info->mssg("sparse image block size issue", response);
-               return -1;
-       }
-
-       puts("Flashing Sparse Image\n");
-
-       /* Start processing chunks */
-       blk = info->start;
-       for (chunk = 0; chunk < sparse_header->total_chunks; chunk++) {
-               /* Read and skip over chunk header */
-               chunk_header = (chunk_header_t *)data;
-               data += sizeof(chunk_header_t);
-
-               if (chunk_header->chunk_type != CHUNK_TYPE_RAW) {
-                       debug("=== Chunk Header ===\n");
-                       debug("chunk_type: 0x%x\n", chunk_header->chunk_type);
-                       debug("chunk_data_sz: 0x%x\n", chunk_header->chunk_sz);
-                       debug("total_size: 0x%x\n", chunk_header->total_sz);
-               }
-
-               if (sparse_header->chunk_hdr_sz > sizeof(chunk_header_t)) {
-                       /*
-                        * Skip the remaining bytes in a header that is longer
-                        * than we expected.
-                        */
-                       data += (sparse_header->chunk_hdr_sz -
-                                sizeof(chunk_header_t));
-               }
-
-               chunk_data_sz = sparse_header->blk_sz * chunk_header->chunk_sz;
-               blkcnt = chunk_data_sz / info->blksz;
-               switch (chunk_header->chunk_type) {
-               case CHUNK_TYPE_RAW:
-                       if (chunk_header->total_sz !=
-                           (sparse_header->chunk_hdr_sz + chunk_data_sz)) {
-                               info->mssg("Bogus chunk size for chunk type Raw",
-                                          response);
-                               return -1;
-                       }
-
-                       if (blk + blkcnt > info->start + info->size) {
-                               printf(
-                                   "%s: Request would exceed partition size!\n",
-                                   __func__);
-                               info->mssg("Request would exceed partition size!",
-                                          response);
-                               return -1;
-                       }
-
-                       blks = info->write(info, blk, blkcnt, data);
-                       /* blks might be > blkcnt (eg. NAND bad-blocks) */
-                       if (blks < blkcnt) {
-                               printf("%s: %s" LBAFU " [" LBAFU "]\n",
-                                      __func__, "Write failed, block #",
-                                      blk, blks);
-                               info->mssg("flash write failure", response);
-                               return -1;
-                       }
-                       blk += blks;
-                       bytes_written += blkcnt * info->blksz;
-                       total_blocks += chunk_header->chunk_sz;
-                       data += chunk_data_sz;
-                       break;
-
-               case CHUNK_TYPE_FILL:
-                       if (chunk_header->total_sz !=
-                           (sparse_header->chunk_hdr_sz + sizeof(uint32_t))) {
-                               info->mssg("Bogus chunk size for chunk type FILL", response);
-                               return -1;
-                       }
-
-                       fill_buf = (uint32_t *)
-                                  memalign(ARCH_DMA_MINALIGN,
-                                           ROUNDUP(
-                                               info->blksz * fill_buf_num_blks,
-                                               ARCH_DMA_MINALIGN));
-                       if (!fill_buf) {
-                               info->mssg("Malloc failed for: CHUNK_TYPE_FILL",
-                                          response);
-                               return -1;
-                       }
-
-                       fill_val = *(uint32_t *)data;
-                       data = (char *)data + sizeof(uint32_t);
-
-                       for (i = 0;
-                            i < (info->blksz * fill_buf_num_blks /
-                                 sizeof(fill_val));
-                            i++)
-                               fill_buf[i] = fill_val;
-
-                       if (blk + blkcnt > info->start + info->size) {
-                               printf(
-                                   "%s: Request would exceed partition size!\n",
-                                   __func__);
-                               info->mssg("Request would exceed partition size!",
-                                          response);
-                               return -1;
-                       }
-
-                       for (i = 0; i < blkcnt;) {
-                               j = blkcnt - i;
-                               if (j > fill_buf_num_blks)
-                                       j = fill_buf_num_blks;
-                               blks = info->write(info, blk, j, fill_buf);
-                               /* blks might be > j (eg. NAND bad-blocks) */
-                               if (blks < j) {
-                                       printf("%s: %s " LBAFU " [%d]\n",
-                                              __func__,
-                                              "Write failed, block #",
-                                              blk, j);
-                                       info->mssg("flash write failure",
-                                                  response);
-                                       free(fill_buf);
-                                       return -1;
-                               }
-                               blk += blks;
-                               i += j;
-                       }
-                       bytes_written += blkcnt * info->blksz;
-                       total_blocks += chunk_data_sz / sparse_header->blk_sz;
-                       free(fill_buf);
-                       break;
-
-               case CHUNK_TYPE_DONT_CARE:
-                       blk += info->reserve(info, blk, blkcnt);
-                       total_blocks += chunk_header->chunk_sz;
-                       break;
-
-               case CHUNK_TYPE_CRC32:
-                       if (chunk_header->total_sz !=
-                           sparse_header->chunk_hdr_sz) {
-                               info->mssg("Bogus chunk size for chunk type Dont Care",
-                                          response);
-                               return -1;
-                       }
-                       total_blocks += chunk_header->chunk_sz;
-                       data += chunk_data_sz;
-                       break;
-
-               default:
-                       printf("%s: Unknown chunk type: %x\n", __func__,
-                              chunk_header->chunk_type);
-                       info->mssg("Unknown chunk type", response);
-                       return -1;
-               }
-       }
-
-       debug("Wrote %d blocks, expected to write %d blocks\n",
-             total_blocks, sparse_header->total_blks);
-       printf("........ wrote %u bytes to '%s'\n", bytes_written, part_name);
-
-       if (total_blocks != sparse_header->total_blks) {
-               info->mssg("sparse image write failure", response);
-               return -1;
-       }
-
-       return 0;
-}
index 1d7caaff996378b5d554f49ffa01b2405b80e23b..0c9ced53dea5130d82c1882e08459d16f75bfd67 100644 (file)
@@ -57,6 +57,7 @@ config FASTBOOT_FLASH
        bool "Enable FASTBOOT FLASH command"
        default y if ARCH_SUNXI
        depends on MMC || (NAND && CMD_MTDPARTS)
+       select IMAGE_SPARSE
        help
          The fastboot protocol includes a "flash" command for writing
          the downloaded image to a non-volatile storage device. Define
index 1590f7afa40250cf3df678fccd57aecaa5e1e940..15c6a52d4a1b57273c1d84ce822191209004fa9f 100644 (file)
@@ -61,6 +61,17 @@ config SPL_STRTO
 config TPL_STRTO
        bool
 
+config IMAGE_SPARSE
+       bool
+
+config IMAGE_SPARSE_FILLBUF_SIZE
+       hex "Android sparse image CHUNK_TYPE_FILL buffer size"
+       default 0x80000
+       depends on IMAGE_SPARSE
+       help
+         Set the size of the fill buffer used when processing CHUNK_TYPE_FILL
+         chunks.
+
 config USE_PRIVATE_LIBGCC
        bool "Use private libgcc"
        depends on HAVE_PRIVATE_LIBGCC
index e6cb4afc232650ac31072fcd553fb5be7c732cc6..c0511cbff84450b28926ed543c050a610766ec74 100644 (file)
@@ -29,6 +29,7 @@ obj-$(CONFIG_FIT) += fdtdec_common.o
 obj-$(CONFIG_TEST_FDTDEC) += fdtdec_test.o
 obj-$(CONFIG_GZIP_COMPRESSED) += gzip.o
 obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += smbios.o
+obj-$(CONFIG_IMAGE_SPARSE) += image-sparse.o
 obj-y += initcall.o
 obj-$(CONFIG_LMB) += lmb.o
 obj-y += ldiv.o
diff --git a/lib/image-sparse.c b/lib/image-sparse.c
new file mode 100644 (file)
index 0000000..0360621
--- /dev/null
@@ -0,0 +1,261 @@
+/*
+ * Copyright (c) 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Copyright (c) 2009-2014, The Linux Foundation. All rights reserved.
+ * Portions Copyright 2014 Broadcom Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of The Linux Foundation nor
+ *       the names of its contributors may be used to endorse or promote
+ *       products derived from this software without specific prior written
+ *       permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * NOTE:
+ *   Although it is very similar, this license text is not identical
+ *   to the "BSD-3-Clause", therefore, DO NOT MODIFY THIS LICENSE TEXT!
+ */
+
+#include <config.h>
+#include <common.h>
+#include <image-sparse.h>
+#include <div64.h>
+#include <malloc.h>
+#include <part.h>
+#include <sparse_format.h>
+
+#include <linux/math64.h>
+
+static void default_log(const char *ignored, char *response) {}
+
+int write_sparse_image(struct sparse_storage *info,
+                      const char *part_name, void *data, char *response)
+{
+       lbaint_t blk;
+       lbaint_t blkcnt;
+       lbaint_t blks;
+       uint32_t bytes_written = 0;
+       unsigned int chunk;
+       unsigned int offset;
+       unsigned int chunk_data_sz;
+       uint32_t *fill_buf = NULL;
+       uint32_t fill_val;
+       sparse_header_t *sparse_header;
+       chunk_header_t *chunk_header;
+       uint32_t total_blocks = 0;
+       int fill_buf_num_blks;
+       int i;
+       int j;
+
+       fill_buf_num_blks = CONFIG_IMAGE_SPARSE_FILLBUF_SIZE / info->blksz;
+
+       /* Read and skip over sparse image header */
+       sparse_header = (sparse_header_t *)data;
+
+       data += sparse_header->file_hdr_sz;
+       if (sparse_header->file_hdr_sz > sizeof(sparse_header_t)) {
+               /*
+                * Skip the remaining bytes in a header that is longer than
+                * we expected.
+                */
+               data += (sparse_header->file_hdr_sz - sizeof(sparse_header_t));
+       }
+
+       if (!info->mssg)
+               info->mssg = default_log;
+
+       debug("=== Sparse Image Header ===\n");
+       debug("magic: 0x%x\n", sparse_header->magic);
+       debug("major_version: 0x%x\n", sparse_header->major_version);
+       debug("minor_version: 0x%x\n", sparse_header->minor_version);
+       debug("file_hdr_sz: %d\n", sparse_header->file_hdr_sz);
+       debug("chunk_hdr_sz: %d\n", sparse_header->chunk_hdr_sz);
+       debug("blk_sz: %d\n", sparse_header->blk_sz);
+       debug("total_blks: %d\n", sparse_header->total_blks);
+       debug("total_chunks: %d\n", sparse_header->total_chunks);
+
+       /*
+        * Verify that the sparse block size is a multiple of our
+        * storage backend block size
+        */
+       div_u64_rem(sparse_header->blk_sz, info->blksz, &offset);
+       if (offset) {
+               printf("%s: Sparse image block size issue [%u]\n",
+                      __func__, sparse_header->blk_sz);
+               info->mssg("sparse image block size issue", response);
+               return -1;
+       }
+
+       puts("Flashing Sparse Image\n");
+
+       /* Start processing chunks */
+       blk = info->start;
+       for (chunk = 0; chunk < sparse_header->total_chunks; chunk++) {
+               /* Read and skip over chunk header */
+               chunk_header = (chunk_header_t *)data;
+               data += sizeof(chunk_header_t);
+
+               if (chunk_header->chunk_type != CHUNK_TYPE_RAW) {
+                       debug("=== Chunk Header ===\n");
+                       debug("chunk_type: 0x%x\n", chunk_header->chunk_type);
+                       debug("chunk_data_sz: 0x%x\n", chunk_header->chunk_sz);
+                       debug("total_size: 0x%x\n", chunk_header->total_sz);
+               }
+
+               if (sparse_header->chunk_hdr_sz > sizeof(chunk_header_t)) {
+                       /*
+                        * Skip the remaining bytes in a header that is longer
+                        * than we expected.
+                        */
+                       data += (sparse_header->chunk_hdr_sz -
+                                sizeof(chunk_header_t));
+               }
+
+               chunk_data_sz = sparse_header->blk_sz * chunk_header->chunk_sz;
+               blkcnt = chunk_data_sz / info->blksz;
+               switch (chunk_header->chunk_type) {
+               case CHUNK_TYPE_RAW:
+                       if (chunk_header->total_sz !=
+                           (sparse_header->chunk_hdr_sz + chunk_data_sz)) {
+                               info->mssg("Bogus chunk size for chunk type Raw",
+                                          response);
+                               return -1;
+                       }
+
+                       if (blk + blkcnt > info->start + info->size) {
+                               printf(
+                                   "%s: Request would exceed partition size!\n",
+                                   __func__);
+                               info->mssg("Request would exceed partition size!",
+                                          response);
+                               return -1;
+                       }
+
+                       blks = info->write(info, blk, blkcnt, data);
+                       /* blks might be > blkcnt (eg. NAND bad-blocks) */
+                       if (blks < blkcnt) {
+                               printf("%s: %s" LBAFU " [" LBAFU "]\n",
+                                      __func__, "Write failed, block #",
+                                      blk, blks);
+                               info->mssg("flash write failure", response);
+                               return -1;
+                       }
+                       blk += blks;
+                       bytes_written += blkcnt * info->blksz;
+                       total_blocks += chunk_header->chunk_sz;
+                       data += chunk_data_sz;
+                       break;
+
+               case CHUNK_TYPE_FILL:
+                       if (chunk_header->total_sz !=
+                           (sparse_header->chunk_hdr_sz + sizeof(uint32_t))) {
+                               info->mssg("Bogus chunk size for chunk type FILL", response);
+                               return -1;
+                       }
+
+                       fill_buf = (uint32_t *)
+                                  memalign(ARCH_DMA_MINALIGN,
+                                           ROUNDUP(
+                                               info->blksz * fill_buf_num_blks,
+                                               ARCH_DMA_MINALIGN));
+                       if (!fill_buf) {
+                               info->mssg("Malloc failed for: CHUNK_TYPE_FILL",
+                                          response);
+                               return -1;
+                       }
+
+                       fill_val = *(uint32_t *)data;
+                       data = (char *)data + sizeof(uint32_t);
+
+                       for (i = 0;
+                            i < (info->blksz * fill_buf_num_blks /
+                                 sizeof(fill_val));
+                            i++)
+                               fill_buf[i] = fill_val;
+
+                       if (blk + blkcnt > info->start + info->size) {
+                               printf(
+                                   "%s: Request would exceed partition size!\n",
+                                   __func__);
+                               info->mssg("Request would exceed partition size!",
+                                          response);
+                               return -1;
+                       }
+
+                       for (i = 0; i < blkcnt;) {
+                               j = blkcnt - i;
+                               if (j > fill_buf_num_blks)
+                                       j = fill_buf_num_blks;
+                               blks = info->write(info, blk, j, fill_buf);
+                               /* blks might be > j (eg. NAND bad-blocks) */
+                               if (blks < j) {
+                                       printf("%s: %s " LBAFU " [%d]\n",
+                                              __func__,
+                                              "Write failed, block #",
+                                              blk, j);
+                                       info->mssg("flash write failure",
+                                                  response);
+                                       free(fill_buf);
+                                       return -1;
+                               }
+                               blk += blks;
+                               i += j;
+                       }
+                       bytes_written += blkcnt * info->blksz;
+                       total_blocks += chunk_data_sz / sparse_header->blk_sz;
+                       free(fill_buf);
+                       break;
+
+               case CHUNK_TYPE_DONT_CARE:
+                       blk += info->reserve(info, blk, blkcnt);
+                       total_blocks += chunk_header->chunk_sz;
+                       break;
+
+               case CHUNK_TYPE_CRC32:
+                       if (chunk_header->total_sz !=
+                           sparse_header->chunk_hdr_sz) {
+                               info->mssg("Bogus chunk size for chunk type Dont Care",
+                                          response);
+                               return -1;
+                       }
+                       total_blocks += chunk_header->chunk_sz;
+                       data += chunk_data_sz;
+                       break;
+
+               default:
+                       printf("%s: Unknown chunk type: %x\n", __func__,
+                              chunk_header->chunk_type);
+                       info->mssg("Unknown chunk type", response);
+                       return -1;
+               }
+       }
+
+       debug("Wrote %d blocks, expected to write %d blocks\n",
+             total_blocks, sparse_header->total_blks);
+       printf("........ wrote %u bytes to '%s'\n", bytes_written, part_name);
+
+       if (total_blocks != sparse_header->total_blks) {
+               info->mssg("sparse image write failure", response);
+               return -1;
+       }
+
+       return 0;
+}
index 117ed2e152698b7721448de6af3a4e6e0d084a46..5304f9577d3de7f750b4773346b138347ca5328d 100644 (file)
@@ -589,7 +589,6 @@ CONFIG_EXYNOS_RELOCATE_CODE_BASE
 CONFIG_EXYNOS_SPL
 CONFIG_EXYNOS_TMU
 CONFIG_FACTORYSET
-CONFIG_FASTBOOT_FLASH_FILLBUF_SIZE
 CONFIG_FAST_FLASH_BIT
 CONFIG_FB_ADDR
 CONFIG_FB_BACKLIGHT