U-Boot
Threads by month
- ----- 2025 -----
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2003 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2002 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2001 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2000 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
August 2009
- 165 participants
- 500 discussions

[U-Boot] [PATCH v2] arm: Kirkwood: add SYSRSTn Duration Counter Support
by Prafulla Wadaskar 19 Aug '09
by Prafulla Wadaskar 19 Aug '09
19 Aug '09
This feature can be used to trigger special command "sysrstcmd" using
reset key long press event and environment variable "sysrstdelay" is set
(useful for reset to factory or manufacturing mode execution)
Kirkwood SoC implements a hardware-based SYSRSTn duration counter.
When SYSRSTn is asserted low, a SYSRSTn duration counter is running.
The counter value is stored in the SYSRSTn Length Counter Register
The counter is based on the 25-MHz reference clock (40ns)
It is a 29-bit counter, yielding a maximum counting duration of
2^29/25 MHz (21.4 seconds). When the counter reach its maximum value,
it remains at this value until counter reset is triggered by setting
bit 31 of KW_REG_SYSRST_CNT
Implementation:
Upon long reset assertion (> ${sysrstdleay} in secs) sysrstcmd will be
executed if pre-defined in environment variables.
This feature will be disabled if "sysrstdelay" variable is unset.
for-ex.
setenv sysrst_cmd "echo starting factory reset;
nand erase 0xa0000 0x20000;
echo finish ed sysrst command;"
will erase particular nand sector if triggered by this event
Signed-off-by: Prafulla Wadaskar <prafulla(a)marvell.com>
---
Change log:
v2: updated as per review feedback for v1
build time error detection added for CONFIG_CMD_RUN
cpu/arm926ejs/kirkwood/cpu.c | 79 +++++++++++++++++++++++++++++++++++
include/asm-arm/arch-kirkwood/cpu.h | 2 +
2 files changed, 81 insertions(+), 0 deletions(-)
diff --git a/cpu/arm926ejs/kirkwood/cpu.c b/cpu/arm926ejs/kirkwood/cpu.c
index 795a739..1d3af4a 100644
--- a/cpu/arm926ejs/kirkwood/cpu.c
+++ b/cpu/arm926ejs/kirkwood/cpu.c
@@ -195,6 +195,82 @@ int kw_config_mpp(u32 mpp0_7, u32 mpp8_15, u32 mpp16_23, u32 mpp24_31,
return 0;
}
+/*
+ * SYSRSTn Duration Counter Support
+ *
+ * Kirkwood SoC implements a hardware-based SYSRSTn duration counter.
+ * When SYSRSTn is asserted low, a SYSRSTn duration counter is running.
+ * The SYSRSTn duration counter is useful for implementing a manufacturer
+ * or factory reset. Upon a long reset assertion that is greater than a
+ * pre-configured environment variable value for sysrstdelay,
+ * The counter value is stored in the SYSRSTn Length Counter Register
+ * The counter is based on the 25-MHz reference clock (40ns)
+ * It is a 29-bit counter, yielding a maximum counting duration of
+ * 2^29/25 MHz (21.4 seconds). When the counter reach its maximum value,
+ * it remains at this value until counter reset is triggered by setting
+ * bit 31 of KW_REG_SYSRST_CNT
+ */
+static void kw_sysrst_action(void)
+{
+ int ret;
+ char *s = getenv("sysrstcmd");
+
+ if (!s) {
+ printf("Error.. %s failed, check sysrstcmd\n",
+ __FUNCTION__);
+ return;
+ }
+
+ printf("Starting %s process...\n", __FUNCTION__);
+#if !defined(CONFIG_SYS_HUSH_PARSER)
+ ret = run_command (s, 0);
+#else
+ ret = parse_string_outer(s, FLAG_PARSE_SEMICOLON
+ | FLAG_EXIT_FROM_LOOP);
+#endif
+ if (ret < 0)
+ printf("Error.. %s failed\n", __FUNCTION__);
+ else
+ printf("%s process finished\n", __FUNCTION__);
+
+#else /* CONFIG_CMD_RUN */
+#error "Error.. CONFIG_CMD_RUN not defined (needed for sysrstcmd support)"
+#endif /* CONFIG_CMD_RUN */
+}
+
+static void kw_sysrst_check(void)
+{
+ u32 sysrst_cnt, sysrst_dly;
+ char *s;
+
+ /*
+ * no action if sysrstdelay environment variable is not defined
+ */
+ s = getenv("sysrstdelay");
+ if (s == NULL)
+ return;
+
+ /* read sysrstdelay value */
+ sysrst_dly = (u32) simple_strtoul(s, NULL, 10);
+
+ /* read SysRst Length counter register (bits 28:0) */
+ sysrst_cnt = (0x1fffffff & readl(KW_REG_SYSRST_CNT));
+ printf("H/w Rst hold time: %d.%d secs\n",
+ sysrst_cnt / SYSRST_CNT_1SEC_VAL,
+ sysrst_cnt % SYSRST_CNT_1SEC_VAL);
+
+ /* clear the counter for next valid read*/
+ writel(1 << 31, KW_REG_SYSRST_CNT);
+
+ /*
+ * sysrst_action:
+ * if H/w Reset key is pressed and hold for time
+ * more than sysrst_dly in seconds
+ */
+ if (sysrst_cnt >= SYSRST_CNT_1SEC_VAL * sysrst_dly)
+ kw_sysrst_action();
+}
+
#if defined(CONFIG_DISPLAY_CPUINFO)
int print_cpuinfo(void)
{
@@ -298,6 +374,9 @@ int arch_misc_init(void)
temp = get_cr();
set_cr(temp & ~CR_V);
+ /* checks and execute resset to factory event */
+ kw_sysrst_check();
+
return 0;
}
#endif /* CONFIG_ARCH_MISC_INIT */
diff --git a/include/asm-arm/arch-kirkwood/cpu.h b/include/asm-arm/arch-kirkwood/cpu.h
index d1440af..b3022a3 100644
--- a/include/asm-arm/arch-kirkwood/cpu.h
+++ b/include/asm-arm/arch-kirkwood/cpu.h
@@ -36,6 +36,8 @@
((_x ? KW_EGIGA0_BASE : KW_EGIGA1_BASE) + 0x44c)
#define KW_REG_DEVICE_ID (KW_MPP_BASE + 0x34)
+#define KW_REG_SYSRST_CNT (KW_MPP_BASE + 0x50)
+#define SYSRST_CNT_1SEC_VAL (25*1000000)
#define KW_REG_MPP_OUT_DRV_REG (KW_MPP_BASE + 0xE0)
enum memory_bank {
--
1.5.3.3
1
0

[U-Boot] [PATCH v2] tools: mkimage: split code into core, default and FIT image specific
by Prafulla Wadaskar 19 Aug '09
by Prafulla Wadaskar 19 Aug '09
19 Aug '09
This is first step towards cleaning mkimage code for kwbimage
support in clean way. Current mkimage code is very specific to
uimg generation whereas the same framework can be used to
generate other image types like Kirkwood boot image (kwbimage-TBD).
For this, the architecture of mkimage code need to modified.
Here is the brief plan for the same:-
a) Split mkimage code into core and image specific support
b) Implement callback function for image specific functions
c) Move image type specific code to respective c files
Currently there are two types of file generation/list
supported (i.e uimg, FIT), the code is abstracted from
mkimage.c/h and put in default_image.c and fit_image.c
all code in these file is static except init function call
d) mkimage_register API is added to add new image type support
All above is addressed in this patch
e) Add kwbimage type support to this new framework (TBD)
Signed-off-by: Prafulla Wadaskar <prafulla(a)marvell.com>
---
Change log:
v2: patch generated on mkimage branch
tools/Makefile | 9 +-
tools/default_image.c | 149 ++++++++++++++
tools/fit_image.c | 212 +++++++++++++++++++
tools/mkimage.c | 539 +++++++++++++++++++++++--------------------------
tools/mkimage.h | 101 +++++++++-
5 files changed, 720 insertions(+), 290 deletions(-)
create mode 100644 tools/default_image.c
create mode 100644 tools/fit_image.c
diff --git a/tools/Makefile b/tools/Makefile
index 6f36f23..10547e1 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -183,7 +183,8 @@ $(obj)inca-swap-bytes$(SFX): $(obj)inca-swap-bytes.o
$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
$(STRIP) $@
-$(obj)mkimage$(SFX): $(obj)crc32.o $(obj)mkimage.o $(obj)image.o $(obj)md5.o $(obj)mkimage.o \
+$(obj)mkimage$(SFX): $(obj)crc32.o $(obj)default_image.o $(obj)fit_image.o $(obj)image.o \
+ $(obj)md5.o $(obj)mkimage.o \
$(obj)os_support.o $(obj)sha1.o $(LIBFDT_OBJS)
$(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^
$(STRIP) $@
@@ -200,6 +201,12 @@ $(obj)ubsha1$(SFX): $(obj)os_support.o $(obj)sha1.o $(obj)ubsha1.o
$(CC) $(CFLAGS) -o $@ $^
# Some files complain if compiled with -pedantic, use FIT_CFLAGS
+$(obj)default_image.o: $(SRCTREE)/tools/default_image.c
+ $(CC) -g $(FIT_CFLAGS) -c -o $@ $<
+
+$(obj)fit_image.o: $(SRCTREE)/tools/fit_image.c
+ $(CC) -g $(FIT_CFLAGS) -c -o $@ $<
+
$(obj)image.o: $(SRCTREE)/common/image.c
$(CC) -g $(FIT_CFLAGS) -c -o $@ $<
diff --git a/tools/default_image.c b/tools/default_image.c
new file mode 100644
index 0000000..f5bad47
--- /dev/null
+++ b/tools/default_image.c
@@ -0,0 +1,149 @@
+/*
+ * (C) Copyright 2008 Semihalf
+ *
+ * (C) Copyright 2000-2004
+ * DENX Software Engineering
+ * Wolfgang Denk, wd(a)denx.de
+ *
+ * Updated-by: Prafulla Wadaskar <prafulla(a)marvell.com>
+ * default_image specific code abstracted from mkimage.c
+ * some functions added to address abstraction
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include "mkimage.h"
+#include <image.h>
+#include <u-boot/crc.h>
+
+static image_header_t header;
+
+static int image_check_image_types (uint8_t type)
+{
+ if ((type > IH_TYPE_INVALID) && (type < IH_TYPE_FLATDT))
+ return EXIT_SUCCESS;
+ else
+ return EXIT_FAILURE;
+}
+
+static int image_check_params (struct mkimage_params *params)
+{
+ return ((params->dflag && (params->fflag || params->lflag)) ||
+ (params->fflag && (params->dflag || params->lflag)) ||
+ (params->lflag && (params->dflag || params->fflag)));
+}
+
+static int image_verify_header (unsigned char *ptr, int image_size,
+ struct mkimage_params *params)
+{
+ uint32_t len;
+ const unsigned char *data;
+ uint32_t checksum;
+ image_header_t header;
+ image_header_t *hdr = &header;
+
+ /*
+ * create copy of header so that we can blank out the
+ * checksum field for checking - this can't be done
+ * on the PROT_READ mapped data.
+ */
+ memcpy (hdr, ptr, sizeof(image_header_t));
+
+ if (be32_to_cpu(hdr->ih_magic) != IH_MAGIC) {
+ fprintf (stderr,
+ "%s: Bad Magic Number: \"%s\" is no valid image\n",
+ params->cmdname, params->imagefile);
+ return -FDT_ERR_BADMAGIC;
+ }
+
+ data = (const unsigned char *)hdr;
+ len = sizeof(image_header_t);
+
+ checksum = be32_to_cpu(hdr->ih_hcrc);
+ hdr->ih_hcrc = cpu_to_be32(0); /* clear for re-calculation */
+
+ if (crc32 (0, data, len) != checksum) {
+ fprintf (stderr,
+ "%s: ERROR: \"%s\" has bad header checksum!\n",
+ params->cmdname, params->imagefile);
+ return -FDT_ERR_BADSTATE;
+ }
+
+ data = (const unsigned char *)ptr + sizeof(image_header_t);
+ len = image_size - sizeof(image_header_t) ;
+
+ checksum = be32_to_cpu(hdr->ih_dcrc);
+ if (crc32 (0, data, len) != checksum) {
+ fprintf (stderr,
+ "%s: ERROR: \"%s\" has corrupted data!\n",
+ params->cmdname, params->imagefile);
+ return -FDT_ERR_BADSTRUCTURE;
+ }
+ return 0;
+}
+
+static void image_set_header (void *ptr, struct stat *sbuf, int ifd,
+ struct mkimage_params *params)
+{
+ uint32_t checksum;
+
+ image_header_t * hdr = (image_header_t *)ptr;
+
+ checksum = crc32 (0,
+ (const unsigned char *)(ptr +
+ sizeof(image_header_t)),
+ sbuf->st_size - sizeof(image_header_t));
+
+ /* Build new header */
+ image_set_magic (hdr, IH_MAGIC);
+ image_set_time (hdr, sbuf->st_mtime);
+ image_set_size (hdr, sbuf->st_size - sizeof(image_header_t));
+ image_set_load (hdr, params->addr);
+ image_set_ep (hdr, params->ep);
+ image_set_dcrc (hdr, checksum);
+ image_set_os (hdr, params->os);
+ image_set_arch (hdr, params->arch);
+ image_set_type (hdr, params->type);
+ image_set_comp (hdr, params->comp);
+
+ image_set_name (hdr, params->imagename);
+
+ checksum = crc32 (0, (const unsigned char *)hdr,
+ sizeof(image_header_t));
+
+ image_set_hcrc (hdr, checksum);
+}
+
+/*
+ * Default image type parameters definition
+ */
+static struct image_type_params defimage_params = {
+ .name = "Default Image support",
+ .header_size = sizeof(image_header_t),
+ .hdr = (void*)&header,
+ .check_image_type = image_check_image_types,
+ .verify_header = image_verify_header,
+ .print_header = image_print_contents,
+ .set_header = image_set_header,
+ .check_params = image_check_params,
+};
+
+void init_default_image_type (void)
+{
+ mkimage_register (&defimage_params);
+}
diff --git a/tools/fit_image.c b/tools/fit_image.c
new file mode 100644
index 0000000..6f5c8c6
--- /dev/null
+++ b/tools/fit_image.c
@@ -0,0 +1,212 @@
+/*
+ * (C) Copyright 2008 Semihalf
+ *
+ * (C) Copyright 2000-2004
+ * DENX Software Engineering
+ * Wolfgang Denk, wd(a)denx.de
+ *
+ * Updated-by: Prafulla Wadaskar <prafulla(a)marvell.com>
+ * fir image specific code abstracted from mkimage.c
+ * some functions added to address abstraction
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include "mkimage.h"
+#include <image.h>
+#include <u-boot/crc.h>
+
+static image_header_t header;
+
+static int fit_verify_header (unsigned char *ptr, int image_size,
+ struct mkimage_params *params)
+{
+ return fdt_check_header ((void *)ptr);
+}
+
+static int fit_check_image_types (uint8_t type)
+{
+ if (type == IH_TYPE_FLATDT)
+ return EXIT_SUCCESS;
+ else
+ return EXIT_FAILURE;
+}
+
+/**
+ * fit_handle_file - main FIT file processing function
+ *
+ * fit_handle_file() runs dtc to convert .its to .itb, includes
+ * binary data, updates timestamp property and calculates hashes.
+ *
+ * datafile - .its file
+ * imagefile - .itb file
+ *
+ * returns:
+ * only on success, otherwise calls exit (EXIT_FAILURE);
+ */
+static int fit_handle_file (struct mkimage_params *params)
+{
+ char tmpfile[MKIMAGE_MAX_TMPFILE_LEN];
+ char cmd[MKIMAGE_MAX_DTC_CMDLINE_LEN];
+ int tfd;
+ struct stat sbuf;
+ unsigned char *ptr;
+
+ /* Flattened Image Tree (FIT) format handling */
+ debug ("FIT format handling\n");
+
+ /* call dtc to include binary properties into the tmp file */
+ if (strlen (params->imagefile) +
+ strlen (MKIMAGE_TMPFILE_SUFFIX) + 1 > sizeof (tmpfile)) {
+ fprintf (stderr, "%s: Image file name (%s) too long, "
+ "can't create tmpfile",
+ params->imagefile, params->cmdname);
+ return (EXIT_FAILURE);
+ }
+ sprintf (tmpfile, "%s%s", params->imagefile, MKIMAGE_TMPFILE_SUFFIX);
+
+ /* dtc -I dts -O -p 200 datafile > tmpfile */
+ sprintf (cmd, "%s %s %s > %s",
+ MKIMAGE_DTC, params->dtc, params->datafile, tmpfile);
+ debug ("Trying to execute \"%s\"\n", cmd);
+ if (system (cmd) == -1) {
+ fprintf (stderr, "%s: system(%s) failed: %s\n",
+ params->cmdname, cmd, strerror(errno));
+ unlink (tmpfile);
+ return (EXIT_FAILURE);
+ }
+
+ /* load FIT blob into memory */
+ tfd = open (tmpfile, O_RDWR|O_BINARY);
+
+ if (tfd < 0) {
+ fprintf (stderr, "%s: Can't open %s: %s\n",
+ params->cmdname, tmpfile, strerror(errno));
+ unlink (tmpfile);
+ return (EXIT_FAILURE);
+ }
+
+ if (fstat (tfd, &sbuf) < 0) {
+ fprintf (stderr, "%s: Can't stat %s: %s\n",
+ params->cmdname, tmpfile, strerror(errno));
+ unlink (tmpfile);
+ return (EXIT_FAILURE);
+ }
+
+ ptr = mmap (0, sbuf.st_size, PROT_READ|PROT_WRITE, MAP_SHARED,
+ tfd, 0);
+ if (ptr == MAP_FAILED) {
+ fprintf (stderr, "%s: Can't read %s: %s\n",
+ params->cmdname, tmpfile, strerror(errno));
+ unlink (tmpfile);
+ return (EXIT_FAILURE);
+ }
+
+ /* check if ptr has a valid blob */
+ if (fdt_check_header (ptr)) {
+ fprintf (stderr, "%s: Invalid FIT blob\n", params->cmdname);
+ unlink (tmpfile);
+ return (EXIT_FAILURE);
+ }
+
+ /* set hashes for images in the blob */
+ if (fit_set_hashes (ptr)) {
+ fprintf (stderr, "%s Can't add hashes to FIT blob",
+ params->cmdname);
+ unlink (tmpfile);
+ return (EXIT_FAILURE);
+ }
+
+ /* add a timestamp at offset 0 i.e., root */
+ if (fit_set_timestamp (ptr, 0, sbuf.st_mtime)) {
+ fprintf (stderr, "%s: Can't add image timestamp\n",
+ params->cmdname);
+ unlink (tmpfile);
+ return (EXIT_FAILURE);
+ }
+ debug ("Added timestamp successfully\n");
+
+ munmap ((void *)ptr, sbuf.st_size);
+ close (tfd);
+
+ if (rename (tmpfile, params->imagefile) == -1) {
+ fprintf (stderr, "%s: Can't rename %s to %s: %s\n",
+ params->cmdname, tmpfile, params->imagefile,
+ strerror (errno));
+ unlink (tmpfile);
+ unlink (params->imagefile);
+ return (EXIT_FAILURE);
+ }
+ return (EXIT_SUCCESS);
+}
+
+static void fit_set_header (void *ptr, struct stat *sbuf, int ifd,
+ struct mkimage_params *params)
+{
+ uint32_t checksum;
+
+ image_header_t * hdr = (image_header_t *)ptr;
+
+ checksum = crc32 (0,
+ (const unsigned char *)(ptr +
+ sizeof(image_header_t)),
+ sbuf->st_size - sizeof(image_header_t));
+
+ /* Build new header */
+ image_set_magic (hdr, IH_MAGIC);
+ image_set_time (hdr, sbuf->st_mtime);
+ image_set_size (hdr, sbuf->st_size - sizeof(image_header_t));
+ image_set_load (hdr, params->addr);
+ image_set_ep (hdr, params->ep);
+ image_set_dcrc (hdr, checksum);
+ image_set_os (hdr, params->os);
+ image_set_arch (hdr, params->arch);
+ image_set_type (hdr, params->type);
+ image_set_comp (hdr, params->comp);
+
+ image_set_name (hdr, params->imagename);
+
+ checksum = crc32 (0, (const unsigned char *)hdr,
+ sizeof(image_header_t));
+
+ image_set_hcrc (hdr, checksum);
+}
+
+static int fit_check_params (struct mkimage_params *params)
+{
+ return ((params->dflag && (params->fflag || params->lflag)) ||
+ (params->fflag && (params->dflag || params->lflag)) ||
+ (params->lflag && (params->dflag || params->fflag)));
+}
+
+static struct image_type_params fitimage_params = {
+ .name = "FIT Image support",
+ .header_size = sizeof(image_header_t),
+ .hdr = (void*)&header,
+ .verify_header = fit_verify_header,
+ .print_header = fit_print_contents,
+ .check_image_type = fit_check_image_types,
+ .fflag_handle = fit_handle_file,
+ .set_header = fit_set_header,
+ .check_params = fit_check_params,
+};
+
+void init_fit_image_type (void)
+{
+ mkimage_register (&fitimage_params);
+}
diff --git a/tools/mkimage.c b/tools/mkimage.c
index 19ae733..66ebb70 100644
--- a/tools/mkimage.c
+++ b/tools/mkimage.c
@@ -24,126 +24,223 @@
#include "mkimage.h"
#include <image.h>
-#include <u-boot/crc.h>
-
-static void copy_file (int, const char *, int);
-static void usage (void);
-static int image_verify_header (char *, int);
-static void fit_handle_file (void);
-
-char *datafile;
-char *imagefile;
-char *cmdname;
-
-int dflag = 0;
-int eflag = 0;
-int fflag = 0;
-int lflag = 0;
-int vflag = 0;
-int xflag = 0;
-int opt_os = IH_OS_LINUX;
-int opt_arch = IH_ARCH_PPC;
-int opt_type = IH_TYPE_KERNEL;
-int opt_comp = IH_COMP_GZIP;
-char *opt_dtc = MKIMAGE_DEFAULT_DTC_OPTIONS;
-
-image_header_t header;
-image_header_t *hdr = &header;
+
+static void copy_file(int, const char *, int);
+static void usage(void);
+
+/* image_type_params link list to maintain registered image type supports */
+struct image_type_params *mkimage_tparams = NULL;
+
+/* parameters initialized by core will be used by the image type code */
+struct mkimage_params params = {
+ .os = IH_OS_LINUX,
+ .arch = IH_ARCH_PPC,
+ .type = IH_TYPE_KERNEL,
+ .comp = IH_COMP_GZIP,
+ .dtc = MKIMAGE_DEFAULT_DTC_OPTIONS,
+};
+
+/*
+ * mkimage_register -
+ *
+ * It is used to register respective image generation/list support to the
+ * mkimage core
+ *
+ * the input struct image_type_params is checked and appended to the link
+ * list, if the input structure is already registered, error
+ */
+void mkimage_register (struct image_type_params *tparams)
+{
+ struct image_type_params **tp;
+
+ if (!tparams) {
+ fprintf (stderr, "%s: %s: Null input\n",
+ params.cmdname, __FUNCTION__);
+ exit (EXIT_FAILURE);
+ }
+
+ /* scan the linked list, check for registry and point the last one */
+ for (tp = &mkimage_tparams; *tp != NULL; tp = &(*tp)->next) {
+ if (!strcmp((*tp)->name, tparams->name)) {
+ fprintf (stderr, "%s: %s already registered\n",
+ params.cmdname, tparams->name);
+ return;
+ }
+ }
+
+ /* add input struct entry at the end of link list */
+ *tp = tparams;
+ /* mark input entry as last entry in the link list */
+ tparams->next = NULL;
+
+ debug ("Registered %s\n", tparams->name);
+}
+
+/*
+ * mkimage_get_type -
+ *
+ * It scans all registers image type supports
+ * checks the input type_id for each supported image type
+ *
+ * if successful,
+ * returns respective image_type_params pointer if success
+ * if input type_id is not supported by any of image_type_support
+ * returns NULL
+ */
+struct image_type_params *mkimage_get_type(int type)
+{
+ struct image_type_params *curr;
+
+ for (curr = mkimage_tparams; curr != NULL; curr = curr->next) {
+ if (curr->check_image_type) {
+ if (!curr->check_image_type (type))
+ return curr;
+ }
+ }
+ return NULL;
+}
+
+/*
+ * mkimage_verify_print_header -
+ *
+ * It scans mkimage_tparams link list,
+ * verifies image_header for each supported image type
+ * if verification is successful, prints respective header
+ *
+ * returns negative if input image format does not match with any of
+ * supported image types
+ */
+int mkimage_verify_print_header (void *ptr, struct stat *sbuf)
+{
+ int retval = -1;
+ struct image_type_params *curr;
+
+ for (curr = mkimage_tparams; curr != NULL; curr = curr->next ) {
+ if (curr->verify_header) {
+ retval = curr->verify_header (
+ (unsigned char *)ptr, sbuf->st_size,
+ ¶ms);
+
+ if (retval == 0) {
+ /*
+ * Print the image information
+ * if verify is successful
+ */
+ if (curr->print_header)
+ curr->print_header (ptr);
+ else {
+ fprintf (stderr,
+ "%s: print_header undefined for %s\n",
+ params.cmdname, curr->name);
+ }
+ break;
+ }
+ }
+ }
+ return retval;
+}
int
main (int argc, char **argv)
{
int ifd = -1;
- uint32_t checksum;
- uint32_t addr;
- uint32_t ep;
struct stat sbuf;
unsigned char *ptr;
- char *name = "";
int retval = 0;
+ struct image_type_params *tparams = NULL;
- cmdname = *argv;
+ /* Init FIT image generation/list support */
+ init_fit_image_type ();
+ /* Init Default image generation/list support */
+ init_default_image_type ();
- addr = ep = 0;
+ params.cmdname = *argv;
+ params.addr = params.ep = 0;
while (--argc > 0 && **++argv == '-') {
while (*++*argv) {
switch (**argv) {
case 'l':
- lflag = 1;
+ params.lflag = 1;
break;
case 'A':
if ((--argc <= 0) ||
- (opt_arch = genimg_get_arch_id (*++argv)) < 0)
+ (params.arch =
+ genimg_get_arch_id (*++argv)) < 0)
usage ();
goto NXTARG;
case 'C':
if ((--argc <= 0) ||
- (opt_comp = genimg_get_comp_id (*++argv)) < 0)
+ (params.comp =
+ genimg_get_comp_id (*++argv)) < 0)
usage ();
goto NXTARG;
case 'D':
if (--argc <= 0)
usage ();
- opt_dtc = *++argv;
+ params.dtc = *++argv;
goto NXTARG;
case 'O':
if ((--argc <= 0) ||
- (opt_os = genimg_get_os_id (*++argv)) < 0)
+ (params.os =
+ genimg_get_os_id (*++argv)) < 0)
usage ();
goto NXTARG;
case 'T':
if ((--argc <= 0) ||
- (opt_type = genimg_get_type_id (*++argv)) < 0)
+ (params.type =
+ genimg_get_type_id (*++argv)) < 0)
usage ();
goto NXTARG;
case 'a':
if (--argc <= 0)
usage ();
- addr = strtoul (*++argv, (char **)&ptr, 16);
+ params.addr = strtoul (*++argv,
+ (char **)&ptr, 16);
if (*ptr) {
fprintf (stderr,
"%s: invalid load address %s\n",
- cmdname, *argv);
+ params.cmdname, *argv);
exit (EXIT_FAILURE);
}
goto NXTARG;
case 'd':
if (--argc <= 0)
usage ();
- datafile = *++argv;
- dflag = 1;
+ params.datafile = *++argv;
+ params.dflag = 1;
goto NXTARG;
case 'e':
if (--argc <= 0)
usage ();
- ep = strtoul (*++argv, (char **)&ptr, 16);
+ params.ep = strtoul (*++argv,
+ (char **)&ptr, 16);
if (*ptr) {
fprintf (stderr,
"%s: invalid entry point %s\n",
- cmdname, *argv);
+ params.cmdname, *argv);
exit (EXIT_FAILURE);
}
- eflag = 1;
+ params.eflag = 1;
goto NXTARG;
case 'f':
if (--argc <= 0)
usage ();
- datafile = *++argv;
- fflag = 1;
+ params.datafile = *++argv;
+ params.fflag = 1;
goto NXTARG;
case 'n':
if (--argc <= 0)
usage ();
- name = *++argv;
+ params.imagename = *++argv;
goto NXTARG;
case 'v':
- vflag++;
+ params.vflag++;
break;
case 'x':
- xflag++;
+ params.xflag++;
break;
default:
usage ();
@@ -152,91 +249,112 @@ main (int argc, char **argv)
NXTARG: ;
}
- if ((argc != 1) ||
- (dflag && (fflag || lflag)) ||
- (fflag && (dflag || lflag)) ||
- (lflag && (dflag || fflag)))
- usage();
+ if (argc != 1)
+ usage ();
+
+ /* set tparams as per input type_id */
+ tparams = mkimage_get_type(params.type);
+ if (tparams == NULL) {
+ fprintf (stderr, "%s: unsupported type %s\n",
+ params.cmdname, genimg_get_type_name(params.type));
+ exit (EXIT_FAILURE);
+ }
- if (!eflag) {
- ep = addr;
+ /*
+ * check the passed arguments parameters meets the requirements
+ * as per image type to be generated/listed
+ */
+ if (tparams->check_params)
+ if (tparams->check_params (¶ms))
+ usage ();
+
+ if (!params.eflag) {
+ params.ep = params.addr;
/* If XIP, entry point must be after the U-Boot header */
- if (xflag)
- ep += image_get_header_size ();
+ if (params.xflag)
+ params.ep += tparams->header_size;
}
/*
* If XIP, ensure the entry point is equal to the load address plus
* the size of the U-Boot header.
*/
- if (xflag) {
- if (ep != addr + image_get_header_size ()) {
+ if (params.xflag) {
+ if (params.ep != params.addr + tparams->header_size) {
fprintf (stderr,
"%s: For XIP, the entry point must be the load addr + %lu\n",
- cmdname,
- (unsigned long)image_get_header_size ());
+ params.cmdname,
+ (unsigned long)tparams->header_size);
exit (EXIT_FAILURE);
}
}
- imagefile = *argv;
+ params.imagefile = *argv;
- if (!fflag){
- if (lflag) {
- ifd = open (imagefile, O_RDONLY|O_BINARY);
+ if (!params.fflag){
+ if (params.lflag) {
+ ifd = open (params.imagefile, O_RDONLY|O_BINARY);
} else {
- ifd = open (imagefile,
+ ifd = open (params.imagefile,
O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0666);
}
if (ifd < 0) {
fprintf (stderr, "%s: Can't open %s: %s\n",
- cmdname, imagefile, strerror(errno));
+ params.cmdname, params.imagefile,
+ strerror(errno));
exit (EXIT_FAILURE);
}
}
- if (lflag) {
+ if (params.lflag) {
/*
* list header information of existing image
*/
if (fstat(ifd, &sbuf) < 0) {
fprintf (stderr, "%s: Can't stat %s: %s\n",
- cmdname, imagefile, strerror(errno));
+ params.cmdname, params.imagefile,
+ strerror(errno));
exit (EXIT_FAILURE);
}
- if ((unsigned)sbuf.st_size < image_get_header_size ()) {
+ if ((unsigned)sbuf.st_size < tparams->header_size) {
fprintf (stderr,
- "%s: Bad size: \"%s\" is no valid image\n",
- cmdname, imagefile);
+ "%s: Bad size: \"%s\" is not valid image\n",
+ params.cmdname, params.imagefile);
exit (EXIT_FAILURE);
}
ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, ifd, 0);
if (ptr == MAP_FAILED) {
fprintf (stderr, "%s: Can't read %s: %s\n",
- cmdname, imagefile, strerror(errno));
+ params.cmdname, params.imagefile,
+ strerror(errno));
exit (EXIT_FAILURE);
}
- if (!(retval = fdt_check_header (ptr))) {
- /* FIT image */
- fit_print_contents (ptr);
- } else if (!(retval = image_verify_header ((char *)ptr,
- sbuf.st_size))) {
- /* old-style image */
- image_print_contents ((image_header_t *)ptr);
- }
+ /*
+ * scan through mkimage registry for all supported image types
+ * and verify the input image file header for match
+ * Print the image information for matched image type
+ * Returns the error code if not matched
+ */
+ retval = mkimage_verify_print_header (ptr, &sbuf);
(void) munmap((void *)ptr, sbuf.st_size);
(void) close (ifd);
exit (retval);
- } else if (fflag) {
- /* Flattened Image Tree (FIT) format handling */
- debug ("FIT format handling\n");
- fit_handle_file ();
+ } else if (params.fflag) {
+ if (tparams->fflag_handle)
+ /*
+ * in some cases, some additional processing needs
+ * to be done if fflag is defined
+ *
+ * For ex. fit_handle_file for Fit file support
+ */
+ retval = tparams->fflag_handle(¶ms);
+
exit (retval);
}
@@ -245,16 +363,17 @@ NXTARG: ;
*
* write dummy header, to be fixed later
*/
- memset (hdr, 0, image_get_header_size ());
+ memset (tparams->hdr, 0, tparams->header_size);
- if (write(ifd, hdr, image_get_header_size ()) != image_get_header_size ()) {
+ if (write(ifd, tparams->hdr, tparams->header_size)
+ != tparams->header_size) {
fprintf (stderr, "%s: Write error on %s: %s\n",
- cmdname, imagefile, strerror(errno));
+ params.cmdname, params.imagefile, strerror(errno));
exit (EXIT_FAILURE);
}
- if (opt_type == IH_TYPE_MULTI || opt_type == IH_TYPE_SCRIPT) {
- char *file = datafile;
+ if (params.type == IH_TYPE_MULTI || params.type == IH_TYPE_SCRIPT) {
+ char *file = params.datafile;
uint32_t size;
for (;;) {
@@ -267,7 +386,7 @@ NXTARG: ;
if (stat (file, &sbuf) < 0) {
fprintf (stderr, "%s: Can't stat %s: %s\n",
- cmdname, file, strerror(errno));
+ params.cmdname, file, strerror(errno));
exit (EXIT_FAILURE);
}
size = cpu_to_uimage (sbuf.st_size);
@@ -277,7 +396,8 @@ NXTARG: ;
if (write(ifd, (char *)&size, sizeof(size)) != sizeof(size)) {
fprintf (stderr, "%s: Write error on %s: %s\n",
- cmdname, imagefile, strerror(errno));
+ params.cmdname, params.imagefile,
+ strerror(errno));
exit (EXIT_FAILURE);
}
@@ -293,7 +413,7 @@ NXTARG: ;
}
}
- file = datafile;
+ file = params.datafile;
for (;;) {
char *sep = strchr(file, ':');
@@ -308,7 +428,7 @@ NXTARG: ;
}
}
} else {
- copy_file (ifd, datafile, 0);
+ copy_file (ifd, params.datafile, 0);
}
/* We're a bit of paranoid */
@@ -320,45 +440,34 @@ NXTARG: ;
if (fstat(ifd, &sbuf) < 0) {
fprintf (stderr, "%s: Can't stat %s: %s\n",
- cmdname, imagefile, strerror(errno));
+ params.cmdname, params.imagefile, strerror(errno));
exit (EXIT_FAILURE);
}
ptr = mmap(0, sbuf.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, ifd, 0);
if (ptr == MAP_FAILED) {
fprintf (stderr, "%s: Can't map %s: %s\n",
- cmdname, imagefile, strerror(errno));
+ params.cmdname, params.imagefile, strerror(errno));
exit (EXIT_FAILURE);
}
- hdr = (image_header_t *)ptr;
-
- checksum = crc32 (0,
- (const unsigned char *)(ptr +
- image_get_header_size ()),
- sbuf.st_size - image_get_header_size ()
- );
-
- /* Build new header */
- image_set_magic (hdr, IH_MAGIC);
- image_set_time (hdr, sbuf.st_mtime);
- image_set_size (hdr, sbuf.st_size - image_get_header_size ());
- image_set_load (hdr, addr);
- image_set_ep (hdr, ep);
- image_set_dcrc (hdr, checksum);
- image_set_os (hdr, opt_os);
- image_set_arch (hdr, opt_arch);
- image_set_type (hdr, opt_type);
- image_set_comp (hdr, opt_comp);
-
- image_set_name (hdr, name);
-
- checksum = crc32 (0, (const unsigned char *)hdr,
- image_get_header_size ());
-
- image_set_hcrc (hdr, checksum);
+ /* Setup the image header as per input image type*/
+ if (tparams->set_header)
+ tparams->set_header (ptr, &sbuf, ifd, ¶ms);
+ else {
+ fprintf (stderr, "%s: Can't set header for %s: %s\n",
+ params.cmdname, tparams->name, strerror(errno));
+ exit (EXIT_FAILURE);
+ }
- image_print_contents (hdr);
+ /* Print the image information by processing image header */
+ if (tparams->print_header)
+ tparams->print_header (ptr);
+ else {
+ fprintf (stderr, "%s: Can't print header for %s: %s\n",
+ params.cmdname, tparams->name, strerror(errno));
+ exit (EXIT_FAILURE);
+ }
(void) munmap((void *)ptr, sbuf.st_size);
@@ -371,7 +480,7 @@ NXTARG: ;
if (close(ifd)) {
fprintf (stderr, "%s: Write error on %s: %s\n",
- cmdname, imagefile, strerror(errno));
+ params.cmdname, params.imagefile, strerror(errno));
exit (EXIT_FAILURE);
}
@@ -388,31 +497,32 @@ copy_file (int ifd, const char *datafile, int pad)
int zero = 0;
int offset = 0;
int size;
+ struct image_type_params *tparams = mkimage_get_type (params.type);
- if (vflag) {
+ if (params.vflag) {
fprintf (stderr, "Adding Image %s\n", datafile);
}
if ((dfd = open(datafile, O_RDONLY|O_BINARY)) < 0) {
fprintf (stderr, "%s: Can't open %s: %s\n",
- cmdname, datafile, strerror(errno));
+ params.cmdname, datafile, strerror(errno));
exit (EXIT_FAILURE);
}
if (fstat(dfd, &sbuf) < 0) {
fprintf (stderr, "%s: Can't stat %s: %s\n",
- cmdname, datafile, strerror(errno));
+ params.cmdname, datafile, strerror(errno));
exit (EXIT_FAILURE);
}
ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, dfd, 0);
if (ptr == MAP_FAILED) {
fprintf (stderr, "%s: Can't read %s: %s\n",
- cmdname, datafile, strerror(errno));
+ params.cmdname, datafile, strerror(errno));
exit (EXIT_FAILURE);
}
- if (xflag) {
+ if (params.xflag) {
unsigned char *p = NULL;
/*
* XIP: do not append the image_header_t at the
@@ -420,29 +530,29 @@ copy_file (int ifd, const char *datafile, int pad)
* reserved for it.
*/
- if ((unsigned)sbuf.st_size < image_get_header_size ()) {
+ if ((unsigned)sbuf.st_size < tparams->header_size) {
fprintf (stderr,
"%s: Bad size: \"%s\" is too small for XIP\n",
- cmdname, datafile);
+ params.cmdname, datafile);
exit (EXIT_FAILURE);
}
- for (p = ptr; p < ptr + image_get_header_size (); p++) {
+ for (p = ptr; p < ptr + tparams->header_size; p++) {
if ( *p != 0xff ) {
fprintf (stderr,
"%s: Bad file: \"%s\" has invalid buffer for XIP\n",
- cmdname, datafile);
+ params.cmdname, datafile);
exit (EXIT_FAILURE);
}
}
- offset = image_get_header_size ();
+ offset = tparams->header_size;
}
size = sbuf.st_size - offset;
if (write(ifd, ptr + offset, size) != size) {
fprintf (stderr, "%s: Write error on %s: %s\n",
- cmdname, imagefile, strerror(errno));
+ params.cmdname, params.imagefile, strerror(errno));
exit (EXIT_FAILURE);
}
@@ -450,7 +560,8 @@ copy_file (int ifd, const char *datafile, int pad)
if (write(ifd, (char *)&zero, 4-tail) != 4-tail) {
fprintf (stderr, "%s: Write error on %s: %s\n",
- cmdname, imagefile, strerror(errno));
+ params.cmdname, params.imagefile,
+ strerror(errno));
exit (EXIT_FAILURE);
}
}
@@ -464,7 +575,7 @@ usage ()
{
fprintf (stderr, "Usage: %s -l image\n"
" -l ==> list image header information\n",
- cmdname);
+ params.cmdname);
fprintf (stderr, " %s [-x] -A arch -O os -T type -C comp "
"-a addr -e ep -n name -d data_file[:data_file...] image\n"
" -A ==> set architecture to 'arch'\n"
@@ -476,157 +587,9 @@ usage ()
" -n ==> set image name to 'name'\n"
" -d ==> use image data from 'datafile'\n"
" -x ==> set XIP (execute in place)\n",
- cmdname);
+ params.cmdname);
fprintf (stderr, " %s [-D dtc_options] -f fit-image.its fit-image\n",
- cmdname);
+ params.cmdname);
exit (EXIT_FAILURE);
}
-
-static int
-image_verify_header (char *ptr, int image_size)
-{
- int len;
- const unsigned char *data;
- uint32_t checksum;
- image_header_t header;
- image_header_t *hdr = &header;
-
- /*
- * create copy of header so that we can blank out the
- * checksum field for checking - this can't be done
- * on the PROT_READ mapped data.
- */
- memcpy (hdr, ptr, sizeof(image_header_t));
-
- if (be32_to_cpu(hdr->ih_magic) != IH_MAGIC) {
- fprintf (stderr,
- "%s: Bad Magic Number: \"%s\" is no valid image\n",
- cmdname, imagefile);
- return -FDT_ERR_BADMAGIC;
- }
-
- data = (const unsigned char *)hdr;
- len = sizeof(image_header_t);
-
- checksum = be32_to_cpu(hdr->ih_hcrc);
- hdr->ih_hcrc = cpu_to_be32(0); /* clear for re-calculation */
-
- if (crc32 (0, data, len) != checksum) {
- fprintf (stderr,
- "%s: ERROR: \"%s\" has bad header checksum!\n",
- cmdname, imagefile);
- return -FDT_ERR_BADSTATE;
- }
-
- data = (const unsigned char *)ptr + sizeof(image_header_t);
- len = image_size - sizeof(image_header_t) ;
-
- if (crc32 (0, data, len) != be32_to_cpu(hdr->ih_dcrc)) {
- fprintf (stderr,
- "%s: ERROR: \"%s\" has corrupted data!\n",
- cmdname, imagefile);
- return -FDT_ERR_BADSTRUCTURE;
- }
- return 0;
-}
-
-/**
- * fit_handle_file - main FIT file processing function
- *
- * fit_handle_file() runs dtc to convert .its to .itb, includes
- * binary data, updates timestamp property and calculates hashes.
- *
- * datafile - .its file
- * imagefile - .itb file
- *
- * returns:
- * only on success, otherwise calls exit (EXIT_FAILURE);
- */
-static void fit_handle_file (void)
-{
- char tmpfile[MKIMAGE_MAX_TMPFILE_LEN];
- char cmd[MKIMAGE_MAX_DTC_CMDLINE_LEN];
- int tfd;
- struct stat sbuf;
- unsigned char *ptr;
-
- /* call dtc to include binary properties into the tmp file */
- if (strlen (imagefile) + strlen (MKIMAGE_TMPFILE_SUFFIX) + 1 >
- sizeof (tmpfile)) {
- fprintf (stderr, "%s: Image file name (%s) too long, "
- "can't create tmpfile",
- imagefile, cmdname);
- exit (EXIT_FAILURE);
- }
- sprintf (tmpfile, "%s%s", imagefile, MKIMAGE_TMPFILE_SUFFIX);
-
- /* dtc -I dts -O -p 200 datafile > tmpfile */
- sprintf (cmd, "%s %s %s > %s",
- MKIMAGE_DTC, opt_dtc, datafile, tmpfile);
- debug ("Trying to execute \"%s\"\n", cmd);
- if (system (cmd) == -1) {
- fprintf (stderr, "%s: system(%s) failed: %s\n",
- cmdname, cmd, strerror(errno));
- unlink (tmpfile);
- exit (EXIT_FAILURE);
- }
-
- /* load FIT blob into memory */
- tfd = open (tmpfile, O_RDWR|O_BINARY);
-
- if (tfd < 0) {
- fprintf (stderr, "%s: Can't open %s: %s\n",
- cmdname, tmpfile, strerror(errno));
- unlink (tmpfile);
- exit (EXIT_FAILURE);
- }
-
- if (fstat (tfd, &sbuf) < 0) {
- fprintf (stderr, "%s: Can't stat %s: %s\n",
- cmdname, tmpfile, strerror(errno));
- unlink (tmpfile);
- exit (EXIT_FAILURE);
- }
-
- ptr = mmap (0, sbuf.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, tfd, 0);
- if (ptr == MAP_FAILED) {
- fprintf (stderr, "%s: Can't read %s: %s\n",
- cmdname, tmpfile, strerror(errno));
- unlink (tmpfile);
- exit (EXIT_FAILURE);
- }
-
- /* check if ptr has a valid blob */
- if (fdt_check_header (ptr)) {
- fprintf (stderr, "%s: Invalid FIT blob\n", cmdname);
- unlink (tmpfile);
- exit (EXIT_FAILURE);
- }
-
- /* set hashes for images in the blob */
- if (fit_set_hashes (ptr)) {
- fprintf (stderr, "%s Can't add hashes to FIT blob", cmdname);
- unlink (tmpfile);
- exit (EXIT_FAILURE);
- }
-
- /* add a timestamp at offset 0 i.e., root */
- if (fit_set_timestamp (ptr, 0, sbuf.st_mtime)) {
- fprintf (stderr, "%s: Can't add image timestamp\n", cmdname);
- unlink (tmpfile);
- exit (EXIT_FAILURE);
- }
- debug ("Added timestamp successfully\n");
-
- munmap ((void *)ptr, sbuf.st_size);
- close (tfd);
-
- if (rename (tmpfile, imagefile) == -1) {
- fprintf (stderr, "%s: Can't rename %s to %s: %s\n",
- cmdname, tmpfile, imagefile, strerror (errno));
- unlink (tmpfile);
- unlink (imagefile);
- exit (EXIT_FAILURE);
- }
-}
diff --git a/tools/mkimage.h b/tools/mkimage.h
index 70c53ad..a9295b6 100644
--- a/tools/mkimage.h
+++ b/tools/mkimage.h
@@ -20,6 +20,9 @@
* MA 02111-1307 USA
*/
+#ifndef _MKIIMAGE_H_
+#define _MKIIMAGE_H_
+
#include "os_support.h"
#include <errno.h>
#include <fcntl.h>
@@ -32,7 +35,7 @@
#include <sha1.h>
#include "fdt_host.h"
-#define MKIMAGE_DEBUG
+#undef MKIMAGE_DEBUG
#ifdef MKIMAGE_DEBUG
#define debug(fmt,args...) printf (fmt ,##args)
@@ -45,3 +48,99 @@
#define MKIMAGE_DEFAULT_DTC_OPTIONS "-I dts -O dtb -p 500"
#define MKIMAGE_MAX_DTC_CMDLINE_LEN 512
#define MKIMAGE_DTC "dtc" /* assume dtc is in $PATH */
+
+/*
+ * This structure defines all such variables those are initialized by
+ * mkimage main core and need to be referred by image type specific
+ * functions
+ */
+struct mkimage_params {
+ int dflag;
+ int eflag;
+ int fflag;
+ int lflag;
+ int vflag;
+ int xflag;
+ int os;
+ int arch;
+ int type;
+ int comp;
+ char *dtc;
+ unsigned int addr;
+ unsigned int ep;
+ char *imagename;
+ char *datafile;
+ char *imagefile;
+ char *cmdname;
+};
+
+/*
+ * image type specific variables and callback functions
+ */
+struct image_type_params {
+ /* name is an identification tag string for added support */
+ char *name;
+ /*
+ * header size is local to the specific image type to be supported,
+ * mkimage core treats this as number of bytes
+ */
+ uint32_t header_size;
+ /* Image type header pointer */
+ void *hdr;
+ /*
+ * There are several arguments that are passed on the command line
+ * and are registered as flags in mkimage_params structure.
+ * This callback function can be used to check the passed arguments
+ * are in-lined with the image type to be supported
+ *
+ * Returns 1 if parameter check is successful
+ */
+ int (*check_params) (struct mkimage_params *);
+ /*
+ * This function is used by list command (i.e. mkimage -l <filename>)
+ * image type verification code must be put here
+ *
+ * Returns 0 if image header verification is successful
+ * otherwise, returns respective negative error codes
+ */
+ int (*verify_header) (unsigned char *, int, struct mkimage_params *);
+ /* Prints image information abstracting from image header */
+ void (*print_header) (void *);
+ /*
+ * The header or image contents need to be set as per image type to
+ * be generated using this callback function.
+ * further output file post processing (for ex. checksum calculation,
+ * padding bytes etc..) can also be done in this callback function.
+ */
+ void (*set_header) (void *, struct stat *, int,
+ struct mkimage_params *);
+ /*
+ * Some image generation support for ex (default image type) supports
+ * more than one type_ids, this callback function is used to check
+ * whether input (-T <image_type>) is supported by registered image
+ * generation/list low level code
+ */
+ int (*check_image_type) (uint8_t);
+ /* This callback function will be executed if fflag is defined */
+ int (*fflag_handle) (struct mkimage_params *);
+ /* pointer to the next registered entry in linked list */
+ struct image_type_params *next;
+};
+
+/*
+ * Exported functions
+ */
+void mkimage_register (struct image_type_params *tparams);
+
+/*
+ * There is a c file associated with supported image type low level code
+ * for ex. default_image.c, fit_image.c
+ * init is the only function referred by mkimage core.
+ * to avoid a single lined header file, you can define them here
+ *
+ * Supported image types init functions
+ */
+void init_default_image_type (void);
+void init_fit_image_type (void);
+
+#endif /* _MKIIMAGE_H_ */
--
1.5.3.4
2
1
----- Original Message -----
From: "Kumar Gala" <galak(a)kernel.crashing.org>
To: "Thirumalai" <thirumalai.p(a)datapatterns.co.in>
Sent: Tuesday, August 18, 2009 7:45 PM
Subject: Re: Regarding 8641D uboot
> Please ask these questions on the u-boot list.
>
> - k
>
> On Aug 17, 2009, at 10:19 PM, Thirumalai wrote:
>
>> Hi Kumar,
>> Correct me if i am wrong. The multi cpu system that mentioned
>> release.S file meant for only dual Core 8641 processor right or will it
>> meant for more than one dual core processor. Kindly clarify me.
>>
>> If suppose i am having a flash memory which is shared among 2 processors
>> is it possible to use the flash by other processors to boot ?
>>
>> Is there any support for RIO has added on the uboot. Kindly let me know
>> if so.
>> Regards,
>> T.
>>
>> ----- Original Message ----- From: "Kumar Gala"
>> <galak(a)kernel.crashing.org
>> >
>> To: "Thirumalai" <thirumalai.p(a)datapatterns.co.in>
>> Sent: Wednesday, August 12, 2009 4:06 AM
>> Subject: Re: Regarding 8641D uboot
>>
>>
>>> 2.6.30 should be perfectly fine for 8641D.
>>>
>>> - k
>>>
>>> On Aug 11, 2009, at 9:48 AM, Thirumalai wrote:
>>>
>>>> Hi kumar,
>>>> What linux kernel version is stable for 8641D processor that i can
>>>> use. Is there any modifications has happened on device tree. kindly
>>>> let me know the information. I have downloaded 2.6.30 kernel which i
>>>> compiled on ELDK-4.0 and try to boot my custom hardware which is
>>>> based on MPC7448 processor with TSI109 system controller. But the pci
>>>> enumeration is not happening properly and because of this the target
>>>> is not booting up fully. i.e hanged up at ethernet driver
>>>> initialization.
>>>>
>>>> Kindly let me know any mailing lists that can information regarding
>>>> powerpc kernel development.
>>>>
>>>> Expecting quick response
>>>> Regards,
>>>> T.
>>>>
>>>>>
>>>>> ----- Original Message ----- From: "Kumar Gala"
>>>>> <galak(a)kernel.crashing.org
>>>>> >
>>>>> To: "Thirumalai" <thirumalai.p(a)datapatterns.co.in>
>>>>> Sent: Thursday, August 06, 2009 7:43 PM
>>>>> Subject: Re: Regarding 8641D uboot
>>>>>
>>>>>
>>>>>> v2009.06 should be fine for 8641D.
>>>>>>
>>>>>> - k
>>>>>>
>>>>>> On Aug 6, 2009, at 1:03 AM, Thirumalai wrote:
>>>>>>
>>>>>>> Hi kumar,
>>>>>>> I just want know what is the stable u-boot release which i can
>>>>>>> use for porting of my new customized 8641D based processor board.
>>>>>>> Earlier i have downloaded u-boot-2009-06.
>>>>>>> Kindly give me the development environment information also.
>>>>>>> Earlier i used ELDK-4.0 for compilation.
>>>>>>> Regards,
>>>>>>> T.
>>>>>>>
>>>>>>> **************** CAUTION - Disclaimer *****************This email
>>>>>>> may contain confidential and privileged material for the
>>>>>>> sole use of the intended recipient(s). Any review, use, retention,
>>>>>>> distribution or disclosure by others is strictly prohibited. If
>>>>>>> you are not the intended recipient (or authorized to receive for
>>>>>>> the recipient), please contact the sender by reply email and
>>>>>>> delete all copies of this message. Also, email is susceptible to
>>>>>>> data corruption, interception, tampering, unauthorized amendment
>>>>>>> and viruses. We only send and receive emails on the basis that we
>>>>>>> are not liable for any such corruption, interception, tampering,
>>>>>>> amendment or viruses or any consequence thereof. *********** End
>>>>>>> of Disclaimer ***********DataPatterns ITS Group**********
>>>>
>>>>
>>>> **************** CAUTION - Disclaimer *****************This email may
>>>> contain confidential and privileged material for the
>>>> sole use of the intended recipient(s). Any review, use, retention,
>>>> distribution or disclosure by others is strictly prohibited. If you
>>>> are not the intended recipient (or authorized to receive for the
>>>> recipient), please contact the sender by reply email and delete all
>>>> copies of this message. Also, email is susceptible to data
>>>> corruption, interception, tampering, unauthorized amendment and
>>>> viruses. We only send and receive emails on the basis that we are not
>>>> liable for any such corruption, interception, tampering, amendment or
>>>> viruses or any consequence thereof. *********** End of Disclaimer
>>>> ***********DataPatterns ITS Group**********
>>
>>
>> **************** CAUTION - Disclaimer *****************This email may
>> contain confidential and privileged material for the
>> sole use of the intended recipient(s). Any review, use, retention,
>> distribution or disclosure by others is strictly prohibited. If you are
>> not the intended recipient (or authorized to receive for the recipient),
>> please contact the sender by reply email and delete all copies of this
>> message. Also, email is susceptible to data corruption, interception,
>> tampering, unauthorized amendment and viruses. We only send and receive
>> emails on the basis that we are not liable for any such corruption,
>> interception, tampering, amendment or viruses or any consequence
>> thereof. *********** End of Disclaimer ***********DataPatterns ITS
>> Group**********
>
**************** CAUTION - Disclaimer *****************This email may contain confidential and privileged material for the
sole use of the intended recipient(s). Any review, use, retention, distribution or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive for the recipient), please contact the sender by reply email and delete all copies of this message. Also, email is susceptible to data corruption, interception, tampering, unauthorized amendment and viruses. We only send and receive emails on the basis that we are not liable for any such corruption, interception, tampering, amendment or viruses or any consequence thereof.
*********** End of Disclaimer ***********DataPatterns ITS Group**********
2
1

