Re: [U-Boot] [PATCH 6/7] getenv_f() env variable exist w/o needing a buffer
Dear James Yang, In message you wrote: > > > Hm... this adds a special case and as such increases complexity - and > > what is the benefit for you? > > The purpose is to avoid having to allocate memory for getenv_f() to What exactly is the problem of adding a dynamic variable on the stack? This is a way cheaper operation than adding the code here... > work. While the unmodified getenv_f() does let me do that if I pass > len=0, it has the side effect of printing a warning message that the > buffer is too small. I want to avoid this message from being printed > as well. Then just provide a big enough buffer. You don't bother about a few bytes of stack space, do you? They cost you nothing... > Part 7 of the patchset runs at a point where memory can only be > allocated from the stack. The stack is in cache, so any available RAM > is precious. The function that calls getenv_f() calls another This argument backfires - because if you detect that the variable is set, then you will call fsl_ddr_interactive(), which then will alocate a buffer (char buffer2[CONFIG_SYS_CBSIZE]) and call getenv_f() again, now for real. Actually you now need TWO such buffers - see this snippet from your patch 7/7: unsigned long long ddrsize; const char *prompt = "FSL DDR>"; char buffer[CONFIG_SYS_CBSIZE]; + char buffer2[CONFIG_SYS_CBSIZE]; + char *p = NULL; char *argv[CONFIG_SYS_MAXARGS + 1]; /* NULL terminated */ int argc; unsigned int next_step = STEP_GET_SPD; I. e. before one such buffer was sufficient, now you need two - if you care about memory, then dumpt his patch, and leave the code as is - both your code and your stack footprint will be smaller. > function, so allocating a buffer with an unmodified getenv_f() would > require the buffer to persist in the calling function's stack frame > uselessly. That buffer is of size CONFIG_SYS_CBSIZE, which is either > 256 or 1024, so I wouldn't call it non-critical. But you do this anyway, just in another part of the code. ANd there you even need two such buffers now! > I imagine that with the modified getenv_f(), other pre-relocation > features could be written to utilize the detection of environment > variables in a similar fashion. This patch set by itself should not > be considered as the sole usage case. Well, the use case you present shows that while the idea sounds good initially, the results tend to be worse than the existing code. You did not convince me that the addition is a good idea. > The description was not written to be a top-down procedural > description. Maybe reordering like this will make it seem more > correct? This will not remove the inconsistent behaviour of returning a 1 in one case, indepoendent of the actual length of the value, and the length in another case. And there is no need for such an inconsistency. > > > + if (!buf) > > > + return 1; > > > > I tend to NAK this part. > > Would it be acceptable if it returns 0 instead? The reason I chose 1 > is because all of the 100+ existing usages of getenv_f() check only > for return value > 0. I was trying to make it consistent with all of > those existing usage cases. Why don't you implement consistent behaviour and always return the correct length of the variable value, and -1 if the variable does not exist? Best regards, Wolfgang Denk -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de A failure will not appear until a unit has passed final inspection. ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] NOR NAND Interference question
Hi, Recently I am start getting strange problem with u-boot-2011.09. MPC8313ERDB like configuration ( main change - I am using different NAND flash - 256MBib - need change page size) If I am access NAND flash before nor u-boot not always read NOR correctly. >mtdparts device nor0 , # parts = 3 #: namesizeoffset mask_flags 0: u-boot 0x000e 0x 0 1: env 0x0002 0x000e 0 2: jffs2 0x01f0 0x0010 0 device nand0 , # parts = 1 #: namesizeoffset mask_flags 0: ubifs 0x1000 0x 0 If I do: ubi part ubifs;ubifsmount iptec_nand and read something from NAND before I read NOR I am getting time to time after Linux update uImage: >run boot_cmd ### JFFS2 loading 'BANK1/uImage' to 0x10 Scanning JFFS2 FS: . done. ### JFFS2 load complete: 4926025 bytes loaded to 0x10 ### JFFS2 loading 'BANK1/vnp100_dtb.dtb' to 0x90 ### JFFS2 load complete: 10205 bytes loaded to 0x90 ## Booting kernel from Legacy Image at 0010 ... Image Name: Linux-2.6.38.8 Image Type: PowerPC Linux Kernel Image (gzip compressed) Data Size:4925961 Bytes = 4.7 MiB Load Address: 0200 Entry Point: 0200 Verifying Checksum ... Bad Data CRC ERROR: can't get kernel image! but if I reset board and skip NAND access it always fine, some times I can add or remove some environment variable after NAND access and it boot even without reset: >run boot_cmd ### JFFS2 loading 'BANK1/uImage' to 0x10 Scanning JFFS2 FS: . done. ### JFFS2 load complete: 4926025 bytes loaded to 0x10 ### JFFS2 loading 'BANK1/vnp100_dtb.dtb' to 0x90 ### JFFS2 load complete: 10205 bytes loaded to 0x90 ## Booting kernel from Legacy Image at 0010 ... Image Name: Linux-2.6.38.8 Image Type: PowerPC Linux Kernel Image (gzip compressed) Data Size:4925961 Bytes = 4.7 MiB Load Address: 0200 Entry Point: 0200 Verifying Checksum ... OK ## Flattened Device Tree blob at 0090 Booting using the fdt blob at 0x90 Uncompressing Kernel Image ... OK Loading Device Tree to 007fa000, end 007ff7dc ... OK I found most stable configuration: mount NAND, read NAND, chaprt nor0,2 boot and most unstable chaprt nor0,2 mount NAND, read NAND, boot And I did increase malloc size to 1M.( ubifs does not like 128K). There is no option for stack size - it is PPC, so it should grow down as needed. As long I am not mixing NOR and NAND evithing working perfect. Any idea? Thanks, Andrei ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 6/7] getenv_f() env variable exist w/o needing a buffer
Hello Wolfgang, On Fri, 4 Jan 2013, Wolfgang Denk wrote: > Dear York Sun, > > In message <1357323245-12455-6-git-send-email-york...@freescale.com> you > wrote: > > From: James Yang > > > > getenv_f() searches the environment for a variable name and copies the > > value of the variable to a buffer pointed to by one of the function's > > parameters. However, this means that the buffer needs to exist and > > needs to be of sufficient length (passed as another parameter to > > getenv_f()) to hold the requested variable's value, even if all that is > > desired is the mere detection of the existence of the variable itself. > > > > This patch removes the requirement that the buffer needs to exist. If > > the pointer to the buffer is set to NULL and the requested variable is > > Hm... this adds a special case and as such increases complexity - and > what is the benefit for you? The purpose is to avoid having to allocate memory for getenv_f() to work. While the unmodified getenv_f() does let me do that if I pass len=0, it has the side effect of printing a warning message that the buffer is too small. I want to avoid this message from being printed as well. > In your code, you use this feature exactly once, which means all you > save is a single buffer on the stack of a function that does not > appear to be critical in terms of stack size. Part 7 of the patchset runs at a point where memory can only be allocated from the stack. The stack is in cache, so any available RAM is precious. The function that calls getenv_f() calls another function, so allocating a buffer with an unmodified getenv_f() would require the buffer to persist in the calling function's stack frame uselessly. That buffer is of size CONFIG_SYS_CBSIZE, which is either 256 or 1024, so I wouldn't call it non-critical. I suppose I could create another function that only calls the unmodified getenv_f() and returns a boolean as to whether or not that variable exists so that the buffer gets deallocated as soon as the function returns, but it would not avoid the need to have that memory to be actually allocated on the stack. Also, if the compiler inlines that function (this can be prevented as well), it would still make that memory persistent. I imagine that with the modified getenv_f(), other pre-relocation features could be written to utilize the detection of environment variables in a similar fashion. This patch set by itself should not be considered as the sole usage case. > > /* > > * Look up variable from environment for restricted C runtime env. > > + * If the variable is found, return the number of bytes copied. > > + * If buf is NULL, len is ignored, and, if the variable is found, return 1. > > + * If the variable is not found, return -1. > > I think your description is not quite correct, and I dislike the > inconsistent behaviour we get though your patch. So far, this > function returns the length of the variable value, or -1 in case of > errors. This should not change even if we implement the suggested > feature, i. e. even when passing NULL as buffer pointer the function > should still return the length, and not some unrelated result. The description was not written to be a top-down procedural description. Maybe reordering like this will make it seem more correct? > > + * If buf is NULL, len is ignored, and, if the variable is found, return 1. > > + * If the variable is found, return the number of bytes copied. > > + * If the variable is not found, return -1. > > + /* found */ > > + if (!buf) > > + return 1; > > I tend to NAK this part. Would it be acceptable if it returns 0 instead? The reason I chose 1 is because all of the 100+ existing usages of getenv_f() check only for return value > 0. I was trying to make it consistent with all of those existing usage cases. Regards, --James -- James YangDigital Networking james.y...@freescale.com Freescale Semiconductor ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH v3] mx6: Add workaround for ARM errata
From: Fabio Estevam Add workaround for the following ARM errata: 743622 and 751472. The motivation for this change is the following kernel commit 62e4d357a (ARM: 7609/1: disable errata work-arounds which access secure registers), which removes the errata from multiplatform kernel. Since imx has been converted to multiplatform in the kernel, we need to apply such workarounds into the bootloader. Workaround code has been taken from arch/arm/mm/proc-v7.S from 3.7.1 kernel. Explanation of each erratum is provided at "Chip Errata for the i.MX 6Dual/6Quad" document available at: cache.freescale.com/files/32bit/doc/errata/IMX6DQCE.pdf Signed-off-by: Fabio Estevam --- Following patch has been proposed into arm kernel mailing list: http://www.spinics.net/lists/arm-kernel/msg214840.html Changes since v2: - Use c15 register (which match both the mx6 errata and kernel code) and also put a note to mx6q erratum document. Changes since v1: - Use the same style of the erratum in arch/arm/cpu/armv7/mx5/lowlevel_init.S. arch/arm/cpu/armv7/mx6/lowlevel_init.S | 10 ++ 1 file changed, 10 insertions(+) diff --git a/arch/arm/cpu/armv7/mx6/lowlevel_init.S b/arch/arm/cpu/armv7/mx6/lowlevel_init.S index acadef2..bf06152 100644 --- a/arch/arm/cpu/armv7/mx6/lowlevel_init.S +++ b/arch/arm/cpu/armv7/mx6/lowlevel_init.S @@ -20,6 +20,16 @@ #include +.macro init_arm_errata + /* ARM erratum ID #743622 */ + mrc p15, 0, r10, c15, c0, 1 /* read diagnostic register */ + orr r10, r10, #1 << 6 /* set bit #6 */ + /* ARM erratum ID #751472 */ + orr r10, r10, #1 << 11 /* set bit #11 */ + mcr p15, 0, r10, c15, c0, 1 /* write diagnostic register */ +.endm + ENTRY(lowlevel_init) + init_arm_errata mov pc, lr ENDPROC(lowlevel_init) -- 1.7.9.5 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] is it possilbe to have uboot find the kernel in the file system?
Hi John Stile, On 01/05/2013 09:25 AM, John Stile wrote: u-boot-2012.10 build does compile with buildroot's .conf settings BR2_TARGET_UBOOT_BOARDNAME="at91sam9g20ek_dataflash_cs1" or BR2_TARGET_UBOOT_BOARDNAME="at91sam9g20ek_nandflash" But after writing my ubootEnvtFileDataFlash.bin to NOR with sam-ba utility (which works with the u-boot-1.3.4), it is not found by the ROM boot loader, so I'm not sure where to go for help. I know ROM boot loader executes what ever it finds at NOR start (0xD000) +0x8400. Does anyone else use a at91sam uboot-2012 and sam-ba, or have any other suggestions? Please check the text base of u-boot for at91sam9g20ek. If you use the old bootstrap, it jump to 0x23f0 after reading u-boot, while the v2012.10 u-boot use 0x21f0 as its text base. If so, you can change u-boot or bootstrap to keep the two address the same. Best Regards, Bo Shen ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 39/44] mkimage: Add -c option to specify a comment for key signing
When signing an image, it is useful to add some details about which tool or person is authorising the signing. Add a comment field which can take care of miscellaneous requirements. Signed-off-by: Simon Glass --- doc/mkimage.1 |6 ++ tools/fit_image.c |2 +- tools/mkimage.c |8 +++- tools/mkimage.h |1 + 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/doc/mkimage.1 b/doc/mkimage.1 index f9c733a..b67a351 100644 --- a/doc/mkimage.1 +++ b/doc/mkimage.1 @@ -97,6 +97,12 @@ Set XIP (execute in place) flag. .B Create FIT image: .TP +.BI "\-c [" "comment" "]" +Specifies a comment to be added when signing. This is typically a useful +message which describes how the image was signed or some other useful +information. + +.TP .BI "\-D [" "dtc options" "]" Provide special options to the device tree compiler that is used to create the image. diff --git a/tools/fit_image.c b/tools/fit_image.c index 835d2fb..82f1597 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -153,7 +153,7 @@ static int fit_handle_file (struct mkimage_params *params) /* set hashes for images in the blob */ if (fit_add_verification_data(params->keydir, - dest_blob, ptr, NULL, 0)) { + dest_blob, ptr, params->comment, 0)) { fprintf (stderr, "%s Can't add hashes to FIT blob", params->cmdname); goto err_add_hashes; diff --git a/tools/mkimage.c b/tools/mkimage.c index 99787d9..d6e47a5 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -183,6 +183,11 @@ main (int argc, char **argv) genimg_get_arch_id (*++argv)) < 0) usage (); goto NXTARG; + case 'c': + if (--argc <= 0) + usage(); + params.comment = *++argv; + goto NXTARG; case 'C': if ((--argc <= 0) || (params.comp = @@ -636,7 +641,8 @@ usage () " -x ==> set XIP (execute in place)\n", params.cmdname); fprintf(stderr, " %s [-k keydir] [-K dtb] [-D dtc_options]" - " [-f fit-image.its|-F] fit-image\n", params.cmdname); + " [ -c ] [-f fit-image.its|-F] fit-image\n", + params.cmdname); fprintf (stderr, " %s -V ==> print version information and exit\n", params.cmdname); diff --git a/tools/mkimage.h b/tools/mkimage.h index 41bec21..4391ca8 100644 --- a/tools/mkimage.h +++ b/tools/mkimage.h @@ -77,6 +77,7 @@ struct mkimage_params { char *cmdname; const char *keydir; /* Directory holding private keys */ const char *keydest;/* Destination .dtb for public key */ + const char *comment;/* Comment to add to signature node */ }; /* -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 25/44] Add stdarg to vsprintf.h
This file uses varargs, so add the header file so that it can be used when common has not been included. TODO: Probably should drop this patch? Signed-off-by: Simon Glass --- include/vsprintf.h |2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/include/vsprintf.h b/include/vsprintf.h index 651077c..704b8cd 100644 --- a/include/vsprintf.h +++ b/include/vsprintf.h @@ -24,6 +24,8 @@ #ifndef __VSPRINTF_H #define __VSPRINTF_H +#include + ulong simple_strtoul(const char *cp, char **endp, unsigned int base); /** -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 41/44] libfdt: Add fdt_find_regions()
Add a function to find regions in device tree given a list of nodes to include and properties to exclude. See the header file for full documentation. Signed-off-by: Simon Glass --- include/libfdt.h | 64 + lib/libfdt/fdt_wip.c | 129 ++ 2 files changed, 193 insertions(+), 0 deletions(-) diff --git a/include/libfdt.h b/include/libfdt.h index 0dfb8a0..c765abe 100644 --- a/include/libfdt.h +++ b/include/libfdt.h @@ -1492,4 +1492,68 @@ int fdt_del_node(void *fdt, int nodeoffset); const char *fdt_strerror(int errval); +struct fdt_region { + int offset; + int size; +}; + +/** + * fdt_find_regions() - find regions in device tree + * + * Given a list of nodes to include and properties to exclude, find + * the regions of the device tree which describe those included parts. + * + * The intent is to get a list of regions which will be invariant provided + * those parts are invariant. For example, if you request a list of regions + * for all nodes but exclude the property "data", then you will get the + * same region contents regardless of any change to "data" properties. + * + * This function can be used to produce a byte-stream to send to a hashing + * function to verify that critical parts of the FDT have not changed. + * + * Nodes which are given in 'inc' are included in the region list, as + * are the names of the immediate subnodes nodes (but not the properties + * or subnodes of those subnodes). + * + * For eaxample "/" means to include the root node, all root properties + * and the FDT_BEGIN_NODE and FDT_END_NODE of all subnodes of /. The latter + * ensures that we capture the names of the subnodes. In a hashing situation + * it prevents the root node from changing at all Any change to non-excluded + * properties, names of subnodes or number of subnodes would be detected. + * + * When used with FITs this provides the ability to hash and sign parts of + * the FIT based on different configurations in the FIT. Then it is + * impossible to change anything about that configuration (include images + * attached to the configuration), but it may be possible to add new + * configurations, new images or new signatures within the existing + * framework. + * + * Adding new properties to a device tree may result in the string table + * being extended (if the new property names are different from those + * already added). This function can optionally include a region for + * the string table so that this can be part of the hash too. + * + * The device tree header is not included in the list. + * + * @fdt: Device tree to check + * @inc: List of node paths to included + * @inc_count: Number of node paths in list + * @exc_prop: List of properties names to exclude + * @exc_prop_count:Number of properties in exclude list + * @region:Returns list of regions + * @max_region:Maximum length of region list + * @path: Pointer to a temporary string for the function to use for + * building path names + * @path_len: Length of path, must be large enough to hold the longest + * path in the tree + * @add_string_tab:1 to add a region for the string table + * @return number of regions in list. If this is >max_regions then the + * region array was exhausted. You should increase max_regions and try + * the call again. + */ +int fdt_find_regions(const void *fdt, char * const inc[], int inc_count, +char * const exc_prop[], int exc_prop_count, +struct fdt_region region[], int max_regions, +char *path, int path_len, int add_string_tab); + #endif /* _LIBFDT_H */ diff --git a/lib/libfdt/fdt_wip.c b/lib/libfdt/fdt_wip.c index e373677..7fcc2a3 100644 --- a/lib/libfdt/fdt_wip.c +++ b/lib/libfdt/fdt_wip.c @@ -120,3 +120,132 @@ int fdt_nop_node(void *fdt, int nodeoffset) endoffset - nodeoffset); return 0; } + +#define FDT_MAX_DEPTH 32 + +static int str_in_list(const char *str, char * const list[], int count) +{ + int i; + + for (i = 0; i < count; i++) + if (!strcmp(list[i], str)) + return 1; + + return 0; +} + +int fdt_find_regions(const void *fdt, char * const inc[], int inc_count, +char * const exc_prop[], int exc_prop_count, +struct fdt_region region[], int max_regions, +char *path, int path_len, int add_string_tab) +{ + int stack[FDT_MAX_DEPTH]; + char *end; + int nextoffset = 0; + uint32_t tag; + int count = 0; + int start = -1; + int depth = -1; + int want = 0; + int base = fdt_off_dt_struct(fdt); + + end = path; + *end = '\0'; + do { + const struct fdt_property *prop; + const char *name; + int include = 0; + int stop_at = 0; + int offset; +
[U-Boot] [RFC PATCH 42/44] image: Add support for signing of FIT configurations
While signing images is useful, it does not provide complete protection against several types of attack. For example, it it possible to create a FIT with the same signed images, but with the configuration changed such that a different one is selected (mix and match attack). It is also possible to substitute a signed image from an older FIT version into a newer FIT (roll-back attack). Add support for signing of FIT configurations using the libfdt's region support. Please see doc/uImage.FIT/signature.txt for more information. Signed-off-by: Simon Glass --- common/cmd_bootm.c | 12 ++ common/image-sig.c | 212 +++- doc/uImage.FIT/sign-configs.its | 45 + doc/uImage.FIT/signature.txt| 167 ++- include/image.h | 15 ++ tools/image-host.c | 350 ++- 6 files changed, 798 insertions(+), 3 deletions(-) create mode 100644 doc/uImage.FIT/sign-configs.its diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index cac9e53..d71ffb5 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -972,6 +972,18 @@ static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc, NULL); printf(" Using '%s' configuration\n", images->fit_uname_cfg); + if (IMAGE_ENABLE_VERIFY && images->verify) { + puts(" Verifying Hash Integrity ... "); + if (!fit_config_verify(fit_hdr, + cfg_noffset)) { + puts("Bad Data Hash\n"); + bootstage_error( + BOOTSTAGE_ID_FIT_CHECK_HASH); + return NULL; + } + puts("OK\n"); + } + bootstage_mark(BOOTSTAGE_ID_FIT_CONFIG); os_noffset = fit_conf_get_kernel_node(fit_hdr, diff --git a/common/image-sig.c b/common/image-sig.c index c74d2f4..cfbb6ed 100644 --- a/common/image-sig.c +++ b/common/image-sig.c @@ -25,7 +25,6 @@ #include DECLARE_GLOBAL_DATA_PTR; #endif /* !USE_HOSTCC*/ -#include #include #include @@ -50,6 +49,27 @@ struct image_sig_algo *image_get_sig_algo(const char *name) return NULL; } +struct image_region *fit_region_make_list(const void *fit, + struct fdt_region *fdt_regions, int count) +{ + struct image_region *region; + int i; + + debug("Hash regions:\n"); + debug("%10s %10s\n", "Offset", "Size"); + region = calloc(sizeof(*region), count); + if (!region) + return NULL; + for (i = 0; i < count; i++) { + debug("%10x %10x\n", fdt_regions[i].offset, + fdt_regions[i].size); + region[i].data = fit + fdt_regions[i].offset; + region[i].size = fdt_regions[i].size; + } + + return region; +} + static int fit_image_setup_verify(struct image_sign_info *info, const void *fit, int noffset, int required_keynode, char **err_msgp) @@ -195,3 +215,193 @@ int fit_image_verify_required_sigs(const void *fit, int image_noffset, return 0; } + +int fit_config_check_sig(const void *fit, int noffset, int required_keynode, +char **err_msgp) +{ + char * const exc_prop[] = {"data"}; + struct fdt_region *fdt_regions; + const char *prop, *end, *name; + struct image_sign_info info; + struct image_region *region; + const uint32_t *strings; + uint8_t *fit_value; + int fit_value_len; + int max_regions; + char **node_inc; + int i, prop_len; + char path[200]; + int count; + + debug("%s: fdt=%p, conf='%s', sig='%s'\n", __func__, gd_fdt_blob(), + fit_get_name(fit, noffset, NULL), + fit_get_name(gd_fdt_blob(), required_keynode, NULL)); + *err_msgp = NULL; + if (fit_image_setup_verify(&info, fit, noffset, required_keynode, + err_msgp)) + return -1; + + if (fit_image_hash_get_value(fit, noffset, &fit_value, + &fit_value_len)) { + *err_msgp = "Can't get hash value property"; + return -1; + } + + /* Count the number of strings in the property */ + prop = fdt_getprop(fit, noffset, "hashed-nodes", &prop_len); + end = prop ? prop + prop_len : prop; + for (name = prop, count = 0; name < end; name++) + if (!*name) + count++; + if (!count) { + *err_msgp = "Can't get hashed-nodes property"; + return -1; +
[U-Boot] [RFC PATCH 36/44] mkimage: Add -k option to specify key directory
Keys required for signing images will be in a specific directory. Add a -k option to specify that directory. Also update the mkimage man page with this information and a clearer list of available commands. Signed-off-by: Simon Glass --- doc/mkimage.1 | 25 ++--- tools/fit_image.c |2 +- tools/mkimage.c |9 +++-- tools/mkimage.h |1 + 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/doc/mkimage.1 b/doc/mkimage.1 index 39652c8..6740fb1 100644 --- a/doc/mkimage.1 +++ b/doc/mkimage.1 @@ -4,7 +4,14 @@ mkimage \- Generate image for U-Boot .SH SYNOPSIS .B mkimage -.RB [\fIoptions\fP] +.RB "\-l [" "uimage file name" "]" + +.B mkimage +.RB [\fIoptions\fP] " \-f [" "image tree source file" "]" " [" "uimage file name" "]" + +.B mkimage +.RB [\fIoptions\fP] " (legacy mode)" + .SH "DESCRIPTION" The .B mkimage @@ -26,7 +33,8 @@ etc. The new .I FIT (Flattened Image Tree) format allows for more flexibility in handling images of various types and also -enhances integrity protection of images with stronger checksums. +enhances integrity protection of images with stronger checksums. It also +supports verified boot. .SH "OPTIONS" @@ -67,6 +75,10 @@ Set load address with a hex number. Set entry point with a hex number. .TP +.BI "\-l" +List the contents of an image. + +.TP .BI "\-n [" "image name" "]" Set image name to 'image name'. @@ -91,6 +103,12 @@ create the image. Image tree source file that describes the structure and contents of the FIT image. +.TP +.BI "\-k [" "key_directory" "]" +Specifies the directory containing keys to use for signing. This directory +should contain a private key file .key for use with signing and a +certificate .crt (containing the public key) for use with verification. + .SH EXAMPLES List image information: @@ -115,4 +133,5 @@ http://www.denx.de/wiki/U-Boot/WebHome .PP .SH AUTHOR This manual page was written by Nobuhiro Iwamatsu -and Wolfgang Denk +and Wolfgang Denk . It was updated for image signing by +Simon Glass . diff --git a/tools/fit_image.c b/tools/fit_image.c index 0f619a2..5d04f96 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -137,7 +137,7 @@ static int fit_handle_file (struct mkimage_params *params) goto err_mmap; /* set hashes for images in the blob */ - if (fit_add_verification_data(NULL, NULL, ptr, NULL, 0)) { + if (fit_add_verification_data(params->keydir, NULL, ptr, NULL, 0)) { fprintf (stderr, "%s Can't add hashes to FIT blob", params->cmdname); goto err_add_hashes; diff --git a/tools/mkimage.c b/tools/mkimage.c index e43b09f..0eae136 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -248,6 +248,11 @@ main (int argc, char **argv) params.datafile = *++argv; params.fflag = 1; goto NXTARG; + case 'k': + if (--argc <= 0) + usage(); + params.keydir = *++argv; + goto NXTARG; case 'n': if (--argc <= 0) usage (); @@ -623,8 +628,8 @@ usage () " -d ==> use image data from 'datafile'\n" " -x ==> set XIP (execute in place)\n", params.cmdname); - fprintf (stderr, " %s [-D dtc_options] -f fit-image.its fit-image\n", - params.cmdname); + fprintf(stderr, " %s [-k keydir] [-D dtc_options]" + " -f fit-image.its fit-image\n", params.cmdname); fprintf (stderr, " %s -V ==> print version information and exit\n", params.cmdname); diff --git a/tools/mkimage.h b/tools/mkimage.h index e07a615..2a5f115 100644 --- a/tools/mkimage.h +++ b/tools/mkimage.h @@ -75,6 +75,7 @@ struct mkimage_params { char *datafile; char *imagefile; char *cmdname; + const char *keydir; /* Directory holding private keys */ }; /* -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 34/44] image: Add RSA support for image signing
RSA provides a public key encryption facility which is ideal for image signing and verification. Images are signed using a private key by mkimage. Then at run-time, the images are verified using a private key. This implementation uses openssl for the host part (mkimage). To avoid bringing large libraries into the U-Boot binary, the RSA public key is encoded using a simple numeric representation in the device tree. Signed-off-by: Simon Glass --- Makefile |1 + README | 10 + common/image-sig.c |7 + config.mk|1 + include/rsa.h| 108 lib/rsa/Makefile | 46 + lib/rsa/rsa-sign.c | 454 ++ lib/rsa/rsa-verify.c | 374 + tools/Makefile | 15 ++- 9 files changed, 1013 insertions(+), 3 deletions(-) create mode 100644 include/rsa.h create mode 100644 lib/rsa/Makefile create mode 100644 lib/rsa/rsa-sign.c create mode 100644 lib/rsa/rsa-verify.c diff --git a/Makefile b/Makefile index ee21b24..3ce0c7b 100644 --- a/Makefile +++ b/Makefile @@ -246,6 +246,7 @@ OBJS := $(addprefix $(obj),$(OBJS) $(RESET_OBJS-)) HAVE_VENDOR_COMMON_LIB = $(if $(wildcard board/$(VENDOR)/common/Makefile),y,n) LIBS-y += lib/libgeneric.o +LIBS-y += lib/rsa/librsa.o LIBS-y += lib/lzma/liblzma.o LIBS-y += lib/lzo/liblzo.o LIBS-y += lib/zlib/libz.o diff --git a/README b/README index 46918c4..a637f91 100644 --- a/README +++ b/README @@ -2461,6 +2461,16 @@ CBFS (Coreboot Filesystem) support Note: There is also a sha1sum command, which should perhaps be deprecated in favour of 'hash sha1'. +- Signing support: + CONFIG_RSA + + This enables the RSA algorithm used for FIT image verification + in U-Boot. See doc/uImage/signature for more information. + + The signing part is build into mkimage regardless of this + option. + + - Show boot progress: CONFIG_SHOW_BOOT_PROGRESS diff --git a/common/image-sig.c b/common/image-sig.c index 793e7d6..c74d2f4 100644 --- a/common/image-sig.c +++ b/common/image-sig.c @@ -27,8 +27,15 @@ DECLARE_GLOBAL_DATA_PTR; #endif /* !USE_HOSTCC*/ #include #include +#include struct image_sig_algo image_sig_algos[] = { + { + "sha1,rsa2048", + rsa_sign, + rsa_add_verify_data, + rsa_verify, + } }; struct image_sig_algo *image_get_sig_algo(const char *name) diff --git a/config.mk b/config.mk index 04cfe89..74e2922 100644 --- a/config.mk +++ b/config.mk @@ -91,6 +91,7 @@ HOSTCFLAGS+= $(call os_x_before, 10, 4, "-traditional-cpp") HOSTLDFLAGS+= $(call os_x_before, 10, 5, "-multiply_defined suppress") else HOSTCC = gcc +HOSTLIBS += -lssl -lcrypto endif ifeq ($(HOSTOS),cygwin) diff --git a/include/rsa.h b/include/rsa.h new file mode 100644 index 000..a5dd676 --- /dev/null +++ b/include/rsa.h @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2013, Google Inc. + * + * (C) Copyright 2008 Semihalf + * + * (C) Copyright 2000-2006 + * Wolfgang Denk, DENX Software Engineering, w...@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 + */ + +#ifndef _RSA_H +#define _RSA_H + +#include +#include + +#if IMAGE_ENABLE_SIGN +/** + * sign() - calculate and return signature for given input data + * + * @info: Specifies key and FIT information + * @data: Pointer to the input data + * @data_len: Data length + * @sigp: Set to an allocated buffer holding the signature + * @sig_len: Set to length of the calculated hash + * + * This computes input data signature according to selected algorithm. + * Resulting signature value is placed in an allocated buffer, the + * pointer is returned as *sigp. The length of the calculated + * signature is returned via the sig_len pointer argument. The caller + * should free *sigp. + * + * @return: 0, on success, -ve on error + */ +int rsa_sign(struct image_sign_info *info, +const struct image_region region[], +int region_count, uint8_t **sigp, uint *sig_len); + +/** + * add_verify_data() - Add verification
[U-Boot] [RFC PATCH 38/44] mkimage: Add -F option to modify an existing .fit file
When signing images it is sometimes necessary to sign with different keys at different times, or make the signer entirely separate from the FIT creation to avoid needing the private keys to be publicly available in the system. Add a -F option so that key signing can be a separate step, and possibly done multiple times as different keys are avaiable. Signed-off-by: Simon Glass --- doc/mkimage.1 | 20 tools/fit_image.c | 18 -- tools/mkimage.c |6 -- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/doc/mkimage.1 b/doc/mkimage.1 index 8185ff5..f9c733a 100644 --- a/doc/mkimage.1 +++ b/doc/mkimage.1 @@ -10,6 +10,9 @@ mkimage \- Generate image for U-Boot .RB [\fIoptions\fP] " \-f [" "image tree source file" "]" " [" "uimage file name" "]" .B mkimage +.RB [\fIoptions\fP] " \-F [" "uimage file name" "]" + +.B mkimage .RB [\fIoptions\fP] " (legacy mode)" .SH "DESCRIPTION" @@ -104,6 +107,13 @@ Image tree source file that describes the structure and contents of the FIT image. .TP +.BI "\-F" +Indicates that an existing FIT image should be modified. No dtc +compilation is performed and the -f flag should not be given. +This can be used to sign images with additional keys after initial image +creation. + +.TP .BI "\-k [" "key_directory" "]" Specifies the directory containing keys to use for signing. This directory should contain a private key file .key for use with signing and a @@ -144,6 +154,16 @@ skipping those for which keys cannot be found. Also add a comment. -c "Kernel 3.8 image for production devices" kernel.itb .fi +.P +Update an existing FIT image, signing it with additional keys. +Add corresponding public keys into u-boot.dtb. This will resign all images +with keys that are available in the new directory. Images that request signing +with unavailable keys are skipped. +.nf +.B mkimage -F -k /secret/signing-keys -K u-boot.dtb +-c "Kernel 3.8 image for production devices" kernel.itb +.fi + .SH HOMEPAGE http://www.denx.de/wiki/U-Boot/WebHome .PP diff --git a/tools/fit_image.c b/tools/fit_image.c index 306298a..835d2fb 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -124,10 +124,16 @@ static int fit_handle_file (struct mkimage_params *params) } sprintf (tmpfile, "%s%s", params->imagefile, MKIMAGE_TMPFILE_SUFFIX); - /* dtc -I dts -O dtb -p 500 datafile > tmpfile */ - sprintf (cmd, "%s %s %s > %s", - MKIMAGE_DTC, params->dtc, params->datafile, tmpfile); - debug ("Trying to execute \"%s\"\n", cmd); + /* We either compile the source file, or use the existing FIT image */ + if (params->datafile) { + /* dtc -I dts -O dtb -p 500 datafile > tmpfile */ + snprintf(cmd, sizeof(cmd), "%s %s %s > %s", + MKIMAGE_DTC, params->dtc, params->datafile, tmpfile); + debug("Trying to execute \"%s\"\n", cmd); + } else { + snprintf(cmd, sizeof(cmd), "cp %s %s", + params->imagefile, tmpfile); + } if (system (cmd) == -1) { fprintf (stderr, "%s: system(%s) failed: %s\n", params->cmdname, cmd, strerror(errno)); @@ -153,8 +159,8 @@ static int fit_handle_file (struct mkimage_params *params) goto err_add_hashes; } - /* add a timestamp at offset 0 i.e., root */ - if (fit_set_timestamp (ptr, 0, sbuf.st_mtime)) { + /* for first image creation, add a timestamp at offset 0 i.e., root */ + if (params->datafile && fit_set_timestamp(ptr, 0, sbuf.st_mtime)) { fprintf (stderr, "%s: Can't add image timestamp\n", params->cmdname); goto err_add_timestamp; diff --git a/tools/mkimage.c b/tools/mkimage.c index 30a5a06..99787d9 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -240,12 +240,14 @@ main (int argc, char **argv) case 'f': if (--argc <= 0) usage (); + params.datafile = *++argv; + /* no break */ + case 'F': /* * The flattened image tree (FIT) format * requires a flattened device tree image type */ params.type = IH_TYPE_FLATDT; - params.datafile = *++argv; params.fflag = 1; goto NXTARG; case 'k': @@ -634,7 +636,7 @@ usage () " -x ==> set XIP (execute in place)\n", params.cmdname); fprintf(stderr, " %s [-k keydir] [-K dtb] [-D dtc_options]" - " -f fit-image.its f
[U-Boot] [RFC PATCH 30/44] sandbox: image: Add support for booting images in sandbox
Much of the image code uses addresses as ulongs and pointers interchangeably, casting between the two forms as needed. This doesn't work with sandbox, which has a U-Boot RAM buffer which is separate from the host machine's memory. Adjust the cost so that translating from a U-Boot address to a pointer uses map_sysmem(). This allows bootm to work correctly on sandbox. Note that there are no exhaustive tests for this code on sandbox, so it is possible that some dark corners remain. Signed-off-by: Simon Glass --- common/cmd_bootm.c | 21 - common/image.c | 46 +++--- include/image.h|2 +- 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index 7b07393..cac9e53 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #if defined(CONFIG_CMD_USB) @@ -92,7 +93,7 @@ static image_header_t *image_get_kernel(ulong img_addr, int verify); static int fit_check_kernel(const void *fit, int os_noffset, int verify); #endif -static void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc, +static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], bootm_headers_t *images, ulong *os_data, ulong *os_len); @@ -192,8 +193,8 @@ static inline void boot_start_lmb(bootm_headers_t *images) { } static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - void*os_hdr; - int ret; + const void *os_hdr; + int ret; memset((void *)&images, 0, sizeof(images)); images.verify = getenv_yesno("verify"); @@ -837,14 +838,15 @@ static int fit_check_kernel(const void *fit, int os_noffset, int verify) * pointer to image header if valid image was found, plus kernel start * address and length, otherwise NULL */ -static void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc, +static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], bootm_headers_t *images, ulong *os_data, ulong *os_len) { image_header_t *hdr; ulong img_addr; + const void *buf; #if defined(CONFIG_FIT) - void*fit_hdr; + const void *fit_hdr; const char *fit_uname_config = NULL; const char *fit_uname_kernel = NULL; const void *data; @@ -880,7 +882,8 @@ static void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc, /* check image type, for FIT images get FIT kernel node */ *os_data = *os_len = 0; - switch (genimg_get_format((void *)img_addr)) { + buf = map_sysmem(img_addr, 0); + switch (genimg_get_format(buf)) { case IMAGE_FORMAT_LEGACY: printf("## Booting kernel from Legacy Image at %08lx ...\n", img_addr); @@ -925,7 +928,7 @@ static void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc, break; #if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: - fit_hdr = (void *)img_addr; + fit_hdr = buf; printf("## Booting kernel from FIT Image at %08lx ...\n", img_addr); @@ -1002,7 +1005,7 @@ static void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc, *os_len = len; *os_data = (ulong)data; - images->fit_hdr_os = fit_hdr; + images->fit_hdr_os = (void *)fit_hdr; images->fit_uname_os = fit_uname_kernel; images->fit_noffset_os = os_noffset; break; @@ -1016,7 +1019,7 @@ static void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc, debug(" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n", *os_data, *os_len, *os_len); - return (void *)img_addr; + return buf; } #ifdef CONFIG_SYS_LONGHELP diff --git a/common/image.c b/common/image.c index 554f269..ed7dd7c 100644 --- a/common/image.c +++ b/common/image.c @@ -52,6 +52,7 @@ #include #include +#include #ifdef CONFIG_CMD_BDI extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); @@ -91,6 +92,7 @@ static const table_entry_t uimage_arch[] = { { IH_ARCH_AVR32, "avr32","AVR32",}, { IH_ARCH_NDS32, "nds32","NDS32",}, { IH_ARCH_OPENRISC, "or1k", "OpenRISC 1000",}, + { IH_ARCH_SANDBOX,"sandbox", "Sandbox", }, { -1, "", "", }, }; @@ -661,7 +663,7 @@ int genimg_get_comp_id(const char *name) * returns: * image format type or IMAGE_FORMAT_INVALID if no image is present */ -
[U-Boot] [RFC PATCH 28/44] sandbox: config: Enable FIT signatures with RSA
We want to sign and verify images using sandbox, so enable these options. Signed-off-by: Simon Glass --- include/configs/sandbox.h |2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index 1c7bbe1..fb1c583 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -33,6 +33,8 @@ #define CONFIG_OF_LIBFDT #define CONFIG_LMB #define CONFIG_FIT +#define CONFIG_FIT_SIGNATURE +#define CONFIG_RSA #define CONFIG_CMD_FDT #define CONFIG_FS_FAT -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 21/44] sandbox: fdt: Support fdt command for sandbox
By using map_sysmem() we can get the fdt command to work correctly with sandbox. Signed-off-by: Simon Glass --- common/cmd_fdt.c | 10 -- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c index a193cc3..3d5ff0f 100644 --- a/common/cmd_fdt.c +++ b/common/cmd_fdt.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -56,7 +57,10 @@ struct fdt_header *working_fdt; void set_working_fdt_addr(void *addr) { - working_fdt = addr; + void *buf; + + buf = map_sysmem((ulong)addr, 0); + working_fdt = buf; setenv_addr("fdtaddr", addr); } @@ -132,14 +136,16 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } addr = simple_strtoul(argv[0], NULL, 16); - blob = (void *)addr; if (control) { #ifdef CONFIG_OF_CONTROL + blob = map_sysmem(addr, 0); if (!fdt_valid(gd->fdt_blob)) return 1; gd->fdt_blob = blob; #endif } else { + blob = map_sysmem(addr, 0); + if (!fdt_valid(blob)) return 1; set_working_fdt_addr((void *)addr); -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 32/44] image: Support signing of images
Add support for signing images using a new signature node. The process is handled by fdt_add_verification_data() which now takes parameters to provide the keys and related information. Signed-off-by: Simon Glass --- doc/uImage.FIT/sign-images.its | 42 + include/image.h| 22 - tools/fit_image.c |2 +- tools/image-host.c | 181 +-- 4 files changed, 232 insertions(+), 15 deletions(-) create mode 100644 doc/uImage.FIT/sign-images.its diff --git a/doc/uImage.FIT/sign-images.its b/doc/uImage.FIT/sign-images.its new file mode 100644 index 000..f69326a --- /dev/null +++ b/doc/uImage.FIT/sign-images.its @@ -0,0 +1,42 @@ +/dts-v1/; + +/ { + description = "Chrome OS kernel image with one or more FDT blobs"; + #address-cells = <1>; + + images { + kernel@1 { + data = /incbin/("test-kernel.bin"); + type = "kernel_noload"; + arch = "sandbox"; + os = "linux"; + compression = "none"; + load = <0x4>; + entry = <0x8>; + kernel-version = <1>; + signature@1 { + algo = "sha1,rsa2048"; + key-name-hint = "dev"; + }; + }; + fdt@1 { + description = "snow"; + data = /incbin/("sandbox-kernel.dtb"); + type = "flat_dt"; + arch = "sandbox"; + compression = "none"; + fdt-version = <1>; + signature@1 { + algo = "sha1,rsa2048"; + key-name-hint = "dev"; + }; + }; + }; + configurations { + default = "conf@1"; + conf@1 { + kernel = "kernel@1"; + fdt = "fdt@1"; + }; + }; +}; diff --git a/include/image.h b/include/image.h index 8c648dc..a1072c0 100644 --- a/include/image.h +++ b/include/image.h @@ -611,12 +611,26 @@ int fit_image_hash_get_ignore(const void *fit, int noffset, int *ignore); int fit_set_timestamp(void *fit, int noffset, time_t timestamp); /** - * fit_add_verification_data() - Calculate and add hashes to FIT + * fit_add_verification_data() - add verification data to FIT image nodes * - * @fit: Fit image to process - * @return 0 if ok, <0 for error + * @keydir:Directory containing keys + * @kwydest: FDT blob to write public key information to + * @fit: Pointer to the FIT format image header + * @comment: Comment to add to signature nodes + * @require_keys: Mark all keys as 'required' + * + * Adds hash values for all component images in the FIT blob. + * Hashes are calculated for all component images which have hash subnodes + * with algorithm property set to one of the supported hash algorithms. + * + * Also add signatures if signature nodes are present. + * + * returns + * 0, on success + * libfdt error code, on failure */ -int fit_add_verification_data(void *fit); +int fit_add_verification_data(const char *keydir, void *keydest, void *fit, + const char *comment, int require_keys); int fit_image_verify(const void *fit, int noffset); int fit_all_image_verify(const void *fit); diff --git a/tools/fit_image.c b/tools/fit_image.c index 8f51159..e0675d7 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -125,7 +125,7 @@ static int fit_handle_file (struct mkimage_params *params) } /* set hashes for images in the blob */ - if (fit_add_verification_data(ptr)) { + if (fit_add_verification_data(NULL, NULL, ptr, NULL, 0)) { fprintf (stderr, "%s Can't add hashes to FIT blob", params->cmdname); unlink (tmpfile); diff --git a/tools/image-host.c b/tools/image-host.c index 4c589af..4196190 100644 --- a/tools/image-host.c +++ b/tools/image-host.c @@ -26,12 +26,8 @@ */ #include "mkimage.h" -#include #include -#include -#include -#include -#include +#include /** * fit_set_hash_value - set hash value in requested has node @@ -113,9 +109,161 @@ static int fit_image_process_hash(void *fit, const char *image_name, } /** - * fit_image_add_verification_data() - calculate/set hash data for image node + * fit_image_write_sig() - write the signature to a FIT * - * This adds hash values for a component image node. + * This writes the signature and signer data to the FIT. + * + * @fit: pointer to the FIT format image header + * @noffset: hash node offset + * @value: signature value to be set + * @value_len: signature value length + * @comment: Text comment to write (NULL for none) + *
[U-Boot] [RFC PATCH 31/44] image: Add signing infrastructure
Add a structure to describe an algorithm which can sign and (later) verify images. Signed-off-by: Simon Glass --- README |5 + common/Makefile |1 + common/image-sig.c | 42 + doc/uImage.FIT/signature.txt | 211 ++ include/image.h | 99 +++- tools/Makefile |2 + 6 files changed, 359 insertions(+), 1 deletions(-) create mode 100644 common/image-sig.c create mode 100644 doc/uImage.FIT/signature.txt diff --git a/README b/README index e54279e..46918c4 100644 --- a/README +++ b/README @@ -2685,6 +2685,11 @@ FIT uImage format: most specific compatibility entry of U-Boot's fdt's root node. The order of entries in the configuration's fdt is ignored. + CONFIG_FIT_SIGNATURE + This option enables signature verification of FIT uImages, + using a hash signed and verified using RSA. See + doc/uImage.FIT/signature.txt for more details. + - Standalone program support: CONFIG_STANDALONE_LOAD_ADDR diff --git a/common/Makefile b/common/Makefile index f945911..8208b0b 100644 --- a/common/Makefile +++ b/common/Makefile @@ -224,6 +224,7 @@ COBJS-y += console.o COBJS-y += dlmalloc.o COBJS-y += image.o COBJS-$(CONFIG_FIT) += image-fit.o +COBJS-$(CONFIG_FIT_SIGNATURE) += image-sig.o COBJS-y += memsize.o COBJS-y += stdio.o diff --git a/common/image-sig.c b/common/image-sig.c new file mode 100644 index 000..841c662 --- /dev/null +++ b/common/image-sig.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2013, Google Inc. + * + * 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 + */ + +#ifdef USE_HOSTCC +#include "mkimage.h" +#include +#else +#include +#endif /* !USE_HOSTCC*/ +#include +#include + +struct image_sig_algo image_sig_algos[] = { +}; + +struct image_sig_algo *image_get_sig_algo(const char *name) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(image_sig_algos); i++) { + if (!strcmp(image_sig_algos[i].name, name)) + return &image_sig_algos[i]; + } + + return NULL; +} diff --git a/doc/uImage.FIT/signature.txt b/doc/uImage.FIT/signature.txt new file mode 100644 index 000..48aa616 --- /dev/null +++ b/doc/uImage.FIT/signature.txt @@ -0,0 +1,211 @@ +U-Boot FIT Signature Verification += + +Introduction + +FIT supports hashing of images so that these hashes can be checked on +loading. This protects against corruption of the image. However it does not +prevent the substitution of one image for another. + +The signature feature allows the hash to be signed with a private key such +that it can be verified using a public key later. Provided that the private +key is kept secret and the public key is stored in a non-volatile place, +any image can be verified in this way. + +See verified-boot.txt for more general information on verified boot. + + +Concepts + +Some familiarity with public key cryptography is assumed in this section. + +The procedure for signing is as follows: + + - hash the image + - sign the hash with a private key to produce a signature + - store the resulting signature in the FIT + +The procedure for verification is: + + - read the FIT + - obtain the public key + - extract the signature from the FIT + - hash the image + - verify (with the public key) that the extracted signature matches the + hash + +The signing is generally performed by mkimage, as part of making a firmware +image for the device. The verification is normally done in U-Boot on the +device. + + +Algorithms +-- +In general any suitable algorithm can be used to sign and verify a hash. +At present only one class of algorithms is supported: SHA1 hashing with RSA. +This works by hashing the image to produce a 20--byte hash. + +While it is acceptable to bring in cryptography libraries such as openssl +on the host side (e.g. mkimage), it is not desirable for U-Boot. For the +run-time verification side, it is important to keep code and data size as +small as possible. + +For this reason the RSA image verification uses pre-processed public keys +which can be used with a very small amount of code
[U-Boot] [RFC PATCH 27/44] hash: Add a way to calculate a hash for any algortihm
Rather than needing to call one of many hashing algorithms in U-Boot, provide a function hash_block() which handles this, and can support all available hash algorithms. Once we have md5 supported within hashing, we can use this function in the FIT image code. Signed-off-by: Simon Glass --- common/hash.c | 22 ++ include/hash.h | 15 +++ 2 files changed, 37 insertions(+), 0 deletions(-) diff --git a/common/hash.c b/common/hash.c index 2e0a67b..897b9a3 100644 --- a/common/hash.c +++ b/common/hash.c @@ -29,6 +29,7 @@ #include #include #include +#include /* * These are the hash algorithms we support. Chips which support accelerated @@ -171,6 +172,27 @@ static void show_hash(struct hash_algo *algo, ulong addr, ulong len, printf("%02x", output[i]); } +int hash_block(const char *algo_name, const void *data, int len, + uint8_t *output, int *output_size) +{ + struct hash_algo *algo; + + algo = find_hash_algo(algo_name); + if (!algo) { + debug("Unknown hash algorithm '%s'\n", algo_name); + return -EPROTONOSUPPORT; + } + if (output_size && *output_size < algo->digest_size) { + debug("Output buffer size %d too small (need %d bytes)", + *output_size, algo->digest_size); + return -ENOSPC; + } + *output_size = algo->digest_size; + algo->hash_func_ws(data, len, output, algo->chunk_size); + + return 0; +} + int hash_command(const char *algo_name, int verify, cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { diff --git a/include/hash.h b/include/hash.h index ba2ba65..dda6f79 100644 --- a/include/hash.h +++ b/include/hash.h @@ -66,4 +66,19 @@ struct hash_algo { int hash_command(const char *algo_name, int verify, cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); +/** + * hash_block() - Hash a block according to the requested algorithm + * + * @algo_name: Hash algorithm to use + * @data: Data to hash + * @len: Lengh of data to hash in bytes + * @output:Place to put hash value + * @output_size: On entry, the number of bytes available in output, + * On exit, the number of bytes used + * @return 0 if ok, -ve on error: -EPROTONOSUPPORT for an unknown algorithm, + * -ENOSPC if the output buffer is not large enough. + */ +int hash_block(const char *algo_name, const void *data, int len, + uint8_t *output, int *output_size); + #endif -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 43/44] Add verified boot information and test
Add a description of how to implement verified boot using signed FIT images, and a simple test which verifies operation on sandbox. Signed-off-by: Simon Glass --- doc/uImage.FIT/verified-boot.txt | 104 test/vboot/.gitignore|3 + test/vboot/sandbox-kernel.dts|7 ++ test/vboot/sandbox-u-boot.dts|7 ++ test/vboot/sign-configs.its | 45 ++ test/vboot/sign-images.its | 42 + test/vboot/vboot_test.sh | 122 ++ 7 files changed, 330 insertions(+), 0 deletions(-) create mode 100644 doc/uImage.FIT/verified-boot.txt create mode 100644 test/vboot/.gitignore create mode 100644 test/vboot/sandbox-kernel.dts create mode 100644 test/vboot/sandbox-u-boot.dts create mode 100644 test/vboot/sign-configs.its create mode 100644 test/vboot/sign-images.its create mode 100755 test/vboot/vboot_test.sh diff --git a/doc/uImage.FIT/verified-boot.txt b/doc/uImage.FIT/verified-boot.txt new file mode 100644 index 000..9fff66d --- /dev/null +++ b/doc/uImage.FIT/verified-boot.txt @@ -0,0 +1,104 @@ +U-Boot Verified Boot + + +Introduction + +Verified boot here means the verification of all software loaded into a +machine during the boot process to ensure that it is authorised and correct +for that machine. + +Verified boot extends from the moment of system reset to as far as you wish +into the boot process. An example might be loading U-Boot from read-only +memory, then loading a signed kernel, then using the kernel's dm-verity +driver to mount a signed root filesystem. + +A key point is that it is possible to field-upgrade the software on machines +which use verified boot. Since the machine will only run software that has +been correctly signed, it is safe to read software from an updatable medium. +It is also possible to add a secondary signed firmware image, in read-write +memory, so that firmware can easily be upgraded in a secure manner. + + +Signing +--- +Verified boot uses cryptographic algorithms to 'sign' software images. +Images are signed using a private key known only to the signer, but can +be verified using a public key. As its name suggests the public key can be +made available without risk to the verification process. The private and +public keys are mathematically related. For more information on how this +works look up "public key cryptography" and "RSA" (a particular algorithm). + +The signing and verification process looks something like this: + + + Signing Verification + === + + +--+ * + | RSA key pair | * +---+ + | .key .crt | * | Public key in | + +--+ +--> public key ->| trusted place | + || * +---+ + || *| + v| *v + +-+ | * +--+ + | |--+ * | | + | signer | * |U-Boot| + | |--+ * | signature |--> yes/no + +-+ | * | verification | + ^ | * | | + | | * +--+ + | | *^ + +--+ | *| + | Software | +> signed image -+ + | image | * + +--+ * + + +The signature algorithm relies only on the public key to do its work. Using +this key it checks the signature that it finds in the image. If it verifies +then we know that the image is OK. + +The public key from the signer allows us to verify and therefore trust +software from updatable memory. + +It is critical that the public key be secure and cannot be tampered with. +It can be stored in read-only memory, or perhaps protected by other on-chip +crypto provided by some modern SOCs. If the public key can ben changed, then +the verification is worthless. + + +Chaining Images +--- +The above method works for a signer providing images to a run-time U-Boot. +It is also possible to extend this scheme to a second level, like this: + +1. Master private key is used by the signer to sign a first-stage image. +2. Master public key is placed in read-only memory. +2. Secondary private key is created and used to sign second-stage images. +3. Secondary public key is placed in first stage images +4. We use the master public key to verify the first-stage image. We then +use the secondary
[U-Boot] [RFC PATCH 29/44] sandbox: Provide a way to map from host RAM to U-Boot RAM
In many cases, pointers to memory are passed around, and these pointers refer to U-Boot memory, not host memory. This in itself is not a problem. However, in a few places, we cast that pointer back to a ulong (being a U-Boot memory address). It is possible to convert many of these cases to avoid this. However there are data structures (e.g. struct bootm_headers) which use pointers. We could with a lot of effort adjust the structs and all code that uses them to use ulong instead of pointers. This seems like an unacceptable cost, since our objective with sandbox is to minimise the impact on U-Boot code while maximising the features available to sandbox. Therefore, create a map_to_sysmem() function which converts from a pointer to a U-Boot address. This can be used sparingly when needed. Signed-off-by: Simon Glass --- arch/sandbox/cpu/cpu.c|5 + arch/sandbox/include/asm/io.h |2 ++ include/common.h |5 + 3 files changed, 12 insertions(+), 0 deletions(-) diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c index d7684d3..6459b01 100644 --- a/arch/sandbox/cpu/cpu.c +++ b/arch/sandbox/cpu/cpu.c @@ -57,6 +57,11 @@ void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags) return (void *)(gd->ram_buf + paddr); } +phys_addr_t map_to_sysmem(void *ptr) +{ + return (u8 *)ptr - gd->ram_buf; +} + void flush_dcache_range(unsigned long start, unsigned long stop) { } diff --git a/arch/sandbox/include/asm/io.h b/arch/sandbox/include/asm/io.h index d8c0236..4ce7a84 100644 --- a/arch/sandbox/include/asm/io.h +++ b/arch/sandbox/include/asm/io.h @@ -49,3 +49,5 @@ static inline void *map_sysmem(phys_addr_t paddr, unsigned long len) static inline void unmap_sysmem(const void *vaddr) { } + +phys_addr_t map_to_sysmem(void *ptr); diff --git a/include/common.h b/include/common.h index cc6bf5e..d2249b1 100644 --- a/include/common.h +++ b/include/common.h @@ -896,6 +896,11 @@ static inline void *map_sysmem(phys_addr_t paddr, unsigned long len) static inline void unmap_sysmem(const void *vaddr) { } + +static inline phys_addr_t map_to_sysmem(void *ptr) +{ + return (phys_addr_t)ptr; +} # endif #endif /* __ASSEMBLY__ */ -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 44/44] WIP: sandbox: config: Add test config for verified boot
This adds a test command to sandbox so that it can be used for running verified boot tests. This patch is not intended to be merged. Signed-off-by: Simon Glass --- include/configs/sandbox.h | 14 +- 1 files changed, 13 insertions(+), 1 deletions(-) diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index fb1c583..baf892a 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -24,6 +24,7 @@ #define CONFIG_NR_DRAM_BANKS 1 #define CONFIG_DRAM_SIZE (128 << 20) +#define CONFIG_SYS_TEXT_BASE 0 /* Number of bits in a C 'long' on this architecture */ #define CONFIG_SANDBOX_BITS_PER_LONG 64 @@ -107,8 +108,19 @@ #define CONFIG_BOOTARGS "" +#define CONFIG_SANDBOX_ENV \ + "test=sb load host 0 100 test.fit; " \ + "fdt addr 100;" \ + "bootm 100;" \ + "reset;" \ + "\0" + #define CONFIG_EXTRA_ENV_SETTINGS "stdin=serial\0" \ "stdout=serial\0" \ - "stderr=serial\0" + "stderr=serial\0" \ + CONFIG_SANDBOX_ENV + +#define CONFIG_BOOTCOMMAND "run test" +#define CONFIG_BOOTDELAY 0 /* -1 to disable auto boot */ #endif -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 06/44] image: Export fit_check_ramdisk()
One we split out the FIT code from image.c we will need this function. Export it in the header. Signed-off-by: Simon Glass --- common/image.c |9 ++--- include/image.h |3 +++ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/common/image.c b/common/image.c index b75a9d0..c030e1a 100644 --- a/common/image.c +++ b/common/image.c @@ -50,14 +50,9 @@ #include #endif -#if defined(CONFIG_FIT) #include #include -static int fit_check_ramdisk(const void *fit, int os_noffset, - uint8_t arch, int verify); -#endif - #ifdef CONFIG_CMD_BDI extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); #endif @@ -3364,8 +3359,8 @@ void fit_conf_print(const void *fit, int noffset, const char *p) * 0, on failure */ #ifndef USE_HOSTCC -static int fit_check_ramdisk(const void *fit, int rd_noffset, uint8_t arch, - int verify) +int fit_check_ramdisk(const void *fit, int rd_noffset, uint8_t arch, + int verify) { fit_image_print(fit, rd_noffset, " "); diff --git a/include/image.h b/include/image.h index e8ddb8f..7543512 100644 --- a/include/image.h +++ b/include/image.h @@ -630,6 +630,9 @@ int fit_conf_get_fdt_node(const void *fit, int noffset); void fit_conf_print(const void *fit, int noffset, const char *p); +int fit_check_ramdisk(const void *fit, int os_noffset, + uint8_t arch, int verify); + #ifndef USE_HOSTCC static inline int fit_image_check_target_arch(const void *fdt, int node) { -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 17/44] sandbox: Add CONFIG_OF_HOSTFILE to read FDT from host file
With sandbox it is tricky to add an FDT to the image at build time (or later) since we build an ELF file, not a plain binary, and the address space of the whole U-Boot is not accessible in the emulated memory map of sandbox. Sandbox can read files directly from the host, though, so add an option to read an FDT from a host file on start-up. Signed-off-by: Simon Glass --- arch/sandbox/cpu/start.c |7 ++ arch/sandbox/include/asm/state.h |1 + arch/sandbox/lib/board.c | 42 - doc/README.fdt-control |6 - include/configs/sandbox.h|2 + 5 files changed, 51 insertions(+), 7 deletions(-) diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index 7603bf9..8589da2 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -104,6 +104,13 @@ static int sb_cmdline_cb_command(struct sandbox_state *state, const char *arg) } SB_CMDLINE_OPT_SHORT(command, 'c', 1, "Execute U-Boot command"); +static int sb_cmdline_cb_fdt(struct sandbox_state *state, const char *arg) +{ + state->fdt_fname = arg; + return 0; +} +SB_CMDLINE_OPT_SHORT(fdt, 'd', 1, "Specify U-Boot's control FDT"); + int main(int argc, char *argv[]) { struct sandbox_state *state; diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h index 2b62b46..9552708 100644 --- a/arch/sandbox/include/asm/state.h +++ b/arch/sandbox/include/asm/state.h @@ -34,6 +34,7 @@ enum exit_type_id { /* The complete state of the test system */ struct sandbox_state { const char *cmd;/* Command to execute */ + const char *fdt_fname; /* Filename of FDT binary */ enum exit_type_id exit_type;/* How we exited U-Boot */ const char *parse_err; /* Error to report from parsing */ int argc; /* Program arguments */ diff --git a/arch/sandbox/lib/board.c b/arch/sandbox/lib/board.c index 83858c1..0e4df4c 100644 --- a/arch/sandbox/lib/board.c +++ b/arch/sandbox/lib/board.c @@ -39,13 +39,15 @@ #include #include +#include +#include #include +#include #include #include #include #include - -#include +#include DECLARE_GLOBAL_DATA_PTR; @@ -89,6 +91,21 @@ static int display_dram_config(void) return 0; } +static int read_fdt_from_file(void) +{ + struct sandbox_state *state = state_get_current(); + int size; + + if (fs_set_blk_dev("host", NULL, FS_TYPE_SANDBOX)) + return 1; + size = fs_read(state->fdt_fname, CONFIG_SYS_FDT_LOAD_ADDR, 0, 0); + if (size < 0) + return 1; + gd->fdt_blob = map_sysmem(CONFIG_SYS_FDT_LOAD_ADDR, size); + + return 0; +} + /* * Breathe some life into the board... * @@ -127,6 +144,9 @@ init_fnc_t *init_sequence[] = { #if defined(CONFIG_ARCH_CPU_INIT) arch_cpu_init, /* basic arch cpu dependent setup */ #endif +#ifdef CONFIG_OF_CONTROL + fdtdec_check_fdt, +#endif #if defined(CONFIG_BOARD_EARLY_INIT_F) board_early_init_f, #endif @@ -156,6 +176,10 @@ void board_init_f(ulong bootflag) assert(gd); memset((void *)gd, 0, sizeof(gd_t)); + mem = os_malloc(CONFIG_SYS_SDRAM_SIZE); + + assert(mem); + gd->ram_buf = mem; #if defined(CONFIG_OF_EMBED) /* Get a pointer to the FDT */ @@ -163,6 +187,8 @@ void board_init_f(ulong bootflag) #elif defined(CONFIG_OF_SEPARATE) /* FDT is at end of image */ gd->fdt_blob = (void *)(_end_ofs + _TEXT_BASE); +#elif defined(CONFIG_OF_HOSTFILE) + read_fdt_from_file(); #endif for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { @@ -170,11 +196,15 @@ void board_init_f(ulong bootflag) hang(); } - size = CONFIG_SYS_SDRAM_SIZE; - mem = os_malloc(CONFIG_SYS_SDRAM_SIZE); +#ifdef CONFIG_OF_CONTROL + /* For now, put this check after the console is ready */ + if (fdtdec_prepare_fdt()) { + panic("** CONFIG_OF_CONTROL defined but no FDT - please see " + "doc/README.fdt-control"); + } +#endif - assert(mem); - gd->ram_buf = mem; + size = CONFIG_SYS_SDRAM_SIZE; addr = (ulong)(mem + size); /* diff --git a/doc/README.fdt-control b/doc/README.fdt-control index 85bda03..69c69de 100644 --- a/doc/README.fdt-control +++ b/doc/README.fdt-control @@ -142,7 +142,11 @@ join the two: and then flash image.bin onto your board. -You cannot use both of these options at the same time. +If CONFIG_OF_HOSTFILE os defined, then it will be read from a file on +startup. This is only useful for sandbox. Use the -d flag to U-Boot to +specify the file to read. + +You cannot use more than one of these options at the same time. If you wish to put the fdt at a different address in memory, you can define the "fdtcontroladdr" environment variable. This is the he
[U-Boot] [RFC PATCH 18/44] fdt: Add a parameter to fdt_valid()
At present this only checks working_fdt, but we want to check other FDTs also. So add the FDT to check as a parameter to fdt_valid(). Signed-off-by: Simon Glass --- common/cmd_fdt.c | 27 ++- 1 files changed, 14 insertions(+), 13 deletions(-) diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c index 0bdf7b6..0adebf1 100644 --- a/common/cmd_fdt.c +++ b/common/cmd_fdt.c @@ -44,7 +44,7 @@ */ DECLARE_GLOBAL_DATA_PTR; -static int fdt_valid(void); +static int fdt_valid(const void *blob); static int fdt_parse_prop(char *const*newval, int count, char *data, int *len); static int fdt_print(const char *pathp, char *prop, int depth); static int is_printable_string(const void *data, int len); @@ -105,7 +105,8 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) * Set the address [and length] of the fdt. */ if (argc == 2) { - if (!fdt_valid()) { + if (!fdt_valid(working_fdt)) { + working_fdt = NULL; return 1; } printf("The address of the fdt is %p\n", working_fdt); @@ -115,7 +116,8 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) addr = simple_strtoul(argv[2], NULL, 16); set_working_fdt_addr((void *)addr); - if (!fdt_valid()) { + if (!fdt_valid(working_fdt)) { + working_fdt = NULL; return 1; } @@ -168,7 +170,8 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) * Set the address and length of the fdt. */ working_fdt = (struct fdt_header *)simple_strtoul(argv[2], NULL, 16); - if (!fdt_valid()) { + if (!fdt_valid(working_fdt)) { + working_fdt = NULL; return 1; } @@ -593,16 +596,16 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) // -static int fdt_valid(void) +static int fdt_valid(const void *blob) { int err; - if (working_fdt == NULL) { + if (blob == NULL) { printf ("The address of the fdt is invalid (NULL).\n"); return 0; } - err = fdt_check_header(working_fdt); + err = fdt_check_header(blob); if (err == 0) return 1; /* valid */ @@ -612,19 +615,17 @@ static int fdt_valid(void) * Be more informative on bad version. */ if (err == -FDT_ERR_BADVERSION) { - if (fdt_version(working_fdt) < + if (fdt_version(blob) < FDT_FIRST_SUPPORTED_VERSION) { printf (" - too old, fdt %d < %d", - fdt_version(working_fdt), + fdt_version(blob), FDT_FIRST_SUPPORTED_VERSION); - working_fdt = NULL; } - if (fdt_last_comp_version(working_fdt) > + if (fdt_last_comp_version(blob) > FDT_LAST_SUPPORTED_VERSION) { printf (" - too new, fdt %d > %d", - fdt_version(working_fdt), + fdt_version(blob), FDT_LAST_SUPPORTED_VERSION); - working_fdt = NULL; } return 0; } -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 19/44] Add getenv_hex() to return an environment variable as hex
This conversion is required in a number of places in U-Boot. Add a standard function to provide this feature, so we avoid all the different variations in the way it is coded. Signed-off-by: Simon Glass --- common/cmd_nvedit.c | 15 +++ include/common.h| 13 + 2 files changed, 28 insertions(+), 0 deletions(-) diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index d646d90..d6d5eea 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -309,6 +309,21 @@ int setenv_hex(const char *varname, ulong value) return setenv(varname, str); } +ulong getenv_hex(const char *varname, ulong default_val) +{ + const char *s; + ulong value; + char *endp; + + s = getenv(varname); + if (s) + value = simple_strtoul(s, &endp, 16); + if (!s || endp == s) + return default_val; + + return value; +} + #ifndef CONFIG_SPL_BUILD static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { diff --git a/include/common.h b/include/common.h index 8ecaf56..cc6bf5e 100644 --- a/include/common.h +++ b/include/common.h @@ -341,6 +341,19 @@ intenvmatch (uchar *, int); char *getenv (const char *); intgetenv_f (const char *name, char *buf, unsigned len); ulong getenv_ulong(const char *name, int base, ulong default_val); + +/** + * getenv_hex() - Return an environment variable as a hex value + * + * Decode an environment as a hex number (it may or may not have a 0x + * prefix). If the environment variable cannot be found, or does not start + * with hex digits, the default value is returned. + * + * @varname: Variable to decode + * @default_val: Value to return on error + */ +ulong getenv_hex(const char *varname, ulong default_val); + /* * Read an environment variable as a boolean * Return -1 if variable does not exist (default to true) -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 40/44] mkimage: Add -r option to specify keys that must be verified
Normally, multiple public keys can be provided and U-Boot is not required to use all of them for verification. This is because some images may not be signed, or may be optionally signed. But we still need a mechanism to determine when a key must be used. This feature cannot be implemented in the FIT itself, since anyone could change it to mark a key as optional. The requirement for key verification must go in with the public keys, in a place that is protected from modification. Add a -r option which tells mkimage to mark all keys that it uses for signing as 'required'. If some keys are optional and some are required, run mkimage several times (perhaps with different key directories if some keys are very secret) using the -F flag to update an existing FIT. Signed-off-by: Simon Glass --- doc/mkimage.1 |6 ++ tools/fit_image.c |5 +++-- tools/mkimage.c |7 +-- tools/mkimage.h |1 + 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/doc/mkimage.1 b/doc/mkimage.1 index b67a351..14374da 100644 --- a/doc/mkimage.1 +++ b/doc/mkimage.1 @@ -133,6 +133,12 @@ the corresponding public key is written into this file for for run-time verification. Typically the file here is the device tree binary used by CONFIG_OF_CONTROL in U-Boot. +.TP +.BI "\-r +Specifies that keys used to sign the FIT are required. This means that they +must be verified for the image to boot. Without this option, the verification +will be optional (useful for testing but not for release). + .SH EXAMPLES List image information: diff --git a/tools/fit_image.c b/tools/fit_image.c index 82f1597..0b9f091 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -153,8 +153,9 @@ static int fit_handle_file (struct mkimage_params *params) /* set hashes for images in the blob */ if (fit_add_verification_data(params->keydir, - dest_blob, ptr, params->comment, 0)) { - fprintf (stderr, "%s Can't add hashes to FIT blob", + dest_blob, ptr, params->comment, + params->require_keys)) { + fprintf(stderr, "%s Can't add hashes to FIT blob\n", params->cmdname); goto err_add_hashes; } diff --git a/tools/mkimage.c b/tools/mkimage.c index d6e47a5..8af84ce 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -270,6 +270,9 @@ main (int argc, char **argv) usage (); params.imagename = *++argv; goto NXTARG; + case 'r': + params.require_keys = 1; + break; case 'R': if (--argc <= 0) usage(); @@ -641,8 +644,8 @@ usage () " -x ==> set XIP (execute in place)\n", params.cmdname); fprintf(stderr, " %s [-k keydir] [-K dtb] [-D dtc_options]" - " [ -c ] [-f fit-image.its|-F] fit-image\n", - params.cmdname); + " [ -c ] [-f fit-image.its|-F] [-r]" + " fit-image\n", params.cmdname); fprintf (stderr, " %s -V ==> print version information and exit\n", params.cmdname); diff --git a/tools/mkimage.h b/tools/mkimage.h index 4391ca8..d82be17 100644 --- a/tools/mkimage.h +++ b/tools/mkimage.h @@ -78,6 +78,7 @@ struct mkimage_params { const char *keydir; /* Directory holding private keys */ const char *keydest;/* Destination .dtb for public key */ const char *comment;/* Comment to add to signature node */ + int require_keys; /* 1 to mark signing keys as 'required' */ }; /* -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 33/44] image: Verify signatures in FIT images
After checking hashes, also check signatures of FIT images. Signed-off-by: Simon Glass --- common/image-fit.c | 80 common/image-sig.c | 148 include/image.h| 37 + 3 files changed, 243 insertions(+), 22 deletions(-) diff --git a/common/image-fit.c b/common/image-fit.c index ed98460..d255595 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -31,6 +31,8 @@ #include #else #include +#include +DECLARE_GLOBAL_DATA_PTR; #endif /* !USE_HOSTCC*/ #include @@ -235,42 +237,42 @@ void fit_print_contents(const void *fit) * @fit: pointer to the FIT format image header * @noffset: offset of the hash node * @p: pointer to prefix string + * @type: Type of information to print ("hash" or "sign") * * fit_image_print_data() lists properies for the processed hash node * * returns: * no returned results */ -static void fit_image_print_data(const void *fit, int noffset, const char *p) +static void fit_image_print_data(const void *fit, int noffset, const char *p, +const char *type) { - char *algo; + const char *keyname; uint8_t *value; int value_len; - int i, ret; - - /* -* Check subnode name, must be equal to "hash". -* Multiple hash nodes require unique unit node -* names, e.g. hash@1, hash@2, etc. -*/ - if (strncmp(fit_get_name(fit, noffset, NULL), - FIT_HASH_NODENAME, - strlen(FIT_HASH_NODENAME)) != 0) - return; - - debug("%s Hash node:'%s'\n", p, - fit_get_name(fit, noffset, NULL)); + char *algo; + int required; + int ret, i; - printf("%s Hash algo:", p); + debug("%s %s node:'%s'\n", p, type, + fit_get_name(fit, noffset, NULL)); + printf("%s %s algo:", p, type); if (fit_image_hash_get_algo(fit, noffset, &algo)) { printf("invalid/unsupported\n"); return; } - printf("%s\n", algo); + printf("%s", algo); + keyname = fdt_getprop(fit, noffset, "key-name-hint", NULL); + required = fdt_getprop(fit, noffset, "required", NULL) != NULL; + if (keyname) + printf(":%s", keyname); + if (required) + printf(" (required)"); + printf("\n"); ret = fit_image_hash_get_value(fit, noffset, &value, &value_len); - printf("%s Hash value: ", p); + printf("%s %s value: ", p, type); if (ret) { printf("unavailable\n"); } else { @@ -279,7 +281,18 @@ static void fit_image_print_data(const void *fit, int noffset, const char *p) printf("\n"); } - debug("%s Hash len: %d\n", p, value_len); + debug("%s %s len: %d\n", p, type, value_len); + + /* Signatures have a time stamp */ + if (IMAGE_ENABLE_TIMESTAMP && keyname) { + time_t timestamp; + + printf("%s Timestamp:", p); + if (fit_get_timestamp(fit, noffset, ×tamp)) + printf("unavailable\n"); + else + genimg_print_time(timestamp); + } } /** @@ -304,8 +317,12 @@ static void fit_image_print_verification_data(const void *fit, int noffset, * names, e.g. hash@1, hash@2, signature@1, signature@2, etc. */ name = fit_get_name(fit, noffset, NULL); - if (!strncmp(name, FIT_HASH_NODENAME, strlen(FIT_HASH_NODENAME))) - fit_image_print_data(fit, noffset, p); + if (!strncmp(name, FIT_HASH_NODENAME, strlen(FIT_HASH_NODENAME))) { + fit_image_print_data(fit, noffset, p, "Hash"); + } else if (!strncmp(name, FIT_SIG_NODENAME, + strlen(FIT_SIG_NODENAME))) { + fit_image_print_data(fit, noffset, p, "Sign"); + } } /** @@ -952,6 +969,8 @@ int fit_image_verify(const void *fit, int image_noffset) int noffset; int ndepth; char*err_msg = ""; + int verify_all = 1; + int ret; /* Get image data and data length */ if (fit_image_get_data(fit, image_noffset, &data, &size)) { @@ -959,6 +978,14 @@ int fit_image_verify(const void *fit, int image_noffset) return 0; } + /* Verify all required signatures */ + if (IMAGE_ENABLE_VERIFY && + fit_image_verify_required_sigs(fit, image_noffset, + data, size, gd_fdt_blob(), &verify_all)) { + err_msg = "Unable to verify required signature"; + goto error; + } + /* Process all hash subnodes of the component image node */ for (ndepth = 0, noffset
[U-Boot] [RFC PATCH 20/44] fdt: Allow fdt command to check and update control FDT
There is an existing fdt command to deal with the working FDT. Enhance this to support the control FDT also (CONFIG_OF_CONTROL). Some nasty #ifdefs are added here - they are required until we move to generic board and every arch has an fdt_blob. Signed-off-by: Simon Glass --- common/cmd_fdt.c | 58 ++--- 1 files changed, 41 insertions(+), 17 deletions(-) diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c index 0adebf1..a193cc3 100644 --- a/common/cmd_fdt.c +++ b/common/cmd_fdt.c @@ -101,42 +101,66 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) */ if (argv[1][0] == 'a') { unsigned long addr; + int control = 0; + void *blob; /* * Set the address [and length] of the fdt. */ - if (argc == 2) { - if (!fdt_valid(working_fdt)) { - working_fdt = NULL; + argc -= 2; + argv += 2; +/* Temporary #ifdef - some archs don't have fdt_blob yet */ +#ifdef CONFIG_OF_CONTROL + if (argc && !strcmp(*argv, "-c")) { + control = 1; + argc--; + argv++; + } +#endif + if (argc == 0) { +#ifdef CONFIG_OF_CONTROL + if (control) + blob = (void *)gd->fdt_blob; + else +#endif + blob = working_fdt; + if (!blob || !fdt_valid(blob)) return 1; - } - printf("The address of the fdt is %p\n", working_fdt); + printf("The address of the fdt is %#08lx\n", + control ? (ulong)blob : + getenv_hex("fdtaddr", 0)); return 0; } - addr = simple_strtoul(argv[2], NULL, 16); - set_working_fdt_addr((void *)addr); - - if (!fdt_valid(working_fdt)) { - working_fdt = NULL; - return 1; + addr = simple_strtoul(argv[0], NULL, 16); + blob = (void *)addr; + if (control) { +#ifdef CONFIG_OF_CONTROL + if (!fdt_valid(gd->fdt_blob)) + return 1; + gd->fdt_blob = blob; +#endif + } else { + if (!fdt_valid(blob)) + return 1; + set_working_fdt_addr((void *)addr); } - if (argc >= 4) { + if (argc >= 2) { int len; int err; /* * Optional new length */ - len = simple_strtoul(argv[3], NULL, 16); - if (len < fdt_totalsize(working_fdt)) { + len = simple_strtoul(argv[1], NULL, 16); + if (len < fdt_totalsize(blob)) { printf ("New length %d < existing length %d, " "ignoring.\n", - len, fdt_totalsize(working_fdt)); + len, fdt_totalsize(blob)); } else { /* * Open in place with a new length. */ - err = fdt_open_into(working_fdt, working_fdt, len); + err = fdt_open_into(blob, blob, len); if (err != 0) { printf ("libfdt fdt_open_into(): %s\n", fdt_strerror(err)); @@ -960,7 +984,7 @@ static int fdt_print(const char *pathp, char *prop, int depth) // #ifdef CONFIG_SYS_LONGHELP static char fdt_help_text[] = - "addr[]- Set the fdt location to \n" + "addr [-c] [] - Set the [control] fdt location to \n" #ifdef CONFIG_OF_BOARD_SETUP "fdt boardsetup - Do board-specific set up\n" #endif -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 16/44] image: Rename hash printing to fit_image_print_verification_data()
This function will be used to print signatures as well as hashes, so rename it. Also make it static since it is not used outside this file. Signed-off-by: Simon Glass --- common/image-fit.c | 132 +++- include/image.h|1 - 2 files changed, 79 insertions(+), 54 deletions(-) diff --git a/common/image-fit.c b/common/image-fit.c index db5382d..ed98460 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -231,6 +231,84 @@ void fit_print_contents(const void *fit) } /** + * fit_image_print_data() - prints out the hash node details + * @fit: pointer to the FIT format image header + * @noffset: offset of the hash node + * @p: pointer to prefix string + * + * fit_image_print_data() lists properies for the processed hash node + * + * returns: + * no returned results + */ +static void fit_image_print_data(const void *fit, int noffset, const char *p) +{ + char *algo; + uint8_t *value; + int value_len; + int i, ret; + + /* +* Check subnode name, must be equal to "hash". +* Multiple hash nodes require unique unit node +* names, e.g. hash@1, hash@2, etc. +*/ + if (strncmp(fit_get_name(fit, noffset, NULL), + FIT_HASH_NODENAME, + strlen(FIT_HASH_NODENAME)) != 0) + return; + + debug("%s Hash node:'%s'\n", p, + fit_get_name(fit, noffset, NULL)); + + printf("%s Hash algo:", p); + if (fit_image_hash_get_algo(fit, noffset, &algo)) { + printf("invalid/unsupported\n"); + return; + } + printf("%s\n", algo); + + ret = fit_image_hash_get_value(fit, noffset, &value, + &value_len); + printf("%s Hash value: ", p); + if (ret) { + printf("unavailable\n"); + } else { + for (i = 0; i < value_len; i++) + printf("%02x", value[i]); + printf("\n"); + } + + debug("%s Hash len: %d\n", p, value_len); +} + +/** + * fit_image_print_verification_data() - prints out the hash/signature details + * @fit: pointer to the FIT format image header + * @noffset: offset of the hash or signature node + * @p: pointer to prefix string + * + * This lists properies for the processed hash node + * + * returns: + * no returned results + */ +static void fit_image_print_verification_data(const void *fit, int noffset, + const char *p) +{ + const char *name; + + /* +* Check subnode name, must be equal to "hash" or "signature". +* Multiple hash/signature nodes require unique unit node +* names, e.g. hash@1, hash@2, signature@1, signature@2, etc. +*/ + name = fit_get_name(fit, noffset, NULL); + if (!strncmp(name, FIT_HASH_NODENAME, strlen(FIT_HASH_NODENAME))) + fit_image_print_data(fit, noffset, p); +} + +/** * fit_image_print - prints out the FIT component image details * @fit: pointer to the FIT format image header * @image_noffset: offset of the component image node @@ -325,64 +403,12 @@ void fit_image_print(const void *fit, int image_noffset, const char *p) noffset = fdt_next_node(fit, noffset, &ndepth)) { if (ndepth == 1) { /* Direct child node of the component image node */ - fit_image_print_hash(fit, noffset, p); + fit_image_print_verification_data(fit, noffset, p); } } } /** - * fit_image_print_hash - prints out the hash node details - * @fit: pointer to the FIT format image header - * @noffset: offset of the hash node - * @p: pointer to prefix string - * - * fit_image_print_hash() lists properies for the processed hash node - * - * returns: - * no returned results - */ -void fit_image_print_hash(const void *fit, int noffset, const char *p) -{ - char *algo; - uint8_t *value; - int value_len; - int i, ret; - - /* -* Check subnode name, must be equal to "hash". -* Multiple hash nodes require unique unit node -* names, e.g. hash@1, hash@2, etc. -*/ - if (strncmp(fit_get_name(fit, noffset, NULL), - FIT_HASH_NODENAME, - strlen(FIT_HASH_NODENAME)) != 0) - return; - - debug("%s Hash node:'%s'\n", p, - fit_get_name(fit, noffset, NULL)); - - printf("%s Hash algo:", p); - if (fit_image_hash_get_algo(fit, noffset, &algo)) { - printf("invalid/unsupported\n"); - return; - } - printf("%s\n", algo); - - ret = fit_image_hash_get_value(fit, noffset, &value, - &value_len); - printf("%s Hash value: ", p); - if (ret) { - printf("
[U-Boot] [RFC PATCH 22/44] env: Fix minor comment typos in cmd_nvedit
This should say 'environmnent'. Signed-off-by: Simon Glass --- common/cmd_nvedit.c |4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index d6d5eea..7685a19 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -282,7 +282,7 @@ int setenv(const char *varname, const char *varvalue) /** * Set an environment variable to an integer value * - * @param varname Environmet variable to set + * @param varname Environment variable to set * @param valueValue to set it to * @return 0 if ok, 1 on error */ @@ -297,7 +297,7 @@ int setenv_ulong(const char *varname, ulong value) /** * Set an environment variable to an value in hex * - * @param varname Environmet variable to set + * @param varname Environment variable to set * @param valueValue to set it to * @return 0 if ok, 1 on error */ -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 12/44] image: Move hash checking into its own functions
The existing function is long and most of the code is indented a long way. Before adding yet more code, split this out into its own function. Signed-off-by: Simon Glass --- common/image-fit.c | 128 1 files changed, 69 insertions(+), 59 deletions(-) diff --git a/common/image-fit.c b/common/image-fit.c index 7fab682..4a78a5c 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -852,6 +852,60 @@ int calculate_hash(const void *data, int data_len, const char *algo, return 0; } +static int fit_image_check_hash(const void *fit, int noffset, const void *data, + size_t size, char **err_msgp) +{ + uint8_t value[FIT_MAX_HASH_LEN]; + int value_len; + char *algo; + uint8_t *fit_value; + int fit_value_len; +#ifndef USE_HOSTCC + int ignore; +#endif + + *err_msgp = NULL; + + if (fit_image_hash_get_algo(fit, noffset, &algo)) { + *err_msgp = " error!\nCan't get hash algo " + "property"; + return -1; + } + printf("%s", algo); + +#ifndef USE_HOSTCC + fit_image_hash_get_ignore(fit, noffset, &ignore); + if (ignore) { + printf("-skipped "); + return 0; + } +#endif + + if (fit_image_hash_get_value(fit, noffset, &fit_value, + &fit_value_len)) { + *err_msgp = " error!\nCan't get hash value " + "property"; + return -1; + } + + if (calculate_hash(data, size, algo, value, + &value_len)) { + *err_msgp = " error!\n" + "Unsupported hash algorithm"; + return -1; + } + + if (value_len != fit_value_len) { + *err_msgp = " error !\nBad hash value len"; + return -1; + } else if (memcmp(value, fit_value, value_len) != 0) { + *err_msgp = " error!\nBad hash value"; + return -1; + } + + return 0; +} + /** * fit_image_verify - verify data intergity * @fit: pointer to the FIT format image header @@ -869,14 +923,6 @@ int fit_image_verify(const void *fit, int image_noffset) { const void *data; size_t size; - char*algo; - uint8_t *fit_value; - int fit_value_len; -#ifndef USE_HOSTCC - int ignore; -#endif - uint8_t value[FIT_MAX_HASH_LEN]; - int value_len; int noffset; int ndepth; char*err_msg = ""; @@ -888,59 +934,23 @@ int fit_image_verify(const void *fit, int image_noffset) } /* Process all hash subnodes of the component image node */ - for (ndepth = 0, noffset = fdt_next_node(fit, image_noffset, &ndepth); -(noffset >= 0) && (ndepth > 0); -noffset = fdt_next_node(fit, noffset, &ndepth)) { - if (ndepth == 1) { - /* Direct child node of the component image node */ + for (ndepth = 0, + noffset = fdt_next_subnode(fit, image_noffset, &ndepth); + noffset >= 0; + noffset = fdt_next_subnode(fit, noffset, &ndepth)) { + const char *name = fit_get_name(fit, noffset, NULL); - /* -* Check subnode name, must be equal to "hash". -* Multiple hash nodes require unique unit node -* names, e.g. hash@1, hash@2, etc. -*/ - if (strncmp(fit_get_name(fit, noffset, NULL), - FIT_HASH_NODENAME, - strlen(FIT_HASH_NODENAME)) != 0) - continue; - - if (fit_image_hash_get_algo(fit, noffset, &algo)) { - err_msg = " error!\nCan't get hash algo " - "property"; - goto error; - } - printf("%s", algo); - -#ifndef USE_HOSTCC - fit_image_hash_get_ignore(fit, noffset, &ignore); - if (ignore) { - printf("-skipped "); - continue; - } -#endif - - if (fit_image_hash_get_value(fit, noffset, &fit_value, - &fit_value_len)) { - err_msg = " error!\nCan't get hash value " - "property"; - goto error; - } - - if (calculate_hash(data, size
[U-Boot] [RFC PATCH 04/44] libfdt: Add fdt_next_subnode() to permit easy subnode iteration
This allows use to replace code like this: for (ndepth = 0, count = 0, noffset = fdt_next_node(fit, images_noffset, &ndepth); (noffset >= 0) && (ndepth > 0); noffset = fdt_next_node(fit, noffset, &ndepth)) { if (ndepth == 1) ... with: for (ndepth = 0, noffset = fdt_next_subnode(fit, image_noffset, &ndepth); noffset >= 0; noffset = fdt_next_subnode(fit, noffset, &ndepth)) { which is slightly better, and doesn't require two levels of indentation for code in the loop. Signed-off-by: Simon Glass --- include/libfdt.h | 17 + lib/libfdt/fdt.c | 12 2 files changed, 29 insertions(+), 0 deletions(-) diff --git a/include/libfdt.h b/include/libfdt.h index c93ae28..0dfb8a0 100644 --- a/include/libfdt.h +++ b/include/libfdt.h @@ -136,6 +136,23 @@ uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset); int fdt_next_node(const void *fdt, int offset, int *depth); +/** + * fdt_next_subnode() - get offset of next direct child + * + * Set depth to 0, offset to parent, then call this function repeatedly + * to get direct subnodes of a parent node. + * + * @fdt: FDT blob + * @offset:Set this to offset of parent for the first call. For + * subsquent calls, pass in the value returns from the last + * call. + * @depth: Used internally to monitor depth - set this to 0 for the + * first call. + * @return offset of next subnode, or -FDT_ERR_NOTFOUND if there are no more + * children + */ +int fdt_next_subnode(const void *fdt, int offset, int *depth); + /**/ /* General functions */ /**/ diff --git a/lib/libfdt/fdt.c b/lib/libfdt/fdt.c index 4157b21..8a0f323 100644 --- a/lib/libfdt/fdt.c +++ b/lib/libfdt/fdt.c @@ -202,6 +202,18 @@ int fdt_next_node(const void *fdt, int offset, int *depth) return offset; } +int fdt_next_subnode(const void *fdt, int offset, int *depth) +{ + /* Loop until we find a direct child of the parent (depth == 1) */ + do { + offset = fdt_next_node(fdt, offset, depth); + if (offset < 0 || *depth < 1) + return -FDT_ERR_NOTFOUND; + } while (*depth > 1); + + return offset; +} + const char *_fdt_find_string(const char *strtab, int tabsize, const char *s) { int len = strlen(s) + 1; -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 35/44] mkimage: Put FIT loading in function and tidy error handling
The fit_handle_file() function is quiet long - split out the part that loads and checks a FIT into its own function. We will use this function for storing public keys into a destination FDT file. The error handling is currently a bit repetitive - tidy it. Signed-off-by: Simon Glass --- tools/fit_image.c | 96 +++- 1 files changed, 57 insertions(+), 39 deletions(-) diff --git a/tools/fit_image.c b/tools/fit_image.c index e0675d7..0f619a2 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -47,6 +47,48 @@ static int fit_check_image_types (uint8_t type) return EXIT_FAILURE; } +int mmap_fdt(struct mkimage_params *params, const char *fname, void **blobp, + struct stat *sbuf) +{ + void *ptr; + int fd; + + /* load FIT blob into memory */ + fd = open(fname, O_RDWR|O_BINARY); + + if (fd < 0) { + fprintf(stderr, "%s: Can't open %s: %s\n", + params->cmdname, fname, strerror(errno)); + unlink(fname); + return -1; + } + + if (fstat(fd, sbuf) < 0) { + fprintf(stderr, "%s: Can't stat %s: %s\n", + params->cmdname, fname, strerror(errno)); + unlink(fname); + return -1; + } + + ptr = mmap(0, sbuf->st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); + if (ptr == MAP_FAILED) { + fprintf(stderr, "%s: Can't read %s: %s\n", + params->cmdname, fname, strerror(errno)); + unlink(fname); + return -1; + } + + /* check if ptr has a valid blob */ + if (fdt_check_header(ptr)) { + fprintf(stderr, "%s: Invalid FIT blob\n", params->cmdname); + unlink(fname); + return -1; + } + + *blobp = ptr; + return fd; +} + /** * fit_handle_file - main FIT file processing function * @@ -65,7 +107,7 @@ static int fit_handle_file (struct mkimage_params *params) char cmd[MKIMAGE_MAX_DTC_CMDLINE_LEN]; int tfd; struct stat sbuf; - unsigned char *ptr; + void *ptr; /* Flattened Image Tree (FIT) format handling */ debug ("FIT format handling\n"); @@ -87,57 +129,25 @@ static int fit_handle_file (struct mkimage_params *params) 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); + goto err_system; } - 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); - } + tfd = mmap_fdt(params, tmpfile, &ptr, &sbuf); + if (tfd < 0) + goto err_mmap; /* set hashes for images in the blob */ if (fit_add_verification_data(NULL, NULL, ptr, NULL, 0)) { fprintf (stderr, "%s Can't add hashes to FIT blob", params->cmdname); - unlink (tmpfile); - return (EXIT_FAILURE); + goto err_add_hashes; } /* 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); + goto err_add_timestamp; } debug ("Added timestamp successfully\n"); @@ -153,6 +163,14 @@ static int fit_handle_file (struct mkimage_params *params) return (EXIT_FAILURE); } return (EXIT_SUCCESS); + +err_add_timestamp: +err_add_hashes: + munmap(ptr, sbuf.st_size);
[U-Boot] [RFC PATCH 14/44] image: Export fit_conf_get_prop_node()
This function will be needed by signature checking code, so export it, and also add docs. Signed-off-by: Simon Glass --- common/image-fit.c |8 include/image.h| 15 +++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/common/image-fit.c b/common/image-fit.c index 19942e2..db5382d 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -1322,7 +1322,7 @@ int fit_conf_get_node(const void *fit, const char *conf_uname) return noffset; } -static int __fit_conf_get_prop_node(const void *fit, int noffset, +int fit_conf_get_prop_node(const void *fit, int noffset, const char *prop_name) { char *uname; @@ -1352,7 +1352,7 @@ static int __fit_conf_get_prop_node(const void *fit, int noffset, */ int fit_conf_get_kernel_node(const void *fit, int noffset) { - return __fit_conf_get_prop_node(fit, noffset, FIT_KERNEL_PROP); + return fit_conf_get_prop_node(fit, noffset, FIT_KERNEL_PROP); } /** @@ -1371,7 +1371,7 @@ int fit_conf_get_kernel_node(const void *fit, int noffset) */ int fit_conf_get_ramdisk_node(const void *fit, int noffset) { - return __fit_conf_get_prop_node(fit, noffset, FIT_RAMDISK_PROP); + return fit_conf_get_prop_node(fit, noffset, FIT_RAMDISK_PROP); } /** @@ -1390,7 +1390,7 @@ int fit_conf_get_ramdisk_node(const void *fit, int noffset) */ int fit_conf_get_fdt_node(const void *fit, int noffset) { - return __fit_conf_get_prop_node(fit, noffset, FIT_FDT_PROP); + return fit_conf_get_prop_node(fit, noffset, FIT_FDT_PROP); } /** diff --git a/include/image.h b/include/image.h index ed351ef..d933bad 100644 --- a/include/image.h +++ b/include/image.h @@ -626,6 +626,21 @@ int fit_conf_get_kernel_node(const void *fit, int noffset); int fit_conf_get_ramdisk_node(const void *fit, int noffset); int fit_conf_get_fdt_node(const void *fit, int noffset); +/** + * fit_conf_get_prop_node() - Get node refered to by a configuration + * + * The conf@ nodes contain references to other nodes, using properties + * like 'kernel = "kernel@1"'. Given such a property name (e.g. "kernel"), + * return the offset of the node referred to (e.g. offset of node + * "/images/kernel@1". + * + * @fit: FIT to check + * @noffset: Offset of conf@xxx node to check + * @prop_name: Property to read from the conf node + */ +int fit_conf_get_prop_node(const void *fit, int noffset, + const char *prop_name); + void fit_conf_print(const void *fit, int noffset, const char *p); int fit_check_ramdisk(const void *fit, int os_noffset, -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 37/44] mkimage: Add -K to write public keys to an FDT blob
FIT image verification requires public keys. Add a convenient option to mkimage to write the public keys to an FDT blob when it uses then for signing an image. This allows us to use: mkimage -f test.its -K dest.dtb -k keys test.fit and have the signatures written to test.fit and the corresponding public keys written to dest.dtb. Then dest.dtb can be used as the control FDT for U-Boot (CONFIG_OF_CONTROL), thus providing U-Boot with access to the public keys it needs. Signed-off-by: Simon Glass --- doc/mkimage.1 | 16 tools/fit_image.c | 21 +++-- tools/mkimage.c |7 ++- tools/mkimage.h |1 + 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/doc/mkimage.1 b/doc/mkimage.1 index 6740fb1..8185ff5 100644 --- a/doc/mkimage.1 +++ b/doc/mkimage.1 @@ -109,6 +109,14 @@ Specifies the directory containing keys to use for signing. This directory should contain a private key file .key for use with signing and a certificate .crt (containing the public key) for use with verification. +.TP +.BI "\-K [" "key_destination" "]" +Specifies a compiled device tree binary file (typically .dtb) to write +public key information into. When a private key is used to sign an image, +the corresponding public key is written into this file for for run-time +verification. Typically the file here is the device tree binary used by +CONFIG_OF_CONTROL in U-Boot. + .SH EXAMPLES List image information: @@ -127,6 +135,14 @@ Create FIT image with compressed PowerPC Linux kernel: .nf .B mkimage -f kernel.its kernel.itb .fi +.P +Create FIT image with compressed kernel and sign it with keys in the +/public/signing-keys directory. Add corresponding public keys into u-boot.dtb, +skipping those for which keys cannot be found. Also add a comment. +.nf +.B mkimage -f kernel.its -k /public/signing-keys -K u-boot.dtb +-c "Kernel 3.8 image for production devices" kernel.itb +.fi .SH HOMEPAGE http://www.denx.de/wiki/U-Boot/WebHome diff --git a/tools/fit_image.c b/tools/fit_image.c index 5d04f96..306298a 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -105,9 +105,11 @@ static int fit_handle_file (struct mkimage_params *params) { char tmpfile[MKIMAGE_MAX_TMPFILE_LEN]; char cmd[MKIMAGE_MAX_DTC_CMDLINE_LEN]; - int tfd; + int tfd, destfd = 0; + void *dest_blob = NULL; struct stat sbuf; void *ptr; + off_t destfd_size = 0; /* Flattened Image Tree (FIT) format handling */ debug ("FIT format handling\n"); @@ -132,12 +134,20 @@ static int fit_handle_file (struct mkimage_params *params) goto err_system; } + if (params->keydest) { + destfd = mmap_fdt(params, params->keydest, &dest_blob, &sbuf); + if (destfd < 0) + goto err_keydest; + destfd_size = sbuf.st_size; + } + tfd = mmap_fdt(params, tmpfile, &ptr, &sbuf); if (tfd < 0) goto err_mmap; /* set hashes for images in the blob */ - if (fit_add_verification_data(params->keydir, NULL, ptr, NULL, 0)) { + if (fit_add_verification_data(params->keydir, + dest_blob, ptr, NULL, 0)) { fprintf (stderr, "%s Can't add hashes to FIT blob", params->cmdname); goto err_add_hashes; @@ -153,6 +163,10 @@ static int fit_handle_file (struct mkimage_params *params) munmap ((void *)ptr, sbuf.st_size); close (tfd); + if (dest_blob) { + munmap(dest_blob, destfd_size); + close(destfd); + } if (rename (tmpfile, params->imagefile) == -1) { fprintf (stderr, "%s: Can't rename %s to %s: %s\n", @@ -168,6 +182,9 @@ err_add_timestamp: err_add_hashes: munmap(ptr, sbuf.st_size); err_mmap: + if (dest_blob) + munmap(dest_blob, destfd_size); +err_keydest: err_system: unlink(tmpfile); return -1; diff --git a/tools/mkimage.c b/tools/mkimage.c index 0eae136..30a5a06 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -253,6 +253,11 @@ main (int argc, char **argv) usage(); params.keydir = *++argv; goto NXTARG; + case 'K': + if (--argc <= 0) + usage(); + params.keydest = *++argv; + goto NXTARG; case 'n': if (--argc <= 0) usage (); @@ -628,7 +633,7 @@ usage () " -d ==> use image data from 'datafile'\n" " -x ==> set XIP (execute in place)\n", params.cmdname); - fprintf(stderr, " %s
[U-Boot] [RFC PATCH 15/44] image: Rename fit_add_hashes() to fit_add_verification_data()
We intend to add signatures to FITs also, so rename this function so that it is not specific to hashing. Also rename fit_image_set_hashes() and make it static since it is not used outside this file. Signed-off-by: Simon Glass --- include/image.h| 10 +++- tools/fit_image.c |2 +- tools/image-host.c | 147 +--- 3 files changed, 79 insertions(+), 80 deletions(-) diff --git a/include/image.h b/include/image.h index d933bad..ca612f3 100644 --- a/include/image.h +++ b/include/image.h @@ -609,8 +609,14 @@ int fit_image_hash_get_ignore(const void *fit, int noffset, int *ignore); #endif int fit_set_timestamp(void *fit, int noffset, time_t timestamp); -int fit_set_hashes(void *fit); -int fit_image_set_hashes(void *fit, int image_noffset); + +/** + * fit_add_verification_data() - Calculate and add hashes to FIT + * + * @fit: Fit image to process + * @return 0 if ok, <0 for error + */ +int fit_add_verification_data(void *fit); int fit_image_verify(const void *fit, int noffset); int fit_all_image_verify(const void *fit); diff --git a/tools/fit_image.c b/tools/fit_image.c index 76bbba1..8f51159 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -125,7 +125,7 @@ static int fit_handle_file (struct mkimage_params *params) } /* set hashes for images in the blob */ - if (fit_set_hashes (ptr)) { + if (fit_add_verification_data(ptr)) { fprintf (stderr, "%s Can't add hashes to FIT blob", params->cmdname); unlink (tmpfile); diff --git a/tools/image-host.c b/tools/image-host.c index d127fc1..4c589af 100644 --- a/tools/image-host.c +++ b/tools/image-host.c @@ -34,51 +34,6 @@ #include /** - * fit_set_hashes - process FIT component image nodes and calculate hashes - * @fit: pointer to the FIT format image header - * - * fit_set_hashes() adds hash values for all component images in the FIT blob. - * Hashes are calculated for all component images which have hash subnodes - * with algorithm property set to one of the supported hash algorithms. - * - * returns - * 0, on success - * libfdt error code, on failure - */ -int fit_set_hashes(void *fit) -{ - int images_noffset; - int noffset; - int ndepth; - int ret; - - /* Find images parent node offset */ - images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); - if (images_noffset < 0) { - printf("Can't find images parent node '%s' (%s)\n", - FIT_IMAGES_PATH, fdt_strerror(images_noffset)); - return images_noffset; - } - - /* Process its subnodes, print out component images details */ - for (ndepth = 0, noffset = fdt_next_node(fit, images_noffset, &ndepth); -(noffset >= 0) && (ndepth > 0); -noffset = fdt_next_node(fit, noffset, &ndepth)) { - if (ndepth == 1) { - /* -* Direct child node of the images parent node, -* i.e. component image node. -*/ - ret = fit_image_set_hashes(fit, noffset); - if (ret) - return ret; - } - } - - return 0; -} - -/** * fit_set_hash_value - set hash value in requested has node * @fit: pointer to the FIT format image header * @noffset: hash node offset @@ -125,23 +80,16 @@ static int fit_image_process_hash(void *fit, const char *image_name, int noffset, const void *data, size_t size) { uint8_t value[FIT_MAX_HASH_LEN]; + const char *node_name; int value_len; char *algo; - /* -* Check subnode name, must be equal to "hash". -* Multiple hash nodes require unique unit node -* names, e.g. hash@1, hash@2, etc. -*/ - if (strncmp(fit_get_name(fit, noffset, NULL), - FIT_HASH_NODENAME, - strlen(FIT_HASH_NODENAME)) != 0) - return 0; + node_name = fit_get_name(fit, noffset, NULL); if (fit_image_hash_get_algo(fit, noffset, &algo)) { printf("Can't get hash algo property for " "'%s' hash node in '%s' image node\n", - fit_get_name(fit, noffset, NULL), image_name); + node_name, image_name); return -1; } @@ -149,7 +97,7 @@ static int fit_image_process_hash(void *fit, const char *image_name, &value_len)) { printf("Unsupported hash algorithm (%s) for " "'%s' hash node in '%s' image node\n", - algo, fit_get_name(fit, noffset, NULL), image_name); + algo, node_name, image_name); return -1; } @@ -157,7 +105,7 @@ static int fit_im
[U-Boot] [RFC PATCH 11/44] image: Rename fit_image_check_hashes() to fit_image_verify()
This is the main entry point to the FIT image verification code. We will be using it to handle image verification with signatures, so rename the function. Signed-off-by: Simon Glass --- common/cmd_bootm.c |4 ++-- common/cmd_fpga.c |2 +- common/cmd_source.c |2 +- common/cmd_ximg.c |2 +- common/image-fit.c | 16 common/image.c |2 +- common/update.c |2 +- include/image.h |4 ++-- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index 2debfe3..7b07393 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -797,7 +797,7 @@ static int fit_check_kernel(const void *fit, int os_noffset, int verify) if (verify) { puts(" Verifying Hash Integrity ... "); - if (!fit_image_check_hashes(fit, os_noffset)) { + if (!fit_image_verify(fit, os_noffset)) { puts("Bad Data Hash\n"); bootstage_error(BOOTSTAGE_ID_FIT_CHECK_HASH); return 0; @@ -1151,7 +1151,7 @@ static int image_info(ulong addr) fit_print_contents(hdr); - if (!fit_all_image_check_hashes(hdr)) { + if (!fit_all_image_verify(hdr)) { puts("Bad hash in FIT image!\n"); return 1; } diff --git a/common/cmd_fpga.c b/common/cmd_fpga.c index 1834246..1341604 100644 --- a/common/cmd_fpga.c +++ b/common/cmd_fpga.c @@ -306,7 +306,7 @@ int do_fpga (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) } /* verify integrity */ - if (!fit_image_check_hashes (fit_hdr, noffset)) { + if (!fit_image_verify(fit_hdr, noffset)) { puts ("Bad Data Hash\n"); return 1; } diff --git a/common/cmd_source.c b/common/cmd_source.c index 02a862c..6a82fb2 100644 --- a/common/cmd_source.c +++ b/common/cmd_source.c @@ -124,7 +124,7 @@ source (ulong addr, const char *fit_uname) /* verify integrity */ if (verify) { - if (!fit_image_check_hashes (fit_hdr, noffset)) { + if (!fit_image_verify(fit_hdr, noffset)) { puts ("Bad Data Hash\n"); return 1; } diff --git a/common/cmd_ximg.c b/common/cmd_ximg.c index ea0a26e..f8722a0 100644 --- a/common/cmd_ximg.c +++ b/common/cmd_ximg.c @@ -160,7 +160,7 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) /* verify integrity */ if (verify) { - if (!fit_image_check_hashes(fit_hdr, noffset)) { + if (!fit_image_verify(fit_hdr, noffset)) { puts("Bad Data Hash\n"); return 1; } diff --git a/common/image-fit.c b/common/image-fit.c index d75ec3a..7fab682 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -853,11 +853,11 @@ int calculate_hash(const void *data, int data_len, const char *algo, } /** - * fit_image_check_hashes - verify data intergity + * fit_image_verify - verify data intergity * @fit: pointer to the FIT format image header * @image_noffset: component image node offset * - * fit_image_check_hashes() goes over component image hash nodes, + * fit_image_verify() goes over component image hash nodes, * re-calculates each data hash and compares with the value stored in hash * node. * @@ -865,7 +865,7 @@ int calculate_hash(const void *data, int data_len, const char *algo, * 1, if all hashes are valid * 0, otherwise (or on error) */ -int fit_image_check_hashes(const void *fit, int image_noffset) +int fit_image_verify(const void *fit, int image_noffset) { const void *data; size_t size; @@ -959,17 +959,17 @@ error: } /** - * fit_all_image_check_hashes - verify data intergity for all images + * fit_all_image_verify - verify data intergity for all images * @fit: pointer to the FIT format image header * - * fit_all_image_check_hashes() goes over all images in the FIT and + * fit_all_image_verify() goes over all images in the FIT and * for every images checks if all it's hashes are valid. * * returns: * 1, if all hashes of all images are valid * 0, otherwise (or on error) */ -int fit_all_image_check_hashes(const void *fit) +int fit_all_image_verify(const void *fit) { int images_noffset; int noffset; @@ -999,7 +999,7 @@ int fit_all_image_check_hashes(const void *fit) printf(" Hash(es) for Image %u (%s): ", count++, fit_get_name(fit, nof
[U-Boot] [RFC PATCH 24/44] Revert "fdt- Tell the FDT library where the device tree is"
This reverts commit 3b73459ea3421e9f8c6c8c62e1d3fe458ca5bc56. In practice it doesn't seem like a good idea to make the the working FDT point to the control FDT. Now that we can access the control FDT using the 'fdt' command, there is no need for this feature. Remove it. Signed-off-by: Simon Glass --- common/main.c |8 1 files changed, 0 insertions(+), 8 deletions(-) diff --git a/common/main.c b/common/main.c index 5d8454e..bbc3be6 100644 --- a/common/main.c +++ b/common/main.c @@ -45,10 +45,6 @@ #include #endif -#ifdef CONFIG_OF_LIBFDT -#include -#endif /* CONFIG_OF_LIBFDT */ - #include #include #include @@ -500,10 +496,6 @@ void main_loop (void) #endif /* CONFIG_MENUKEY */ #endif /* CONFIG_BOOTDELAY */ -#if defined CONFIG_OF_CONTROL - set_working_fdt_addr((void *)gd->fdt_blob); -#endif /* CONFIG_OF_CONTROL */ - /* * Main Loop for Monitor Command Processing */ -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 23/44] fdt: Skip checking FDT if the pointer is NULL
If we have no FDT, don't attempt to read from it. This allows sandbox to run without an FDT if required. Signed-off-by: Simon Glass --- lib/fdtdec.c |3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 6dba438..740bd56 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -318,7 +318,8 @@ int fdtdec_check_fdt(void) */ int fdtdec_prepare_fdt(void) { - if (((uintptr_t)gd->fdt_blob & 3) || fdt_check_header(gd->fdt_blob)) { + if (!gd->fdt_blob || ((uintptr_t)gd->fdt_blob & 3) || + fdt_check_header(gd->fdt_blob)) { printf("No valid FDT found - please append one to U-Boot " "binary, use u-boot-dtb.bin or define " "CONFIG_OF_EMBED\n"); -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 26/44] Add minor updates to README.fdt-control
A few things have changed since this doc was written, so update it to match the current state of things. Signed-off-by: Simon Glass --- doc/README.fdt-control |7 ++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/doc/README.fdt-control b/doc/README.fdt-control index 69c69de..ba17879 100644 --- a/doc/README.fdt-control +++ b/doc/README.fdt-control @@ -49,6 +49,10 @@ the features of each board in the device tree file, and have a single generic source base. To enable this feature, add CONFIG_OF_CONTROL to your board config file. +It is currently supported on ARM, x86 and Microblaze - other architectures +will need to add code to their arch/xxx/lib/board.c file to locate the +FDT, at least until generic board support is complete. For ARM, Tegra and +Exynos5 have device trees available for common devices. What is a Flat Device Tree? @@ -99,7 +103,8 @@ Then run the compiler (your version will vary): * Bad configuration: 0 * Strange test result: 0 -You will also find a useful ftdump utility for decoding a binary file. +You will also find a useful fdtdump utility for decoding a binary file, as +well as fdtget/fdtput for reading and writing properties in a binary file. Where do I get an fdt file for my board? -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 08/44] image: Move HOSTCC image code to tools/
This code is never compiled into U-Boot, so move it into a separate file in tools/ to avoid the large #ifdef. Signed-off-by: Simon Glass --- common/image-fit.c | 175 + include/image.h|3 + tools/Makefile |2 + tools/image-host.c | 205 4 files changed, 211 insertions(+), 174 deletions(-) create mode 100644 tools/image-host.c diff --git a/common/image-fit.c b/common/image-fit.c index 6f2ecd2..d75ec3a 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -830,7 +830,7 @@ int fit_set_timestamp(void *fit, int noffset, time_t timestamp) * 0, on success *-1, when algo is unsupported */ -static int calculate_hash(const void *data, int data_len, const char *algo, +int calculate_hash(const void *data, int data_len, const char *algo, uint8_t *value, int *value_len) { if (strcmp(algo, "crc32") == 0) { @@ -852,179 +852,6 @@ static int calculate_hash(const void *data, int data_len, const char *algo, return 0; } -#ifdef USE_HOSTCC -/** - * fit_set_hashes - process FIT component image nodes and calculate hashes - * @fit: pointer to the FIT format image header - * - * fit_set_hashes() adds hash values for all component images in the FIT blob. - * Hashes are calculated for all component images which have hash subnodes - * with algorithm property set to one of the supported hash algorithms. - * - * returns - * 0, on success - * libfdt error code, on failure - */ -int fit_set_hashes(void *fit) -{ - int images_noffset; - int noffset; - int ndepth; - int ret; - - /* Find images parent node offset */ - images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); - if (images_noffset < 0) { - printf("Can't find images parent node '%s' (%s)\n", - FIT_IMAGES_PATH, fdt_strerror(images_noffset)); - return images_noffset; - } - - /* Process its subnodes, print out component images details */ - for (ndepth = 0, noffset = fdt_next_node(fit, images_noffset, &ndepth); -(noffset >= 0) && (ndepth > 0); -noffset = fdt_next_node(fit, noffset, &ndepth)) { - if (ndepth == 1) { - /* -* Direct child node of the images parent node, -* i.e. component image node. -*/ - ret = fit_image_set_hashes(fit, noffset); - if (ret) - return ret; - } - } - - return 0; -} - -/** - * fit_image_set_hashes - calculate/set hashes for given component image node - * @fit: pointer to the FIT format image header - * @image_noffset: requested component image node - * - * fit_image_set_hashes() adds hash values for an component image node. All - * existing hash subnodes are checked, if algorithm property is set to one of - * the supported hash algorithms, hash value is computed and corresponding - * hash node property is set, for example: - * - * Input component image node structure: - * - * o image@1 (at image_noffset) - * | - data = [binary data] - * o hash@1 - * |- algo = "sha1" - * - * Output component image node structure: - * - * o image@1 (at image_noffset) - * | - data = [binary data] - * o hash@1 - * |- algo = "sha1" - * |- value = sha1(data) - * - * returns: - * 0 on sucess - *<0 on failure - */ -int fit_image_set_hashes(void *fit, int image_noffset) -{ - const void *data; - size_t size; - char *algo; - uint8_t value[FIT_MAX_HASH_LEN]; - int value_len; - int noffset; - int ndepth; - - /* Get image data and data length */ - if (fit_image_get_data(fit, image_noffset, &data, &size)) { - printf("Can't get image data/size\n"); - return -1; - } - - /* Process all hash subnodes of the component image node */ - for (ndepth = 0, noffset = fdt_next_node(fit, image_noffset, &ndepth); -(noffset >= 0) && (ndepth > 0); -noffset = fdt_next_node(fit, noffset, &ndepth)) { - if (ndepth == 1) { - /* Direct child node of the component image node */ - - /* -* Check subnode name, must be equal to "hash". -* Multiple hash nodes require unique unit node -* names, e.g. hash@1, hash@2, etc. -*/ - if (strncmp(fit_get_name(fit, noffset, NULL), - FIT_HASH_NODENAME, - strlen(FIT_HASH_NODENAME)) != 0) { - /* Not a hash subnode, skip it */ - continue; - } - - if (fit_image
[U-Boot] [RFC PATCH 10/44] image: Convert fit_image_hash_set_value() to static, and rename
This function doesn't need to be exported, and with verification we want to use it for setting the 'value' property in any node, so rename it. Signed-off-by: Simon Glass --- include/image.h|2 - tools/image-host.c | 62 ++-- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/include/image.h b/include/image.h index 819b131..f723b62 100644 --- a/include/image.h +++ b/include/image.h @@ -611,8 +611,6 @@ int fit_image_hash_get_ignore(const void *fit, int noffset, int *ignore); int fit_set_timestamp(void *fit, int noffset, time_t timestamp); int fit_set_hashes(void *fit); int fit_image_set_hashes(void *fit, int image_noffset); -int fit_image_hash_set_value(void *fit, int noffset, uint8_t *value, - int value_len); int fit_image_check_hashes(const void *fit, int noffset); int fit_all_image_check_hashes(const void *fit); diff --git a/tools/image-host.c b/tools/image-host.c index da96ab1..d127fc1 100644 --- a/tools/image-host.c +++ b/tools/image-host.c @@ -79,6 +79,36 @@ int fit_set_hashes(void *fit) } /** + * fit_set_hash_value - set hash value in requested has node + * @fit: pointer to the FIT format image header + * @noffset: hash node offset + * @value: hash value to be set + * @value_len: hash value length + * + * fit_set_hash_value() attempts to set hash value in a node at offset + * given and returns operation status to the caller. + * + * returns + * 0, on success + * -1, on failure + */ +static int fit_set_hash_value(void *fit, int noffset, uint8_t *value, + int value_len) +{ + int ret; + + ret = fdt_setprop(fit, noffset, FIT_VALUE_PROP, value, value_len); + if (ret) { + printf("Can't set hash '%s' property for '%s' node(%s)\n", + FIT_VALUE_PROP, fit_get_name(fit, noffset, NULL), + fdt_strerror(ret)); + return -1; + } + + return 0; +} + +/** * fit_image_process_hash - Process a single subnode of the images/ node * * Check each subnode and process accordingly. For hash nodes we generate @@ -123,7 +153,7 @@ static int fit_image_process_hash(void *fit, const char *image_name, return -1; } - if (fit_image_hash_set_value(fit, noffset, value, + if (fit_set_hash_value(fit, noffset, value, value_len)) { printf("Can't set hash value for " "'%s' hash node in '%s' image node\n", @@ -193,33 +223,3 @@ int fit_image_set_hashes(void *fit, int image_noffset) return 0; } - -/** - * fit_image_hash_set_value - set hash value in requested has node - * @fit: pointer to the FIT format image header - * @noffset: hash node offset - * @value: hash value to be set - * @value_len: hash value length - * - * fit_image_hash_set_value() attempts to set hash value in a node at offset - * given and returns operation status to the caller. - * - * returns - * 0, on success - * -1, on failure - */ -int fit_image_hash_set_value(void *fit, int noffset, uint8_t *value, - int value_len) -{ - int ret; - - ret = fdt_setprop(fit, noffset, FIT_VALUE_PROP, value, value_len); - if (ret) { - printf("Can't set hash '%s' property for '%s' node(%s)\n", - FIT_VALUE_PROP, fit_get_name(fit, noffset, NULL), - fdt_strerror(ret)); - return -1; - } - - return 0; -} -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 03/44] mkimage: Move ARRAY_SIZE to header file
Move this definition from aisimage.c to mkimage.h so that it is available more widely. Signed-off-by: Simon Glass --- tools/aisimage.c |1 - tools/mkimage.h |2 ++ 2 files changed, 2 insertions(+), 1 deletions(-) diff --git a/tools/aisimage.c b/tools/aisimage.c index c645708..659df8c 100644 --- a/tools/aisimage.c +++ b/tools/aisimage.c @@ -32,7 +32,6 @@ #define WORD_ALIGN04 #define WORD_ALIGN(len) (((len)+WORD_ALIGN0-1) & ~(WORD_ALIGN0-1)) #define MAX_CMD_BUFFER 4096 -#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) static uint32_t ais_img_size; diff --git a/tools/mkimage.h b/tools/mkimage.h index ea45f5c..e07a615 100644 --- a/tools/mkimage.h +++ b/tools/mkimage.h @@ -42,6 +42,8 @@ #define debug(fmt,args...) #endif /* MKIMAGE_DEBUG */ +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + #define MKIMAGE_TMPFILE_SUFFIX ".tmp" #define MKIMAGE_MAX_TMPFILE_LEN256 #define MKIMAGE_DEFAULT_DTC_OPTIONS"-I dts -O dtb -p 500" -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 05/44] image: Move timestamp #ifdefs to header file
Rather than repeat the line #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || \ defined(USE_HOSTCC) everywhere, put this in a header file and #define IMAGE_ENABLE_TIMESTAMP to either 1 or 0. Then we can use a plain if() in most code and avoid the #ifdefs. The compiler's dead code elimination ensures that the result is the same. Signed-off-by: Simon Glass --- common/image.c | 50 +- include/image.h |8 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/common/image.c b/common/image.c index 936b08c..b75a9d0 100644 --- a/common/image.c +++ b/common/image.c @@ -39,9 +39,7 @@ #include #endif -#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) #include -#endif #include #include @@ -163,10 +161,6 @@ static const table_entry_t uimage_comp[] = { { -1, "", "", }, }; -#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) -static void genimg_print_time(time_t timestamp); -#endif - /*/ /* Legacy format routines */ /*/ @@ -312,10 +306,10 @@ void image_print_contents(const void *ptr) #endif printf("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name(hdr)); -#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) - printf("%sCreated: ", p); - genimg_print_time((time_t)image_get_time(hdr)); -#endif + if (IMAGE_ENABLE_TIMESTAMP) { + printf("%sCreated: ", p); + genimg_print_time((time_t)image_get_time(hdr)); + } printf("%sImage Type: ", p); image_print_type(hdr); printf("%sData Size:", p); @@ -524,8 +518,8 @@ void genimg_print_size(uint32_t size) #endif } -#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) -static void genimg_print_time(time_t timestamp) +#if IMAGE_ENABLE_TIMESTAMP +void genimg_print_time(time_t timestamp) { #ifndef USE_HOSTCC struct rtc_time tm; @@ -538,7 +532,7 @@ static void genimg_print_time(time_t timestamp) printf("%s", ctime(×tamp)); #endif } -#endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */ +#endif /** * get_table_entry_name - translate entry id to long name @@ -1911,9 +1905,7 @@ void fit_print_contents(const void *fit) int count = 0; int ret; const char *p; -#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) time_t timestamp; -#endif #ifdef USE_HOSTCC p = ""; @@ -1929,14 +1921,14 @@ void fit_print_contents(const void *fit) else printf("%s\n", desc); -#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) - ret = fit_get_timestamp(fit, 0, ×tamp); - printf("%sCreated: ", p); - if (ret) - printf("unavailable\n"); - else - genimg_print_time(timestamp); -#endif + if (IMAGE_ENABLE_TIMESTAMP) { + ret = fit_get_timestamp(fit, 0, ×tamp); + printf("%sCreated: ", p); + if (ret) + printf("unavailable\n"); + else + genimg_print_time(timestamp); + } /* Find images parent node offset */ images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); @@ -3047,13 +3039,13 @@ int fit_check_format(const void *fit) return 0; } -#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) - /* mandatory / node 'timestamp' property */ - if (fdt_getprop(fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) { - debug("Wrong FIT format: no timestamp\n"); - return 0; + if (IMAGE_ENABLE_TIMESTAMP) { + /* mandatory / node 'timestamp' property */ + if (fdt_getprop(fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) { + debug("Wrong FIT format: no timestamp\n"); + return 0; + } } -#endif /* mandatory subimages parent '/images' node */ if (fdt_path_offset(fit, FIT_IMAGES_PATH) < 0) { diff --git a/include/image.h b/include/image.h index b958b18..e8ddb8f 100644 --- a/include/image.h +++ b/include/image.h @@ -330,6 +330,14 @@ int genimg_get_type_id(const char *name); int genimg_get_comp_id(const char *name); void genimg_print_size(uint32_t size); +#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || \ + defined(USE_HOSTCC) +#define IMAGE_ENABLE_TIMESTAMP 1 +#else +#define IMAGE_ENABLE_TIMESTAMP 0 +#endif +void genimg_print_time(time_t timestamp); + #ifndef USE_HOSTCC /* Image format types, returned by _get_format() routine */ #define IMAGE_FORMAT_INVALID 0x0
[U-Boot] [RFC PATCH 13/44] image: Move error! string to common place
The string " error\n" appears in each error string. Move it out to a common place. Signed-off-by: Simon Glass --- common/image-fit.c | 16 1 files changed, 8 insertions(+), 8 deletions(-) diff --git a/common/image-fit.c b/common/image-fit.c index 4a78a5c..19942e2 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -867,7 +867,7 @@ static int fit_image_check_hash(const void *fit, int noffset, const void *data, *err_msgp = NULL; if (fit_image_hash_get_algo(fit, noffset, &algo)) { - *err_msgp = " error!\nCan't get hash algo " + *err_msgp = "Can't get hash algo " "property"; return -1; } @@ -883,23 +883,23 @@ static int fit_image_check_hash(const void *fit, int noffset, const void *data, if (fit_image_hash_get_value(fit, noffset, &fit_value, &fit_value_len)) { - *err_msgp = " error!\nCan't get hash value " + *err_msgp = "Can't get hash value " "property"; return -1; } if (calculate_hash(data, size, algo, value, &value_len)) { - *err_msgp = " error!\n" + *err_msgp = "" "Unsupported hash algorithm"; return -1; } if (value_len != fit_value_len) { - *err_msgp = " error !\nBad hash value len"; + *err_msgp = "Bad hash value len"; return -1; } else if (memcmp(value, fit_value, value_len) != 0) { - *err_msgp = " error!\nBad hash value"; + *err_msgp = "Bad hash value"; return -1; } @@ -929,7 +929,7 @@ int fit_image_verify(const void *fit, int image_noffset) /* Get image data and data length */ if (fit_image_get_data(fit, image_noffset, &data, &size)) { - printf("Can't get image data/size\n"); + err_msg = "Can't get image data/size"; return 0; } @@ -955,14 +955,14 @@ int fit_image_verify(const void *fit, int image_noffset) } if (noffset == -FDT_ERR_TRUNCATED || noffset == -FDT_ERR_BADSTRUCTURE) { - err_msg = " error!\nCorrupted or truncated tree"; + err_msg = "Corrupted or truncated tree"; goto error; } return 1; error: - printf("%s for '%s' hash node in '%s' image node\n", + printf(" error!\n%s for '%s' hash node in '%s' image node\n", err_msg, fit_get_name(fit, noffset, NULL), fit_get_name(fit, image_noffset, NULL)); return 0; -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 09/44] image: Split hash node processing into its own function
This function has become quite long and much of the body is indented quite a bit. Move it into a separate function to make it easier to work with. Signed-off-by: Simon Glass --- tools/image-host.c | 106 +++- 1 files changed, 63 insertions(+), 43 deletions(-) diff --git a/tools/image-host.c b/tools/image-host.c index 8c9b645..da96ab1 100644 --- a/tools/image-host.c +++ b/tools/image-host.c @@ -79,6 +79,62 @@ int fit_set_hashes(void *fit) } /** + * fit_image_process_hash - Process a single subnode of the images/ node + * + * Check each subnode and process accordingly. For hash nodes we generate + * a hash of the supplised data and store it in the node. + * + * @fit: pointer to the FIT format image header + * @image_name:name of image being processes (used to display errors) + * @noffset: subnode offset + * @data: data to process + * @size: size of data in bytes + * @return 0 if ok, -1 on error + */ +static int fit_image_process_hash(void *fit, const char *image_name, + int noffset, const void *data, size_t size) +{ + uint8_t value[FIT_MAX_HASH_LEN]; + int value_len; + char *algo; + + /* +* Check subnode name, must be equal to "hash". +* Multiple hash nodes require unique unit node +* names, e.g. hash@1, hash@2, etc. +*/ + if (strncmp(fit_get_name(fit, noffset, NULL), + FIT_HASH_NODENAME, + strlen(FIT_HASH_NODENAME)) != 0) + return 0; + + if (fit_image_hash_get_algo(fit, noffset, &algo)) { + printf("Can't get hash algo property for " + "'%s' hash node in '%s' image node\n", + fit_get_name(fit, noffset, NULL), image_name); + return -1; + } + + if (calculate_hash(data, size, algo, value, + &value_len)) { + printf("Unsupported hash algorithm (%s) for " + "'%s' hash node in '%s' image node\n", + algo, fit_get_name(fit, noffset, NULL), image_name); + return -1; + } + + if (fit_image_hash_set_value(fit, noffset, value, + value_len)) { + printf("Can't set hash value for " + "'%s' hash node in '%s' image node\n", + fit_get_name(fit, noffset, NULL), image_name); + return -1; + } + + return 0; +} + +/** * fit_image_set_hashes - calculate/set hashes for given component image node * @fit: pointer to the FIT format image header * @image_noffset: requested component image node @@ -111,11 +167,9 @@ int fit_image_set_hashes(void *fit, int image_noffset) { const void *data; size_t size; - char *algo; - uint8_t value[FIT_MAX_HASH_LEN]; - int value_len; int noffset; int ndepth; + const char *image_name; /* Get image data and data length */ if (fit_image_get_data(fit, image_noffset, &data, &size)) { @@ -123,51 +177,17 @@ int fit_image_set_hashes(void *fit, int image_noffset) return -1; } + image_name = fit_get_name(fit, image_noffset, NULL); + /* Process all hash subnodes of the component image node */ for (ndepth = 0, noffset = fdt_next_node(fit, image_noffset, &ndepth); -(noffset >= 0) && (ndepth > 0); -noffset = fdt_next_node(fit, noffset, &ndepth)) { + (noffset >= 0) && (ndepth > 0); + noffset = fdt_next_node(fit, noffset, &ndepth)) { if (ndepth == 1) { /* Direct child node of the component image node */ - - /* -* Check subnode name, must be equal to "hash". -* Multiple hash nodes require unique unit node -* names, e.g. hash@1, hash@2, etc. -*/ - if (strncmp(fit_get_name(fit, noffset, NULL), - FIT_HASH_NODENAME, - strlen(FIT_HASH_NODENAME)) != 0) { - /* Not a hash subnode, skip it */ - continue; - } - - if (fit_image_hash_get_algo(fit, noffset, &algo)) { - printf("Can't get hash algo property for " - "'%s' hash node in '%s' image node\n", - fit_get_name(fit, noffset, NULL), - fit_get_name(fit, image_noffset, NULL)); - return -1; - } - - if (calculate_hash(data, size, algo, value, -
[U-Boot] [RFC PATCH 02/44] bootstage: Don't build for HOSTCC
We don't measure boot timing on the host, or with SPL, so use both conditions in the bootstage header. This allows us to avoid using conditional compilation around bootstage_...() calls. (#ifdef) Signed-off-by: Simon Glass --- include/bootstage.h |5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/bootstage.h b/include/bootstage.h index 3b2216b..08bf2b0 100644 --- a/include/bootstage.h +++ b/include/bootstage.h @@ -221,7 +221,7 @@ enum bootstage_id { */ ulong timer_get_boot_us(void); -#ifndef CONFIG_SPL_BUILD +#if !defined(CONFIG_SPL_BUILD) && !defined(USE_HOSTCC) /* * Board code can implement show_boot_progress() if needed. * @@ -233,7 +233,8 @@ void show_boot_progress(int val); #define show_boot_progress(val) do {} while (0) #endif -#if defined(CONFIG_BOOTSTAGE) && !defined(CONFIG_SPL_BUILD) +#if defined(CONFIG_BOOTSTAGE) && !defined(CONFIG_SPL_BUILD) \ + && !defined(USE_HOSTCC) /* This is the full bootstage implementation */ /** -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 01/44] sandbox: config: Enable CONFIG_FIT and CONFIG_CMD_FIT
Enable these options to use FITs on sandbox. Signed-off-by: Simon Glass --- include/configs/sandbox.h |2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index 406da43..67d788a 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -31,6 +31,8 @@ #define CONFIG_OF_CONTROL #define CONFIG_OF_LIBFDT #define CONFIG_LMB +#define CONFIG_FIT +#define CONFIG_CMD_FDT #define CONFIG_FS_FAT #define CONFIG_FS_EXT4 -- 1.7.7.3 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [RFC PATCH 0/44] RFC: Verified boot implementation based on FIT
This series implemented a verified boot system based around FIT images as discussed on the U-Boot mailing list, including on this thread: http://permalink.gmane.org/gmane.comp.boot-loaders.u-boot/147830 RSA is used to implement the encryption. Images are signed by mkimage using private keys created by the user. Public keys are written into U-Boot control FDT (CONFIG_OF_CONTROL) for access by bootm etc. at run-time. The control FDT must be stored in a secure place where it cannot be changed after manufacture. Some notes are provided in the documentaion on how this can be achieved. When images are loaded, they are verified with the public keys. Some minor restructuring of the image code is included in this series, since we now support signatures as well as hashes. It is important to have a test framework for this series. For this, sandbox is used, and a script is provided which signs images and gets sandbox to load them using a script, to check that all is well. So some of the patches here release to adding image support for sandbox. This series is not quite in final form since it still needs rollback support, using a TPM or some other mechanism to make sure that an attacker cannot boot your system with an old image that has been compromised. Also a few more tests are needed to check that image corruption has the desired effect, some proofreading is required, another review of error checking, etc. This series relies on two previous series: sandbox filesystem and sandbox memory. Without these, it is (at best) not possible to run the verified boot test on sandbox. This series and its dependencies are available at: http://git.denx.de/u-boot-x86.git in the branch 'vboot'. Comments welcome. Simon Glass (44): sandbox: config: Enable CONFIG_FIT and CONFIG_CMD_FIT bootstage: Don't build for HOSTCC mkimage: Move ARRAY_SIZE to header file libfdt: Add fdt_next_subnode() to permit easy subnode iteration image: Move timestamp #ifdefs to header file image: Export fit_check_ramdisk() image: Split FIT code into new image-fit.c image: Move HOSTCC image code to tools/ image: Split hash node processing into its own function image: Convert fit_image_hash_set_value() to static, and rename image: Rename fit_image_check_hashes() to fit_image_verify() image: Move hash checking into its own functions image: Move error! string to common place image: Export fit_conf_get_prop_node() image: Rename fit_add_hashes() to fit_add_verification_data() image: Rename hash printing to fit_image_print_verification_data() sandbox: Add CONFIG_OF_HOSTFILE to read FDT from host file fdt: Add a parameter to fdt_valid() Add getenv_hex() to return an environment variable as hex fdt: Allow fdt command to check and update control FDT sandbox: fdt: Support fdt command for sandbox env: Fix minor comment typos in cmd_nvedit fdt: Skip checking FDT if the pointer is NULL Revert "fdt- Tell the FDT library where the device tree is" Add stdarg to vsprintf.h Add minor updates to README.fdt-control hash: Add a way to calculate a hash for any algortihm sandbox: config: Enable FIT signatures with RSA sandbox: Provide a way to map from host RAM to U-Boot RAM sandbox: image: Add support for booting images in sandbox image: Add signing infrastructure image: Support signing of images image: Verify signatures in FIT images image: Add RSA support for image signing mkimage: Put FIT loading in function and tidy error handling mkimage: Add -k option to specify key directory mkimage: Add -K to write public keys to an FDT blob mkimage: Add -F option to modify an existing .fit file mkimage: Add -c option to specify a comment for key signing mkimage: Add -r option to specify keys that must be verified libfdt: Add fdt_find_regions() image: Add support for signing of FIT configurations Add verified boot information and test WIP: sandbox: config: Add test config for verified boot Makefile |1 + README | 15 + arch/sandbox/cpu/cpu.c |5 + arch/sandbox/cpu/start.c |7 + arch/sandbox/include/asm/io.h|2 + arch/sandbox/include/asm/state.h |1 + arch/sandbox/lib/board.c | 42 +- common/Makefile |2 + common/cmd_bootm.c | 37 +- common/cmd_fdt.c | 83 ++- common/cmd_fpga.c|2 +- common/cmd_nvedit.c | 19 +- common/cmd_source.c |2 +- common/cmd_ximg.c|2 +- common/hash.c| 22 + common/image-fit.c | 1544 +++ common/image-sig.c | 407 + common/image.c | 1677 +- common/main.c|8 - common/update.c |2 +- config.mk|1 + doc/README.fdt-control
Re: [U-Boot] [PATCH v2] mx6: Add workaround for ARM errata
On 1/4/2013 5:54 PM, Fabio Estevam wrote: From: Fabio Estevam Add workaround for the following ARM errata: 743622 and 751472. The motivation for this change is the following kernel commit 62e4d357a (ARM: 7609/1: disable errata work-arounds which access secure registers), which removes the errata from multiplatform kernel. Since imx has been converted to multiplatform in the kernel, we need to apply such workaround into the bootloader. Workaround code has been taken from arch/arm/mm/proc-v7.S from 3.7.1 kernel. Signed-off-by: Fabio Estevam --- Following patch has been proposed into arm kernel mailing list: http://www.spinics.net/lists/arm-kernel/msg214840.html Changes since v1: - Use the same style of the erratum in arch/arm/cpu/armv7/mx5/lowlevel_init.S. arch/arm/cpu/armv7/mx6/lowlevel_init.S | 10 ++ 1 file changed, 10 insertions(+) diff --git a/arch/arm/cpu/armv7/mx6/lowlevel_init.S b/arch/arm/cpu/armv7/mx6/lowlevel_init.S index acadef2..ae8141d 100644 --- a/arch/arm/cpu/armv7/mx6/lowlevel_init.S +++ b/arch/arm/cpu/armv7/mx6/lowlevel_init.S @@ -20,6 +20,16 @@ #include +.macro init_arm_errata + mrc 15, 0, r1, c1, c0, 1/* read diagnostic register */ i.MX 6Quad_6Dual Errata (Rev 0) TO1.2.pdf says this should be mrc 15, 0, r1, c15, c0, 1 Since it also says "undocumented Diagnostic Control register" and "c1, c0, 1" is "Auxiliary Control Register" I think c15 is right. Besides, you had C15 in rev 1. + /* ARM erratum ID #743622 */ + orr r1, r1, #(1 << 6) /* set bit #6 */ + /* ARM erratum ID #751472 */ + orr r1, r1, #(1 << 11)/* set bit #11 */ + mcr 15, 0, r1, c1, c0, 1/* write diagnostic register */ mcr 15, 0, r1, c15, c0, 1 +.endm + ENTRY(lowlevel_init) + init_arm_errata mov pc, lr ENDPROC(lowlevel_init) ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] is it possilbe to have uboot find the kernel in the file system?
On Fri, 2013-01-04 at 23:12 +0100, Wolfgang Denk wrote: > Dear John Stile, > > In message <1357323597.6335.19.ca...@genx.eng.msli.com> you wrote: > > > > > I see the following board configurations supported in current mainline > > > code: at91sam9g20ek_nandflash, at91sam9g20ek_dataflash_cs0, and > > > at91sam9g20ek_dataflash_cs1 . Anything wrong with those? > > > > I'm going to have to wrestle with buildroot's uboot configuration or > > something... But it would be helpful to know what he build error means. > ... > > BR2_TARGET_UBOOT_BOARDNAME="at91sam9g20ek" > > I don't know what "BOARDNAME" is exactly supposed to mean here, but > probably this should be one of the configuration names I listed above. > > ... > > BR2_TARGET_AT91BOOTSTRAP_BOARD="at91sam9g20ek" > > Or this? I have no idea what the difference between BOARDNAME and > BOARD might be... > > > BR2_TARGET_AT91BOOTSTRAP_MEMORY="dataflash" > > OK, it appears you want one of the at91sam9g20ek_dataflash_csX > configurations... > > > make: *** No rule to make target `at91sam9g20ek_config'. Stop. > > Well, as mentioned in my previous message, the known config names are > "at91sam9g20ek_nandflash", "at91sam9g20ek_dataflash_cs0", and > "at91sam9g20ek_dataflash_cs1"; plain "at91sam9g20ek" is NOT a known > config name. > > > What should the target be? > > Depending whether you want to use CS0 or CS1 to address the dataflash > on your board, it should probably be "at91sam9g20ek_dataflash_cs0" > or "at91sam9g20ek_dataflash_cs1". > > > Maybe my buildroot is also so old it doesn't support the new uboot > > configuration syntax? > > I think it's just misconfigured. > > Best regards, > > Wolfgang Denk > u-boot-2012.10 build does compile with buildroot's .conf settings BR2_TARGET_UBOOT_BOARDNAME="at91sam9g20ek_dataflash_cs1" or BR2_TARGET_UBOOT_BOARDNAME="at91sam9g20ek_nandflash" But after writing my ubootEnvtFileDataFlash.bin to NOR with sam-ba utility (which works with the u-boot-1.3.4), it is not found by the ROM boot loader, so I'm not sure where to go for help. I know ROM boot loader executes what ever it finds at NOR start (0xD000) +0x8400. Does anyone else use a at91sam uboot-2012 and sam-ba, or have any other suggestions? ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH RESEND] video:cache:fix: Buffer alignment and dcache flush for lcd subsystem
Hi Lukasz, On Wed, Jan 2, 2013 at 8:25 AM, Lukasz Majewski wrote: > This commit makes the video subsystem code cache aware. > Memory allocated for decompressed BMP memory is now cache line aligned. > > Flushing of the dcache is also performed after copying BMP data to fb > address (it is done for 32 BPP bitmap used on Trats board (Exynos4210)). > Sorry if I have this wrong, just have a few comments. > > Tested-by: Lukasz Majewski > Signed-off-by: Lukasz Majewski > Signed-off-by: Kyungmin Park > Cc: Anatolij Gustschin > --- > common/cmd_bmp.c |2 +- > common/lcd.c |3 +++ > 2 files changed, 4 insertions(+), 1 deletions(-) > > diff --git a/common/cmd_bmp.c b/common/cmd_bmp.c > index 5a52edd..57f3eb5 100644 > --- a/common/cmd_bmp.c > +++ b/common/cmd_bmp.c > @@ -55,7 +55,7 @@ bmp_image_t *gunzip_bmp(unsigned long addr, unsigned long > *lenp) > * Decompress bmp image > */ > len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE; > - dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE); > + dst = memalign(CONFIG_SYS_CACHELINE_SIZE, len); Why do you need to align this one? It is just returned to the caller, isn't it? > if (dst == NULL) { > puts("Error: malloc in gunzip failed!\n"); > return NULL; > diff --git a/common/lcd.c b/common/lcd.c > index 4778655..784d1fb 100644 > --- a/common/lcd.c > +++ b/common/lcd.c > @@ -1023,6 +1023,9 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y) > } > fb -= (lcd_line_length + width * (bpix / 8)); > } > + flush_dcache_range((unsigned long) fb, > + (unsigned long) fb + > + (lcd_line_length * height)); I'm not sure this is needed - there is a call to lcd_sync() at the bottom of this function now which should do the same thing, Please can you take a look at currently mainline and see if you need to do anything more? > break; > #endif /* CONFIG_BMP_32BPP */ > default: > -- > 1.7.2.3 > Regards, Simon ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v4 1/2] arm: move C runtime setup code in crt0.S
Hi Albert, On Wed, Dec 26, 2012 at 12:41 PM, Simon Glass wrote: > Hi Albert, > > On Sun, Dec 23, 2012 at 7:03 AM, Albert ARIBAUD > wrote: >> Hi Simon, >> >> On Fri, 30 Nov 2012 14:10:01 -0800, Simon Glass >> wrote: >> >>> >> I tried to test it on a snow (exynos5250) but couldn't really sync up >>> >> with our tree, so gave up. I am not completely sure about how the >>> >> CONFIG_SPL_BUILD stuff fits together in start.S and I got a build >>> >> error I wasn't sure how to correct (arch/arm/cpu/armv7/start.S:179: >>> >> undefined reference to `relocate_done') >>> > >>> > Thansk Simon. >>> > >>> > In file arch/arm/cpu/armv7/start.S, line 179 uses relocate_done and >>> > line 228 provides it, and there is no preprocessor conditional >>> > in-between, so I fail to see how you could get this error. >>> > >>> > Is your tree (and branch) available so that I can try and see the issue >>> > for myself? Either it'll uncover a problem in my patch series, or it'll >>> > help you merge it (or both). >>> >>> OK I will try a bit harder and come back to you. Sorry I can't do that >>> immediately but will be soon... >> >> Did you manage to reproduce or sort out this issue? > > No, I was hoping that I would be able to test upstream U-Boot on snow > (waiting on some memory patches to appear), but that hasn't happened. > I will have another go at working out the problem - either this week > or next depending on when I can set aside the time for it. However, > please don't hold up the series for it. I have tested this on snow at last. My problem was basically the distance between our tree and upstream - we are just coming up to a rebase so are at the furthest point. Tested-by: Simon Glass Acked-by: Simon Glass > >> >>> Regards, >>> Simon >> >> Amicalement, >> -- >> Albert. > > Regards, > Simon ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH v2] mx6: Add workaround for ARM errata
From: Fabio Estevam Add workaround for the following ARM errata: 743622 and 751472. The motivation for this change is the following kernel commit 62e4d357a (ARM: 7609/1: disable errata work-arounds which access secure registers), which removes the errata from multiplatform kernel. Since imx has been converted to multiplatform in the kernel, we need to apply such workaround into the bootloader. Workaround code has been taken from arch/arm/mm/proc-v7.S from 3.7.1 kernel. Signed-off-by: Fabio Estevam --- Following patch has been proposed into arm kernel mailing list: http://www.spinics.net/lists/arm-kernel/msg214840.html Changes since v1: - Use the same style of the erratum in arch/arm/cpu/armv7/mx5/lowlevel_init.S. arch/arm/cpu/armv7/mx6/lowlevel_init.S | 10 ++ 1 file changed, 10 insertions(+) diff --git a/arch/arm/cpu/armv7/mx6/lowlevel_init.S b/arch/arm/cpu/armv7/mx6/lowlevel_init.S index acadef2..ae8141d 100644 --- a/arch/arm/cpu/armv7/mx6/lowlevel_init.S +++ b/arch/arm/cpu/armv7/mx6/lowlevel_init.S @@ -20,6 +20,16 @@ #include +.macro init_arm_errata + mrc 15, 0, r1, c1, c0, 1/* read diagnostic register */ + /* ARM erratum ID #743622 */ + orr r1, r1, #(1 << 6) /* set bit #6 */ + /* ARM erratum ID #751472 */ + orr r1, r1, #(1 << 11) /* set bit #11 */ + mcr 15, 0, r1, c1, c0, 1/* write diagnostic register */ +.endm + ENTRY(lowlevel_init) + init_arm_errata mov pc, lr ENDPROC(lowlevel_init) -- 1.7.9.5 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH] mx6: Add workaround for ARM errata
From: Fabio Estevam Add workaround for the following ARM errata: 743622 and 751472. The motivation for this change is the following kernel commit 62e4d357a (ARM: 7609/1: disable errata work-arounds which access secure registers), which removes the errata from multiplatform kernel. Since imx has been converted to multiplatform in the kernel, we need to apply such workaround into the bootloader. Workaround code has been taken from arch/arm/mm/proc-v7.S from 3.7.1 kernel. Signed-off-by: Fabio Estevam --- Following patch has been proposed into arm kernel mailing list: http://www.spinics.net/lists/arm-kernel/msg214840.html arch/arm/cpu/armv7/mx6/lowlevel_init.S | 10 ++ 1 file changed, 10 insertions(+) diff --git a/arch/arm/cpu/armv7/mx6/lowlevel_init.S b/arch/arm/cpu/armv7/mx6/lowlevel_init.S index acadef2..bf06152 100644 --- a/arch/arm/cpu/armv7/mx6/lowlevel_init.S +++ b/arch/arm/cpu/armv7/mx6/lowlevel_init.S @@ -20,6 +20,16 @@ #include +.macro init_arm_errata + /* ARM erratum ID #743622 */ + mrceq p15, 0, r10, c15, c0, 1 /* read diagnostic register */ + orreq r10, r10, #1 << 6 /* set bit #6 */ + /* ARM erratum ID #751472 */ + orrlt r10, r10, #1 << 11 /* set bit #11 */ + mcrlt p15, 0, r10, c15, c0, 1 /* write diagnostic register */ +.endm + ENTRY(lowlevel_init) + init_arm_errata mov pc, lr ENDPROC(lowlevel_init) -- 1.7.9.5 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v2] tools: imximage: Load a size that is multiple of 512
On Fri, Jan 4, 2013 at 10:08 PM, Fabio Estevam wrote: > On Fri, Jan 4, 2013 at 7:03 AM, Stefano Babic wrote: > >>> Is this i.MX53 specific or is this valid for i.MX6, too? >> >> It seems that i.MX6 is not afflicted by this issue. For i.MX6 it adds >> only some padding to the resulting image. > > Correct, I also tested this change on mx25/mx51/mx6 and they all boot fine. > > It is safe to apply this patch into 2012.01. Sorry, I meant 2013.01 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v2] tools: imximage: Load a size that is multiple of 512
On Fri, Jan 4, 2013 at 7:03 AM, Stefano Babic wrote: >> Is this i.MX53 specific or is this valid for i.MX6, too? > > It seems that i.MX6 is not afflicted by this issue. For i.MX6 it adds > only some padding to the resulting image. Correct, I also tested this change on mx25/mx51/mx6 and they all boot fine. It is safe to apply this patch into 2012.01. Regards, Fabio Estevam ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] is it possilbe to have uboot find the kernel in the file system?
Dear John Stile, In message <1357323597.6335.19.ca...@genx.eng.msli.com> you wrote: > > > I see the following board configurations supported in current mainline > > code: at91sam9g20ek_nandflash, at91sam9g20ek_dataflash_cs0, and > > at91sam9g20ek_dataflash_cs1 . Anything wrong with those? > > I'm going to have to wrestle with buildroot's uboot configuration or > something... But it would be helpful to know what he build error means. ... > BR2_TARGET_UBOOT_BOARDNAME="at91sam9g20ek" I don't know what "BOARDNAME" is exactly supposed to mean here, but probably this should be one of the configuration names I listed above. ... > BR2_TARGET_AT91BOOTSTRAP_BOARD="at91sam9g20ek" Or this? I have no idea what the difference between BOARDNAME and BOARD might be... > BR2_TARGET_AT91BOOTSTRAP_MEMORY="dataflash" OK, it appears you want one of the at91sam9g20ek_dataflash_csX configurations... > make: *** No rule to make target `at91sam9g20ek_config'. Stop. Well, as mentioned in my previous message, the known config names are "at91sam9g20ek_nandflash", "at91sam9g20ek_dataflash_cs0", and "at91sam9g20ek_dataflash_cs1"; plain "at91sam9g20ek" is NOT a known config name. > What should the target be? Depending whether you want to use CS0 or CS1 to address the dataflash on your board, it should probably be "at91sam9g20ek_dataflash_cs0" or "at91sam9g20ek_dataflash_cs1". > Maybe my buildroot is also so old it doesn't support the new uboot > configuration syntax? I think it's just misconfigured. Best regards, Wolfgang Denk -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de I don't see any direct evidence ... but, then, my crystal ball is in dire need of an ectoplasmic upgrade. :-) -- Howard Smith ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 6/7] getenv_f() env variable exist w/o needing a buffer
Dear York Sun, In message <1357323245-12455-6-git-send-email-york...@freescale.com> you wrote: > From: James Yang > > getenv_f() searches the environment for a variable name and copies the > value of the variable to a buffer pointed to by one of the function's > parameters. However, this means that the buffer needs to exist and > needs to be of sufficient length (passed as another parameter to > getenv_f()) to hold the requested variable's value, even if all that is > desired is the mere detection of the existence of the variable itself. > > This patch removes the requirement that the buffer needs to exist. If > the pointer to the buffer is set to NULL and the requested variable is Hm... this adds a special case and as such increases complexity - and what is the benefit for you? In your code, you use this feature exactly once, which means all you save is a single buffer on the stack of a function that does not appear to be critical in terms of stack size. > /* > * Look up variable from environment for restricted C runtime env. > + * If the variable is found, return the number of bytes copied. > + * If buf is NULL, len is ignored, and, if the variable is found, return 1. > + * If the variable is not found, return -1. I think your description is not quite correct, and I dislike the inconsistent behaviour we get though your patch. So far, this function returns the length of the variable value, or -1 in case of errors. This should not change even if we implement the suggested feature, i. e. even when passing NULL as buffer pointer the function should still return the length, and not some unrelated result. > + /* found */ > + if (!buf) > + return 1; I tend to NAK this part. Best regards, Wolfgang Denk -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de "One lawyer can steal more than a hundred men with guns." - The Godfather ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] is it possilbe to have uboot find the kernel in the file system?
Hello John, On 01/04/2013 07:19 PM, John Stile wrote: On Fri, 2013-01-04 at 09:00 +0100, Wolfgang Denk wrote: Dear John Stile, In message <1357265217.7939.131.camel@genx> you wrote: u-boot-2012.10.tar.bz2 does not have support for the at91sam9g20ek I treid to apply my patches for u-boot-1.3.4, but they are way too old. Is there a newer patch set? I see the following board configurations supported in current mainline code: at91sam9g20ek_nandflash, at91sam9g20ek_dataflash_cs0, and at91sam9g20ek_dataflash_cs1 . Anything wrong with those? note the trailing _nandflash, _dataflash_cs0 etc. I'm going to have to wrestle with buildroot's uboot configuration or something... But it would be helpful to know what he build error means. my buildroot .config sets: BR2_TARGET_UBOOT=y BR2_TARGET_UBOOT_BOARDNAME="at91sam9g20ek" BR2_TARGET_UBOOT_CUSTOM_TARBALL=y BR2_TARGET_UBOOT_CUSTOM_TARBALL_LOCATION="ftp://ftp.denx.de/pub/u-boot/u-boot-2012.10.tar.bz2"; BR2_TARGET_UBOOT_VERSION="custom" BR2_TARGET_UBOOT_FORMAT_BIN=y BR2_TARGET_AT91BOOTSTRAP=y BR2_TARGET_AT91BOOTSTRAP_BOARD="at91sam9g20ek" BR2_TARGET_AT91BOOTSTRAP_DATAFLASH=y BR2_TARGET_AT91BOOTSTRAP_MEMORY="dataflash" uboot build error: uboot custom Configuring PATH="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/bin:/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin:/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/sbin/:/home/jstile/Komodo-Edit-7/bin:/home/jstile/Komodo-Edit-7/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.4:/usr/games/bin:/home/jstile/bin:/home/jstile/bin" AR="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-ar" AS="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-as" LD="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-ld" NM="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-nm" CC="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-gcc" GCC="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-l in ux-uclibcgnueabi-gcc" CPP="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-cpp" CXX="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-g++" FC="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-gfortran" RANLIB="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-ranlib" STRIP="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-strip" OBJCOPY="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-objcopy" OBJDUMP="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-objdump" AR_FOR_BUILD="/usr/bin/ar" AS_FOR_BUILD="/usr/bin/as" CC_FOR_BUILD="/usr/bin/gcc" GCC_FOR_BUILD="/usr/bin/gcc" CXX_FOR_BUILD="/usr/bin/g++" FC_FOR_BUILD="/usr/bin/ld" LD_FOR_BUILD="/usr/bin/ld " C FLAGS_FOR_BUILD="-O2 -I/home/jstile/svn_rmserver/buildroot-2011.11/output/host/include -I/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/include" CXXFLAGS_FOR_BUILD="-I/home/jstile/svn_rmserver/buildroot-2011.11/output/host/include -I/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/include" LDFLAGS_FOR_BUILD="-L/home/jstile/svn_rmserver/buildroot-2011.11/output/host/lib -L/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/lib -Wl,-rpath,/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/lib" FCFLAGS_FOR_BUILD="" DEFAULT_ASSEMBLER="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-as" DEFAULT_LINKER="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-ld" CFLAGS="-pipe -Os -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64" CXXFLAGS="-pipe -Os -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64" LDFLAGS="" FCFLAGS=" " P KG_CONFIG="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/pkg-config" PERLLIB="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/lib/perl" STAGING_DIR="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/arm-unknown-linux-uclibcgnueabi/sysroot" CONFIG_NOSOFTFLOAT=1 /usr/bin/make -j2 -C /home/jstile/svn_rmserver/buildroot-2011.11/output/build/uboot-custom CROSS_COMPILE=" /home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-" ARCH=arm at91sam9g20ek_config last word, misses the _nandflash, you should get it there somehow.. make[1]: Entering directory `/home/jstile/svn_rmserver/buildroot-2011.11/output/build/uboot-custom' make[1]: Leaving directory `/home/jstile/svn_rmser
Re: [U-Boot] [RFC]: always relocate u-boot before the framebuffer
Hi Wolfgang, On 01/03/2013 09:28 PM, Wolfgang Denk wrote: The frame buffer is then at the same physical address and I regain 15MB of memory. So solved as far as I am concerned till proven that it really hurts performance. I can't grok this, though. I could understand if you say you saved up to 2 MB by lifting the 2 MB alignment requirement - but 15 MB? Please elucidate where this number is coming from. I had the frame buffer at 16mb before the end of the ram to allow u-boot, heap etc to relocated itself into the end of the frame buffer / ram. Without the CONFIG_FB_ADDR, the frame buffer it is located at 1mb before the end and u-boot relocates itself before it. So now linux has 15mb more since the framebuffer is at the 1mb before the end of ram and not 16mb as it used to be. Regards, Jeroen ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] is it possilbe to have uboot find the kernel in the file system?
On Fri, 2013-01-04 at 09:00 +0100, Wolfgang Denk wrote: > Dear John Stile, > > In message <1357265217.7939.131.camel@genx> you wrote: > > > > u-boot-2012.10.tar.bz2 does not have support for the at91sam9g20ek > > I treid to apply my patches for u-boot-1.3.4, but they are way too old. > > Is there a newer patch set? > > I see the following board configurations supported in current mainline > code: at91sam9g20ek_nandflash, at91sam9g20ek_dataflash_cs0, and > at91sam9g20ek_dataflash_cs1 . Anything wrong with those? I'm going to have to wrestle with buildroot's uboot configuration or something... But it would be helpful to know what he build error means. my buildroot .config sets: BR2_TARGET_UBOOT=y BR2_TARGET_UBOOT_BOARDNAME="at91sam9g20ek" BR2_TARGET_UBOOT_CUSTOM_TARBALL=y BR2_TARGET_UBOOT_CUSTOM_TARBALL_LOCATION="ftp://ftp.denx.de/pub/u-boot/u-boot-2012.10.tar.bz2"; BR2_TARGET_UBOOT_VERSION="custom" BR2_TARGET_UBOOT_FORMAT_BIN=y BR2_TARGET_AT91BOOTSTRAP=y BR2_TARGET_AT91BOOTSTRAP_BOARD="at91sam9g20ek" BR2_TARGET_AT91BOOTSTRAP_DATAFLASH=y BR2_TARGET_AT91BOOTSTRAP_MEMORY="dataflash" uboot build error: >>> uboot custom Configuring PATH="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/bin:/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin:/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/sbin/:/home/jstile/Komodo-Edit-7/bin:/home/jstile/Komodo-Edit-7/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.4:/usr/games/bin:/home/jstile/bin:/home/jstile/bin" AR="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-ar" AS="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-as" LD="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-ld" NM="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-nm" CC="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-gcc" GCC="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-lin ux-uclibcgnueabi-gcc" CPP="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-cpp" CXX="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-g++" FC="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-gfortran" RANLIB="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-ranlib" STRIP="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-strip" OBJCOPY="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-objcopy" OBJDUMP="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-objdump" AR_FOR_BUILD="/usr/bin/ar" AS_FOR_BUILD="/usr/bin/as" CC_FOR_BUILD="/usr/bin/gcc" GCC_FOR_BUILD="/usr/bin/gcc" CXX_FOR_BUILD="/usr/bin/g++" FC_FOR_BUILD="/usr/bin/ld" LD_FOR_BUILD="/usr/bin/ld" C FLAGS_FOR_BUILD="-O2 -I/home/jstile/svn_rmserver/buildroot-2011.11/output/host/include -I/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/include" CXXFLAGS_FOR_BUILD="-I/home/jstile/svn_rmserver/buildroot-2011.11/output/host/include -I/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/include" LDFLAGS_FOR_BUILD="-L/home/jstile/svn_rmserver/buildroot-2011.11/output/host/lib -L/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/lib -Wl,-rpath,/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/lib" FCFLAGS_FOR_BUILD="" DEFAULT_ASSEMBLER="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-as" DEFAULT_LINKER="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-ld" CFLAGS="-pipe -Os -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64" CXXFLAGS="-pipe -Os -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64" LDFLAGS="" FCFLAGS="" P KG_CONFIG="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/pkg-config" PERLLIB="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/lib/perl" STAGING_DIR="/home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/arm-unknown-linux-uclibcgnueabi/sysroot" CONFIG_NOSOFTFLOAT=1 /usr/bin/make -j2 -C /home/jstile/svn_rmserver/buildroot-2011.11/output/build/uboot-custom CROSS_COMPILE=" /home/jstile/svn_rmserver/buildroot-2011.11/output/host/usr/bin/arm-unknown-linux-uclibcgnueabi-" ARCH=arm at91sam9g20ek_config make[1]: Entering directory `/home/jstile/svn_rmserver/buildroot-2011.11/output/build/uboot-custom' make[1]: Leaving directory `/home/jstile/svn_rmserver/buildroot-2011.11/output/build/uboot-custom' make[1]: Entering directory `/home/jstile/svn_rmserver/buildroot-2011.11/output/build
[U-Boot] [PATCH 6/7] getenv_f() env variable exist w/o needing a buffer
From: James Yang getenv_f() searches the environment for a variable name and copies the value of the variable to a buffer pointed to by one of the function's parameters. However, this means that the buffer needs to exist and needs to be of sufficient length (passed as another parameter to getenv_f()) to hold the requested variable's value, even if all that is desired is the mere detection of the existence of the variable itself. This patch removes the requirement that the buffer needs to exist. If the pointer to the buffer is set to NULL and the requested variable is found, getenv_f() returns 1, else it returns -1. The buffer length parameter is ignored if the pointer is set to NULL. The original functionality of getenv_f() is retained (return number of bytes copied if variable is found, -1 if not), other than being able to copy the variable's value to the address 0. Signed-off-by: James Yang --- common/cmd_nvedit.c |9 - 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 7633f0c..caa8a36 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -587,6 +587,9 @@ char *getenv(const char *name) /* * Look up variable from environment for restricted C runtime env. + * If the variable is found, return the number of bytes copied. + * If buf is NULL, len is ignored, and, if the variable is found, return 1. + * If the variable is not found, return -1. */ int getenv_f(const char *name, char *buf, unsigned len) { @@ -604,7 +607,11 @@ int getenv_f(const char *name, char *buf, unsigned len) if (val < 0) continue; - /* found; copy out */ + /* found */ + if (!buf) + return 1; + + /* copy out */ for (n = 0; n < len; ++n, ++buf) { *buf = env_get_char(val++); if (*buf == '\0') -- 1.7.9.5 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH 5/7] README.fsl-ddr typos and update to reflect hotkey
From: James Yang Documentation fix to README.fsl-ddr to fix typos and to reflect use of 'd' hotkey to enter the FSL DDR debugger. Signed-off-by: James Yang --- doc/README.fsl-ddr | 35 +-- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/doc/README.fsl-ddr b/doc/README.fsl-ddr index b2a7c0f..1243a12 100644 --- a/doc/README.fsl-ddr +++ b/doc/README.fsl-ddr @@ -263,17 +263,21 @@ Reference http://www.samsung.com/global/business/semiconductor/products/dram/dow Interactive DDR debugging === -For DDR parameter tuning up and debugging, the interactive DDR debugging can -be activated by saving an environment variable "ddr_interactive". The value -doesn't matter. Once activated, U-boot prompts "FSL DDR>" before enabling DDR -controller. The available commands can be seen by typing "help". - -Another way to enter debug mode without using environment variable is to send -a key press during boot, like one would do to abort auto boot. To save booting -time, no additioal delay is added so the window to send the key press is very -short. For example, user can send the key press using reset command followed by -hitting enter key twice. In case of power on reset, user can keep hitting any -key while applying the power. +For DDR parameter tuning up and debugging, the interactive DDR debugger can +be activated by setting the environment variable "ddr_interactive" to any +value. (The value of ddr_interactive may have a meaning in the future, but, +for now, the presence of the variable will cause the debugger to run.) Once +activated, U-boot will show the prompt "FSL DDR>" before enabling the DDR +controller. The available commands are printed by typing "help". + +Another way to enter the interactive DDR debugger without setting the +environment variable is to send the 'd' character early during the boot +process. To save booting time, no additional delay is added, so the window +to send the key press is very short -- basically, it is the time before the +memory controller code starts to run. For example, when rebooting from +within u-boot, the user must press 'd' IMMEDIATELY after hitting enter to +initiate a 'reset' command. In case of power on/reset, the user can hold +down the 'd' key while applying power or hitting the board's reset button. The example flow of using interactive debugging is type command "compute" to calculate the parameters from the default @@ -281,13 +285,16 @@ type command "print" with arguments to show SPD, options, registers type command "edit" with arguments to change any if desired type command "copy" with arguments to copy controller/dimm settings type command "go" to continue calculation and enable DDR controller + +Additional commands to restart the debugging are: type command "reset" to reset the board type command "recompute" to reload SPD and start over Note, check "next_step" to show the flow. For example, after edit opts, the next_step is STEP_ASSIGN_ADDRESSES. After editing registers, the next_step is -STEP_PROGRAM_REGS. Upon issuing command "go", DDR controller will be enabled -with current setting without further calculation. +STEP_PROGRAM_REGS. Upon issuing command "go", the debugger will program the +DDR controller with the current setting without further calculation and then +exit to resume the booting of the machine. The detail syntax for each commands are @@ -340,7 +347,7 @@ Examples of debugging flow FSL DDR>compute Detected UDIMM UG51U6400N8SU-ACF - SL DDR>print + FSL DDR>print print [c] [d] [spd] [dimmparms] [commonparms] [opts] [addresses] [regs] FSL DDR>print dimmparms DIMM parameters: Controller=0 DIMM=0 -- 1.7.9.5 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH 3/7] Fix data stage name matching issue
From: James Yang This fix allows the name of the stage to be specifed after the controler and DIMM is specified. Prior to this fix, if the data stage name is not the first entry on the command line, the operation is applied to all controller and DIMMs. Signed-off-by: James Yang --- arch/powerpc/cpu/mpc8xxx/ddr/interactive.c |3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/cpu/mpc8xxx/ddr/interactive.c b/arch/powerpc/cpu/mpc8xxx/ddr/interactive.c index 4d1cf3c..0474acc 100644 --- a/arch/powerpc/cpu/mpc8xxx/ddr/interactive.c +++ b/arch/powerpc/cpu/mpc8xxx/ddr/interactive.c @@ -1390,9 +1390,10 @@ static unsigned int fsl_ddr_parse_interactive_cmd( unsigned int i, j; unsigned int error = 0; - unsigned int matched = 0; for (i = 1; i < argc; i++) { + unsigned int matched = 0; + for (j = 0; j < n_opts; j++) { if (strcmp(options[j].data_name, argv[i]) != 0) continue; -- 1.7.9.5 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH 2/7] Move DDR command parsing to separate function
From: James Yang Move the FSL DDR prompt command parsing to a separate function so that it can be reused. Signed-off-by: James Yang --- arch/powerpc/cpu/mpc8xxx/ddr/interactive.c | 153 ++-- 1 file changed, 74 insertions(+), 79 deletions(-) diff --git a/arch/powerpc/cpu/mpc8xxx/ddr/interactive.c b/arch/powerpc/cpu/mpc8xxx/ddr/interactive.c index cb71f94..4d1cf3c 100644 --- a/arch/powerpc/cpu/mpc8xxx/ddr/interactive.c +++ b/arch/powerpc/cpu/mpc8xxx/ddr/interactive.c @@ -1369,14 +1369,15 @@ struct data_strings { #define DATA_OPTIONS(name, step, dimm) {#name, step, dimm} -unsigned long long fsl_ddr_interactive(fsl_ddr_info_t *pinfo) -{ - unsigned long long ddrsize; - const char *prompt = "FSL DDR>"; - char buffer[CONFIG_SYS_CBSIZE]; - char *argv[CONFIG_SYS_MAXARGS + 1]; /* NULL terminated */ - int argc; - unsigned int next_step = STEP_GET_SPD; +static unsigned int fsl_ddr_parse_interactive_cmd( + char **argv, + int argc, + unsigned int *pstep_mask, + unsigned int *pctlr_mask, + unsigned int *pdimm_mask, + unsigned int *pdimm_number_required +) { + static const struct data_strings options[] = { DATA_OPTIONS(spd, STEP_GET_SPD, 1), DATA_OPTIONS(dimmparms, STEP_COMPUTE_DIMM_PARMS, 1), @@ -1386,6 +1387,56 @@ unsigned long long fsl_ddr_interactive(fsl_ddr_info_t *pinfo) DATA_OPTIONS(regs, STEP_COMPUTE_REGS, 0), }; static const unsigned int n_opts = ARRAY_SIZE(options); + + unsigned int i, j; + unsigned int error = 0; + unsigned int matched = 0; + + for (i = 1; i < argc; i++) { + for (j = 0; j < n_opts; j++) { + if (strcmp(options[j].data_name, argv[i]) != 0) + continue; + *pstep_mask |= options[j].step_mask; + *pdimm_number_required = + options[j].dimm_number_required; + matched = 1; + break; + } + + if (matched) + continue; + + if (argv[i][0] == 'c') { + char c = argv[i][1]; + if (isdigit(c)) + *pctlr_mask |= 1 << (c - '0'); + continue; + } + + if (argv[i][0] == 'd') { + char c = argv[i][1]; + if (isdigit(c)) + *pdimm_mask |= 1 << (c - '0'); + continue; + } + + printf("unknown arg %s\n", argv[i]); + *pstep_mask = 0; + error = 1; + break; + } + + return error; +} + +unsigned long long fsl_ddr_interactive(fsl_ddr_info_t *pinfo) +{ + unsigned long long ddrsize; + const char *prompt = "FSL DDR>"; + char buffer[CONFIG_SYS_CBSIZE]; + char *argv[CONFIG_SYS_MAXARGS + 1]; /* NULL terminated */ + int argc; + unsigned int next_step = STEP_GET_SPD; const char *usage = { "commands:\n" "print print SPD and intermediate computed data\n" @@ -1426,7 +1477,6 @@ unsigned long long fsl_ddr_interactive(fsl_ddr_info_t *pinfo) } if (strcmp(argv[0], "edit") == 0) { - unsigned int i, j; unsigned int error = 0; unsigned int step_mask = 0; unsigned int ctlr_mask = 0; @@ -1436,7 +1486,6 @@ unsigned long long fsl_ddr_interactive(fsl_ddr_info_t *pinfo) unsigned int dimm_number_required = 0; unsigned int ctrl_num; unsigned int dimm_num; - unsigned int matched = 0; if (argc == 1) { /* Only the element and value must be last */ @@ -1448,41 +1497,13 @@ unsigned long long fsl_ddr_interactive(fsl_ddr_info_t *pinfo) continue; } - for (i = 1; i < argc - 2; i++) { - for (j = 0; j < n_opts; j++) { - if (strcmp(options[j].data_name, - argv[i]) != 0) - continue; - step_mask |= options[j].step_mask; - dimm_number_required = - options[j].dimm_number_required; - matched = 1; - break; - } - - if (matched) - continue; -
[U-Boot] [PATCH 1/7] powerpc/mpc8xxx: Enable entering DDR debugging by key press
Using environmental variable "ddr_interactive" to activate interactive DDR debugging seomtiems is not enough. For example, after updating SPD with a valid but wrong image, u-boot won't come up due to wrong DDR configuration. By enabling key press method, we can enter debug mode to have a chance to boot without using other tools to recover the board. CONFIG_FSL_DDR_INTERACTIVE needs to be defined in header file. To enter the debug mode by key press, press key 'd' shortly after reset, like one would do to abort auto booting. It is fixed to lower case 'd' at this moment. Signed-off-by: York Sun --- arch/powerpc/cpu/mpc8xxx/ddr/main.c |6 -- doc/README.fsl-ddr |7 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/cpu/mpc8xxx/ddr/main.c b/arch/powerpc/cpu/mpc8xxx/ddr/main.c index d6b73c7..a33c9e2 100644 --- a/arch/powerpc/cpu/mpc8xxx/ddr/main.c +++ b/arch/powerpc/cpu/mpc8xxx/ddr/main.c @@ -532,9 +532,11 @@ phys_size_t fsl_ddr_sdram(void) /* Compute it once normally. */ #ifdef CONFIG_FSL_DDR_INTERACTIVE - if (getenv("ddr_interactive")) + if (getenv("ddr_interactive")) { total_memory = fsl_ddr_interactive(&info); - else + } else if (tstc() && (getc() == 'd')) { /* we got a key press of 'd' */ + total_memory = fsl_ddr_interactive(&info); + } else #endif total_memory = fsl_ddr_compute(&info, STEP_GET_SPD, 0); diff --git a/doc/README.fsl-ddr b/doc/README.fsl-ddr index 3992640..59583b3 100644 --- a/doc/README.fsl-ddr +++ b/doc/README.fsl-ddr @@ -268,6 +268,13 @@ be activated by saving an environment variable "ddr_interactive". The value doesn't matter. Once activated, U-boot prompts "FSL DDR>" before enabling DDR controller. The available commands can be seen by typing "help". +Another way to enter debug mode without using environment variable is to send +a key press during boot, like one would do to abort auto boot. To save booting +time, no additioal delay is added so the window to send the key press is very +short. For example, user can send the key press using reset command followed by +hitting enter key twice. In case of power on reset, user can keep hitting any +key while applying the power. + The example flow of using interactive debugging is type command "compute" to calculate the parameters from the default type command "print" with arguments to show SPD, options, registers -- 1.7.9.5 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH 4/7] Add copy command to FSL DDR interactive
From: James Yang Add copy command which allows copying of DIMM/controller settings. This saves tedious retyping of parameters for each identical DIMM or controller. Signed-off-by: James Yang --- arch/powerpc/cpu/mpc8xxx/ddr/interactive.c | 127 doc/README.fsl-ddr |5 ++ 2 files changed, 132 insertions(+) diff --git a/arch/powerpc/cpu/mpc8xxx/ddr/interactive.c b/arch/powerpc/cpu/mpc8xxx/ddr/interactive.c index 0474acc..e5ee775 100644 --- a/arch/powerpc/cpu/mpc8xxx/ddr/interactive.c +++ b/arch/powerpc/cpu/mpc8xxx/ddr/interactive.c @@ -1445,6 +1445,7 @@ unsigned long long fsl_ddr_interactive(fsl_ddr_info_t *pinfo) "recompute reload SPD and options to default and recompute regs\n" "edit modify spd, parameter, or option\n" "computerecompute registers from current next_step to end\n" + "copy copy parameters\n" "next_step shows current next_step\n" "help this message\n" "go program the memory controller and continue with u-boot\n" @@ -1477,6 +1478,132 @@ unsigned long long fsl_ddr_interactive(fsl_ddr_info_t *pinfo) continue; } + if (strcmp(argv[0], "copy") == 0) { + unsigned int error = 0; + unsigned int step_mask = 0; + unsigned int src_ctlr_mask = 0; + unsigned int src_dimm_mask = 0; + unsigned int dimm_number_required = 0; + unsigned int src_ctlr_num = 0; + unsigned int src_dimm_num = 0; + unsigned int dst_ctlr_num = -1; + unsigned int dst_dimm_num = -1; + unsigned int i, num_dest_parms; + + if (argc == 1) { + printf("copy \n"); + continue; + } + + error = fsl_ddr_parse_interactive_cmd( + argv, argc, + &step_mask, + &src_ctlr_mask, + &src_dimm_mask, + &dimm_number_required + ); + + /* XXX: only dimm_number_required and step_mask will + be used by this function. Parse the controller and + DIMM number separately because it is easier. */ + + if (error) + continue; + + /* parse source destination controller / DIMM */ + + num_dest_parms = dimm_number_required ? 2 : 1; + + for (i = 0; i < argc; i++) { + if (argv[i][0] == 'c') { + char c = argv[i][1]; + if (isdigit(c)) { + src_ctlr_num = (c - '0'); + break; + } + } + } + + for (i = 0; i < argc; i++) { + if (argv[i][0] == 'd') { + char c = argv[i][1]; + if (isdigit(c)) { + src_dimm_num = (c - '0'); + break; + } + } + } + + /* parse destination controller / DIMM */ + + for (i = argc - 1; i >= argc - num_dest_parms; i--) { + if (argv[i][0] == 'c') { + char c = argv[i][1]; + if (isdigit(c)) { + dst_ctlr_num = (c - '0'); + break; + } + } + } + + for (i = argc - 1; i >= argc - num_dest_parms; i--) { + if (argv[i][0] == 'd') { + char c = argv[i][1]; + if (isdigit(c)) { + dst_dimm_num = (c - '0'); + break; + } + } + } + + /* TODO: validate inputs */ + + debug("src_ctlr_num = %u, src_dimm_num = %u, dst_ctlr_num = %u, dst_dimm_num = %u, step_mask = %x\n"
[U-Boot] [PATCH 7/7] powerpc/mpc8xxx: FSL DDR debugger auto run of stored commands
From: James Yang This patch adds the ability for the FSL DDR interactive debugger to automatically run the sequence of commands stored in the ddr_interactive environment variable. Commands are separated using ';'. For example, ddr_interactive=compute; edit c0 d0 dimmparms caslat_X 0x3FC0; go Signed-off-by: James Yang --- arch/powerpc/cpu/mpc8xxx/ddr/ddr.h |2 +- arch/powerpc/cpu/mpc8xxx/ddr/interactive.c | 37 +++- arch/powerpc/cpu/mpc8xxx/ddr/main.c|8 +++--- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/arch/powerpc/cpu/mpc8xxx/ddr/ddr.h b/arch/powerpc/cpu/mpc8xxx/ddr/ddr.h index c8b0f91..369eaf7 100644 --- a/arch/powerpc/cpu/mpc8xxx/ddr/ddr.h +++ b/arch/powerpc/cpu/mpc8xxx/ddr/ddr.h @@ -86,7 +86,7 @@ void fsl_ddr_set_lawbar( unsigned int memctl_interleaved, unsigned int ctrl_num); -unsigned long long fsl_ddr_interactive(fsl_ddr_info_t *pinfo); +unsigned long long fsl_ddr_interactive(fsl_ddr_info_t *pinfo, int var_is_set); void fsl_ddr_get_spd(generic_spd_eeprom_t *ctrl_dimms_spd, unsigned int ctrl_num); diff --git a/arch/powerpc/cpu/mpc8xxx/ddr/interactive.c b/arch/powerpc/cpu/mpc8xxx/ddr/interactive.c index e5ee775..1d9ddcc 100644 --- a/arch/powerpc/cpu/mpc8xxx/ddr/interactive.c +++ b/arch/powerpc/cpu/mpc8xxx/ddr/interactive.c @@ -1430,11 +1430,13 @@ static unsigned int fsl_ddr_parse_interactive_cmd( return error; } -unsigned long long fsl_ddr_interactive(fsl_ddr_info_t *pinfo) +unsigned long long fsl_ddr_interactive(fsl_ddr_info_t *pinfo, int var_is_set) { unsigned long long ddrsize; const char *prompt = "FSL DDR>"; char buffer[CONFIG_SYS_CBSIZE]; + char buffer2[CONFIG_SYS_CBSIZE]; + char *p = NULL; char *argv[CONFIG_SYS_MAXARGS + 1]; /* NULL terminated */ int argc; unsigned int next_step = STEP_GET_SPD; @@ -1451,16 +1453,39 @@ unsigned long long fsl_ddr_interactive(fsl_ddr_info_t *pinfo) "go program the memory controller and continue with u-boot\n" }; + if (var_is_set) { + if (getenv_f("ddr_interactive", buffer2, CONFIG_SYS_CBSIZE) > 0) { + p = buffer2; + } else { + var_is_set = 0; + } + } + /* * The strategy for next_step is that it points to the next * step in the computation process that needs to be done. */ while (1) { - /* -* No need to worry for buffer overflow here in -* this function; readline() maxes out at CFG_CBSIZE -*/ - readline_into_buffer(prompt, buffer, 0); + if (var_is_set) { + char *pend = strchr(p, ';'); + if (pend) { + /* found commmand separator, copy this command and evaluate it. */ + *pend = '\0'; + strcpy(buffer, p); + p = pend + 1; + } else { + /* separator was not found, so copy the entire string */ + strcpy(buffer, p); + p = NULL; + var_is_set = 0; + } + } else { + /* +* No need to worry for buffer overflow here in +* this function; readline() maxes out at CFG_CBSIZE +*/ + readline_into_buffer(prompt, buffer, 0); + } argc = parse_line(buffer, argv); if (argc == 0) continue; diff --git a/arch/powerpc/cpu/mpc8xxx/ddr/main.c b/arch/powerpc/cpu/mpc8xxx/ddr/main.c index a33c9e2..741cd0f 100644 --- a/arch/powerpc/cpu/mpc8xxx/ddr/main.c +++ b/arch/powerpc/cpu/mpc8xxx/ddr/main.c @@ -532,10 +532,10 @@ phys_size_t fsl_ddr_sdram(void) /* Compute it once normally. */ #ifdef CONFIG_FSL_DDR_INTERACTIVE - if (getenv("ddr_interactive")) { - total_memory = fsl_ddr_interactive(&info); - } else if (tstc() && (getc() == 'd')) { /* we got a key press of 'd' */ - total_memory = fsl_ddr_interactive(&info); + if (tstc() && (getc() == 'd')) {/* we got a key press of 'd' */ + total_memory = fsl_ddr_interactive(&info, 0); + } else if (getenv_f("ddr_interactive", NULL, 0) > 0) { + total_memory = fsl_ddr_interactive(&info, 1); } else #endif total_memory = fsl_ddr_compute(&info, STEP_GET_SPD, 0); -- 1.7.9.5 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 9/9] dfu: Support larger than memory transfers.
Hi Kasim, On Jan 3, 2013, at 10:30 AM, kasim ling wrote: > Hi, Pantelis, > A little confusion about FAT fs write supporting, > > > On Sat, Dec 1, 2012 at 12:51 AM, Pantelis Antoniou > wrote: >> >> We didn't support upload/download larger than available memory. >> This is pretty bad when you have to update your root filesystem for >> example. >> >> This patch removes the limitation (and the crashes when you transfered >> any file larger than 4MB). >> On top of that reduces the huge dfu buffer from 4MB to just 64K, which >> was over the top. >> >> The sequence number is a 16 bit counter; make sure we >> handle rollover correctly. This fixes the wrong transfers for >> large (> 256MB) images. >> >> Also utilize a variable to handle initialization, so that we >> don't rely on just the counter sent by the host. >> >> Signed-off-by: Pantelis Antoniou >> --- >> drivers/dfu/dfu.c | 244 >> +++--- >> drivers/dfu/dfu_mmc.c | 82 +++-- >> include/dfu.h | 21 - >> 3 files changed, 264 insertions(+), 83 deletions(-) > >> diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c >> index 083d745..29a2c2e 100644 >> --- a/drivers/dfu/dfu_mmc.c >> +++ b/drivers/dfu/dfu_mmc.c >> @@ -22,6 +22,7 @@ >> #include >> #include >> #include >> +#include >> #include >> >> enum dfu_mmc_op { >> @@ -30,35 +31,48 @@ enum dfu_mmc_op { >> }; >> >> static int mmc_block_op(enum dfu_mmc_op op, struct dfu_entity *dfu, >> - void *buf, long *len) >> + u64 offset, void *buf, long *len) >> { >>char cmd_buf[DFU_CMD_BUF_SIZE]; >> + u32 blk_start, blk_count; >> >> - sprintf(cmd_buf, "mmc %s 0x%x %x %x", >> - op == DFU_OP_READ ? "read" : "write", >> - (unsigned int) buf, >> - dfu->data.mmc.lba_start, >> - dfu->data.mmc.lba_size); >> - >> - if (op == DFU_OP_READ) >> + /* if buf == NULL return total size of the area */ >> + if (buf == NULL) { >>*len = dfu->data.mmc.lba_blk_size * dfu->data.mmc.lba_size; >> + return 0; >> + } >> + >> + blk_start = dfu->data.mmc.lba_start + >> + (u32)lldiv(offset, dfu->data.mmc.lba_blk_size); >> + blk_count = *len / dfu->data.mmc.lba_blk_size; >> + if (blk_start + blk_count > >> + dfu->data.mmc.lba_start + dfu->data.mmc.lba_size) { >> + debug("%s: block_op out of bounds\n", __func__); >> + return -1; >> + } >> + >> + sprintf(cmd_buf, "mmc %s %p %x %x", >> + op == DFU_OP_READ ? "read" : "write", >> +buf, blk_start, blk_count); >> >>debug("%s: %s 0x%p\n", __func__, cmd_buf, cmd_buf); >>return run_command(cmd_buf, 0); >> } >> >> -static inline int mmc_block_write(struct dfu_entity *dfu, void *buf, long >> *len) >> +static inline int mmc_block_write(struct dfu_entity *dfu, >> + u64 offset, void *buf, long *len) >> { >> - return mmc_block_op(DFU_OP_WRITE, dfu, buf, len); >> + return mmc_block_op(DFU_OP_WRITE, dfu, offset, buf, len); >> } >> >> -static inline int mmc_block_read(struct dfu_entity *dfu, void *buf, long >> *len) >> +static inline int mmc_block_read(struct dfu_entity *dfu, >> + u64 offset, void *buf, long *len) >> { >> - return mmc_block_op(DFU_OP_READ, dfu, buf, len); >> + return mmc_block_op(DFU_OP_READ, dfu, offset, buf, len); >> } >> >> static int mmc_file_op(enum dfu_mmc_op op, struct dfu_entity *dfu, >> - void *buf, long *len) >> + u64 offset, void *buf, long *len) >> { >>char cmd_buf[DFU_CMD_BUF_SIZE]; >>char *str_env; >> @@ -66,12 +80,17 @@ static int mmc_file_op(enum dfu_mmc_op op, struct >> dfu_entity *dfu, >> >>switch (dfu->layout) { >>case DFU_FS_FAT: >> - sprintf(cmd_buf, "fat%s mmc %d:%d 0x%x %s %lx", >> + sprintf(cmd_buf, "fat%s mmc %d:%d 0x%x %s %lx %llx", >>op == DFU_OP_READ ? "load" : "write", >>dfu->data.mmc.dev, dfu->data.mmc.part, >> - (unsigned int) buf, dfu->name, *len); >> + (unsigned int) buf, dfu->name, *len, offset); > Did you tested it on FAT partitions? According to do_fat_fswrite() > defined in common/cmd_fat.c, the "fatwrite" command does not support > "offset" argument. > No I haven't had a use case either for fat or ext2/3/4. So I guess it is as broken as it was before. If you want to write to a file, make sure it's smaller than the DFU buffer. One of these days the file access functions must be fixed. > > Thanks, > Alex Regards -- Pantelis ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH] mxs: Add NAND fdt and ramdisk partition to m28evk
Dear Scott Wood, > On 01/04/2013 10:04:06 AM, Marek Vasut wrote: > > Dear Scott Wood, > > > > > On 01/04/2013 09:58:28 AM, Marek Vasut wrote: > > > > Dear Scott Wood, > > > > > > > > > On 01/03/2013 11:19:35 PM, Marek Vasut wrote: > > > > > > Dear Scott Wood, > > > > > > > > > > > > > On 12/26/2012 12:26:13 PM, Otavio Salvador wrote: > > > > > > > > On Wed, Dec 26, 2012 at 1:13 AM, Marek Vasut > > > > > > > > > > > > wrote: > > > > > > > > > Dear Otavio Salvador, > > > > > > > > > > > > > > > > > >> On Tue, Dec 25, 2012 at 11:08 PM, Marek Vasut > > > > > > > > > > > > > > > > > > > > wrote: > > > > > > > > >> > Adjust the NAND partitioning layout so that there is > > > > a > > > > > > > > separate > > > > > > > > > > > > > > partition > > > > > > > > > > > > > > > > >> > for the ramdisk and fdt blob on the NAND. > > > > > > > > >> > > > > > > > > > >> > Signed-off-by: Marek Vasut > > > > > > > > >> > > > > > > > > >> A partition for a ramdisk? maybe initramfs or initrd > > > > might > > > > > > be > > > > > > > > > > > > better? > > > > > > > > > > > > > > > > > Separate ramdisk (initrd). > > > > > > > > > > > > > > > > So maybe name it 'initrd' in the partition table? > > > > > > > > > > > > > > Why bias users against using initramfs instead? > > > > > > > > > > > > I'm not biasing users against initramfs, but some users simply > > > > > > > > want > > > > > > > > > > separate > > > > > > ramdisk outside of the kernel. > > > > > > > > > > initramfs and initrd are different ways of formatting a ramdisk. > > > > > > > > It's > > > > > > > > > orthogonal to whether it's separate from the kernel image. > > > > > > > > True, so what is the discussion here about anyway? I fail to see > > > > the > > > > > > point -- is > > > > there a problem with the patch or not? If not, please apply for > > > > .01 > > > > > > release. > > > > > > I have no problem with it. My point was that "ramdisk" is a better > > > name than "initrd". > > > > The patch contains "ramdisk" ... go look at the patch please. > > Sigh... I said I have no problem with the patch. I was responding to > Otavio's suggestion to change it to initrd. Sigh ... I got lost in this (pointless) discussion, sorry. Best regards, Marek Vasut ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH] mxs: Add NAND fdt and ramdisk partition to m28evk
On 01/04/2013 10:04:06 AM, Marek Vasut wrote: Dear Scott Wood, > On 01/04/2013 09:58:28 AM, Marek Vasut wrote: > > Dear Scott Wood, > > > > > On 01/03/2013 11:19:35 PM, Marek Vasut wrote: > > > > Dear Scott Wood, > > > > > > > > > On 12/26/2012 12:26:13 PM, Otavio Salvador wrote: > > > > > > On Wed, Dec 26, 2012 at 1:13 AM, Marek Vasut > > > > > > > > wrote: > > > > > > > Dear Otavio Salvador, > > > > > > > > > > > > > >> On Tue, Dec 25, 2012 at 11:08 PM, Marek Vasut > > > > > > > > > > > > wrote: > > > > > > >> > Adjust the NAND partitioning layout so that there is a > > > > > > > > separate > > > > > > > > > > partition > > > > > > > > > > > > >> > for the ramdisk and fdt blob on the NAND. > > > > > > >> > > > > > > > >> > Signed-off-by: Marek Vasut > > > > > > >> > > > > > > >> A partition for a ramdisk? maybe initramfs or initrd might > > > > be > > > > > > > > better? > > > > > > > > > > > > > Separate ramdisk (initrd). > > > > > > > > > > > > So maybe name it 'initrd' in the partition table? > > > > > > > > > > Why bias users against using initramfs instead? > > > > > > > > I'm not biasing users against initramfs, but some users simply > > > > want > > > > > > separate > > > > ramdisk outside of the kernel. > > > > > > initramfs and initrd are different ways of formatting a ramdisk. > > > > It's > > > > > orthogonal to whether it's separate from the kernel image. > > > > True, so what is the discussion here about anyway? I fail to see the > > point -- is > > there a problem with the patch or not? If not, please apply for .01 > > release. > > I have no problem with it. My point was that "ramdisk" is a better > name than "initrd". The patch contains "ramdisk" ... go look at the patch please. Sigh... I said I have no problem with the patch. I was responding to Otavio's suggestion to change it to initrd. -Scott ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH] mxs: Add NAND fdt and ramdisk partition to m28evk
Dear Scott Wood, > On 01/04/2013 09:58:28 AM, Marek Vasut wrote: > > Dear Scott Wood, > > > > > On 01/03/2013 11:19:35 PM, Marek Vasut wrote: > > > > Dear Scott Wood, > > > > > > > > > On 12/26/2012 12:26:13 PM, Otavio Salvador wrote: > > > > > > On Wed, Dec 26, 2012 at 1:13 AM, Marek Vasut > > > > > > > > wrote: > > > > > > > Dear Otavio Salvador, > > > > > > > > > > > > > >> On Tue, Dec 25, 2012 at 11:08 PM, Marek Vasut > > > > > > > > > > > > wrote: > > > > > > >> > Adjust the NAND partitioning layout so that there is a > > > > > > > > separate > > > > > > > > > > partition > > > > > > > > > > > > >> > for the ramdisk and fdt blob on the NAND. > > > > > > >> > > > > > > > >> > Signed-off-by: Marek Vasut > > > > > > >> > > > > > > >> A partition for a ramdisk? maybe initramfs or initrd might > > > > be > > > > > > > > better? > > > > > > > > > > > > > Separate ramdisk (initrd). > > > > > > > > > > > > So maybe name it 'initrd' in the partition table? > > > > > > > > > > Why bias users against using initramfs instead? > > > > > > > > I'm not biasing users against initramfs, but some users simply > > > > want > > > > > > separate > > > > ramdisk outside of the kernel. > > > > > > initramfs and initrd are different ways of formatting a ramdisk. > > > > It's > > > > > orthogonal to whether it's separate from the kernel image. > > > > True, so what is the discussion here about anyway? I fail to see the > > point -- is > > there a problem with the patch or not? If not, please apply for .01 > > release. > > I have no problem with it. My point was that "ramdisk" is a better > name than "initrd". The patch contains "ramdisk" ... go look at the patch please. Best regards, Marek Vasut ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH] mxs: Add NAND fdt and ramdisk partition to m28evk
On 01/04/2013 09:58:28 AM, Marek Vasut wrote: Dear Scott Wood, > On 01/03/2013 11:19:35 PM, Marek Vasut wrote: > > Dear Scott Wood, > > > > > On 12/26/2012 12:26:13 PM, Otavio Salvador wrote: > > > > On Wed, Dec 26, 2012 at 1:13 AM, Marek Vasut > > > > wrote: > > > > > Dear Otavio Salvador, > > > > > > > > > >> On Tue, Dec 25, 2012 at 11:08 PM, Marek Vasut > > > > > > > > wrote: > > > > >> > Adjust the NAND partitioning layout so that there is a > > > > separate > > > > > > partition > > > > > > > > >> > for the ramdisk and fdt blob on the NAND. > > > > >> > > > > > >> > Signed-off-by: Marek Vasut > > > > >> > > > > >> A partition for a ramdisk? maybe initramfs or initrd might be > > > > > > > > better? > > > > > > > > > Separate ramdisk (initrd). > > > > > > > > So maybe name it 'initrd' in the partition table? > > > > > > Why bias users against using initramfs instead? > > > > I'm not biasing users against initramfs, but some users simply want > > separate > > ramdisk outside of the kernel. > > initramfs and initrd are different ways of formatting a ramdisk. It's > orthogonal to whether it's separate from the kernel image. True, so what is the discussion here about anyway? I fail to see the point -- is there a problem with the patch or not? If not, please apply for .01 release. I have no problem with it. My point was that "ramdisk" is a better name than "initrd". -Scott ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH] mxs: Add NAND fdt and ramdisk partition to m28evk
Dear Scott Wood, > On 01/03/2013 11:19:35 PM, Marek Vasut wrote: > > Dear Scott Wood, > > > > > On 12/26/2012 12:26:13 PM, Otavio Salvador wrote: > > > > On Wed, Dec 26, 2012 at 1:13 AM, Marek Vasut > > > > wrote: > > > > > Dear Otavio Salvador, > > > > > > > > > >> On Tue, Dec 25, 2012 at 11:08 PM, Marek Vasut > > > > > > > > wrote: > > > > >> > Adjust the NAND partitioning layout so that there is a > > > > separate > > > > > > partition > > > > > > > > >> > for the ramdisk and fdt blob on the NAND. > > > > >> > > > > > >> > Signed-off-by: Marek Vasut > > > > >> > > > > >> A partition for a ramdisk? maybe initramfs or initrd might be > > > > > > > > better? > > > > > > > > > Separate ramdisk (initrd). > > > > > > > > So maybe name it 'initrd' in the partition table? > > > > > > Why bias users against using initramfs instead? > > > > I'm not biasing users against initramfs, but some users simply want > > separate > > ramdisk outside of the kernel. > > initramfs and initrd are different ways of formatting a ramdisk. It's > orthogonal to whether it's separate from the kernel image. True, so what is the discussion here about anyway? I fail to see the point -- is there a problem with the patch or not? If not, please apply for .01 release. Best regards, Marek Vasut ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH] mxs: Add NAND fdt and ramdisk partition to m28evk
On 01/03/2013 06:49:05 PM, Otavio Salvador wrote: On Thu, Jan 3, 2013 at 9:42 PM, Scott Wood wrote: > On 12/26/2012 12:26:13 PM, Otavio Salvador wrote: >> >> On Wed, Dec 26, 2012 at 1:13 AM, Marek Vasut wrote: >> > Dear Otavio Salvador, >> > >> >> On Tue, Dec 25, 2012 at 11:08 PM, Marek Vasut wrote: >> >> > Adjust the NAND partitioning layout so that there is a separate >> >> > partition >> >> > for the ramdisk and fdt blob on the NAND. >> >> > >> >> > Signed-off-by: Marek Vasut >> >> >> >> A partition for a ramdisk? maybe initramfs or initrd might be better? >> > >> > Separate ramdisk (initrd). >> >> So maybe name it 'initrd' in the partition table? > > > Why bias users against using initramfs instead? I have nothing against initramfs or any other name, I just think 'ramdisk' is confusing (but it might be just my impression) that's why I commented in the patch so others can comment on it too. How is an abbreviation for "initial ramdisk" less confusing than "ramdisk"? -Scott ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH] mxs: Add NAND fdt and ramdisk partition to m28evk
On 01/03/2013 11:19:35 PM, Marek Vasut wrote: Dear Scott Wood, > On 12/26/2012 12:26:13 PM, Otavio Salvador wrote: > > On Wed, Dec 26, 2012 at 1:13 AM, Marek Vasut wrote: > > > Dear Otavio Salvador, > > > > > >> On Tue, Dec 25, 2012 at 11:08 PM, Marek Vasut > > > > wrote: > > >> > Adjust the NAND partitioning layout so that there is a separate > > > > partition > > > > >> > for the ramdisk and fdt blob on the NAND. > > >> > > > >> > Signed-off-by: Marek Vasut > > >> > > >> A partition for a ramdisk? maybe initramfs or initrd might be > > > > better? > > > > > Separate ramdisk (initrd). > > > > So maybe name it 'initrd' in the partition table? > > Why bias users against using initramfs instead? I'm not biasing users against initramfs, but some users simply want separate ramdisk outside of the kernel. initramfs and initrd are different ways of formatting a ramdisk. It's orthogonal to whether it's separate from the kernel image. -Scott ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH 2/2] powerpc/p2041: set RCW and PBI files for .pbl build or P2041RDB
In order to be able to build a u-boot.pbl image, both the CONFIG_PBLPBI_CONFIG and CONFIG_PBLRCW_CONFIG variables have to be defined. This patch sets these two files for the P2041RDB board. Signed-off-by: Valentin Longchamp --- include/configs/P2041RDB.h |2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/include/configs/P2041RDB.h b/include/configs/P2041RDB.h index 8b9b0db..bbc53ce 100644 --- a/include/configs/P2041RDB.h +++ b/include/configs/P2041RDB.h @@ -34,6 +34,8 @@ #ifdef CONFIG_RAMBOOT_PBL #define CONFIG_RAMBOOT_TEXT_BASE CONFIG_SYS_TEXT_BASE #define CONFIG_RESET_VECTOR_ADDRESS0xfffc +#define CONFIG_PBLPBI_CONFIG $(SRCTREE)/board/freescale/corenet_ds/pbi.cfg +#define CONFIG_PBLRCW_CONFIG $(SRCTREE)/board/freescale/corenet_ds/rcw_p2041rdb.cfg #endif #ifdef CONFIG_SRIO_PCIE_BOOT_SLAVE -- 1.7.1 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH 1/2] powerpc/p2041: add RCW file for P2041RDB
All the dev boards of Freescale's QorIQ family have a RCW that is supported by the u-boot.pbl build target. This patch adds one for the P2041 dev board. This RCW is suitable for the RAMBOOT_PBL scenarios and was tested on the P2041RDB booting from the eSPI NOR Flash (P2041RDB_SPIFLASH config). Signed-off-by: Valentin Longchamp --- board/freescale/corenet_ds/rcw_p2041rdb.cfg | 11 +++ 1 files changed, 11 insertions(+), 0 deletions(-) create mode 100644 board/freescale/corenet_ds/rcw_p2041rdb.cfg diff --git a/board/freescale/corenet_ds/rcw_p2041rdb.cfg b/board/freescale/corenet_ds/rcw_p2041rdb.cfg new file mode 100644 index 000..8df19dd --- /dev/null +++ b/board/freescale/corenet_ds/rcw_p2041rdb.cfg @@ -0,0 +1,11 @@ +# +# Default RCW for P2041RDB. +# + +#PBL preamble and RCW header +aa55aa55 010e0100 +#64 bytes RCW data +1260 241C +649FA0C1 C3C02000 5800 4000 + D0030F07 + -- 1.7.1 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH 0/2] powerpc/p2041: u-boot.pbl build for P2041RDB
This series enables the build of a u-boot.pbl for the P2041RDB dev board. Valentin Longchamp (2): powerpc/p2041: add RCW file for P2041RDB powerpc/p2041: set RCW and PBI files for .pbl build or P2041RDB board/freescale/corenet_ds/rcw_p2041rdb.cfg | 11 +++ include/configs/P2041RDB.h |2 ++ 2 files changed, 13 insertions(+), 0 deletions(-) create mode 100644 board/freescale/corenet_ds/rcw_p2041rdb.cfg ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v7] qi_lb60: add nand spl support
Hi Any chance merge this commit to upstream. make it a new year gift for me. :) Thanks Xiangfu On 10/30/2012 08:41 AM, Scott Wood wrote: > On 10/26/2012 08:07:47 PM, xian...@openmobilefree.net wrote: >> From: Xiangfu >> >> The JZ4740 CPU can load 8KB from two different addresses: >>1. the normal area up to 8KB starting from NAND flash address 0x >>2. the backup area up to 8KB starting from NAND flash address 0x2000 >> >> Signed-off-by: Xiangfu >> --- >> Makefile | 12 +++ >> arch/mips/cpu/xburst/Makefile |7 +- >> arch/mips/cpu/xburst/cpu.c|4 + >> arch/mips/cpu/xburst/jz4740.c | 82 +++-- >> arch/mips/cpu/xburst/spl/Makefile | 47 ++ >> arch/mips/cpu/xburst/spl/start.S | 63 + >> board/qi/qi_lb60/Makefile |4 + >> board/qi/qi_lb60/qi_lb60-spl.c| 30 +++ >> board/qi/qi_lb60/qi_lb60.c|8 +- >> board/qi/qi_lb60/u-boot-spl.lds | 61 + >> drivers/mtd/nand/jz4740_nand.c| 39 - >> include/configs/qi_lb60.h | 175 >> ++--- >> 12 files changed, 386 insertions(+), 146 deletions(-) >> create mode 100644 arch/mips/cpu/xburst/spl/Makefile >> create mode 100644 arch/mips/cpu/xburst/spl/start.S >> create mode 100644 board/qi/qi_lb60/qi_lb60-spl.c >> create mode 100644 board/qi/qi_lb60/u-boot-spl.lds > > For the drivers/mtd/nand part: > Acked-by: Scott Wood > > -Scott ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH V4 7/9] MMC: APIs to support resize of EMMC boot partition
Hi Amar, I wonder that include the moviNAND specific code in mmc.c? mmc_boot_partiton_size_change() looks like every vendor can use this function. Best Regards, Jaehoon Chung On 01/04/2013 06:34 PM, Amar wrote: > This patch adds APIs to open, close and to resize boot partiton for EMMC. > > Changes from V1: > New patch. > > Changes from V2: > 1)Updation of commit message and resubmition of proper patch set. > > Changes from V3: > No change. > > Signed-off-by: Amar > --- > drivers/mmc/mmc.c | 118 > ++ > include/mmc.h | 16 > 2 files changed, 134 insertions(+) > > diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c > index 72e8ce6..8175b49 100644 > --- a/drivers/mmc/mmc.c > +++ b/drivers/mmc/mmc.c > @@ -1327,3 +1327,121 @@ int mmc_initialize(bd_t *bis) > > return 0; > } > + > +int mmc_boot_partition_size_change(struct mmc *mmc, unsigned long bootsize, > + unsigned long rpmbsize) > +{ > + int err; > + struct mmc_cmd cmd; > + > + /* Only use this command for raw EMMC moviNAND */ > + /* Enter backdoor mode */ > + cmd.cmdidx = MMC_CMD_RES_MAN; > + cmd.resp_type = MMC_RSP_R1b; > + cmd.cmdarg = MMC_CMD62_ARG1; > + > + err = mmc_send_cmd(mmc, &cmd, NULL); > + if (err) { > + debug("mmc_boot_partition_size_change: Error1 = %d\n", err); > + return err; > + } > + > + /* Boot partition changing mode */ > + cmd.cmdidx = MMC_CMD_RES_MAN; > + cmd.resp_type = MMC_RSP_R1b; > + cmd.cmdarg = MMC_CMD62_ARG2; > + > + err = mmc_send_cmd(mmc, &cmd, NULL); > + if (err) { > + debug("mmc_boot_partition_size_change: Error2 = %d\n", err); > + return err; > + } > + /* boot partition size is multiple of 128KB */ > + bootsize = ((bootsize*1024)/128); > + > + /* Arg: boot partition size */ > + cmd.cmdidx = MMC_CMD_RES_MAN; > + cmd.resp_type = MMC_RSP_R1b; > + cmd.cmdarg = bootsize; > + > + err = mmc_send_cmd(mmc, &cmd, NULL); > + if (err) { > + debug("mmc_boot_partition_size_change: Error3 = %d\n", err); > + return err; > + } > + /* RPMB partition size is multiple of 128KB */ > + rpmbsize = ((rpmbsize*1024)/128); > + /* Arg: RPMB partition size */ > + cmd.cmdidx = MMC_CMD_RES_MAN; > + cmd.resp_type = MMC_RSP_R1b; > + cmd.cmdarg = rpmbsize; > + > + err = mmc_send_cmd(mmc, &cmd, NULL); > + if (err) { > + debug("mmc_boot_partition_size_change: Error4 = %d\n", err); > + return err; > + } > + return 0; > +} > + > +int mmc_boot_open(struct mmc *mmc) > +{ > + int err; > + struct mmc_cmd cmd; > + > + /* Boot ack enable, boot partition enable , boot partition access */ > + cmd.cmdidx = MMC_CMD_SWITCH; > + cmd.resp_type = MMC_RSP_R1b; > + > + cmd.cmdarg = (MMC_SWITCH_MODE_WRITE_BYTE << 24 | > + EXT_CSD_PART_CONF << 16 | > + (EXT_CSD_BOOT_ACK_ENABLE | > + EXT_CSD_BOOT_PARTITION_ENABLE | > + EXT_CSD_PARTITION_ACCESS_ENABLE) << 8); > + > + err = mmc_send_cmd(mmc, &cmd, NULL); > + if (err) { > + debug("mmc_boot_open: Error1 = %d\n", err); > + return err; > + } > + > + /* 4bit transfer mode at booting time. */ > + cmd.cmdidx = MMC_CMD_SWITCH; > + cmd.resp_type = MMC_RSP_R1b; > + > + cmd.cmdarg = (MMC_SWITCH_MODE_WRITE_BYTE << 24| > + EXT_CSD_BOOT_BUS_WIDTH << 16| > + ((1<<0) << 8)); > + > + err = mmc_send_cmd(mmc, &cmd, NULL); > + if (err) { > + debug("mmc_boot_open: Error2 = %d\n", err); > + return err; > + } > + > + return 0; > +} > + > +int mmc_boot_close(struct mmc *mmc) > +{ > + int err; > + struct mmc_cmd cmd; > + > + /* Boot ack enable, boot partition enable , boot partition access */ > + cmd.cmdidx = MMC_CMD_SWITCH; > + cmd.resp_type = MMC_RSP_R1b; > + > + cmd.cmdarg = (MMC_SWITCH_MODE_WRITE_BYTE << 24| > + EXT_CSD_PART_CONF << 16| > + (EXT_CSD_BOOT_ACK_ENABLE | > + EXT_CSD_BOOT_PARTITION_ENABLE | > + EXT_CSD_PARTITION_ACCESS_DISABLE) << 8); > + > + err = mmc_send_cmd(mmc, &cmd, NULL); > + if (err) { > + debug("mmc_boot_close: Error = %d\n", err); > + return err; > + } > + > + return 0; > +} > diff --git a/include/mmc.h b/include/mmc.h > index a13e2bd..999f0a3 100644 > --- a/include/mmc.h > +++ b/include/mmc.h > @@ -86,6 +86,11 @@ > #define MMC_CMD_APP_CMD 55 > #define MMC_CMD_SPI_READ_OCR 58 > #define MMC_CMD_SPI_CRC_ON_OFF 59 > +#define MMC_CMD_RES_MAN 62 > + > +#define MMC_CMD62_ARG1 0xefac62ec > +#define MMC_CMD62_AR
Re: [U-Boot] [PATCH] drivers/block/systemace: replaced in16/out16 with more common readw/writew macros
Dear Alexey, In message you wrote: > > but then do you think if there's any way to use some generic > read/write routines? For reference, please see section "KERNEL I/O BARRIER EFFECTS" in the Linux kernel Documentation/memory-barriers.txt file. According to that, we should strive to using ioreadX(), iowriteX() (and some kernel hackers actually support such an oppinion) - however, there is little support for thjis in existing code. ARM traditionally tends to be using readX(), writeX(), at least on the LE implmentamtions (I don't know what the BE variants do). PowerPC has tradtitionally been using inX(), outX() resp. their explicit counterparts in_leX() / in_beX() / out_leX() / out_beX(). These functions are also available in ARM, and have been used for drivers for IP blocks shared between SoCs of different architectures. > The problem is we use ml509 board loaded with Synopsys DW ACR700 core > and we need to access SystemACE CF-card controller (to boot Linux > kernel mainly). > > Or should I just add conditional branch for ARC architecture? Is there a need to change the driver at all? Can you not just provide the needed inX(), outX() accessors for your architecture? Best regards, Wolfgang Denk -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de "Why waste negative entropy on comments, when you could use the same entropy to create bugs instead?"- Steve Elias ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 9/9] COMMON: MMC: Command to support EMMC booting
Dear Amarendra Reddy, In message you wrote: > > Thanks for the review comments. > I would like to clarify that this patch resizes EMMC partitions. But does > not create partitions. > I think the statement *"..close and create partitions on EMMC"* was > misleading, which I corrected in latest patch set. > > The EMMC4.4 chips are provided with 2 boot partitons and 1 RPMB partition. > This patch merely deals with resizing Boot partitions & RPMB partition, by > sending proper commands to EMMC chip. I see, but I still think that instead of adding (E)MMC specific partition handling, we should instead start and add a generc command to create/change/delete partitions, and then provide the (E)MMC specific implementation for it. This way we can later add partition handling for other storage media if someone needs this. Otherwise we would have a growing number of completely separate implementations, with incomplatible user interfaces and all the other maintenance nightmares this would cause. That means the core of your implementation will remain the same, just the command interface should be made generic so it can be extended to add support for other storage devices. Best regards, Wolfgang Denk -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall in <1991nov13.194420.28...@netlabs.com> ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH] drivers/block/systemace: replaced in16/out16 with more common readw/writew macros
Hi Wolfgang, but then do you think if there's any way to use some generic read/write routines? The problem is we use ml509 board loaded with Synopsys DW ACR700 core and we need to access SystemACE CF-card controller (to boot Linux kernel mainly). Or should I just add conditional branch for ARC architecture? Regards, Alexey 2013/1/3 Wolfgang Denk : > Dear Alexey, > > please don't top post / full quote, and please keep the ML on Cc: - thanks. > > In message > you > wrote: >> >> And what if you use "__raw_writew"/"__raw_readw" instead? > > I'd rather not try that, as the __raw_* functions are missing the > memory barriers that are mandatory for such device access. > > Best regards, > > Wolfgang Denk > > -- > DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel > HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany > Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de > Hegel was right when he said that we learn from history that man can > never learn anything from history. - George Bernard Shaw ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 9/9] COMMON: MMC: Command to support EMMC booting
Dear Wolfgang, Thanks for the review comments. I would like to clarify that this patch resizes EMMC partitions. But does not create partitions. I think the statement *"..close and create partitions on EMMC"* was misleading, which I corrected in latest patch set. The EMMC4.4 chips are provided with 2 boot partitons and 1 RPMB partition. This patch merely deals with resizing Boot partitions & RPMB partition, by sending proper commands to EMMC chip. Thanks & Regards Amarendra Reddy. On 28 December 2012 21:11, Wolfgang Denk wrote: > Dear Amar, > > In message <1356709972-26549-10-git-send-email-amarendra...@samsung.com> > you wrote: > > This patch adds commands to open, close and create partitions on EMMC > > In which way are partitions on MC devices special, compare to > partitions on other storage devies? > > I mean, does it reeally make sense to create a (E?) MMC specific > command here, instead of providing general partition support hat can > also be used on other storage devices? > > Best regards, > > Wolfgang Denk > > -- > DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel > HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany > Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de > "Never face facts; if you do, you'll never get up in the morning." > - Marlo Thomas > ___ > U-Boot mailing list > U-Boot@lists.denx.de > http://lists.denx.de/mailman/listinfo/u-boot > ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH V4 8/9] SMDK5250: Enable EMMC booting
This patch adds support for EMMC booting on SMDK5250. Changes from V1: 1)Updated spl_boot.c file to maintain irom pointer table instead of using the #define values defined in header file. Changes from V2: 1)Updation of commit message and resubmition of proper patch set. Changes from V3: No change. Signed-off-by: Amar --- board/samsung/smdk5250/clock_init.c | 15 +++ board/samsung/smdk5250/clock_init.h | 5 board/samsung/smdk5250/spl_boot.c | 52 - 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/board/samsung/smdk5250/clock_init.c b/board/samsung/smdk5250/clock_init.c index c009ae5..154993c 100644 --- a/board/samsung/smdk5250/clock_init.c +++ b/board/samsung/smdk5250/clock_init.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "clock_init.h" #include "setup.h" @@ -664,3 +665,17 @@ void clock_init_dp_clock(void) /* We run DP at 267 Mhz */ setbits_le32(&clk->div_disp1_0, CLK_DIV_DISP1_0_FIMD1); } + +/* + * Set clock divisor value for booting from EMMC. + * Set DWMMC channel-0 clk div to operate mmc0 device at 50MHz. + */ +void emmc_boot_clk_div_set(void) +{ + struct exynos5_clock *clk = (struct exynos5_clock *)EXYNOS5_CLOCK_BASE; + unsigned int div_mmc; + + div_mmc = readl((unsigned int) &clk->div_fsys1) & ~FSYS1_MMC0_DIV_MASK; + div_mmc |= FSYS1_MMC0_DIV_VAL; + writel(div_mmc, (unsigned int) &clk->div_fsys1); +} diff --git a/board/samsung/smdk5250/clock_init.h b/board/samsung/smdk5250/clock_init.h index f751bcb..20a1d47 100644 --- a/board/samsung/smdk5250/clock_init.h +++ b/board/samsung/smdk5250/clock_init.h @@ -146,4 +146,9 @@ struct mem_timings *clock_get_mem_timings(void); * Initialize clock for the device */ void system_clock_init(void); + +/* + * Set clock divisor value for booting from EMMC. + */ +void emmc_boot_clk_div_set(void); #endif diff --git a/board/samsung/smdk5250/spl_boot.c b/board/samsung/smdk5250/spl_boot.c index d8f3c1e..906e197 100644 --- a/board/samsung/smdk5250/spl_boot.c +++ b/board/samsung/smdk5250/spl_boot.c @@ -23,16 +23,38 @@ #include #include +#include +#include +#include + +#include "clock_init.h" + +/* Index into irom ptr table */ +enum index { + MMC_INDEX, + EMMC44_INDEX, + EMMC44_END_INDEX, + SPI_INDEX, +}; + +/* IROM Function Pointers Table */ +u32 irom_ptr_table[] = { + [MMC_INDEX] = 0x02020030, /* iROM Function Pointer-SDMMC boot */ + [EMMC44_INDEX] = 0x02020044,/* iROM Function Pointer-EMMC4.4 boot*/ + [EMMC44_END_INDEX] = 0x02020048,/* iROM Function Pointer + -EMMC4.4 end boot operation */ + [SPI_INDEX] = 0x02020058, /* iROM Function Pointer-SPI boot */ + }; + enum boot_mode { BOOT_MODE_MMC = 4, BOOT_MODE_SERIAL = 20, + BOOT_MODE_EMMC = 8, /* EMMC4.4 */ /* Boot based on Operating Mode pin settings */ BOOT_MODE_OM = 32, BOOT_MODE_USB, /* Boot using USB download */ }; - typedef u32 (*spi_copy_func_t)(u32 offset, u32 nblock, u32 dst); - /* * Copy U-boot from mmc to RAM: * COPY_BL2_FNPTR_ADDR: Address in iRAM, which Contains @@ -40,23 +62,39 @@ enum boot_mode { */ void copy_uboot_to_ram(void) { - spi_copy_func_t spi_copy; enum boot_mode bootmode; - u32 (*copy_bl2)(u32, u32, u32); - + u32 (*spi_copy)(u32 offset, u32 nblock, u32 dst); + u32 (*copy_bl2)(u32 offset, u32 nblock, u32 dst); + u32 (*copy_bl2_from_emmc)(u32 nblock, u32 dst); + void (*end_bootop_from_emmc)(void); + /* read Operation Mode ststus register to find the bootmode */ bootmode = readl(EXYNOS5_POWER_BASE) & OM_STAT; switch (bootmode) { case BOOT_MODE_SERIAL: - spi_copy = *(spi_copy_func_t *)EXYNOS_COPY_SPI_FNPTR_ADDR; + spi_copy = (void *) *(u32 *)irom_ptr_table[SPI_INDEX]; spi_copy(SPI_FLASH_UBOOT_POS, CONFIG_BL2_SIZE, CONFIG_SYS_TEXT_BASE); break; case BOOT_MODE_MMC: - copy_bl2 = (void *) *(u32 *)COPY_BL2_FNPTR_ADDR; + copy_bl2 = (void *) *(u32 *)irom_ptr_table[MMC_INDEX]; copy_bl2(BL2_START_OFFSET, BL2_SIZE_BLOC_COUNT, CONFIG_SYS_TEXT_BASE); break; + case BOOT_MODE_EMMC: + /* Set the FSYS1 clock divisor value for EMMC boot */ + emmc_boot_clk_div_set(); + + copy_bl2_from_emmc = + (void *) *(u32 *)irom_ptr_table[EMMC44_INDEX]; + end_bootop_from_emmc = + (void *) *(u32 *)irom_ptr_table[EMMC44_END_INDEX]; + + copy_bl2_from_emmc(BL2_SIZE_BLOC_COUNT, CONFIG_SYS_TEXT_BASE); + end_bootop_from_emmc(); + +
[U-Boot] [PATCH V4 5/9] EXYNOS5: DWMMC: API to set mmc clock divisor
This API computes the divisor value based on MPLL clock and writes it into the FSYS1 register. Changes from V1: 1)Updated the function exynos5_mmc_set_clk_div() to receive 'device_i'd as input parameter instead of 'index'. Changes from V2: 1)Updation of commit message and resubmition of proper patch set. Changes from V3: 1)Removed the new API exynos5_mmc_set_clk_div() from clock.c, because existing API set_mmc_clk() can be used to set mmc clock. Signed-off-by: Amar --- arch/arm/cpu/armv7/exynos/clock.c | 4 ++-- arch/arm/include/asm/arch-exynos/clk.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/arm/cpu/armv7/exynos/clock.c b/arch/arm/cpu/armv7/exynos/clock.c index 973b84e..89574ba 100644 --- a/arch/arm/cpu/armv7/exynos/clock.c +++ b/arch/arm/cpu/armv7/exynos/clock.c @@ -490,7 +490,7 @@ static unsigned long exynos4_get_mmc_clk(int dev_index) (struct exynos4_clock *)samsung_get_base_clock(); unsigned long uclk, sclk; unsigned int sel, ratio, pre_ratio; - int shift; + int shift = 0; sel = readl(&clk->src_fsys); sel = (sel >> (dev_index << 2)) & 0xf; @@ -539,7 +539,7 @@ static unsigned long exynos5_get_mmc_clk(int dev_index) (struct exynos5_clock *)samsung_get_base_clock(); unsigned long uclk, sclk; unsigned int sel, ratio, pre_ratio; - int shift; + int shift = 0; sel = readl(&clk->src_fsys); sel = (sel >> (dev_index << 2)) & 0xf; diff --git a/arch/arm/include/asm/arch-exynos/clk.h b/arch/arm/include/asm/arch-exynos/clk.h index 1935b0b..a4d5b4e 100644 --- a/arch/arm/include/asm/arch-exynos/clk.h +++ b/arch/arm/include/asm/arch-exynos/clk.h @@ -29,6 +29,9 @@ #define VPLL 4 #define BPLL 5 +#define FSYS1_MMC0_DIV_MASK0xff0f +#define FSYS1_MMC0_DIV_VAL 0x0701 + unsigned long get_pll_clk(int pllreg); unsigned long get_arm_clk(void); unsigned long get_i2c_clk(void); -- 1.8.0 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH V4 4/9] EXYNOS5: DWMMC: Added FDT support for DWMMC
This patch adds FDT support for DWMMC, by reading the DWMMC node data from the device tree and initialising DWMMC channels as per data obtained from the node. Changes from V1: 1)Updated code to have same signature for the function exynos_dwmci_init() for both FDT and non-FDT versions. 2)Updated code to pass device_id parameter to the function exynos5_mmc_set_clk_div() instead of index. 3)Updated code to decode the value of "samsung,width" from FDT. 4)Channel index is computed instead of getting from FDT. Changes from V2: 1)Updation of commit message and resubmition of proper patch set. Changes from V3: 1)Replaced the new function exynos5_mmc_set_clk_div() with the existing function set_mmc_clk(). set_mmc_clk() will do the purpose. 2)Computation of FSYS block clock divisor (pre-ratio) is added. Signed-off-by: Vivek Gautam Signed-off-by: Amar --- arch/arm/include/asm/arch-exynos/dwmmc.h | 4 + drivers/mmc/exynos_dw_mmc.c | 129 +-- include/dwmmc.h | 4 + 3 files changed, 130 insertions(+), 7 deletions(-) diff --git a/arch/arm/include/asm/arch-exynos/dwmmc.h b/arch/arm/include/asm/arch-exynos/dwmmc.h index 8acdf9b..40dcc7b 100644 --- a/arch/arm/include/asm/arch-exynos/dwmmc.h +++ b/arch/arm/include/asm/arch-exynos/dwmmc.h @@ -29,8 +29,12 @@ int exynos_dwmci_init(u32 regbase, int bus_width, int index); +#ifdef CONFIG_OF_CONTROL +unsigned int exynos_dwmmc_init(const void *blob); +#else static inline unsigned int exynos_dwmmc_init(int index, int bus_width) { unsigned int base = samsung_get_base_mmc() + (0x1 * index); return exynos_dwmci_init(base, bus_width, index); } +#endif diff --git a/drivers/mmc/exynos_dw_mmc.c b/drivers/mmc/exynos_dw_mmc.c index 72a31b7..d7ca7d0 100644 --- a/drivers/mmc/exynos_dw_mmc.c +++ b/drivers/mmc/exynos_dw_mmc.c @@ -19,39 +19,154 @@ */ #include -#include #include +#include +#include +#include #include #include +#include + +#defineDWMMC_MAX_CH_NUM4 +#defineDWMMC_MAX_FREQ 5200 +#defineDWMMC_MIN_FREQ 40 +#defineDWMMC_MMC0_CLKSEL_VAL 0x03030001 +#defineDWMMC_MMC2_CLKSEL_VAL 0x03020001 +#defineONE_MEGA_HZ 100 +#defineSCALED_VAL_FOUR_HUNDRED 400 static char *EXYNOS_NAME = "EXYNOS DWMMC"; +u32 timing[3]; +/* + * Function used as callback function to initialise the + * CLKSEL register for every mmc channel. + */ static void exynos_dwmci_clksel(struct dwmci_host *host) { - u32 val; - val = DWMCI_SET_SAMPLE_CLK(DWMCI_SHIFT_0) | - DWMCI_SET_DRV_CLK(DWMCI_SHIFT_0) | DWMCI_SET_DIV_RATIO(0); + dwmci_writel(host, DWMCI_CLKSEL, host->clksel_val); +} - dwmci_writel(host, DWMCI_CLKSEL, val); +unsigned int exynos_dwmci_get_clk(int dev_index) +{ + return get_mmc_clk(dev_index); } int exynos_dwmci_init(u32 regbase, int bus_width, int index) { struct dwmci_host *host = NULL; + unsigned int clock, div; host = malloc(sizeof(struct dwmci_host)); if (!host) { printf("dwmci_host malloc fail!\n"); return 1; } + /* +* The max operating freq of FSYS block is 400MHz. +* Scale down the 400MHz to number 400. +* Scale down the MPLL clock by dividing MPLL_CLK with ONE_MEGA_HZ. +* Arrive at the divisor value taking 400 as the reference. +*/ + + /* get mpll clock and divide it by ONE_MEGA_HZ */ + clock = get_pll_clk(MPLL) / ONE_MEGA_HZ; + + /* Arrive at the divisor value. */ + for (div = 0; div <= 0xf; div++) { + if ((clock / (div + 1)) <= SCALED_VAL_FOUR_HUNDRED) + break; + } + + /* set the clock divisor for mmc */ + set_mmc_clk(index, div); + host->name = EXYNOS_NAME; host->ioaddr = (void *)regbase; host->buswidth = bus_width; +#ifdef CONFIG_OF_CONTROL + host->clksel_val = (DWMCI_SET_SAMPLE_CLK(timing[0]) | + DWMCI_SET_DRV_CLK(timing[1]) | + DWMCI_SET_DIV_RATIO(timing[2])); +#else + if (0 == index) + host->clksel_val = DWMMC_MMC0_CLKSEL_VAL; + if (2 == index) + host->clksel_val = DWMMC_MMC2_CLKSEL_VAL; +#endif host->clksel = exynos_dwmci_clksel; host->dev_index = index; - - add_dwmci(host, 5200, 40); + host->mmc_clk = exynos_dwmci_get_clk; + /* Add the mmc chennel to be registered with mmc core */ + add_dwmci(host, DWMMC_MAX_FREQ, DWMMC_MIN_FREQ); return 0; } +#ifdef CONFIG_OF_CONTROL +unsigned int exynos_dwmmc_init(const void *blob) +{ + u32 base; + int index, bus_width; + int node_list[DWMMC_MAX_CH
[U-Boot] [PATCH V4 2/9] EXYNOS5: FDT: Add DWMMC device node data
This patch adds DWMMC device node data for exynos5. This patch also adds binding file for DWMMC device node. Changes from V1: 1)Added binding file for DWMMC device node at the location "doc/device-tree-bindings/exynos/dwmmc.txt". 2)Removed the propname 'index' from device node. 3)Prefixed the vendor name 'samsung' before propname in device node. Changes from V2: 1)Updation of commit message and resubmition of proper patch set. Changes from V3: No change. Signed-off-by: Vivek Gautam Signed-off-by: Amar X --- arch/arm/dts/exynos5250.dtsi | 32 +++ board/samsung/dts/exynos5250-smdk5250.dts | 22 + doc/device-tree-bindings/exynos/dwmmc.txt | 29 3 files changed, 83 insertions(+) create mode 100644 doc/device-tree-bindings/exynos/dwmmc.txt diff --git a/arch/arm/dts/exynos5250.dtsi b/arch/arm/dts/exynos5250.dtsi index 1008797..b701ae5 100644 --- a/arch/arm/dts/exynos5250.dtsi +++ b/arch/arm/dts/exynos5250.dtsi @@ -138,4 +138,36 @@ reg = <0x131b 0x30>; interrupts = <0 130 0>; }; + + dwmmc@1220 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "samsung,exynos5250-dwmmc"; + reg = <0x1220 0x1000>; + interrupts = <0 75 0>; + }; + + dwmmc@1221 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "samsung,exynos5250-dwmmc"; + reg = <0x1221 0x1000>; + interrupts = <0 76 0>; + }; + + dwmmc@1222 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "samsung,exynos5250-dwmmc"; + reg = <0x1222 0x1000>; + interrupts = <0 77 0>; + }; + + dwmmc@1223 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "samsung,exynos5250-dwmmc"; + reg = <0x1223 0x1000>; + interrupts = <0 78 0>; + }; }; diff --git a/board/samsung/dts/exynos5250-smdk5250.dts b/board/samsung/dts/exynos5250-smdk5250.dts index a8e62da..9baf622 100644 --- a/board/samsung/dts/exynos5250-smdk5250.dts +++ b/board/samsung/dts/exynos5250-smdk5250.dts @@ -30,6 +30,10 @@ spi2 = "/spi@12d4"; spi3 = "/spi@131a"; spi4 = "/spi@131b"; + dwmmc0 = "/dwmmc@1220"; + dwmmc1 = "/dwmmc@1221"; + dwmmc2 = "/dwmmc@1222"; + dwmmc3 = "/dwmmc@1223"; }; sromc@1225 { @@ -59,4 +63,22 @@ compatible = "wolfson,wm8994-codec"; }; }; + + dwmmc@1220 { + samsung,bus-width = <8>; + samsung,timing = <1 3 3>; + }; + + dwmmc@1221 { + status = "disabled"; + }; + + dwmmc@1222 { + samsung,bus-width = <4>; + samsung,timing = <1 2 3>; + }; + + dwmmc@1223 { + status = "disabled"; + }; }; diff --git a/doc/device-tree-bindings/exynos/dwmmc.txt b/doc/device-tree-bindings/exynos/dwmmc.txt new file mode 100644 index 000..6232ad6 --- /dev/null +++ b/doc/device-tree-bindings/exynos/dwmmc.txt @@ -0,0 +1,29 @@ +* Exynos 5250 DWC_mobile_storage + +The Exynos 5250 provides DWC_mobile_storage interface which supports +. Embedded Multimedia Cards (EMMC-version 4.5) +. Secure Digital memory (SD mem-version 2.0) +. Secure Digital I/O (SDIO-version 3.0) +. Consumer Electronics Advanced Transport Architecture (CE-ATA-version 1.1) + +The Exynos 5250 DWC_mobile_storage provides four channels. +SOC specific and Board specific properties are channel specific. + +Required SoC Specific Properties: + +- compatible: should be + - samsung,exynos5250-dwmmc: for exynos5250 platforms + +- reg: physical base address of the controller and length of memory mapped + region. + +- interrupts: The interrupt number to the cpu. + +Required Board Specific Properties: + +- #address-cells: should be 1. +- #size-cells: should be 0. +- samsung,bus-width: The width of the bus used to interface the devices + supported by DWC_mobile_storage (SD-MMC/EMMC/SDIO). +- samsung,timing: The timing values to be written into the + Drv/sample clock selection register of corresponding channel. -- 1.8.0 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH V4 9/9] COMMON: MMC: Command to support EMMC booting and to
This patch adds commands to open, close and resize boot partitions on EMMC. Changes from V1: 1)Combined the common piece of code between 'open' and 'close' operations. Changes from V2: 1)Updation of commit message and resubmition of proper patch set. Changes from V3: No change. Signed-off-by: Amar --- common/cmd_mmc.c | 84 +++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/common/cmd_mmc.c b/common/cmd_mmc.c index 7dacd51..1dabb5b 100644 --- a/common/cmd_mmc.c +++ b/common/cmd_mmc.c @@ -248,6 +248,84 @@ static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) curr_device, mmc->part_num); return 0; + } else if ((strcmp(argv[1], "open") == 0) || + (strcmp(argv[1], "close") == 0)) { + int dev; + struct mmc *mmc; + + if (argc == 2) + dev = curr_device; + else if (argc == 3) + dev = simple_strtoul(argv[2], NULL, 10); + else + return CMD_RET_USAGE; + + mmc = find_mmc_device(dev); + if (!mmc) { + printf("no mmc device at slot %x\n", dev); + return 1; + } + + if (IS_SD(mmc)) { + printf("SD device cannot be opened/closed\n"); + return 1; + } + + if (strcmp(argv[1], "open") == 0) { + if (!(mmc_boot_open(mmc))) { + printf("EMMC OPEN Success.\n"); + printf("\t\t\t!!!Notice!!!\n"); + printf("!You must close EMMC" + " boot Partition after all" + " images are written\n"); + printf("!EMMC boot partition" + " has continuity at" + " image writing time.\n"); + printf("!So, Do not close boot" + " partition, Before, all" + " images are written.\n"); + return 0; + } else { + printf("EMMC OPEN Failed.\n"); + return 1; + } + } + + if (strcmp(argv[1], "close") == 0) { + if (!(mmc_boot_close(mmc))) { + printf("EMMC CLOSE Success.\n"); + return 0; + } else { + printf("EMMC CLOSE Failed.\n"); + return 1; + } + } + } else if (strcmp(argv[1], "bootpart") == 0) { + int dev; + dev = simple_strtoul(argv[2], NULL, 10); + + u32 bootsize = simple_strtoul(argv[3], NULL, 10); + u32 rpmbsize = simple_strtoul(argv[4], NULL, 10); + struct mmc *mmc = find_mmc_device(dev); + if (!mmc) { + printf("no mmc device at slot %x\n", dev); + return 1; + } + + if (IS_SD(mmc)) { + printf("It is not a EMMC device\n"); + return 1; + } + + if (0 == mmc_boot_partition_size_change(mmc, + bootsize, rpmbsize)) { + printf("EMMC boot partition Size %d MB\n", bootsize); + printf("EMMC RPMB partition Size %d MB\n", rpmbsize); + return 0; + } else { + printf("EMMC boot partition Size change Failed.\n"); + return 1; + } } state = MMC_INVALID; @@ -317,5 +395,9 @@ U_BOOT_CMD( "mmc rescan\n" "mmc part - lists available partition on current mmc device\n" "mmc dev [dev] [part] - show or set current mmc device [partition]\n" - "mmc list - lists available devices"); + "mmc list - lists available devices\n" + "mmc open - opens the specified device\n" + "mmc close - closes the specified device\n" + "mmc bootpart \n" + " - change sizes of boot and RPMB partions of specified device\n"); #endif -- 1.8.0 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH V4 7/9] MMC: APIs to support resize of EMMC boot partition
This patch adds APIs to open, close and to resize boot partiton for EMMC. Changes from V1: New patch. Changes from V2: 1)Updation of commit message and resubmition of proper patch set. Changes from V3: No change. Signed-off-by: Amar --- drivers/mmc/mmc.c | 118 ++ include/mmc.h | 16 2 files changed, 134 insertions(+) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 72e8ce6..8175b49 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -1327,3 +1327,121 @@ int mmc_initialize(bd_t *bis) return 0; } + +int mmc_boot_partition_size_change(struct mmc *mmc, unsigned long bootsize, + unsigned long rpmbsize) +{ + int err; + struct mmc_cmd cmd; + + /* Only use this command for raw EMMC moviNAND */ + /* Enter backdoor mode */ + cmd.cmdidx = MMC_CMD_RES_MAN; + cmd.resp_type = MMC_RSP_R1b; + cmd.cmdarg = MMC_CMD62_ARG1; + + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) { + debug("mmc_boot_partition_size_change: Error1 = %d\n", err); + return err; + } + + /* Boot partition changing mode */ + cmd.cmdidx = MMC_CMD_RES_MAN; + cmd.resp_type = MMC_RSP_R1b; + cmd.cmdarg = MMC_CMD62_ARG2; + + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) { + debug("mmc_boot_partition_size_change: Error2 = %d\n", err); + return err; + } + /* boot partition size is multiple of 128KB */ + bootsize = ((bootsize*1024)/128); + + /* Arg: boot partition size */ + cmd.cmdidx = MMC_CMD_RES_MAN; + cmd.resp_type = MMC_RSP_R1b; + cmd.cmdarg = bootsize; + + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) { + debug("mmc_boot_partition_size_change: Error3 = %d\n", err); + return err; + } + /* RPMB partition size is multiple of 128KB */ + rpmbsize = ((rpmbsize*1024)/128); + /* Arg: RPMB partition size */ + cmd.cmdidx = MMC_CMD_RES_MAN; + cmd.resp_type = MMC_RSP_R1b; + cmd.cmdarg = rpmbsize; + + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) { + debug("mmc_boot_partition_size_change: Error4 = %d\n", err); + return err; + } + return 0; +} + +int mmc_boot_open(struct mmc *mmc) +{ + int err; + struct mmc_cmd cmd; + + /* Boot ack enable, boot partition enable , boot partition access */ + cmd.cmdidx = MMC_CMD_SWITCH; + cmd.resp_type = MMC_RSP_R1b; + + cmd.cmdarg = (MMC_SWITCH_MODE_WRITE_BYTE << 24 | + EXT_CSD_PART_CONF << 16 | + (EXT_CSD_BOOT_ACK_ENABLE | + EXT_CSD_BOOT_PARTITION_ENABLE | + EXT_CSD_PARTITION_ACCESS_ENABLE) << 8); + + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) { + debug("mmc_boot_open: Error1 = %d\n", err); + return err; + } + + /* 4bit transfer mode at booting time. */ + cmd.cmdidx = MMC_CMD_SWITCH; + cmd.resp_type = MMC_RSP_R1b; + + cmd.cmdarg = (MMC_SWITCH_MODE_WRITE_BYTE << 24| + EXT_CSD_BOOT_BUS_WIDTH << 16| + ((1<<0) << 8)); + + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) { + debug("mmc_boot_open: Error2 = %d\n", err); + return err; + } + + return 0; +} + +int mmc_boot_close(struct mmc *mmc) +{ + int err; + struct mmc_cmd cmd; + + /* Boot ack enable, boot partition enable , boot partition access */ + cmd.cmdidx = MMC_CMD_SWITCH; + cmd.resp_type = MMC_RSP_R1b; + + cmd.cmdarg = (MMC_SWITCH_MODE_WRITE_BYTE << 24| + EXT_CSD_PART_CONF << 16| + (EXT_CSD_BOOT_ACK_ENABLE | + EXT_CSD_BOOT_PARTITION_ENABLE | + EXT_CSD_PARTITION_ACCESS_DISABLE) << 8); + + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) { + debug("mmc_boot_close: Error = %d\n", err); + return err; + } + + return 0; +} diff --git a/include/mmc.h b/include/mmc.h index a13e2bd..999f0a3 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -86,6 +86,11 @@ #define MMC_CMD_APP_CMD55 #define MMC_CMD_SPI_READ_OCR 58 #define MMC_CMD_SPI_CRC_ON_OFF 59 +#define MMC_CMD_RES_MAN62 + +#define MMC_CMD62_ARG1 0xefac62ec +#define MMC_CMD62_ARG2 0xcbaea7 + #define SD_CMD_SEND_RELATIVE_ADDR 3 #define SD_CMD_SWITCH_FUNC 6 @@ -153,6 +158,7 @@ */ #define EXT_CSD_PARTITIONING_SUPPORT 160 /* RO */ #define EXT_CSD_ERASE_GROUP_DEF175 /* R/W */ +#define EXT_CSD_BOOT_BUS_WIDTH 177 #define EXT_CSD_PART_CONF 179
[U-Boot] [PATCH V4 1/9] FDT: Add compatible string for DWMMC
Add required compatible information for DWMMC driver. Changes from V1: No change. Changes from V2: 1)Updation of commit message and resubmition of proper patch set. Changes from V3: No change. Signed-off-by: Vivek Gautam Signed-off-by: Amar Acked-by: Simon Glass --- include/fdtdec.h | 1 + lib/fdtdec.c | 1 + 2 files changed, 2 insertions(+) diff --git a/include/fdtdec.h b/include/fdtdec.h index ce10bf4..dcd4142 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -76,6 +76,7 @@ enum fdt_compat_id { COMPAT_SAMSUNG_EXYNOS5_SOUND, /* Exynos Sound */ COMPAT_WOLFSON_WM8994_CODEC,/* Wolfson WM8994 Sound Codec */ COMPAT_SAMSUNG_EXYNOS_SPI, /* Exynos SPI */ + COMPAT_SAMSUNG_EXYNOS5_DWMMC, /* Exynos5 DWMMC controller */ COMPAT_COUNT, }; diff --git a/lib/fdtdec.c b/lib/fdtdec.c index aa75710..646d5d6 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -51,6 +51,7 @@ static const char * const compat_names[COMPAT_COUNT] = { COMPAT(SAMSUNG_EXYNOS5_SOUND, "samsung,exynos-sound"), COMPAT(WOLFSON_WM8994_CODEC, "wolfson,wm8994-codec"), COMPAT(SAMSUNG_EXYNOS_SPI, "samsung,exynos-spi"), + COMPAT(SAMSUNG_EXYNOS5_DWMMC, "samsung,exynos5250-dwmmc"), }; const char *fdtdec_get_compatible(enum fdt_compat_id id) -- 1.8.0 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH V4 6/9] SMDK5250: Initialise and Enable DWMMC, support FDT and non-FDT
This patch enables and initialises DWMMC for SMDK5250. Supports both FDT and non-FDT. This patch creates a new file 'exynos5-dt.c' meant for FDT support. exynos5-dt.c: This file shall contain all code which supports FDT. Any addition of FDT support for any module needs to be added in this file. smdk5250.c: This file shall contain the code which supports non-FDT. version. Any addition of non-FDT support for any module needs to be added in this file. May be, the file smdk5250.c can be removed in near future when non-FDT is not required. The Makefile is updated to compile only one of the files exynos5-dt.c / smdk5250.c based on FDT configuration. NOTE: Please note that all additions corresponding to FDT need to be added into the file exynos5-dt.c. At same time if non-FDT support is required then add the corresponding updations into smdk5250.c. Changes from V1: 1)A new file 'exynos5-dt.c' is created meant for FDT support 2)Makefile is updated to compile only one of the files exynos5-dt.c / smdk5250.c based on FDT configuration Changes from V2: 1)Updation of commit message and resubmition of proper patch set. Changes from V3: No change. Signed-off-by: Amar --- board/samsung/smdk5250/Makefile | 4 + board/samsung/smdk5250/exynos5-dt.c | 242 board/samsung/smdk5250/smdk5250.c | 97 +++ include/configs/exynos5250-dt.h | 2 + include/i2c.h | 2 + 5 files changed, 292 insertions(+), 55 deletions(-) create mode 100644 board/samsung/smdk5250/exynos5-dt.c diff --git a/board/samsung/smdk5250/Makefile b/board/samsung/smdk5250/Makefile index 47c6a5a..ecca9f3 100644 --- a/board/samsung/smdk5250/Makefile +++ b/board/samsung/smdk5250/Makefile @@ -32,8 +32,12 @@ COBJS+= tzpc_init.o COBJS += smdk5250_spl.o ifndef CONFIG_SPL_BUILD +ifdef CONFIG_OF_CONTROL +COBJS += exynos5-dt.o +else COBJS += smdk5250.o endif +endif ifdef CONFIG_SPL_BUILD COBJS += spl_boot.o diff --git a/board/samsung/smdk5250/exynos5-dt.c b/board/samsung/smdk5250/exynos5-dt.c new file mode 100644 index 000..da539ca --- /dev/null +++ b/board/samsung/smdk5250/exynos5-dt.c @@ -0,0 +1,242 @@ +/* + * Copyright (C) 2012 Samsung Electronics + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +int board_init(void) +{ + gd->bd->bi_boot_params = (PHYS_SDRAM_1 + 0x100UL); +#ifdef CONFIG_EXYNOS_SPI + spi_init(); +#endif + return 0; +} + +int dram_init(void) +{ + gd->ram_size= get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE) + + get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE) + + get_ram_size((long *)PHYS_SDRAM_3, PHYS_SDRAM_3_SIZE) + + get_ram_size((long *)PHYS_SDRAM_4, PHYS_SDRAM_4_SIZE) + + get_ram_size((long *)PHYS_SDRAM_5, PHYS_SDRAM_7_SIZE) + + get_ram_size((long *)PHYS_SDRAM_6, PHYS_SDRAM_7_SIZE) + + get_ram_size((long *)PHYS_SDRAM_7, PHYS_SDRAM_7_SIZE) + + get_ram_size((long *)PHYS_SDRAM_8, PHYS_SDRAM_8_SIZE); + return 0; +} + +#if defined(CONFIG_POWER) +int power_init_board(void) +{ + if (pmic_init(I2C_PMIC)) + return -1; + else + return 0; +} +#endif + +void dram_init_banksize(void) +{ + gd->bd->bi_dram[0].start = PHYS_SDRAM_1; + gd->bd->bi_dram[0].size = get_ram_size((long *)PHYS_SDRAM_1, + PHYS_SDRAM_1_SIZE); + gd->bd->bi_dram[1].start = PHYS_SDRAM_2; + gd->bd->bi_dram[1].size = get_ram_size((long *)PHYS_SDRAM_2, + PHYS_SDRAM_2_SIZE); + gd->bd->bi_dram[2].start = PHYS_SDRAM_3; + gd->bd->bi_dram[2].size = get_ram_size((long *)PHYS_SDRAM_3
[U-Boot] [PATCH V4 0/9] EXYNOS5: Enable DWMMC, add FDT support for DWMMC and
This patch set enables and initialises DWMMC for Exynos5250 on SMDK5250. Adds driver changes required for DWMMC. Adds FDT support for DWMMC. Adds EMMC boot support for SMDK5250. This patch set is based on: "EXYNOS: mmc: support DesignWare Controller for Samsung-SoC", which is merged in u-boot-mmc. "Exynos: clock: support get_mmc_clk for exynos". "Add DT based ethernet driver for SMDK5250". "SMDK5250: Add FDT support" present at the following link http://comments.gmane.org/gmane.comp.boot-loaders.u-boot/149991 Changes from V1: 1)Corrected in response to review comments. 2)Created separate board files for FDT and non-FDT versions. 3)Added binding file for DWMMC device node. 4)Removed the propname 'index' from device node. 5)Prefixed the vendor name 'samsung' before propname in device node. 6)Ensured to have same signature for the function exynos_dwmci_init() for both FDT and non-FDT versions. 7)EMMC clock setting has been moved from spl_boot.c to clock_init.c. Changes from V2: 1)Updation of commit message and resubmition of proper patch set. Changes from V3: 1)Updated to use the macro DWMCI_CTRL_SEND_AS_CCSD instead of the hard coded value (1 << 10). 2)In the file exynos_dw_mmc.c, replaced the new function exynos5_mmc_set_clk_div() with the existing function set_mmc_clk(). set_mmc_clk() will do the purpose. 3)In the file exynos_dw_mmc.c, computation of FSYS block clock divisor (pre-ratio) value is added. 4)Removed the new function exynos5_mmc_set_clk_div() from clock.c. Amar (9): FDT: Add compatible string for DWMMC EXYNOS5: FDT: Add DWMMC device node data DWMMC: Initialise dwmci and resolve EMMC read write issues EXYNOS5: DWMMC: Added FDT support for DWMMC EXYNOS5: DWMMC: API to set mmc clock divisor SMDK5250: Initialise and Enable DWMMC, support FDT and non-FDT MMC: APIs to support resize of EMMC boot partition SMDK5250: Enable EMMC booting COMMON: MMC: Command to support EMMC booting and to arch/arm/cpu/armv7/exynos/clock.c | 4 +- arch/arm/dts/exynos5250.dtsi | 32 arch/arm/include/asm/arch-exynos/clk.h| 3 + arch/arm/include/asm/arch-exynos/dwmmc.h | 4 + board/samsung/dts/exynos5250-smdk5250.dts | 22 +++ board/samsung/smdk5250/Makefile | 4 + board/samsung/smdk5250/clock_init.c | 15 ++ board/samsung/smdk5250/clock_init.h | 5 + board/samsung/smdk5250/exynos5-dt.c | 242 ++ board/samsung/smdk5250/smdk5250.c | 97 ++-- board/samsung/smdk5250/spl_boot.c | 52 ++- common/cmd_mmc.c | 84 ++- doc/device-tree-bindings/exynos/dwmmc.txt | 29 drivers/mmc/dw_mmc.c | 14 +- drivers/mmc/exynos_dw_mmc.c | 129 +++- drivers/mmc/mmc.c | 118 +++ include/configs/exynos5250-dt.h | 2 + include/dwmmc.h | 4 + include/fdtdec.h | 1 + include/i2c.h | 2 + include/mmc.h | 16 ++ lib/fdtdec.c | 1 + 22 files changed, 806 insertions(+), 74 deletions(-) create mode 100644 board/samsung/smdk5250/exynos5-dt.c create mode 100644 doc/device-tree-bindings/exynos/dwmmc.txt -- 1.8.0 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH V4 3/9] DWMMC: Initialise dwmci and resolve EMMC read write issues
This patch enumerates dwmci and set auto stop command during dwmci initialisation. EMMC read/write is not happening in current implementation due to improper fifo size computation. Hence Modified the fifo size computation to resolve EMMC read write issues. Changes from V1: 1)Created the macros RX_WMARK_SHIFT and RX_WMARK_MASK in header file. Changes from V2: 1)Updation of commit message and resubmition of proper patch set. Changes from V3: 1)Updated to use the macro DWMCI_CTRL_SEND_AS_CCSD instead of the hard coded value (1 << 10). Signed-off-by: Amar --- drivers/mmc/dw_mmc.c | 14 -- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/dw_mmc.c b/drivers/mmc/dw_mmc.c index 4070d4e..776fdb6 100644 --- a/drivers/mmc/dw_mmc.c +++ b/drivers/mmc/dw_mmc.c @@ -136,6 +136,7 @@ static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, return TIMEOUT; } timeout--; + mdelay(1); } dwmci_writel(host, DWMCI_RINTSTS, DWMCI_INTMSK_ALL); @@ -314,7 +315,7 @@ static void dwmci_set_ios(struct mmc *mmc) static int dwmci_init(struct mmc *mmc) { struct dwmci_host *host = (struct dwmci_host *)mmc->priv; - u32 fifo_size, fifoth_val; + u32 fifo_size, fifoth_val, ier; dwmci_writel(host, DWMCI_PWREN, 1); @@ -323,6 +324,14 @@ static int dwmci_init(struct mmc *mmc) return -1; } + /* Enumerate at 400KHz */ + dwmci_setup_bus(host, mmc->f_min); + + /* Set auto stop command */ + ier = dwmci_readl(host, DWMCI_CTRL); + ier |= DWMCI_CTRL_SEND_AS_CCSD; + dwmci_writel(host, DWMCI_CTRL, ier); + dwmci_writel(host, DWMCI_RINTSTS, 0x); dwmci_writel(host, DWMCI_INTMASK, 0); @@ -332,10 +341,11 @@ static int dwmci_init(struct mmc *mmc) dwmci_writel(host, DWMCI_BMOD, 1); fifo_size = dwmci_readl(host, DWMCI_FIFOTH); + fifo_size = ((fifo_size & RX_WMARK_MASK) >> RX_WMARK_SHIFT) + 1; if (host->fifoth_val) fifoth_val = host->fifoth_val; else - fifoth_val = MSIZE(0x2) | RX_WMARK(fifo_size/2 -1) | + fifoth_val = MSIZE(0x2) | RX_WMARK(fifo_size/2 - 1) | TX_WMARK(fifo_size/2); dwmci_writel(host, DWMCI_FIFOTH, fifoth_val); -- 1.8.0 ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH 0/3] Enable eMMC on mx6qsabresd board
On 31/12/2012 01:22, Shawn Guo wrote: > On Mon, Dec 31, 2012 at 08:14:57AM +0800, Shawn Guo wrote: >> The series is to enable the use of eMMC on mx6qsabresd board, so that >> we do not need to carry an external card to boot the board. The DDR >> mode support for eMMC is not included. >> Hi Shawn, >> Shawn Guo (3): >> fsl_esdhc: add MMC_MODE_HC host_caps >> mx6qsabresd: add usdhc2 and usdhc4 support >> mx6qsabresd: use on-board eMMC to store environment >> > Forgot adding [U-Boot] prefix for these patches. Will do next time. Never mind - and nobody adds [U-Boot] to a patch. I think it is added automatically by the mailing list server. Best regards, Stefano Babic -- = DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de = ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v2] tools: imximage: Load a size that is multiple of 512
On 04/01/2013 07:20, Dirk Behme wrote: > On 03.01.2013 19:24, Fabio Estevam wrote: >> In order to mx53 ROM to properly load the U-boot image, its header >> size should be multiple of 512 bytes. >> Hi Dirk, > ... >> Signed-off-by: Troy Kisky >> Signed-off-by: Fabio Estevam >> --- >> Changes since v1: >> - Improvec commit log >> include/image.h |3 +++ >> tools/imximage.c |9 - >> 2 files changed, 11 insertions(+), 1 deletion(-) >> >> diff --git a/include/image.h b/include/image.h >> index f54d983..e1e83b4 100644 >> --- a/include/image.h >> +++ b/include/image.h >> @@ -179,6 +179,9 @@ >> #define IH_MAGIC0x27051956/* Image Magic Number*/ >> #define IH_NMLEN32/* Image Name Length*/ >> >> +/* Reused from common.h */ >> +#define ROUND(a, b)(((a) + (b) - 1) & ~((b) - 1)) >> + >> /* >> * Legacy format image header, >> * all data in network byte order (aka natural aka bigendian). >> diff --git a/tools/imximage.c b/tools/imximage.c >> index 63f88b6..a93d7eb 100644 >> --- a/tools/imximage.c >> +++ b/tools/imximage.c >> @@ -515,7 +515,14 @@ static void imximage_set_header(void *ptr, struct >> stat *sbuf, int ifd, >> >> /* Set the imx header */ >> (*set_imx_hdr)(imxhdr, dcd_len, params->ep, imxhdr->flash_offset); >> -*header_size_ptr = sbuf->st_size + imxhdr->flash_offset; >> + >> +/* >> + * ROM bug alert >> + * mx53 only loads 512 byte multiples. > > Is this i.MX53 specific or is this valid for i.MX6, too? It seems that i.MX6 is not afflicted by this issue. For i.MX6 it adds only some padding to the resulting image. Best regards, Stefano Babic -- = DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de = ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] is it possilbe to have uboot find the kernel in the file system?
Dear John Stile, In message <1357265217.7939.131.camel@genx> you wrote: > > u-boot-2012.10.tar.bz2 does not have support for the at91sam9g20ek > I treid to apply my patches for u-boot-1.3.4, but they are way too old. > Is there a newer patch set? I see the following board configurations supported in current mainline code: at91sam9g20ek_nandflash, at91sam9g20ek_dataflash_cs0, and at91sam9g20ek_dataflash_cs1 . Anything wrong with those? Best regards, Wolfgang Denk -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de "The whole problem with the world is that fools and fanatics are always so certain of themselves, but wiser people so full of doubts." - Bertrand Russell ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH] arm:exynos4:pinmux: Modify the gpio function for mmc
Hi Jaehoon, > On 01/03/2013 04:31 PM, Piotr Wilczek wrote: > > This patch add pinmux settings for Exynos4 for mmc0 and mmc2 > Didn't consider about the mmc4? I know that exynos4 can be used mmc4 > for eMMC. This patch shall be regarded as fixing regression introduced after merge. We would like to stick (at least for now) to eMMC cotrollers tied to mmc0 and mmc2. When mmc4 (dw_mmc) will be enabled, then surely we will modify the pinmux code. -- Best regards, Lukasz Majewski Samsung R&D Poland (SRPOL) | Linux Platform Group ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot