summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/aboot.c243
-rw-r--r--common/board_f.c18
-rw-r--r--common/board_r.c19
-rw-r--r--common/bouncebuf.c2
-rw-r--r--common/cmd_mem.c7
-rw-r--r--common/cmd_mtdparts.c4
-rw-r--r--common/kgdb.c14
-rw-r--r--common/spl/spl.c2
-rw-r--r--common/stdio.c18
9 files changed, 290 insertions, 37 deletions
diff --git a/common/aboot.c b/common/aboot.c
new file mode 100644
index 0000000..d5c464b
--- /dev/null
+++ b/common/aboot.c
@@ -0,0 +1,243 @@
+/*
+ * 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 <aboot.h>
+#include <malloc.h>
+#include <part.h>
+#include <sparse_format.h>
+
+void write_sparse_image(block_dev_desc_t *dev_desc,
+ disk_partition_t *info, const char *part_name,
+ void *data, unsigned sz)
+{
+ lbaint_t blk;
+ lbaint_t blkcnt;
+ lbaint_t blks;
+ uint32_t bytes_written = 0;
+ unsigned int chunk;
+ 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 i;
+
+ /* 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));
+ }
+
+ 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 sparse_header->blk_sz is an exact multiple of info->blksz */
+ if (sparse_header->blk_sz !=
+ (sparse_header->blk_sz & ~(info->blksz - 1))) {
+ printf("%s: Sparse image block size issue [%u]\n",
+ __func__, sparse_header->blk_sz);
+ fastboot_fail("sparse image block size issue");
+ return;
+ }
+
+ 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))
+ {
+ fastboot_fail(
+ "Bogus chunk size for chunk type Raw");
+ return;
+ }
+
+ if (blk + blkcnt > info->start + info->size) {
+ printf(
+ "%s: Request would exceed partition size!\n",
+ __func__);
+ fastboot_fail(
+ "Request would exceed partition size!");
+ return;
+ }
+
+ blks = dev_desc->block_write(dev_desc->dev, blk, blkcnt,
+ data);
+ if (blks != blkcnt) {
+ printf("%s: Write failed " LBAFU "\n",
+ __func__, blks);
+ fastboot_fail("flash write failure");
+ return;
+ }
+ blk += blkcnt;
+ 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)))
+ {
+ fastboot_fail(
+ "Bogus chunk size for chunk type FILL");
+ return;
+ }
+
+ fill_buf = (uint32_t *)
+ memalign(ARCH_DMA_MINALIGN,
+ ROUNDUP(info->blksz,
+ ARCH_DMA_MINALIGN));
+ if (!fill_buf)
+ {
+ fastboot_fail(
+ "Malloc failed for: CHUNK_TYPE_FILL");
+ return;
+ }
+
+ fill_val = *(uint32_t *)data;
+ data = (char *) data + sizeof(uint32_t);
+
+ for (i = 0; i < (info->blksz / 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__);
+ fastboot_fail(
+ "Request would exceed partition size!");
+ return;
+ }
+
+ for (i = 0; i < blkcnt; i++) {
+ blks = dev_desc->block_write(dev_desc->dev,
+ blk, 1, fill_buf);
+ if (blks != 1) {
+ printf(
+ "%s: Write failed, block # " LBAFU "\n",
+ __func__, blkcnt);
+ fastboot_fail("flash write failure");
+ free(fill_buf);
+ return;
+ }
+ blk++;
+ }
+ bytes_written += blkcnt * info->blksz;
+ total_blocks += chunk_data_sz / sparse_header->blk_sz;
+
+ free(fill_buf);
+ break;
+
+ case CHUNK_TYPE_DONT_CARE:
+ total_blocks += chunk_header->chunk_sz;
+ break;
+
+ case CHUNK_TYPE_CRC32:
+ if (chunk_header->total_sz !=
+ sparse_header->chunk_hdr_sz)
+ {
+ fastboot_fail(
+ "Bogus chunk size for chunk type Dont Care");
+ return;
+ }
+ total_blocks += chunk_header->chunk_sz;
+ data += chunk_data_sz;
+ break;
+
+ default:
+ printf("%s: Unknown chunk type: %x\n", __func__,
+ chunk_header->chunk_type);
+ fastboot_fail("Unknown chunk type");
+ return;
+ }
+ }
+
+ 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)
+ fastboot_fail("sparse image write failure");
+
+ fastboot_okay("");
+ return;
+}
diff --git a/common/board_f.c b/common/board_f.c
index 4ece2b6..e6aa298 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -34,7 +34,7 @@
#ifdef CONFIG_MPC5xxx
#include <mpc5xxx.h>
#endif
-#if (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
+#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
#include <asm/mp.h>
#endif
@@ -341,21 +341,23 @@ static int setup_ram_buf(void)
static int setup_fdt(void)
{
-#ifdef CONFIG_OF_EMBED
+#ifdef CONFIG_OF_CONTROL
+# ifdef CONFIG_OF_EMBED
/* Get a pointer to the FDT */
gd->fdt_blob = __dtb_dt_begin;
-#elif defined CONFIG_OF_SEPARATE
+# elif defined CONFIG_OF_SEPARATE
/* FDT is at end of image */
gd->fdt_blob = (ulong *)&_end;
-#elif defined(CONFIG_OF_HOSTFILE)
+# elif defined(CONFIG_OF_HOSTFILE)
if (read_fdt_from_file()) {
puts("Failed to read control FDT\n");
return -1;
}
-#endif
+# endif
/* Allow the early environment to override the fdt address */
gd->fdt_blob = (void *)getenv_ulong("fdtcontroladdr", 16,
(uintptr_t)gd->fdt_blob);
+#endif
return 0;
}
@@ -392,7 +394,7 @@ static int setup_dest_addr(void)
gd->ram_top = board_get_usable_ram_top(gd->mon_len);
gd->relocaddr = gd->ram_top;
debug("Ram top: %08lX\n", (ulong)gd->ram_top);
-#if (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
+#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
/*
* We need to make sure the location we intend to put secondary core
* boot code is reserved and not used by any part of u-boot
@@ -831,6 +833,8 @@ static init_fnc_t init_sequence_f[] = {
#ifdef CONFIG_OF_CONTROL
fdtdec_check_fdt,
#endif
+ initf_malloc,
+ initf_dm,
#if defined(CONFIG_BOARD_EARLY_INIT_F)
board_early_init_f,
#endif
@@ -866,8 +870,6 @@ static init_fnc_t init_sequence_f[] = {
sdram_adjust_866,
init_timebase,
#endif
- initf_malloc,
- initf_dm,
init_baud_rate, /* initialze baudrate settings */
serial_init, /* serial communications setup */
console_init_f, /* stage 1 init of console */
diff --git a/common/board_r.c b/common/board_r.c
index 551429c..231c6d6 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -715,6 +715,15 @@ init_fnc_t init_sequence_r[] = {
/* TODO: could x86/PPC have this also perhaps? */
#ifdef CONFIG_ARM
initr_caches,
+#endif
+ initr_reloc_global_data,
+ initr_barrier,
+ initr_malloc,
+ bootstage_relocate,
+#ifdef CONFIG_DM
+ initr_dm,
+#endif
+#ifdef CONFIG_ARM
board_init, /* Setup chipselects */
#endif
/*
@@ -726,7 +735,7 @@ init_fnc_t init_sequence_r[] = {
#ifdef CONFIG_CLOCKS
set_cpu_clk_info, /* Setup clock information */
#endif
- initr_reloc_global_data,
+ stdio_init_tables,
initr_serial,
initr_announce,
INIT_FUNC_WATCHDOG_RESET
@@ -763,12 +772,6 @@ init_fnc_t init_sequence_r[] = {
#ifdef CONFIG_WINBOND_83C553
initr_w83c553f,
#endif
- initr_barrier,
- initr_malloc,
- bootstage_relocate,
-#ifdef CONFIG_DM
- initr_dm,
-#endif
#ifdef CONFIG_ARCH_EARLY_INIT_R
arch_early_init_r,
#endif
@@ -818,7 +821,7 @@ init_fnc_t init_sequence_r[] = {
*/
initr_pci,
#endif
- stdio_init,
+ stdio_add_devices,
initr_jumptable,
#ifdef CONFIG_API
initr_api,
diff --git a/common/bouncebuf.c b/common/bouncebuf.c
index 9eece6d..054d9e0 100644
--- a/common/bouncebuf.c
+++ b/common/bouncebuf.c
@@ -23,7 +23,7 @@ static int addr_aligned(struct bounce_buffer *state)
/* Check if length is aligned */
if (state->len != state->len_aligned) {
- debug("Unaligned buffer length %d\n", state->len);
+ debug("Unaligned buffer length %zu\n", state->len);
return 0;
}
diff --git a/common/cmd_mem.c b/common/cmd_mem.c
index 1febddb..bfca59e 100644
--- a/common/cmd_mem.c
+++ b/common/cmd_mem.c
@@ -215,7 +215,7 @@ static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
}
#ifdef CONFIG_MX_CYCLIC
-int do_mem_mdc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_mem_mdc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
int i;
ulong count;
@@ -242,7 +242,7 @@ int do_mem_mdc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return 0;
}
-int do_mem_mwc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_mem_mwc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
int i;
ulong count;
@@ -595,7 +595,8 @@ static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
}
#ifdef CONFIG_LOOPW
-int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_mem_loopw(cmd_tbl_t *cmdtp, int flag, int argc,
+ char * const argv[])
{
ulong addr, length, i, bytes;
int size;
diff --git a/common/cmd_mtdparts.c b/common/cmd_mtdparts.c
index 3cb0571..422c069 100644
--- a/common/cmd_mtdparts.c
+++ b/common/cmd_mtdparts.c
@@ -862,7 +862,7 @@ static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_
debug("dev type = %d (%s), dev num = %d, mtd-id = %s\n",
id->type, MTD_DEV_TYPE(id->type),
id->num, id->mtd_id);
- debug("parsing partitions %.*s\n", (pend ? pend - p : strlen(p)), p);
+ debug("parsing partitions %.*s\n", (int)(pend ? pend - p : strlen(p)), p);
/* parse partitions */
@@ -1007,7 +1007,7 @@ static struct mtdids* id_find_by_mtd_id(const char *mtd_id, unsigned int mtd_id_
list_for_each(entry, &mtdids) {
id = list_entry(entry, struct mtdids, link);
- debug("entry: '%s' (len = %d)\n",
+ debug("entry: '%s' (len = %zu)\n",
id->mtd_id, strlen(id->mtd_id));
if (mtd_id_len != strlen(id->mtd_id))
diff --git a/common/kgdb.c b/common/kgdb.c
index 8a621ad..d357463 100644
--- a/common/kgdb.c
+++ b/common/kgdb.c
@@ -103,7 +103,7 @@ static char remcomOutBuffer[BUFMAX];
static char remcomRegBuffer[BUFMAX];
static int initialized = 0;
-static int kgdb_active = 0, first_entry = 1;
+static int kgdb_active;
static struct pt_regs entry_regs;
static long error_jmp_buf[BUFMAX/2];
static int longjmp_on_fault = 0;
@@ -348,16 +348,7 @@ handle_exception (struct pt_regs *regs)
kgdb_enter(regs, &kd);
- if (first_entry) {
- /*
- * the first time we enter kgdb, we save the processor
- * state so that we can return to the monitor if the
- * remote end quits gdb (or at least, tells us to quit
- * with the 'k' packet)
- */
- entry_regs = *regs;
- first_entry = 0;
- }
+ entry_regs = *regs;
ptr = remcomOutBuffer;
@@ -459,7 +450,6 @@ handle_exception (struct pt_regs *regs)
case 'k': /* kill the program, actually return to monitor */
kd.extype = KGDBEXIT_KILL;
*regs = entry_regs;
- first_entry = 1;
goto doexit;
case 'C': /* CSS continue with signal SS */
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 774fdad..b16664f 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -86,7 +86,7 @@ void spl_parse_image_header(const struct image_header *header)
spl_image.os = image_get_os(header);
spl_image.name = image_get_name(header);
debug("spl: payload image: %.*s load addr: 0x%x size: %d\n",
- sizeof(spl_image.name), spl_image.name,
+ (int)sizeof(spl_image.name), spl_image.name,
spl_image.load_addr, spl_image.size);
} else {
/* Signature not found - assume u-boot.bin */
diff --git a/common/stdio.c b/common/stdio.c
index 692ca7f..c878103 100644
--- a/common/stdio.c
+++ b/common/stdio.c
@@ -215,7 +215,7 @@ int stdio_deregister(const char *devname)
}
#endif /* CONFIG_SYS_STDIO_DEREGISTER */
-int stdio_init (void)
+int stdio_init_tables(void)
{
#if defined(CONFIG_NEEDS_MANUAL_RELOC)
/* already relocated for current ARM implementation */
@@ -232,6 +232,11 @@ int stdio_init (void)
/* Initialize the list */
INIT_LIST_HEAD(&(devs.list));
+ return 0;
+}
+
+int stdio_add_devices(void)
+{
#ifdef CONFIG_SYS_I2C
i2c_init_all();
#else
@@ -265,5 +270,14 @@ int stdio_init (void)
#ifdef CONFIG_CBMEM_CONSOLE
cbmemc_init();
#endif
- return (0);
+
+ return 0;
+}
+
+int stdio_init(void)
+{
+ stdio_init_tables();
+ stdio_add_devices();
+
+ return 0;
}