19 Aug '09
This patch adds and uses common code for all Matrix Vision boards.
Signed-off-by: André Schwarz <andre.schwarz(a)matrix-vision.de>
---
Heiko's comments have been addressed and common/mv_common.h has been
included where needed.
board/matrix_vision/common/Makefile | 54 ++++++++++++++
board/matrix_vision/common/mv_common.c | 125
++++++++++++++++++++++++++++++++
board/matrix_vision/common/mv_common.h | 25 +++++++
board/matrix_vision/mvbc_p/mvbc_p.c | 76 +-------------------
board/matrix_vision/mvblm7/mvblm7.c | 38 +++-------
board/matrix_vision/mvblm7/pci.c | 35 ++--------
include/configs/MVBC_P.h | 14 +++-
include/configs/MVBLM7.h | 49 +++++--------
8 files changed, 254 insertions(+), 162 deletions(-)
diff --git a/board/matrix_vision/common/Makefile
b/board/matrix_vision/common/Makefile
new file mode 100644
index 0000000..b496258
--- /dev/null
+++ b/board/matrix_vision/common/Makefile
@@ -0,0 +1,54 @@
+#
+# (C) Copyright 2006
+# Wolfgang Denk, DENX Software Engineering, wd(a)denx.de.
+#
+# See file CREDITS for list of people who contributed to this
+# project.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+
+include $(TOPDIR)/config.mk
+
+ifneq ($(OBJTREE),$(SRCTREE))
+$(shell mkdir -p $(obj)board/$(VENDOR)/common)
+endif
+
+LIB = $(obj)lib$(VENDOR).a
+
+COBJS-y = mv_common.o
+
+SRCS := $(SOBJS:.o=.S) $(COBJS-y:.o=.c)
+OBJS := $(addprefix $(obj),$(COBJS-y))
+SOBJS := $(addprefix $(obj),$(SOBJS))
+
+$(LIB): $(obj).depend $(OBJS)
+ $(AR) $(ARFLAGS) $@ $(OBJS)
+
+clean:
+ rm -f $(SOBJS) $(OBJS)
+
+distclean: clean
+ rm -f $(LIB) core *.bak $(obj).depend
+
+#########################################################################
+
+# defines $(obj).depend target
+include $(SRCTREE)/rules.mk
+
+sinclude $(obj).depend
+
+#########################################################################
diff --git a/board/matrix_vision/common/mv_common.c
b/board/matrix_vision/common/mv_common.c
new file mode 100644
index 0000000..284de16
--- /dev/null
+++ b/board/matrix_vision/common/mv_common.c
@@ -0,0 +1,125 @@
+/*
+ * (C) Copyright 2008
+ * Andre Schwarz, Matrix Vision GmbH, andre.schwarz(a)matrix-vision.de
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <malloc.h>
+#include <environment.h>
+#include <asm/io.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static char* entries_to_keep[] = {
+ "serial#", "ethaddr", "eth1addr", "model_info", "sensor_cnt",
+ "fpgadatasize", "ddr_size", "use_dhcp", "use_static_ipaddr",
+ "static_ipaddr", "static_netmask", "static_gateway",
+ "syslog", "watchdog", "netboot", "evo8serialnumber" };
+
+#define MV_MAX_ENV_ENTRY_LENGTH 64
+#define MV_KEEP_ENTRIES ARRAY_SIZE(entries_to_keep)
+
+void mv_reset_environment(void)
+{
+ int i;
+ char *s[MV_KEEP_ENTRIES];
+ char entries[MV_KEEP_ENTRIES][MV_MAX_ENV_ENTRY_LENGTH];
+
+ printf("\n*** RESET ENVIRONMENT ***\n");
+
+ memset(entries, 0, MV_KEEP_ENTRIES * MV_MAX_ENV_ENTRY_LENGTH);
+ for (i = 0; i < MV_KEEP_ENTRIES; i++) {
+ s[i] = getenv(entries_to_keep[i]);
+ if (s[i]) {
+ printf("save '%s' : %s\n", entries_to_keep[i], s[i]);
+ strncpy(entries[i], s[i], MV_MAX_ENV_ENTRY_LENGTH);
+ }
+ }
+
+ gd->env_valid = 0;
+ env_relocate();
+
+ for (i = 0; i < MV_KEEP_ENTRIES; i++) {
+ if (s[i]) {
+ printf("restore '%s' : %s\n", entries_to_keep[i], s[i]);
+ setenv(entries_to_keep[i], s[i]);
+ }
+ }
+
+ saveenv();
+}
+
+int mv_load_fpga(void)
+{
+ int result;
+ size_t data_size = 0;
+ void *fpga_data = NULL;
+ char *datastr = getenv("fpgadata");
+ char *sizestr = getenv("fpgadatasize");
+
+ if (getenv("skip_fpga")) {
+ printf("found 'skip_fpga' -> FPGA _not_ loaded !\n");
+ return -1;
+ }
+ printf("loading FPGA\n");
+
+ if (datastr)
+ fpga_data = (void *)simple_strtoul(datastr, NULL, 16);
+ if (sizestr)
+ data_size = (size_t)simple_strtoul(sizestr, NULL, 16);
+ if (!data_size) {
+ printf("fpgadatasize invalid -> FPGA _not_ loaded !\n");
+ return -1;
+ }
+
+ result = fpga_load(0, fpga_data, data_size);
+ if (!result)
+ show_boot_progress(0);
+
+ return result;
+}
+
+u8 *dhcp_vendorex_prep(u8 *e)
+{
+ char *ptr;
+
+ /* DHCP vendor-class-identifier = 60 */
+ if ((ptr = getenv("dhcp_vendor-class-identifier"))) {
+ *e++ = 60;
+ *e++ = strlen(ptr);
+ while (*ptr)
+ *e++ = *ptr++;
+ }
+ /* DHCP_CLIENT_IDENTIFIER = 61 */
+ if ((ptr = getenv("dhcp_client_id"))) {
+ *e++ = 61;
+ *e++ = strlen(ptr);
+ while (*ptr)
+ *e++ = *ptr++;
+ }
+
+ return e;
+}
+
+u8 *dhcp_vendorex_proc(u8 *popt)
+{
+ return NULL;
+}
diff --git a/board/matrix_vision/common/mv_common.h
b/board/matrix_vision/common/mv_common.h
new file mode 100644
index 0000000..046c038
--- /dev/null
+++ b/board/matrix_vision/common/mv_common.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2008 Matrix Vision GmbH
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+
+extern int mv_load_fpga(void);
+extern void mv_reset_environment(void);
diff --git a/board/matrix_vision/mvbc_p/mvbc_p.c
b/board/matrix_vision/mvbc_p/mvbc_p.c
index a300342..4ebe185 100644
--- a/board/matrix_vision/mvbc_p/mvbc_p.c
+++ b/board/matrix_vision/mvbc_p/mvbc_p.c
@@ -39,6 +39,7 @@
#include <asm/io.h>
#include "fpga.h"
#include "mvbc_p.h"
+#include "../common/mv_common.h"
#define SDRAM_MODE 0x00CD0000
#define SDRAM_CONTROL 0x504F0000
@@ -134,23 +135,6 @@ void mvbc_init_gpio(void)
printf("sint_gpioe : 0x%08x\n", gpio->sint_gpioe);
}
-void reset_environment(void)
-{
- char *s, sernr[64];
-
- printf("\n*** RESET ENVIRONMENT ***\n");
- memset(sernr, 0, sizeof(sernr));
- s = getenv("serial#");
- if (s) {
- printf("found serial# : %s\n", s);
- strncpy(sernr, s, 64);
- }
- gd->env_valid = 0;
- env_relocate();
- if (s)
- setenv("serial#", sernr);
-}
-
int misc_init_r(void)
{
char *s = getenv("reset_env");
@@ -166,7 +150,7 @@ int misc_init_r(void)
return 0;
}
printf(" === FACTORY RESET ===\n");
- reset_environment();
+ mv_reset_environment();
saveenv();
return -1;
@@ -234,69 +218,15 @@ struct pci_controller hose = {
fixup_irq:pci_mvbc_fixup_irq
};
-int mvbc_p_load_fpga(void)
-{
- size_t data_size = 0;
- void *fpga_data = NULL;
- char *datastr = getenv("fpgadata");
- char *sizestr = getenv("fpgadatasize");
-
- if (datastr)
- fpga_data = (void *)simple_strtoul(datastr, NULL, 16);
- if (sizestr)
- data_size = (size_t)simple_strtoul(sizestr, NULL, 16);
-
- return fpga_load(0, fpga_data, data_size);
-}
-
extern void pci_mpc5xxx_init(struct pci_controller *);
void pci_init_board(void)
{
- char *s;
- int load_fpga = 1;
-
mvbc_p_init_fpga();
- s = getenv("skip_fpga");
- if (s) {
- printf("found 'skip_fpga' -> FPGA _not_ loaded !\n");
- load_fpga = 0;
- }
- if (load_fpga) {
- printf("loading FPGA ... ");
- mvbc_p_load_fpga();
- printf("done\n");
- }
+ mv_load_fpga();
pci_mpc5xxx_init(&hose);
}
-u8 *dhcp_vendorex_prep(u8 *e)
-{
- char *ptr;
-
- /* DHCP vendor-class-identifier = 60 */
- if ((ptr = getenv("dhcp_vendor-class-identifier"))) {
- *e++ = 60;
- *e++ = strlen(ptr);
- while (*ptr)
- *e++ = *ptr++;
- }
- /* DHCP_CLIENT_IDENTIFIER = 61 */
- if ((ptr = getenv("dhcp_client_id"))) {
- *e++ = 61;
- *e++ = strlen(ptr);
- while (*ptr)
- *e++ = *ptr++;
- }
-
- return e;
-}
-
-u8 *dhcp_vendorex_proc (u8 *popt)
-{
- return NULL;
-}
-
void show_boot_progress(int val)
{
struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
diff --git a/board/matrix_vision/mvblm7/mvblm7.c
b/board/matrix_vision/mvblm7/mvblm7.c
index 6984af9..2cecd1f 100644
--- a/board/matrix_vision/mvblm7/mvblm7.c
+++ b/board/matrix_vision/mvblm7/mvblm7.c
@@ -64,7 +64,7 @@ int fixed_sdram(void)
im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
- im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CNTL;
+ im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL;
udelay(300);
@@ -88,40 +88,22 @@ phys_size_t initdram(int board_type)
return msize * 1024 * 1024;
}
-int checkboard(void)
+int misc_init_r(void)
{
- puts("Board: Matrix Vision mvBlueLYNX-M7\n");
-
- return 0;
-}
+ char *s = getenv("reset_env");
-u8 *dhcp_vendorex_prep(u8 *e)
-{
- char *ptr;
-
- /* DHCP vendor-class-identifier = 60 */
- ptr = getenv("dhcp_vendor-class-identifier");
- if (ptr) {
- *e++ = 60;
- *e++ = strlen(ptr);
- while (*ptr)
- *e++ = *ptr++;
- }
- /* DHCP_CLIENT_IDENTIFIER = 61 */
- ptr = getenv("dhcp_client_id");
- if (ptr) {
- *e++ = 61;
- *e++ = strlen(ptr);
- while (*ptr)
- *e++ = *ptr++;
+ if (s) {
+ mv_reset_environment();
}
- return e;
+ return 0;
}
-u8 *dhcp_vendorex_proc(u8 *popt)
+int checkboard(void)
{
- return NULL;
+ puts("Board: Matrix Vision mvBlueLYNX-M7\n");
+
+ return 0;
}
#ifdef CONFIG_HARD_SPI
diff --git a/board/matrix_vision/mvblm7/pci.c
b/board/matrix_vision/mvblm7/pci.c
index 9f31719..2db51f1 100644
--- a/board/matrix_vision/mvblm7/pci.c
+++ b/board/matrix_vision/mvblm7/pci.c
@@ -32,24 +32,10 @@
#include <fpga.h>
#include "mvblm7.h"
#include "fpga.h"
+#include "../common/mv_common.h"
DECLARE_GLOBAL_DATA_PTR;
-int mvblm7_load_fpga(void)
-{
- size_t data_size = 0;
- void *fpga_data = NULL;
- char *datastr = getenv("fpgadata");
- char *sizestr = getenv("fpgadatasize");
-
- if (datastr)
- fpga_data = (void *)simple_strtoul(datastr, NULL, 16);
- if (sizestr)
- data_size = (size_t)simple_strtoul(sizestr, NULL, 16);
-
- return fpga_load(0, fpga_data, data_size);
-}
-
static struct pci_region pci_regions[] = {
{
bus_start: CONFIG_SYS_PCI1_MEM_BASE,
@@ -73,10 +59,8 @@ static struct pci_region pci_regions[] = {
void pci_init_board(void)
{
- char *s;
int i;
int warmboot;
- int load_fpga;
volatile immap_t *immr;
volatile pcictrl83xx_t *pci_ctrl;
volatile gpio83xx_t *gpio;
@@ -84,32 +68,23 @@ void pci_init_board(void)
volatile law83xx_t *pci_law;
struct pci_region *reg[] = { pci_regions };
- load_fpga = 1;
immr = (immap_t *) CONFIG_SYS_IMMR;
clk = (clk83xx_t *) &immr->clk;
pci_ctrl = immr->pci_ctrl;
pci_law = immr->sysconf.pcilaw;
gpio = (volatile gpio83xx_t *)&immr->gpio[0];
- s = getenv("skip_fpga");
- if (s) {
- printf("found 'skip_fpga' -> FPGA _not_ loaded !\n");
- load_fpga = 0;
- }
-
gpio->dat = MV_GPIO_DAT;
gpio->odr = MV_GPIO_ODE;
- if (load_fpga)
- gpio->dir = MV_GPIO_OUT;
- else
- gpio->dir = MV_GPIO_OUT & ~(FPGA_DIN|FPGA_CCLK);
+ gpio->dir = MV_GPIO_OUT;
printf("SICRH / SICRL : 0x%08x / 0x%08x\n", immr->sysconf.sicrh,
immr->sysconf.sicrl);
mvblm7_init_fpga();
- if (load_fpga)
- mvblm7_load_fpga();
+ mv_load_fpga();
+
+ gpio->dir = MV_GPIO_OUT & ~(FPGA_DIN|FPGA_CCLK);
/* Enable PCI_CLK_OUTPUTs 0 and 1 with 1:1 clocking */
clk->occr = 0xc0000000;
diff --git a/include/configs/MVBC_P.h b/include/configs/MVBC_P.h
index edbc701..867e8e0 100644
--- a/include/configs/MVBC_P.h
+++ b/include/configs/MVBC_P.h
@@ -68,9 +68,9 @@
#define MV_VCI mvBlueCOUGAR-P
#define MV_FPGA_DATA 0xff860000
#define MV_FPGA_SIZE 0x0003c886
-#define MV_KERNEL_ADDR 0xffc00000
+#define MV_KERNEL_ADDR 0xffd00000
#define MV_INITRD_ADDR 0xff900000
-#define MV_INITRD_LENGTH 0x00300000
+#define MV_INITRD_LENGTH 0x00400000
#define MV_SCRATCH_ADDR 0x00000000
#define MV_SCRATCH_LENGTH MV_INITRD_LENGTH
#define MV_SOURCE_ADDR 0xff840000
@@ -105,6 +105,7 @@
#define CONFIG_CMD_SDRAM
#define CONFIG_CMD_PCI
#define CONFIG_CMD_FPGA
+#define CONFIG_CMD_I2C
#undef CONFIG_WATCHDOG
@@ -182,6 +183,7 @@
"propdev_debug=0\0" \
"gevss_debug=0\0" \
"watchdog=1\0" \
+ "sensor_cnt=1\0" \
""
#undef XMK_STR
@@ -249,6 +251,14 @@
#define CONFIG_SYS_BOOTMAPSZ (8 << 20)
/*
+ * I2C configuration
+ */
+#define CONFIG_HARD_I2C 1
+#define CONFIG_SYS_I2C_MODULE 1
+#define CONFIG_SYS_I2C_SPEED 86000
+#define CONFIG_SYS_I2C_SLAVE 0x7F
+
+/*
* Ethernet configuration
*/
#define CONFIG_NET_MULTI
diff --git a/include/configs/MVBLM7.h b/include/configs/MVBLM7.h
index ac8cb57..3e3a2c0 100644
--- a/include/configs/MVBLM7.h
+++ b/include/configs/MVBLM7.h
@@ -47,10 +47,9 @@
#define CONFIG_MPC8XXX_SPI
#define CONFIG_HARD_SPI
#define MVBLM7_MMC_CS 0x04000000
+#define CONFIG_MISC_INIT_R
/* I2C */
-#undef CONFIG_SOFT_I2C
-
#define CONFIG_FSL_I2C
#define CONFIG_I2C_MULTI_BUS
#define CONFIG_SYS_I2C_OFFSET 0x3000
@@ -62,44 +61,36 @@
/*
* DDR Setup
*/
+#undef CONFIG_SPD_EEPROM
+
#define CONFIG_SYS_DDR_BASE 0x00000000
#define CONFIG_SYS_SDRAM_BASE CONFIG_SYS_DDR_BASE
#define CONFIG_SYS_DDR_SDRAM_BASE CONFIG_SYS_DDR_BASE
#define CONFIG_SYS_83XX_DDR_USES_CS0 1
#define CONFIG_SYS_MEMTEST_START (60<<20)
#define CONFIG_SYS_MEMTEST_END (70<<20)
+#define CONFIG_VERY_BIG_RAM
-#define CONFIG_SYS_DDR_SDRAM_CLK_CNTL (DDR_SDRAM_CLK_CNTL_SS_EN | \
- DDR_SDRAM_CLK_CNTL_CLK_ADJUST_05
-
-#define CONFIG_SYS_DDR_SIZE 256
+#define CONFIG_SYS_DDRCDR 0x22000001
+#define CONFIG_SYS_DDR_SDRAM_CLK_CNTL DDR_SDRAM_CLK_CNTL_CLK_ADJUST_05
-/* HC, 75Ohm, DDR-II, DRQ */
-#define CONFIG_SYS_DDRCDR 0x80000001
-/* EN, ODT_WR, 3BA, 14row, 10col */
-#define CONFIG_SYS_DDR_CS0_CONFIG 0x80014102
-#define CONFIG_SYS_DDR_CS1_CONFIG 0x0
-#define CONFIG_SYS_DDR_CS2_CONFIG 0x0
-#define CONFIG_SYS_DDR_CS3_CONFIG 0x0
+#define CONFIG_SYS_DDR_SIZE 512
-#define CONFIG_SYS_DDR_CS0_BNDS 0x0000000f
-#define CONFIG_SYS_DDR_CS1_BNDS 0x0
-#define CONFIG_SYS_DDR_CS2_BNDS 0x0
-#define CONFIG_SYS_DDR_CS3_BNDS 0x0
+#define CONFIG_SYS_DDR_CS0_CONFIG 0x80014202
-#define CONFIG_SYS_DDR_CLK_CNTL 0x02000000
+#define CONFIG_SYS_DDR_CS0_BNDS 0x0000003f
-#define CONFIG_SYS_DDR_TIMING_0 0x00260802
-#define CONFIG_SYS_DDR_TIMING_1 0x2625b221
-#define CONFIG_SYS_DDR_TIMING_2 0x1f9820c7
-#define CONFIG_SYS_DDR_TIMING_3 0x00000000
+#define CONFIG_SYS_DDR_TIMING_0 0x00260802
+#define CONFIG_SYS_DDR_TIMING_1 0x3837c322
+#define CONFIG_SYS_DDR_TIMING_2 0x0f9848c6
+#define CONFIG_SYS_DDR_TIMING_3 0x00000000
-/* ~MEM_EN, SREN, DDR-II, 32_BE */
-#define CONFIG_SYS_DDR_SDRAM_CFG 0x43080000
+#define CONFIG_SYS_DDR_SDRAM_CFG 0x43080008
#define CONFIG_SYS_DDR_SDRAM_CFG2 0x00401000
-#define CONFIG_SYS_DDR_INTERVAL 0x04060100
+#define CONFIG_SYS_DDR_INTERVAL 0x02000100
-#define CONFIG_SYS_DDR_MODE 0x078e0232
+#define CONFIG_SYS_DDR_MODE 0x04040242
+#define CONFIG_SYS_DDR_MODE2 0x00800000
/* Flash */
#define CONFIG_SYS_FLASH_CFI
@@ -405,8 +396,8 @@
#define MV_CI mvBL-M7
#define MV_VCI mvBL-M7
-#define MV_FPGA_DATA 0xfff80000
-#define MV_FPGA_SIZE 0x00076ca2
+#define MV_FPGA_DATA 0xfff40000
+#define MV_FPGA_SIZE 0
#define MV_KERNEL_ADDR 0xff810000
#define MV_INITRD_ADDR 0xffb00000
#define MV_SOURCE_ADDR 0xff804000
@@ -453,7 +444,7 @@
"static_ipaddr=192.168.90.10\0" \
"static_netmask=255.255.255.0\0" \
"static_gateway=0.0.0.0\0" \
- "initrd_name=uInitrd.mvblm7-xenorfs\0" \
+ "initrd_name=uInitrd.mvBL-M7-rfs\0" \
"zcip=no\0" \
"netboot=yes\0" \
"mvtest=Ff\0" \
MATRIX VISION GmbH, Talstrasse 16, DE-71570 Oppenweiler
Registergericht: Amtsgericht Stuttgart, HRB 271090
Geschiaeftsf�hrer: Gerhard Thullner, Werner Armingeon, Uwe Furtner, Hans-Joachim Reich
2
2
Hi all,
How do i go about the SDRAM/DDR initialization on my board. IS the
function partitoned or is it just done in a single place.
I would think that board specifc dram_init is just a generic
function. There has to be a specific place where the SDRAM controller
is told about the DRR/SDRAM.
Is the porting documented somewhere or are there any good example to
follow to stick to U-boot conventions.
Please enlighten me.
Thanks & Regards,
ALfred
3
2
Hi kumar,
The CONFIG_PHYS_64BIT was not defined on the header file of HPCN
but extended address translation was enabled on the start.S irrespective of
the MPC8641D_hpcn compilation option why?.
Regards,
T.
**************** CAUTION - Disclaimer *****************This email may contain confidential and privileged material for the
sole use of the intended recipient(s). Any review, use, retention, distribution or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive for the recipient), please contact the sender by reply email and delete all copies of this message. Also, email is susceptible to data corruption, interception, tampering, unauthorized amendment and viruses. We only send and receive emails on the basis that we are not liable for any such corruption, interception, tampering, amendment or viruses or any consequence thereof.
*********** End of Disclaimer ***********DataPatterns ITS Group**********
3
2

18 Aug '09
From: Sandeep Paulraj <s-paulraj(a)ti.com>
This patch adds 4 BIT ECC support in the DaVinci NAND
driver. Tested on both the DM355 and DM365.
V3 version of the patch resolves compilation warnings pointed to by
Scott Wood. These compilation warnings occur when 4 BIT ECC support
is not enabled
Signed-off-by: Sandeep Paulraj <s-paulraj(a)ti.com>
---
For feature completeness this patch should be used along with
[PATCH v2] ARM: DaVinci DM355: Updating the DM355 EVM config
that i just sent to the mailing list
drivers/mtd/nand/davinci_nand.c | 283 +++++++++++++++++++++++++++++-
include/asm-arm/arch-davinci/emif_defs.h | 10 +
2 files changed, 291 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/nand/davinci_nand.c b/drivers/mtd/nand/davinci_nand.c
index 7837a8e..eabaf3e 100644
--- a/drivers/mtd/nand/davinci_nand.c
+++ b/drivers/mtd/nand/davinci_nand.c
@@ -47,6 +47,16 @@
#include <asm/arch/nand_defs.h>
#include <asm/arch/emif_defs.h>
+/* Definitions for 4-bit hardware ECC */
+#define NAND_TIMEOUT 10240
+#define NAND_ECC_BUSY 0xC
+#define NAND_4BITECC_MASK 0x03FF03FF
+#define EMIF_NANDFSR_ECC_STATE_MASK 0x00000F00
+#define ECC_STATE_NO_ERR 0x0
+#define ECC_STATE_TOO_MANY_ERRS 0x1
+#define ECC_STATE_ERR_CORR_COMP_P 0x2
+#define ECC_STATE_ERR_CORR_COMP_N 0x3
+
static emif_registers *const emif_regs = (void *) DAVINCI_ASYNC_EMIF_CNTRL_BASE;
static void nand_davinci_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
@@ -170,6 +180,267 @@ static int nand_davinci_correct_data(struct mtd_info *mtd, u_char *dat, u_char *
}
#endif /* CONFIG_SYS_NAND_HW_ECC */
+#ifdef CONFIG_SYS_NAND_4BIT_HW_ECC_OOBFIRST
+static struct nand_ecclayout nand_davinci_4bit_layout_oobfirst = {
+/*
+ * TI uses a different layout for 4K page deviecs. Since the
+ * eccpos filed can hold only a limited number of entries, adding
+ * support for 4K page will result in compilation warnings
+ * 4K Support will be added later
+ */
+#ifdef CONFIG_SYS_NAND_PAGE_2K
+ .eccbytes = 40,
+ .eccpos = {
+ 24, 25, 26, 27, 28,
+ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
+ 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
+ 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
+ 59, 60, 61, 62, 63,
+ },
+ .oobfree = {
+ {.offset = 2, .length = 22, },
+ },
+#endif
+};
+
+static void nand_davinci_4bit_enable_hwecc(struct mtd_info *mtd, int mode)
+{
+ u32 val;
+
+ switch (mode) {
+ case NAND_ECC_WRITE:
+ case NAND_ECC_READ:
+ /*
+ * Start a new ECC calculation for reading or writing 512 bytes
+ * of data.
+ */
+ val = (emif_regs->NANDFCR & ~(3 << 4)) | (1 << 12);
+ emif_regs->NANDFCR = val;
+ break;
+ case NAND_ECC_READSYN:
+ val = emif_regs->NAND4BITECC1;
+ break;
+ default:
+ break;
+ }
+}
+
+static u32 nand_davinci_4bit_readecc(struct mtd_info *mtd, unsigned int ecc[4])
+{
+ ecc[0] = emif_regs->NAND4BITECC1 & NAND_4BITECC_MASK;
+ ecc[1] = emif_regs->NAND4BITECC2 & NAND_4BITECC_MASK;
+ ecc[2] = emif_regs->NAND4BITECC3 & NAND_4BITECC_MASK;
+ ecc[3] = emif_regs->NAND4BITECC4 & NAND_4BITECC_MASK;
+
+ return 0;
+}
+
+static int nand_davinci_4bit_calculate_ecc(struct mtd_info *mtd,
+ const uint8_t *dat,
+ uint8_t *ecc_code)
+{
+ unsigned int hw_4ecc[4] = { 0, 0, 0, 0 };
+ unsigned int const1 = 0, const2 = 0;
+ unsigned char count1 = 0;
+
+ nand_davinci_4bit_readecc(mtd, hw_4ecc);
+
+ /*Convert 10 bit ecc value to 8 bit */
+ for (count1 = 0; count1 < 2; count1++) {
+ const2 = count1 * 5;
+ const1 = count1 * 2;
+
+ /* Take first 8 bits from val1 (count1=0) or val5 (count1=1) */
+ ecc_code[const2] = hw_4ecc[const1] & 0xFF;
+
+ /*
+ * Take 2 bits as LSB bits from val1 (count1=0) or val5
+ * (count1=1) and 6 bits from val2 (count1=0) or
+ * val5 (count1=1)
+ */
+ ecc_code[const2 + 1] =
+ ((hw_4ecc[const1] >> 8) & 0x3) | ((hw_4ecc[const1] >> 14) &
+ 0xFC);
+
+ /*
+ * Take 4 bits from val2 (count1=0) or val5 (count1=1) and
+ * 4 bits from val3 (count1=0) or val6 (count1=1)
+ */
+ ecc_code[const2 + 2] =
+ ((hw_4ecc[const1] >> 22) & 0xF) |
+ ((hw_4ecc[const1 + 1] << 4) & 0xF0);
+
+ /*
+ * Take 6 bits from val3(count1=0) or val6 (count1=1) and
+ * 2 bits from val4 (count1=0) or val7 (count1=1)
+ */
+ ecc_code[const2 + 3] =
+ ((hw_4ecc[const1 + 1] >> 4) & 0x3F) |
+ ((hw_4ecc[const1 + 1] >> 10) & 0xC0);
+
+ /* Take 8 bits from val4 (count1=0) or val7 (count1=1) */
+ ecc_code[const2 + 4] = (hw_4ecc[const1 + 1] >> 18) & 0xFF;
+ }
+ return 0;
+}
+
+
+static int nand_davinci_4bit_correct_data(struct mtd_info *mtd, uint8_t *dat,
+ uint8_t *read_ecc, uint8_t *calc_ecc)
+{
+ unsigned short ecc_10bit[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+ int i;
+ unsigned int hw_4ecc[4] = { 0, 0, 0, 0 }, iserror = 0;
+ unsigned short *pspare = NULL, *pspare1 = NULL;
+ unsigned int numerrors, erroraddress, errorvalue;
+ u32 val;
+
+ /*
+ * Check for an ECC where all bytes are 0xFF. If this is the case, we
+ * will assume we are looking at an erased page and we should ignore
+ * the ECC.
+ */
+ for (i = 0; i < 10; i++) {
+ if (read_ecc[i] != 0xFF)
+ break;
+ }
+ if (i == 10)
+ return 0;
+
+ /* Convert 8 bit in to 10 bit */
+ pspare = (unsigned short *)&read_ecc[2];
+ pspare1 = (unsigned short *)&read_ecc[0];
+
+ /* Take 10 bits from 0th and 1st bytes */
+ ecc_10bit[0] = (*pspare1) & 0x3FF;
+
+ /* Take 6 bits from 1st byte and 4 bits from 2nd byte */
+ ecc_10bit[1] = (((*pspare1) >> 10) & 0x3F)
+ | (((pspare[0]) << 6) & 0x3C0);
+
+ /* Take 4 bits form 2nd bytes and 6 bits from 3rd bytes */
+ ecc_10bit[2] = ((pspare[0]) >> 4) & 0x3FF;
+
+ /*Take 2 bits from 3rd byte and 8 bits from 4th byte */
+ ecc_10bit[3] = (((pspare[0]) >> 14) & 0x3)
+ | ((((pspare[1])) << 2) & 0x3FC);
+
+ /* Take 8 bits from 5th byte and 2 bits from 6th byte */
+ ecc_10bit[4] = ((pspare[1]) >> 8)
+ | ((((pspare[2])) << 8) & 0x300);
+
+ /* Take 6 bits from 6th byte and 4 bits from 7th byte */
+ ecc_10bit[5] = (pspare[2] >> 2) & 0x3FF;
+
+ /* Take 4 bits from 7th byte and 6 bits from 8th byte */
+ ecc_10bit[6] = (((pspare[2]) >> 12) & 0xF)
+ | ((((pspare[3])) << 4) & 0x3F0);
+
+ /*Take 2 bits from 8th byte and 8 bits from 9th byte */
+ ecc_10bit[7] = ((pspare[3]) >> 6) & 0x3FF;
+
+ /*
+ * Write the parity values in the NAND Flash 4-bit ECC Load register.
+ * Write each parity value one at a time starting from 4bit_ecc_val8
+ * to 4bit_ecc_val1.
+ */
+ for (i = 7; i >= 0; i--)
+ emif_regs->NAND4BITECCLOAD = ecc_10bit[i];
+
+ /*
+ * Perform a dummy read to the EMIF Revision Code and Status register.
+ * This is required to ensure time for syndrome calculation after
+ * writing the ECC values in previous step.
+ */
+
+ val = emif_regs->NANDFSR;
+
+ /*
+ * Read the syndrome from the NAND Flash 4-Bit ECC 1-4 registers.
+ * A syndrome value of 0 means no bit errors. If the syndrome is
+ * non-zero then go further otherwise return.
+ */
+ nand_davinci_4bit_readecc(mtd, hw_4ecc);
+
+ if (hw_4ecc[0] == ECC_STATE_NO_ERR && hw_4ecc[1] == ECC_STATE_NO_ERR &&
+ hw_4ecc[2] == ECC_STATE_NO_ERR && hw_4ecc[3] == ECC_STATE_NO_ERR)
+ return 0;
+
+ /*
+ * Clear any previous address calculation by doing a dummy read of an
+ * error address register.
+ */
+ val = emif_regs->NANDERRADD1;
+
+ /*
+ * Set the addr_calc_st bit(bit no 13) in the NAND Flash Control
+ * register to 1.
+ */
+ emif_regs->NANDFCR |= 1 << 13;
+
+ /*
+ * Wait for the corr_state field (bits 8 to 11)in the
+ * NAND Flash Status register to be equal to 0x0, 0x1, 0x2, or 0x3.
+ */
+ i = NAND_TIMEOUT;
+ do {
+ val = emif_regs->NANDFSR;
+ val &= 0xc00;
+ i--;
+ } while ((i > 0) && val);
+
+ iserror = emif_regs->NANDFSR;
+ iserror &= EMIF_NANDFSR_ECC_STATE_MASK;
+ iserror = iserror >> 8;
+
+ /*
+ * ECC_STATE_TOO_MANY_ERRS (0x1) means errors cannot be
+ * corrected (five or more errors). The number of errors
+ * calculated (err_num field) differs from the number of errors
+ * searched. ECC_STATE_ERR_CORR_COMP_P (0x2) means error
+ * correction complete (errors on bit 8 or 9).
+ * ECC_STATE_ERR_CORR_COMP_N (0x3) means error correction
+ * complete (error exists).
+ */
+
+ if (iserror == ECC_STATE_NO_ERR) {
+ val = emif_regs->NANDERRVAL1;
+ return 0;
+ } else if (iserror == ECC_STATE_TOO_MANY_ERRS) {
+ val = emif_regs->NANDERRVAL1;
+ return -1;
+ }
+
+ numerrors = ((emif_regs->NANDFSR >> 16) & 0x3) + 1;
+
+ /* Read the error address, error value and correct */
+ for (i = 0; i < numerrors; i++) {
+ if (i > 1) {
+ erroraddress =
+ ((emif_regs->NANDERRADD2 >>
+ (16 * (i & 1))) & 0x3FF);
+ erroraddress = ((512 + 7) - erroraddress);
+ errorvalue =
+ ((emif_regs->NANDERRVAL2 >>
+ (16 * (i & 1))) & 0xFF);
+ } else {
+ erroraddress =
+ ((emif_regs->NANDERRADD1 >>
+ (16 * (i & 1))) & 0x3FF);
+ erroraddress = ((512 + 7) - erroraddress);
+ errorvalue =
+ ((emif_regs->NANDERRVAL1 >>
+ (16 * (i & 1))) & 0xFF);
+ }
+ /* xor the corrupt data with error value */
+ if (erroraddress < 512)
+ dat[erroraddress] ^= errorvalue;
+ }
+
+ return numerrors;
+}
+#endif /* CONFIG_SYS_NAND_4BIT_HW_ECC_OOBFIRST */
+
static int nand_davinci_dev_ready(struct mtd_info *mtd)
{
return emif_regs->NANDFSR & 0x1;
@@ -215,7 +486,7 @@ void davinci_nand_init(struct nand_chip *nand)
{
nand->chip_delay = 0;
#ifdef CONFIG_SYS_NAND_USE_FLASH_BBT
- nand->options = NAND_USE_FLASH_BBT;
+ nand->options |= NAND_USE_FLASH_BBT;
#endif
#ifdef CONFIG_SYS_NAND_HW_ECC
nand->ecc.mode = NAND_ECC_HW;
@@ -227,7 +498,15 @@ void davinci_nand_init(struct nand_chip *nand)
#else
nand->ecc.mode = NAND_ECC_SOFT;
#endif /* CONFIG_SYS_NAND_HW_ECC */
-
+#ifdef CONFIG_SYS_NAND_4BIT_HW_ECC_OOBFIRST
+ nand->ecc.mode = NAND_ECC_HW_OOB_FIRST;
+ nand->ecc.size = 512;
+ nand->ecc.bytes = 10;
+ nand->ecc.calculate = nand_davinci_4bit_calculate_ecc;
+ nand->ecc.correct = nand_davinci_4bit_correct_data;
+ nand->ecc.hwctl = nand_davinci_4bit_enable_hwecc;
+ nand->ecc.layout = &nand_davinci_4bit_layout_oobfirst;
+#endif
/* Set address of hardware control function */
nand->cmd_ctrl = nand_davinci_hwcontrol;
diff --git a/include/asm-arm/arch-davinci/emif_defs.h b/include/asm-arm/arch-davinci/emif_defs.h
index 646fc77..c91e30c 100644
--- a/include/asm-arm/arch-davinci/emif_defs.h
+++ b/include/asm-arm/arch-davinci/emif_defs.h
@@ -55,6 +55,16 @@ typedef struct {
dv_reg NANDF2ECC;
dv_reg NANDF3ECC;
dv_reg NANDF4ECC;
+ u_int8_t RSVD2[60];
+ dv_reg NAND4BITECCLOAD;
+ dv_reg NAND4BITECC1;
+ dv_reg NAND4BITECC2;
+ dv_reg NAND4BITECC3;
+ dv_reg NAND4BITECC4;
+ dv_reg NANDERRADD1;
+ dv_reg NANDERRADD2;
+ dv_reg NANDERRVAL1;
+ dv_reg NANDERRVAL2;
} emif_registers;
typedef emif_registers *emifregs;
--
1.6.0.4
2
1
Paulraj, Sandeep wrote:
> And please correct me if I am wrong, but J-C can't actually pull these patches into his next branch correct?
Right, not yet.
> That is because it will require 2 of the NAND patches that I sent a week ago.
>
> Thus you might have to accept the DM355 EVM config update patch as well which actually enables the NAND support.
I could do that with an ACK from JC if it does not depend on anything in
his tree -- or I could send Wolfgang a -next pull request and then JC
could sync with that.
-Scott
3
2

18 Aug '09
Support USB on PSC3 on the mpc5200. Before this patch, enabling USB support
would reconfigure PSC4 and PSC5 to USB. The mpc5200 does not support USB
enabled on both the standard USB port and PSC3. This patch masks the
appropriate bits when enabling USB.
Signed-off-by: Eric Millbrandt <emillbrandt(a)dekaresearch.com>
---
README | 4 ++++
cpu/mpc5xxx/usb.c | 6 +++++-
cpu/mpc5xxx/usb_ohci.c | 6 +++++-
3 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/README b/README
index 9071472..a8dc1cd 100644
--- a/README
+++ b/README
@@ -854,9 +854,13 @@ The following options need to be configured:
MPC5200 USB requires additional defines:
CONFIG_USB_CLOCK
for 528 MHz Clock: 0x0001bbbb
+ CONFIG_PSC3_USB
+ for USB on PSC3
CONFIG_USB_CONFIG
for differential drivers: 0x00001000
for single ended drivers: 0x00005000
+ for differential drivers on PSC3: 0x00000100
+ for single ended drivers on PSC3: 0x00004100
CONFIG_SYS_USB_EVENT_POLL
May be defined to allow interrupt polling
instead of using asynchronous interrupts
diff --git a/cpu/mpc5xxx/usb.c b/cpu/mpc5xxx/usb.c
index 8f2b66a..bec7da3 100644
--- a/cpu/mpc5xxx/usb.c
+++ b/cpu/mpc5xxx/usb.c
@@ -32,9 +32,13 @@ int usb_cpu_init(void)
/* Set the USB Clock */
*(vu_long *)MPC5XXX_CDM_48_FDC = CONFIG_USB_CLOCK;
+#ifdef CONFIG_PSC3_USB /* USB is using the alternate configuration */
+ /* remove all PSC3 USB bits first before ORing in ours */
+ *(vu_long *)MPC5XXX_GPS_PORT_CONFIG &= ~0x00804f00;
+#else
/* remove all USB bits first before ORing in ours */
*(vu_long *)MPC5XXX_GPS_PORT_CONFIG &= ~0x00807000;
-
+#endif
/* Activate USB port */
*(vu_long *)MPC5XXX_GPS_PORT_CONFIG |= CONFIG_USB_CONFIG;
diff --git a/cpu/mpc5xxx/usb_ohci.c b/cpu/mpc5xxx/usb_ohci.c
index 61a4e3f..66a4af8 100644
--- a/cpu/mpc5xxx/usb_ohci.c
+++ b/cpu/mpc5xxx/usb_ohci.c
@@ -1576,9 +1576,13 @@ int usb_lowlevel_init(void)
/* Set the USB Clock */
*(vu_long *)MPC5XXX_CDM_48_FDC = CONFIG_USB_CLOCK;
+#ifdef CONFIG_PSC3_USB /* USB is using the alternate configuration */
+ /* remove all PSC3 USB bits first before ORing in ours */
+ *(vu_long *)MPC5XXX_GPS_PORT_CONFIG &= ~0x00804f00;
+#else
/* remove all USB bits first before ORing in ours */
*(vu_long *)MPC5XXX_GPS_PORT_CONFIG &= ~0x00807000;
-
+#endif
/* Activate USB port */
*(vu_long *)MPC5XXX_GPS_PORT_CONFIG |= CONFIG_USB_CONFIG;
--
1.6.3.1
4
4
This RTC is used in some Calao boards. The driver code is taken from the
linux rtc-m41t94 driver
Signed-off-by: Albin Tonnerre <albin.tonnerre(a)free-electrons.com>
---
I guess the bin2bcd and bcd2bin functions belong somewhere in common/ rather
than this particular driver ... Where should I put them ?
drivers/rtc/Makefile | 1 +
drivers/rtc/m41t94.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 138 insertions(+), 0 deletions(-)
create mode 100644 drivers/rtc/m41t94.c
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 822dc1a..ea7d899 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -44,6 +44,7 @@ COBJS-$(CONFIG_RTC_ISL1208) += isl1208.o
COBJS-$(CONFIG_RTC_M41T11) += m41t11.o
COBJS-$(CONFIG_RTC_M41T60) += m41t60.o
COBJS-$(CONFIG_RTC_M41T62) += m41t62.o
+COBJS-$(CONFIG_RTC_M41T94) += m41t94.o
COBJS-$(CONFIG_RTC_M48T35A) += m48t35ax.o
COBJS-$(CONFIG_RTC_MAX6900) += max6900.o
COBJS-$(CONFIG_RTC_MC13783) += mc13783-rtc.o
diff --git a/drivers/rtc/m41t94.c b/drivers/rtc/m41t94.c
new file mode 100644
index 0000000..6e828a7
--- /dev/null
+++ b/drivers/rtc/m41t94.c
@@ -0,0 +1,137 @@
+/*
+ * Driver for ST M41T94 SPI RTC
+ *
+ * Taken from the Linux kernel drivier:
+ * Copyright (C) 2008 Kim B. Heino
+ *
+ * Adaptation for U-Boot:
+ * Copyright (C) 2009
+ * Albin Tonnerre, Free Electrons <albin.tonnerre(a)free-electrons.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <common.h>
+#include <rtc.h>
+#include <spi.h>
+
+static struct spi_slave *slave;
+
+#define M41T94_REG_SECONDS 0x01
+#define M41T94_REG_MINUTES 0x02
+#define M41T94_REG_HOURS 0x03
+#define M41T94_REG_WDAY 0x04
+#define M41T94_REG_DAY 0x05
+#define M41T94_REG_MONTH 0x06
+#define M41T94_REG_YEAR 0x07
+#define M41T94_REG_HT 0x0c
+
+#define M41T94_BIT_HALT 0x40
+#define M41T94_BIT_STOP 0x80
+#define M41T94_BIT_CB 0x40
+#define M41T94_BIT_CEB 0x80
+
+static unsigned bcd2bin (uchar n);
+static unsigned char bin2bcd (unsigned int n);
+
+int rtc_set(struct rtc_time *tm)
+{
+ u8 buf[8]; /* write cmd + 7 registers */
+ int ret;
+
+ if (!slave) {
+ slave = spi_setup_slave(CONFIG_M41T94_SPI_BUS,
+ CONFIG_M41T94_SPI_CS, 1000000,
+ SPI_MODE_3);
+ if (!slave)
+ return -1;
+ }
+ spi_claim_bus(slave);
+
+ buf[0] = 0x80 | M41T94_REG_SECONDS; /* write time + date */
+ buf[M41T94_REG_SECONDS] = bin2bcd(tm->tm_sec);
+ buf[M41T94_REG_MINUTES] = bin2bcd(tm->tm_min);
+ buf[M41T94_REG_HOURS] = bin2bcd(tm->tm_hour);
+ buf[M41T94_REG_WDAY] = bin2bcd(tm->tm_wday + 1);
+ buf[M41T94_REG_DAY] = bin2bcd(tm->tm_mday);
+ buf[M41T94_REG_MONTH] = bin2bcd(tm->tm_mon + 1);
+
+ buf[M41T94_REG_HOURS] |= M41T94_BIT_CEB;
+ if (tm->tm_year >= 100)
+ buf[M41T94_REG_HOURS] |= M41T94_BIT_CB;
+ buf[M41T94_REG_YEAR] = bin2bcd(tm->tm_year % 100);
+
+ ret = spi_xfer(slave, 64, buf, NULL, SPI_XFER_BEGIN | SPI_XFER_END);
+ spi_release_bus(slave);
+ return ret;
+}
+
+int rtc_get(struct rtc_time *tm)
+{
+ u8 buf[2];
+ int ret, hour;
+
+ if (!slave) {
+ slave = spi_setup_slave(CONFIG_M41T94_SPI_BUS,
+ CONFIG_M41T94_SPI_CS, 1000000,
+ SPI_MODE_3);
+ if (!slave)
+ return -1;
+ }
+ spi_claim_bus(slave);
+
+ /* clear halt update bit */
+ ret = spi_w8r8(slave, M41T94_REG_HT);
+ if (ret < 0)
+ return ret;
+ if (ret & M41T94_BIT_HALT) {
+ buf[0] = 0x80 | M41T94_REG_HT;
+ buf[1] = ret & ~M41T94_BIT_HALT;
+ spi_xfer(slave, 16, buf, NULL, SPI_XFER_BEGIN | SPI_XFER_END);
+ }
+
+ /* clear stop bit */
+ ret = spi_w8r8(slave, M41T94_REG_SECONDS);
+ if (ret < 0)
+ return ret;
+ if (ret & M41T94_BIT_STOP) {
+ buf[0] = 0x80 | M41T94_REG_SECONDS;
+ buf[1] = ret & ~M41T94_BIT_STOP;
+ spi_xfer(slave, 16, buf, NULL, SPI_XFER_BEGIN | SPI_XFER_END);
+ }
+
+ tm->tm_sec = bcd2bin(spi_w8r8(slave, M41T94_REG_SECONDS));
+ tm->tm_min = bcd2bin(spi_w8r8(slave, M41T94_REG_MINUTES));
+ hour = spi_w8r8(slave, M41T94_REG_HOURS);
+ tm->tm_hour = bcd2bin(hour & 0x3f);
+ tm->tm_wday = bcd2bin(spi_w8r8(slave, M41T94_REG_WDAY)) - 1;
+ tm->tm_mday = bcd2bin(spi_w8r8(slave, M41T94_REG_DAY));
+ tm->tm_mon = bcd2bin(spi_w8r8(slave, M41T94_REG_MONTH)) - 1;
+ tm->tm_year = bcd2bin(spi_w8r8(slave, M41T94_REG_YEAR));
+ if ((hour & M41T94_BIT_CB) || !(hour & M41T94_BIT_CEB))
+ tm->tm_year += 100;
+
+ spi_release_bus(slave);
+ return 0;
+}
+
+void rtc_reset(void)
+{
+ /*
+ * Could not be tested as the reset pin is not wired on
+ * the sbc35-ag20 board
+ */
+ return 0;
+}
+
+static unsigned bcd2bin (uchar n)
+{
+ return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
+}
+
+static unsigned char bin2bcd (unsigned int n)
+{
+ return (((n / 10) << 4) | (n % 10));
+}
--
1.6.0.4
3
4