Various patches in common/
Subsystems (2)
v2 cover Various patches in common/
This collection of patches to common/ adds the following:
- EDID support for LCD displays
- TPM stress test
- gettime command to find out the time since boot
- Adds coreboot information to the 'version' command
- Fixes LMB on x86
- SHA256 hashing using a new hashing framework created in response to list feedback
- Reading raw data from a partition of a block device
Some patches have been dropped from v2 in response to list feedback.
Also fixes a few minor bugs and tidy-ups.
Changes in v2:
- Remove arm: tag from bootstage step patch
- Convert space to tab in README
- Update gettime commit message to include boards without CONFIG_SYS_HZ
- Add more comments to the stdio strncpy commit message
- Add new patch to adjust sha1 functions to use const/unsigned
- Add new patch to adjust sha256 functions to const and watchdog
- Add stricmp() patch again since it is used in this series
- Add generic hash API to allow SHA256 command to be added without duplication
- Add new patch to change sha1sum to use generic hash API
- Add new hash command to support generic hash API
- Rework DRAM info feature to use a command instead of updating arm code
- Add patch to enable hashing and EDID on smdk5250
- Add x86 patch to enable io command for coreboot
- Add x86 tag to version command patch
Anton Staaf (1):
Add gettime command
Kenneth Waters (1):
Add a command to read raw blocks from a partition
Luigi Semenzato (1):
tpm: Add TPM stress test
Simon Glass (13):
Add new bootstage step for the main loop
Fix use of conditional LMB
Update time command to avoid using get_timer_masked()
sha1: Use const where possible, and unsigned for input len
sha256: Use const where possible and add watchdog function Add stricmp() and strnicmp()
Add generic hash API
sha1sum: Use generic hash layer
Add hash command to perform hashing using various algorithms
console: Enable function to display console info Add command to show DRAM configuration
exynos: Enable hashing functions and EDID for smdk5250
x86: coreboot: Enable io command
Stefan Reinauer (1):
x86: Add coreboot version to u-boot's version command
Taylor Hutt (1):
mmc: Fix incorrect handling of 'read' & 'write' commands
Tom Wai-Hong Tam (3):
edid: Library of EDID decode and print
edid: Add I2C command for printing the EDID
fdt: edid: Enable fdt_add_edid() function when CONFIG_LCD defined
Vadim Bendebury (1):
Add console command to access io space registers
Vincent Palatin (1):
stdio: remove useless strncpy
README | 33 +++++ common/Makefile | 6 + common/cmd_bootm.c | 2 +- common/cmd_gettime.c | 56 ++++++++ common/cmd_hash.c | 63 +++++++++ common/cmd_i2c.c | 39 ++++++ common/cmd_io.c | 93 +++++++++++++ common/cmd_mem.c | 25 ++++ common/cmd_mmc.c | 9 +- common/cmd_read.c | 81 ++++++++++++ common/cmd_sha1sum.c | 129 +------------------ common/cmd_time.c | 5 +- common/cmd_tpm.c | 93 +++++++++++++- common/cmd_version.c | 7 +- common/console.c | 6 +- common/edid.c | 307 ++++++++++++++++++++++++++++++++++++++++++++ common/fdt_support.c | 2 +- common/hash.c | 221 +++++++++++++++++++++++++++++++ common/main.c | 2 + common/stdio.c | 1 - include/command.h | 8 +- include/config_cmd_all.h | 4 + include/configs/coreboot.h | 1 + include/configs/smdk5250.h | 7 + include/edid.h | 275 +++++++++++++++++++++++++++++++++++++++ include/hash.h | 69 ++++++++++ include/linux/string.h | 4 + include/sha1.h | 26 ++--- include/sha256.h | 8 +- lib/sha1.c | 19 ++- lib/sha256.c | 37 +++++- lib/string.c | 12 ++- 32 files changed, 1472 insertions(+), 178 deletions(-) create mode 100644 common/cmd_gettime.c create mode 100644 common/cmd_hash.c create mode 100644 common/cmd_io.c create mode 100644 common/cmd_read.c create mode 100644 common/edid.c create mode 100644 common/hash.c create mode 100644 include/edid.h create mode 100644 include/hash.h
Signature · 1 line
1.7.7.3
PATCH v2 1/23 Add new bootstage step for the main loop
Mark when we get to the main loop.
---
Changes in v2:
- Remove arm: tag from bootstage step patch
common/main.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
common/main.c +2 -0
@@ -299,6 +299,8 @@ void main_loop (void)char bcs_set[16 ];#endif /* CONFIG_BOOTCOUNT_LIMIT */ +bootstage_mark_name (BOOTSTAGE_ID_MAIN_LOOP ,"main_loop" ); +#ifdef CONFIG_BOOTCOUNT_LIMIT bootcount =bootcount_load (); bootcount++;
Signature · 1 line
1.7.7.3
PATCH v2 2/23 Add gettime command
In reply to Simon GlassFrom: Anton Staaf <[email protected]>
Gettime returns the current timer value. If CONFIG_SYS_HZ is defined then the timer value is also converted to seconds.
Tegra20 (SeaBoard) # gettime
Timer val: 7754
Seconds : 7
Remainder : 754sys_hz = 1000
There has been some discussion about whether this is useful enough to be included in U-Boot. The following boards do not have CONFIG_SYS_HZ defined:
M52277EVBM52277EVB_stmicro
M53017EVB
M54418TWRM54418TWR_nand_miiM54418TWR_nand_rmiiM54418TWR_nand_rmii_lowfreqM54418TWR_serial_miiM54418TWR_serial_rmii
---
Changes in v2:
- Convert space to tab in README
- Update gettime commit message to include boards without CONFIG_SYS_HZ
README | 1 + common/Makefile | 1 + common/cmd_gettime.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++ include/config_cmd_all.h | 1 + 4 files changed, 59 insertions(+), 0 deletions(-) create mode 100644 common/cmd_gettime.c
README +1 -0
@@ -819,6 +819,7 @@ The following options need to be configured: CONFIG_CMD_FDOS * Dos diskette Support CONFIG_CMD_FLASH flinfo, erase, protect CONFIG_CMD_FPGA FPGA device initialization support + CONFIG_CMD_GETTIME * Get time since boot CONFIG_CMD_GO * the 'go' command (exec code) CONFIG_CMD_GREPENV * search environment CONFIG_CMD_HWFLOW * RTS/CTS hw flow control
common/Makefile +1 -0
@@ -100,6 +100,7 @@ ifdef CONFIG_FPGA COBJS-$(CONFIG_CMD_FPGA) += cmd_fpga.o endif COBJS-$(CONFIG_CMD_FS_GENERIC) += cmd_fs.o +COBJS-$(CONFIG_CMD_GETTIME) += cmd_gettime.o COBJS-$(CONFIG_CMD_GPIO) += cmd_gpio.o COBJS-$(CONFIG_CMD_I2C) += cmd_i2c.o COBJS-$(CONFIG_CMD_IDE) += cmd_ide.o
common/cmd_gettime.c new file +56 -0
56 lines not on this page · raw message
include/config_cmd_all.h +1 -0
@@ -40,6 +40,7 @@#define CONFIG_CMD_FDOS /* Floppy DOS support */ #define CONFIG_CMD_FLASH /* flinfo, erase, protect */ #define CONFIG_CMD_FPGA /* FPGA configuration Support */ +#define CONFIG_CMD_GETTIME /* Get time since boot */ #define CONFIG_CMD_HWFLOW /* RTS/CTS hw flow control */ #define CONFIG_CMD_I2C /* I2C serial bus support */ #define CONFIG_CMD_IDE /* IDE harddisk support */
Signature · 1 line
1.7.7.3
PATCH v2 3/23 Add a command to read raw blocks from a partition
In reply to Simon GlassFrom: Kenneth Waters <[email protected]>
Sometimes data is on a block device and within a partition, but not in a particular filesystem.
This commands permits reading raw data from a partition.
---
Changes in v2: None
README | 1 + common/Makefile | 1 + common/cmd_read.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++ include/config_cmd_all.h | 1 + 4 files changed, 84 insertions(+), 0 deletions(-) create mode 100644 common/cmd_read.c
README +1 -0
@@ -856,6 +856,7 @@ The following options need to be configured: CONFIG_CMD_PING * send ICMP ECHO_REQUEST to network host CONFIG_CMD_PORTIO * Port I/O + CONFIG_CMD_READ * Read raw data from partition CONFIG_CMD_REGINFO * Register dump CONFIG_CMD_RUN run command in env variable CONFIG_CMD_SAVES * save S record dump
common/Makefile +1 -0
@@ -142,6 +142,7 @@ endif COBJS-y += cmd_pcmcia.o COBJS-$(CONFIG_CMD_PORTIO) += cmd_portio.o COBJS-$(CONFIG_CMD_PXE) += cmd_pxe.o +COBJS-$(CONFIG_CMD_READ) += cmd_read.o COBJS-$(CONFIG_CMD_REGINFO) += cmd_reginfo.o COBJS-$(CONFIG_CMD_REISER) += cmd_reiser.o COBJS-$(CONFIG_CMD_SATA) += cmd_sata.o
common/cmd_read.c new file +81 -0
81 lines not on this page · raw message
include/config_cmd_all.h +1 -0
@@ -71,6 +71,7 @@#define CONFIG_CMD_REGINFO /* Register dump */ #define CONFIG_CMD_REISER /* Reiserfs support */ #define CONFIG_CMD_RARP /* rarpboot support */ +#define CONFIG_CMD_READ /* Read data from partition */ #define CONFIG_CMD_RUN /* run command in env variable */ #define CONFIG_CMD_SAVEENV /* saveenv */ #define CONFIG_CMD_SAVES /* save S record dump */
Signature · 1 line
1.7.7.3
PATCH v2 4/23 Fix use of conditional LMB
In reply to Simon GlassThis code was not guarded with CONFIG_LMB so failed to build on x86.
---
Changes in v2: None
common/cmd_bootm.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
common/cmd_bootm.c +1 -1
@@ -537,7 +537,7 @@ static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc, }break ;#endif -#if defined(CONFIG_OF_LIBFDT ) +#if defined(CONFIG_OF_LIBFDT ) && defined(CONFIG_LMB )case BOOTM_STATE_FDT : { boot_fdt_add_mem_rsv_regions(&images.lmb,
Signature · 1 line
1.7.7.3
PATCH v2 5/23 stdio: remove useless strncpy
In reply to Simon GlassFrom: Vincent Palatin <[email protected]>
The name is already copied when we memcpy() the whole structure.
This is because struct stdio_dev has this field:
char name[16]; /* Device name */
So the data is inline, rather than being a pointer.
---
Changes in v2:
- Add more comments to the stdio strncpy commit message
common/stdio.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
common/stdio.c +0 -1
@@ -135,7 +135,6 @@ struct stdio_dev* stdio_clone(struct stdio_dev *dev)return NULL ;memcpy (_dev, dev,sizeof (struct stdio_dev )); -strncpy (_dev->name, dev->name,16 );return _dev; }
Signature · 1 line
1.7.7.3
PATCH v2 6/23 Update time command to avoid using get_timer_masked()
In reply to Simon GlassIt is better to use get_timer() by itself now, according to the new timer API.
---
Changes in v2: None
common/cmd_time.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
common/cmd_time.c +3 -2
@@ -32,6 +32,7 @@ static int run_command_and_time_it(int flag, int argc, char * const argv[], {cmd_tbl_t *cmdtp =find_cmd (argv[0 ]);int retval =0 ; +ulong start;if (!cmdtp) {printf ("%s: command not found\n" , argv[0 ]);
@@ -45,9 +46,9 @@ static int run_command_and_time_it(int flag, int argc, char * const argv[],* boards. We could use the new timer API that Graeme is proposing * so that this piece of code would be arch-independent. */ - *cycles =get_timer_masked (); + start =get_timer (0 ); retval = cmdtp->cmd (cmdtp, flag, argc, argv); - *cycles =get_timer_masked () - *cycles; + *cycles =get_timer (start);return retval; }
Signature · 1 line
1.7.7.3
PATCH v2 6/23 Update time command to avoid using get_timer_masked()
Hi,
Quoted 6 lines · Simon Glass
It is better to use
get_timer()by itself now, according to the new timer API.Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
I am going to drop this patch as Richard Genoud has refactored the code in a pending patch, so I don't think this is needed.
Regards,
Simon
Quoted 31 lines
common/cmd_time.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)common/cmd_time.c +3
-3@@ -32,6 +32,7 @@ static int run_command_and_time_it(int flag, int argc, char * const argv[], {cmd_tbl_t *cmdtp =find_cmd (argv[0 ]);int retval =0 ; +ulong start;if (!cmdtp) {printf ("%s: command not found\n" , argv[0 ]);@@ -45,9 +46,9 @@ static int run_command_and_time_it(int flag, int argc, char * const argv[],* boards. We could use the new timer API that Graeme is proposing * so that this piece of code would be arch-independent. */ - *cycles =get_timer_masked (); + start =get_timer (0 ); retval = cmdtp->cmd (cmdtp, flag, argc, argv); - *cycles =get_timer_masked () - *cycles; + *cycles =get_timer (start);return retval; } --1.7.7.3
PATCH v2 7/23 sha1: Use const where possible, and unsigned for input len
In reply to Simon GlassIn preparation for making the hash function common, we may as well use const where we can. Also the input length cannot be negative, but may be very large, so use unsigned.
---
Changes in v2:
- Add new patch to adjust sha1 functions to use const/unsigned
include/sha1.h | 26 +++++++++----------------- lib/sha1.c | 19 +++++++++++-------- 2 files changed, 20 insertions(+), 25 deletions(-)
include/sha1.h +9 -17
@@ -59,7 +59,8 @@ void sha1_starts( sha1_context *ctx );* \param input buffer holding the data * \param ilen length of the input data */ -void sha1_update (sha1_context *ctx,unsigned char *input,int ilen ); +void sha1_update (sha1_context *ctx,const unsigned char *input, +unsigned int ilen);/** * \brief SHA-1 final digest
@@ -76,8 +77,8 @@ void sha1_finish( sha1_context *ctx, unsigned char output[20] );* \param ilen length of the input data * \param output SHA-1 checksum result */ -void sha1_csum (unsigned char *input,int ilen, -unsigned char output[20 ] ); +void sha1_csum (const unsigned char *input,unsigned int ilen, +unsigned char *output);/** * \brief Output = SHA-1( input buffer ), with watchdog triggering
@@ -87,17 +88,8 @@ void sha1_csum( unsigned char *input, int ilen,* \param output SHA-1 checksum result * \param chunk_sz watchdog triggering period (in bytes of input processed) */ -void sha1_csum_wd (unsigned char *input,int ilen, -unsigned char output[20 ],unsigned int chunk_sz); - -/** -* \brief Output = SHA-1( file contents ) -* -* \param path input file name -* \param output SHA-1 checksum result -* \return 0 if successful, or 1 if fopen failed -*/ -int sha1_file (char *path,unsigned char output[20 ] ); +void sha1_csum_wd (const unsigned char *input,unsigned int ilen, +unsigned char *output,unsigned int chunk_sz);/** * \brief Output = HMAC-SHA-1( input buffer, hmac key )
@@ -108,9 +100,9 @@ int sha1_file( char *path, unsigned char output[20] );* \param ilen length of the input data * \param output HMAC-SHA-1 result */ -void sha1_hmac (unsigned char *key,int keylen, -unsigned char *input,int ilen, -unsigned char output[20 ] ); +void sha1_hmac (const unsigned char *key,int keylen, +const unsigned char *input,unsigned int ilen, +unsigned char *output);/** * \brief Checkup routine
lib/sha1.c +11 -8
@@ -73,7 +73,7 @@ void sha1_starts (sha1_context * ctx) ctx->state[4 ] =0xC3D2E1F0 ; } -static void sha1_process (sha1_context * ctx,unsigned char data[64 ]) +static void sha1_process (sha1_context *ctx,const unsigned char data[64 ]) {unsigned long temp,W [16 ],A ,B ,C ,D ,E ;
@@ -230,7 +230,8 @@ static void sha1_process (sha1_context * ctx, unsigned char data[64])/* * SHA-1 process buffer */ -void sha1_update (sha1_context * ctx,unsigned char *input,int ilen) +void sha1_update (sha1_context *ctx,const unsigned char *input, +unsigned int ilen) {int fill;unsigned long left;
@@ -305,7 +306,8 @@ void sha1_finish (sha1_context * ctx, unsigned char output[20])/* * Output = SHA-1( input buffer ) */ -void sha1_csum (unsigned char *input,int ilen,unsigned char output[20 ]) +void sha1_csum (const unsigned char *input,unsigned int ilen, +unsigned char *output) {sha1_context ctx;
@@ -318,12 +320,12 @@ void sha1_csum (unsigned char *input, int ilen, unsigned char output[20])* Output = SHA-1( input buffer ). Trigger the watchdog every 'chunk_sz' * bytes of input processed. */ -void sha1_csum_wd (unsigned char *input,int ilen,unsigned char output[20 ], -unsigned int chunk_sz) +void sha1_csum_wd (const unsigned char *input,unsigned int ilen, +unsigned char *output,unsigned int chunk_sz) {sha1_context ctx;#if defined(CONFIG_HW_WATCHDOG ) || defined(CONFIG_WATCHDOG ) -unsigned char *end, *curr; +const unsigned char *end, *curr;int chunk;#endif
@@ -350,8 +352,9 @@ void sha1_csum_wd (unsigned char *input, int ilen, unsigned char output[20],/* * Output = HMAC-SHA-1( input buffer, hmac key ) */ -void sha1_hmac (unsigned char *key,int keylen, -unsigned char *input,int ilen,unsigned char output[20 ]) +void sha1_hmac (const unsigned char *key,int keylen, +const unsigned char *input,unsigned int ilen, +unsigned char *output) {int i;sha1_context ctx;
Signature · 1 line
1.7.7.3
PATCH v2 8/23 sha256: Use const where possible and add watchdog function
In reply to Simon GlassIn preparation for making the hash function common, we may as well use const where we can.
Also add a watchdog version of the hashing function.
---
Changes in v2:
- Add new patch to adjust sha256 functions to const and watchdog
include/sha256.h | 8 +++++++- lib/sha256.c | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 3 deletions(-)
include/sha256.h +7 -1
@@ -3,6 +3,9 @@#define SHA256_SUM_LEN 32 +/* Reset watchdog each time we process this many bytes */ +#define CHUNKSZ_SHA256 (64 * 1024) + typedef struct { uint32_t total[2]; uint32_t state[8];
@@ -10,7 +13,10 @@ typedef struct { } sha256_context;void sha256_starts (sha256_context * ctx); -void sha256_update (sha256_context * ctx,uint8_t * input,uint32_t length); +void sha256_update (sha256_context *ctx,const uint8_t *input,uint32_t length);void sha256_finish (sha256_context * ctx,uint8_t digest[SHA256_SUM_LEN ]); +void sha256_csum_wd (const unsigned char *input,unsigned int ilen, +unsigned char *output,unsigned int chunk_sz); +#endif /* _SHA256_H */
lib/sha256.c +35 -2
@@ -60,7 +60,7 @@ void sha256_starts(sha256_context * ctx) ctx->state[7 ] =0x5BE0CD19 ; } -void sha256_process (sha256_context * ctx,uint8_t data[64 ]) +static void sha256_process (sha256_context *ctx,const uint8_t data[64 ]) {uint32_t temp1, temp2;uint32_t W [64 ];
@@ -191,7 +191,7 @@ void sha256_process(sha256_context * ctx, uint8_t data[64]) ctx->state[7 ] +=H ; } -void sha256_update (sha256_context * ctx,uint8_t * input,uint32_t length) +void sha256_update (sha256_context *ctx,const uint8_t *input,uint32_t length) {uint32_t left, fill;
@@ -260,3 +260,36 @@ void sha256_finish(sha256_context * ctx, uint8_t digest[32])PUT_UINT32_BE (ctx->state[6 ], digest,24 );PUT_UINT32_BE (ctx->state[7 ], digest,28 ); } + +/* +* Output = SHA-256( input buffer ). Trigger the watchdog every 'chunk_sz' +* bytes of input processed. +*/ +void sha256_csum_wd (const unsigned char *input,unsigned int ilen, +unsigned char *output,unsigned int chunk_sz) +{ +sha256_context ctx; +#if defined(CONFIG_HW_WATCHDOG ) || defined(CONFIG_WATCHDOG ) +unsigned char *end, *curr; +int chunk; +#endif + +sha256_starts (&ctx); + +#if defined(CONFIG_HW_WATCHDOG ) || defined(CONFIG_WATCHDOG ) + curr = input; + end = input + ilen; +while (curr < end) { + chunk = end - curr; +if (chunk > chunk_sz) + chunk = chunk_sz; +sha256_update (&ctx, curr, chunk); + curr += chunk; +WATCHDOG_RESET (); + } +#else +sha256_update (&ctx, input, ilen); +#endif + +sha256_finish (&ctx, output); +}
Signature · 1 line
1.7.7.3
PATCH v2 9/23 Add stricmp() and strnicmp()
In reply to Simon Glassstrnicmp() is present but disabled. Make it available and define stricmp() also. There is a only a small performance penalty to having stricmp() call strnicmp(), so do this instead of a standalone function, to save code space.
---
Changes in v2:
- Add stricmp() patch again since it is used in this series
include/linux/string.h | 4 ++++ lib/string.c | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-)
include/linux/string.h +4 -0
@@ -20,6 +20,10 @@ extern __kernel_size_t strspn(const char *,const char *);*/ #include <asm/string.h> +int strnicmp (const char *s1,const char *s2,size_t len); + +int stricmp (const char *s1,const char *s2); +#ifndef __HAVE_ARCH_STRCPYextern char *strcpy (char *,const char *);#endif
lib/string.c +10 -2
@@ -21,7 +21,6 @@#include <malloc.h> -#if 0 /* not used - was: #ifndef __HAVE_ARCH_STRNICMP */ /** * strnicmp - Case insensitive, length-limited string comparison * @s1: One string
@@ -52,7 +51,16 @@ int strnicmp(const char *s1, const char *s2, size_t len) }return (int )c1 - (int )c2; } -#endif + +/** +* stricmp - Case insensitive string comparison +* @s1: One string +* @s2: The other string +*/ +int stricmp (const char *s1,const char *s2) +{ +return strnicmp (s1, s2,-1U ); +}char * ___strtok;
Signature · 1 line
1.7.7.3
PATCH v2 9/23 Add stricmp() and strnicmp()
Quoted 6 lines · Simon Glass
strnicmp()is present but disabled. Make it available and definestricmp()
also. There is a only a small performance penalty to havingstricmp()callstrnicmp(), so do this instead of a standalone function, to save code
space.
Both POSIX and the Linux kernel call this strcasecmp() rather than stricmp()...
-Scott
PATCH v2 9/23 Add stricmp() and strnicmp()
Hi Scott,
Quoted 11 lines · Scott Wood
Quoted 5 lines · Simon Glass
strnicmp()is present but disabled. Make it available and definestricmp()also. There is a only a small performance penalty to havingstricmp()callstrnicmp(), so do this instead of a standalone function, to save code space.Both POSIX and the Linux kernel call this
strcasecmp()rather thanstricmp()...
Yes, I will fix this. I will also need to tidy up a few prototypes in other archs.
Regards,
Simon
Quoted 1 line
-Scott
PATCH v2 10/23 Add generic hash API
In reply to Simon GlassWe have a SHA1 command and want to add a SHA256 command also. Instead of duplicating the code, create a generic hash API which can process commands for different algorithms.
---
Changes in v2:
- Add generic hash API to allow SHA256 command to be added without duplication
common/Makefile | 1 + common/hash.c | 221 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/hash.h | 69 +++++++++++++++++ 3 files changed, 291 insertions(+), 0 deletions(-) create mode 100644 common/hash.c create mode 100644 include/hash.h
common/Makefile +1 -0
@@ -31,6 +31,7 @@ COBJS-y += main.o COBJS-y += command.o COBJS-y += exports.o COBJS-$(CONFIG_SYS_HUSH_PARSER) += hush.o +COBJS-y += hash.o COBJS-y += s_record.o COBJS-y += xyzModem.o COBJS-y += cmd_disk.o
common/hash.c new file +221 -0
221 lines not on this page · raw message
include/hash.h new file +69 -0
69 lines not on this page · raw message
Signature · 1 line
1.7.7.3
PATCH v2 10/23 Add generic hash API
Hi Simon,
Quoted 21 lines · Simon Glass
We have a SHA1 command and want to add a SHA256 command also. Instead of duplicating the code, create a generic hash API which can process commands for different algorithms.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Add generic hash API to allow SHA256 command to be added without duplicationcommon/Makefile | 1 + common/hash.c | 221 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/hash.h | 69 +++++++++++++++++ 3 files changed, 291 insertions(+), 0 deletions(-) create mode 100644 common/hash.c create mode 100644 include/hash.hcommon/Makefile +0
-0
common/Makefile COBJS-y += main.o · line 34
Quoted 4 lines
common/Makefile +1
-0@@ -31,6 +31,7 @@ COBJS-y += main.o COBJS-y += command.o COBJS-y += exports.o COBJS-$(CONFIG_SYS_HUSH_PARSER) += hush.o +COBJS-y += hash.o
Why not put them in alphabetical order?
Quoted 198 lines
common/Makefile +0
-0COBJS-y += s_record.o COBJS-y += xyzModem.o COBJS-y += cmd_disk.ocommon/hash.c new file +189
-0@@ -0,0 +1,221 @@ +/* +* Copyright (c) 2012 The Chromium OS Authors. +* +* (C) Copyright 2011 +* Joe Hershberger, National Instruments, joe.hershberger at ni.com +* +* (C) Copyright 2000 +* Wolfgang Denk, DENX Software Engineering, wd at denx.de. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +*/ + +#include <common.h> +#include <command.h> +#include <hash.h> +#include <sha1.h> +#include <sha256.h> + +/* +* These are the hash algorithms we support. Chips which support accelerated +* crypto could perhaps add named version of these algorithms here. +*/ +static struct hash_algo hash_algo[] = { +#ifdef CONFIG_SHA1 + { + "SHA1", + SHA1_SUM_LEN, + sha1_csum_wd, + CHUNKSZ_SHA1, + }, +#endif +#ifdef CONFIG_SHA256 + { + "SHA256", + SHA256_SUM_LEN, + sha256_csum_wd, + CHUNKSZ_SHA256, + }, +#endif +}; + +/** + * store_result: Store the resulting sum to an address or variable + * + * @algo: Hash algorithm being used + * @sum: Hash digest (algo->digest_size bytes) + * @dest: Destination, interpreted as a hex address if it starts + * with * or otherwise as an environment variable. + */ +static void store_result(struct hash_algo *algo, const u8 *sum, + const char *dest) +{ + unsigned int i; + + if (*dest == '*') { + u8 *ptr; + + ptr = (u8 *)simple_strtoul(dest + 1, NULL, 16); + memcpy(ptr, sum, algo->digest_size); + } else { + char str_output[HASH_MAX_DIGEST_SIZE * 2 + 1]; + char *str_ptr = str_output; + + for (i = 0; i < algo->digest_size; i++) { + sprintf(str_ptr, "%02x", sum[i]); + str_ptr += 2; + } + str_ptr = '\0'; + setenv(dest, str_output); + } +} + +/** + * parse_verify_sum: Parse a hash verification parameter + * + * @algo: Hash algorithm being used + * @verify_str: Argument to parse. If it starts with * then it is + * interpreted as a hex address containing the hash. + * If the length is exactly the right number of hex digits + * for the digest size, then we assume it is a hex digest. + * Otherwise we assume it is an environment variable, and + * look up its value (it must contain a hex digest). + * @vsum: Returns binary digest value (algo->digest_size bytes) + * @return 0 if ok, non-zero on error + */ +static int parse_verify_sum(struct hash_algo *algo, char *verify_str, u8 *vsum) +{ + if (*verify_str == '*') { + u8 *ptr; + + ptr = (u8 *)simple_strtoul(verify_str + 1, NULL, 16); + memcpy(vsum, ptr, algo->digest_size); + } else { + unsigned int i; + char *vsum_str; + int digits = algo->digest_size * 2; + + /* + * As with the original code from sha1sum.c, we assume that a + * string which matches the digest size exactly is a hex + * string and not an environment variable. + */ + if (strlen(verify_str) == digits) + vsum_str = verify_str; + else { + vsum_str = getenv(verify_str); + if (vsum_str == NULL || strlen(vsum_str) != digits) { + printf("Expected %d hex digits in env var\n", + digits); + return 1; + } + } + + for (i = 0; i < algo->digest_size; i++) { + char *nullp = vsum_str + (i + 1) * 2; + char end = *nullp; + + *nullp = '\0'; + vsum[i] = simple_strtoul(vsum_str + (i * 2), NULL, 16); + *nullp = end; + } + } + return 0; +} + +static struct hash_algo *find_hash_algo(const char *name) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(hash_algo); i++) { + if (!stricmp(name, hash_algo[i].name)) + return &hash_algo[i]; + } + + return NULL; +} + +static void show_hash(struct hash_algo *algo, ulong addr, ulong len, + u8 *output) +{ + int i; + + printf("%s for %08lx ... %08lx ==> ", algo->name, addr, addr + len - 1); + for (i = 0; i < algo->digest_size; i++) + printf("%02x", output[i]); +} + +int hash_command(const char *algo_name, int verify, cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) +{ + struct hash_algo *algo; + ulong addr, len; + u8 output[HASH_MAX_DIGEST_SIZE]; + u8 vsum[HASH_MAX_DIGEST_SIZE]; + + if (argc < 2) + return CMD_RET_USAGE; + + algo = find_hash_algo(algo_name); + if (!algo) { + printf("Unknown hash algorithm '%s'\n", algo_name); + return CMD_RET_USAGE; + } + addr = simple_strtoul(*argv++, NULL, 16); + len = simple_strtoul(*argv++, NULL, 16); + argc -= 2; + + if (algo->digest_size > HASH_MAX_DIGEST_SIZE) { + puts("HASH_MAX_DIGEST_SIZE exceeded\n"); + return 1; + } + + algo->hash_func_ws((const unsigned char *)addr, len, output, + algo->chunk_size); + + /* Try to avoid code bloat when verify is not needed */
common/hash.c line 199
Quoted 10 lines
common/hash.c new file +10
-0+#ifdef CONFIG_HASH_VERIFY +if (verify) { +#else +if (0 ) { +#endif +if (!argc) +return CMD_RET_USAGE ; +if (parse_verify_sum (algo, *argv, vsum)) { +printf ("ERROR: %s does not contain a valid SHA1 sum\n" , + *argv);
You should probably use the name of the algo in the error message, not a fixed SHA1.
Quoted 87 lines
common/hash.c new file +22
-0+return 1 ; + } +if (memcmp (output, vsum, algo->digest_size) !=0 ) { +int i; + +show_hash (algo, addr, len, output); +printf (" != " ); +for (i =0 ; i < algo->digest_size; i++) +printf ("%02x" , vsum[i]); +puts (" ** ERROR **\n" ); +return 1 ; + } + }else { +show_hash (algo, addr, len, output); +printf ("\n" ); + +if (argc) +store_result (algo, output, *argv); + } + +return 0 ; +}include/hash.h new file +59
-0@@ -0,0 +1,69 @@ +/* +* Copyright (c) 2012 The Chromium OS Authors. +* 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 _HASH_H +#define _HASH_H + +#ifdef CONFIG_SHA1SUM_VERIFY +#define CONFIG_HASH_VERIFY +#endif + +struct hash_algo { +const char *name;/* Name of algorithm */ +int digest_size;/* Length of digest */ +/** +* hash_func_ws: Generic hashing function +* +* This is the generic prototype for a hashing function. We only +* have the watchdog version at present. +* +* @input: Input buffer +* @ilen: Input buffer length +* @output: Checksum result (length depends on algorithm) +* @chunk_sz: Trigger watchdog after processing this many bytes +*/ +void (*hash_func_ws)(const unsigned char *input,unsigned int ilen, +unsigned char *output,unsigned int chunk_sz); +int chunk_size;/* Watchdog chunk size */ +}; + +/* +* Maximum digest size for all algorithms we support. Having this value +* avoids a malloc() or C99 local declaration in common/cmd_hash.c. +*/ +#define HASH_MAX_DIGEST_SIZE 32 + +/** +* hash_command: Process a hash command for a particular algorithm +* +* This common function is used to implement specific hash commands. +* +* @algo_name: Hash algorithm being used
include/hash.h line 69
Quoted 10 lines
include/hash.h new file +10
-0+* @verify: Non-zero to enable verify mode +* @cmdtp: Pointer to command table entry +* @flag: Some flags normally 0 (see CMD_FLAG_.. above) +* @argc: Number of arguments (arg 0 must be the command text) +* @argv: Arguments +*/ +int hash_command (const char *algo_name,int verify,cmd_tbl_t *cmdtp,int flag, +int argc,char *const argv[]); + +#endif
Otherwise, looks good.
-Joe
PATCH v2 11/23 sha1sum: Use generic hash layer
In reply to Simon GlassUpdate the code to use the hash layer instead of local code.
---
Changes in v2:
- Add new patch to change sha1sum to use generic hash API
common/cmd_sha1sum.c | 129 ++------------------------------------------------ 1 files changed, 4 insertions(+), 125 deletions(-)
common/cmd_sha1sum.c +4 -125
@@ -26,73 +26,11 @@#include <common.h> #include <command.h> +#include <hash.h> #include <sha1.h> -/* -* Store the resulting sum to an address or variable -*/ -static void store_result (const u8 *sum,const char *dest) -{ -unsigned int i; - -if (*dest =='*' ) { -u8 *ptr; - - ptr = (u8 *)simple_strtoul (dest +1 ,NULL ,16 ); -for (i =0 ; i <20 ; i++) - *ptr++ = sum[i]; - }else { -char str_output[41 ]; -char *str_ptr = str_output; - -for (i =0 ; i <20 ; i++) { -sprintf (str_ptr,"%02x" , sum[i]); - str_ptr +=2 ; - } - str_ptr ='\0' ; -setenv (dest, str_output); - } -} - -#ifdef CONFIG_SHA1SUM_VERIFY -static int parse_verify_sum (char *verify_str,u8 *vsum) -{ -if (*verify_str =='*' ) { -u8 *ptr; - - ptr = (u8 *)simple_strtoul (verify_str +1 ,NULL ,16 ); -memcpy (vsum, ptr,20 ); - }else { -unsigned int i; -char *vsum_str; - -if (strlen (verify_str) ==40 ) - vsum_str = verify_str; -else { - vsum_str =getenv (verify_str); -if (vsum_str ==NULL ||strlen (vsum_str) !=40 ) -return 1 ; - } - -for (i =0 ; i <20 ; i++) { -char *nullp = vsum_str + (i +1 ) *2 ; -char end = *nullp; - - *nullp ='\0' ; - *(u8 *)(vsum + i) = -simple_strtoul (vsum_str + (i *2 ),NULL ,16 ); - *nullp = end; - } - } -return 0 ; -} -int do_sha1sum (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) { -ulong addr, len; -unsigned int i; -u8 output[20 ]; -u8 vsum[20 ];int verify =0 ;int ac;char *const *av;
@@ -102,75 +40,16 @@ int do_sha1sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) av = argv +1 ; ac = argc -1 ; +#ifdef CONFIG_SHA1SUM_VERIFY if (strcmp (*av,"-v" ) ==0 ) { verify =1 ; av++; ac--; -if (ac <3 ) -return CMD_RET_USAGE ; } +#endif - addr =simple_strtoul (*av++,NULL ,16 ); - len =simple_strtoul (*av++,NULL ,16 ); - -sha1_csum_wd ((unsigned char *) addr, len, output,CHUNKSZ_SHA1 ); - -if (!verify) { -printf ("SHA1 for %08lx ... %08lx ==> " , addr, addr + len -1 ); -for (i =0 ; i <20 ; i++) -printf ("%02x" , output[i]); -printf ("\n" ); - -if (ac >2 ) -store_result (output, *av); - }else { -char *verify_str = *av++; - -if (parse_verify_sum (verify_str, vsum)) { -printf ("ERROR: %s does not contain a valid SHA1 sum\n" , - verify_str); -return 1 ; - } -if (memcmp (output, vsum,20 ) !=0 ) { -printf ("SHA1 for %08lx ... %08lx ==> " , addr, - addr + len -1 ); -for (i =0 ; i <20 ; i++) -printf ("%02x" , output[i]); -printf (" != " ); -for (i =0 ; i <20 ; i++) -printf ("%02x" , vsum[i]); -printf (" ** ERROR **\n" ); -return 1 ; - } - } - -return 0 ; -} -#else -static int do_sha1sum (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) -{ -unsigned long addr, len; -unsigned int i; -u8 output[20 ]; - -if (argc <3 ) -return CMD_RET_USAGE ; - - addr =simple_strtoul (argv[1 ],NULL ,16 ); - len =simple_strtoul (argv[2 ],NULL ,16 ); - -sha1_csum_wd ((unsigned char *) addr, len, output,CHUNKSZ_SHA1 ); -printf ("SHA1 for %08lx ... %08lx ==> " , addr, addr + len -1 ); -for (i =0 ; i <20 ; i++) -printf ("%02x" , output[i]); -printf ("\n" ); - -if (argc >3 ) -store_result (output, argv[3 ]); - -return 0 ; +return hash_command ("sha1" , verify, cmdtp, flag, ac, av); } -#endif #ifdef CONFIG_SHA1SUM_VERIFY U_BOOT_CMD(
Signature · 1 line
1.7.7.3
PATCH v2 12/23 Add hash command to perform hashing using various algorithms
In reply to Simon GlassThis new command supports hashing SHA1 and SHA256. It could be extended to others such as MD5 and the CRC algorithms. The syntax is modeled on those:
hash <algorithm> <address> <length> [*<dest_addr> | <dest_envvar>]
to calculate a hash, and:
hash -v <algorithm> <address> <length> [*<verify_addr> | <verify_envvar>]
to verify a hash.
Use CONFIG_CMD_HASH to enable the command, CONFIG_SHA1 to enable SHA1 and CONFIG_SHA256 to enable SHA256.
The existing sha1sum command remains.
---
Changes in v2:
- Add new hash command to support generic hash API
README | 18 +++++++++++++ common/Makefile | 1 + common/cmd_hash.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++ include/config_cmd_all.h | 1 + 4 files changed, 83 insertions(+), 0 deletions(-) create mode 100644 common/cmd_hash.c
README +18 -0
@@ -822,6 +822,7 @@ The following options need to be configured: CONFIG_CMD_GETTIME * Get time since boot CONFIG_CMD_GO * the 'go' command (exec code) CONFIG_CMD_GREPENV * search environment + CONFIG_CMD_HASH * calculate hash / digest CONFIG_CMD_HWFLOW * RTS/CTS hw flow control CONFIG_CMD_I2C * I2C serial bus support CONFIG_CMD_IDE * IDE harddisk support
@@ -2391,6 +2392,23 @@ CBFS (Coreboot Filesystem) support A better solution is to properly configure the firewall, but sometimes that is not allowed. +- Hashing support: + CONFIG_CMD_HASH + + This enables a generic 'hash' command which can produce + hashes / digests from a few algorithms (e.g. SHA1, SHA256). + + CONFIG_HASH_VERIFY + + Enable the hash verify command (hash -v). This adds to code + size a little. + + CONFIG_SHA1 - support SHA1 hashing + CONFIG_SHA256 - support SHA256 hashing + + Note: There is also a sha1sum command, which should perhaps + be deprecated in favour of 'hash sha1'. + - Show boot progress: CONFIG_SHOW_BOOT_PROGRESS
common/Makefile +1 -0
@@ -104,6 +104,7 @@ COBJS-$(CONFIG_CMD_FS_GENERIC) += cmd_fs.o COBJS-$(CONFIG_CMD_GETTIME) += cmd_gettime.o COBJS-$(CONFIG_CMD_GPIO) += cmd_gpio.o COBJS-$(CONFIG_CMD_I2C) += cmd_i2c.o +COBJS-$(CONFIG_CMD_HASH) += cmd_hash.o COBJS-$(CONFIG_CMD_IDE) += cmd_ide.o COBJS-$(CONFIG_CMD_IMMAP) += cmd_immap.o COBJS-$(CONFIG_CMD_INI) += cmd_ini.o
common/cmd_hash.c new file +63 -0
63 lines not on this page · raw message
include/config_cmd_all.h +1 -0
@@ -41,6 +41,7 @@#define CONFIG_CMD_FLASH /* flinfo, erase, protect */ #define CONFIG_CMD_FPGA /* FPGA configuration Support */ #define CONFIG_CMD_GETTIME /* Get time since boot */ +#define CONFIG_CMD_HASH /* calculate hash / digest */ #define CONFIG_CMD_HWFLOW /* RTS/CTS hw flow control */ #define CONFIG_CMD_I2C /* I2C serial bus support */ #define CONFIG_CMD_IDE /* IDE harddisk support */
Signature · 1 line
1.7.7.3
PATCH v2 12/23 Add hash command to perform hashing using various algorithms
Hi Simon,
Quoted 126 lines · Simon Glass
This new command supports hashing SHA1 and SHA256. It could be extended to others such as MD5 and the CRC algorithms. The syntax is modeled on those:
hash <algorithm> <address> <length> [*<dest_addr> | <
dest_envvar>]to calculate a hash, and:
hash -v <algorithm> <address> <length> [*<verify_addr> | <
verify_envvar>]to verify a hash.
Use
CONFIG_CMD_HASHto enable the command,CONFIG_SHA1to enable SHA1 andCONFIG_SHA256to enable SHA256.The existing sha1sum command remains.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Add new hash command to support generic hash APIREADME | 18 +++++++++++++ common/Makefile | 1 + common/cmd_hash.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++ include/config_cmd_all.h | 1 + 4 files changed, 83 insertions(+), 0 deletions(-) create mode 100644 common/cmd_hash.cREADME +18
-0@@ -822,6 +822,7 @@ The following options need to be configured: CONFIG_CMD_GETTIME * Get time since boot CONFIG_CMD_GO * the 'go' command (exec code) CONFIG_CMD_GREPENV * search environment + CONFIG_CMD_HASH * calculate hash / digest CONFIG_CMD_HWFLOW * RTS/CTS hw flow control CONFIG_CMD_I2C * I2C serial bus support CONFIG_CMD_IDE * IDE harddisk support@@ -2391,6 +2392,23 @@ CBFS (Coreboot Filesystem) support A better solution is to properly configure the firewall, but sometimes that is not allowed. +- Hashing support: + CONFIG_CMD_HASH + + This enables a generic 'hash' command which can produce + hashes / digests from a few algorithms (e.g. SHA1, SHA256). + + CONFIG_HASH_VERIFY + + Enable the hash verify command (hash -v). This adds to code + size a little. + + CONFIG_SHA1 - support SHA1 hashing + CONFIG_SHA256 - support SHA256 hashing + + Note: There is also a sha1sum command, which should perhaps + be deprecated in favour of 'hash sha1'. + - Show boot progress: CONFIG_SHOW_BOOT_PROGRESScommon/Makefile +1
-0@@ -104,6 +104,7 @@ COBJS-$(CONFIG_CMD_FS_GENERIC) += cmd_fs.o COBJS-$(CONFIG_CMD_GETTIME) += cmd_gettime.o COBJS-$(CONFIG_CMD_GPIO) += cmd_gpio.o COBJS-$(CONFIG_CMD_I2C) += cmd_i2c.o +COBJS-$(CONFIG_CMD_HASH) += cmd_hash.o COBJS-$(CONFIG_CMD_IDE) += cmd_ide.o COBJS-$(CONFIG_CMD_IMMAP) += cmd_immap.o COBJS-$(CONFIG_CMD_INI) += cmd_ini.ocommon/cmd_hash.c new file +43
-0@@ -0,0 +1,63 @@ +/* +* Copyright (c) 2012 The Chromium OS Authors. +* +* (C) Copyright 2011 +* Joe Hershberger, National Instruments, joe.hershberger at ni.com +* +* (C) Copyright 2000 +* Wolfgang Denk, DENX Software Engineering, wd at denx.de. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +*/ + +#include <common.h> +#include <command.h> +#include <hash.h> + +static int do_hash (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +#ifdef CONFIG_HASH_VERIFY +int verify =0 ; + +if (!strcmp (argv[1 ],"-v" )) { + verify =1 ; + argc--; + argv++; + } +#endif +/* Move forward to 'algorithm' parameter */ + argc--; + argv++;
common/cmd_hash.c line 53
Quoted 10 lines
common/cmd_hash.c new file +10
-0+return hash_command (*argv, verify, cmdtp, flag, argc -1 , argv +1 ); +} + +#ifdef CONFIG_HASH_VERIFY +U_BOOT_CMD ( + hash,6 ,1 , do_hash, +"compute hash message digest" , +"algorithm address count [[*]sum_dest]\n" +" - compute message digest [save to env var / *address]\n" + "sha1sum -v algorithm address count [*]sum\n"
The command is now hash, not sha1sum.
common/cmd_hash.c line 54
Quoted 1 line
common/cmd_hash.c new file +1
-0+" - verify sha1sum of memory area with env var / *address"
You probably shouldn't directly refer to sha1sum in the description
Quoted 14 lines
common/cmd_hash.c new file +9
-0+); +#else +U_BOOT_CMD ( + hash,5 ,1 , do_hash, +"compute message digest" , +"algorithm address count [[*]sum_dest]\n" +" - compute message digest [save to env var / *address]" +); +#endif include/config_cmd_all.h +0
-0
include/config_cmd_all.h line 47
Quoted 7 lines
include/config_cmd_all.h +1
-0@@ -41,6 +41,7 @@#define CONFIG_CMD_FLASH /* flinfo, erase, protect */ #define CONFIG_CMD_FPGA /* FPGA configuration Support */ #define CONFIG_CMD_GETTIME /* Get time since boot */ +#define CONFIG_CMD_HASH /* calculate hash / digest */ #define CONFIG_CMD_HWFLOW /* RTS/CTS hw flow control */ #define CONFIG_CMD_I2C /* I2C serial bus support */ #define CONFIG_CMD_IDE /* IDE harddisk support */
Cheers,
-Joe
PATCH v2 13/23 edid: Library of EDID decode and print
In reply to Simon GlassFrom: Tom Wai-Hong Tam <[email protected]>
This implements a library for accessing EDID data from an LCD panel. This is used to obtain information about the panel such as its resolution and type.
This is a tidied-up version of the original code pulled from
https://github.com/ynezz/u-boot-edid.
The changes we made are:
- removed bit fields in the struct;
- removed endianness cases in the struct;
- fixed some wrong definitions;
- fixed to fit 80 columns;
- fixed some code styles.
---
Changes in v2: None
common/Makefile | 1 + common/edid.c | 307 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/edid.h | 275 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 583 insertions(+), 0 deletions(-) create mode 100644 common/edid.c create mode 100644 include/edid.h
common/Makefile +1 -0
@@ -188,6 +188,7 @@ COBJS-$(CONFIG_BOOTSTAGE) += bootstage.o COBJS-$(CONFIG_CONSOLE_MUX) += iomux.o COBJS-y += flash.o COBJS-$(CONFIG_CMD_KGDB) += kgdb.o kgdb_stubs.o +COBJS-$(CONFIG_I2C_EDID) += edid.o COBJS-$(CONFIG_KALLSYMS) += kallsyms.o COBJS-$(CONFIG_LCD) += lcd.o COBJS-$(CONFIG_LYNXKDI) += lynxkdi.o
common/edid.c new file +307 -0
307 lines not on this page · raw message
include/edid.h new file +275 -0
275 lines not on this page · raw message
Signature · 1 line
1.7.7.3
PATCH v2 14/23 edid: Add I2C command for printing the EDID
In reply to Simon GlassFrom: Tom Wai-Hong Tam <[email protected]>
Add a single command to read the EDID information over I2C.
For example:
SMDK5250 # i2c dev 7
Setting bus to 7
SMDK5250 # i2c edid 50
EDID version: 1.4
Product ID code: 305c
Manufacturer: AUO
Serial number: 00000000
Manufactured in week: 0 year: 2011
Video input definition: digital signal, voltage level 0, blank to black Monitor is non-RGB
Maximum visible display size: 26 cm x 14 cm
Power management features: no active off, no suspend, no standby Estabilished timings:
Standard timings:
1366x768 60 Hz (detailed)
1366x768 60 Hz (detailed)Monitor ID: 2VD2K.B116XW
---
Changes in v2: None
README | 5 +++++ common/cmd_i2c.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 0 deletions(-)
README +5 -0
@@ -1476,6 +1476,11 @@ CBFS (Coreboot Filesystem) support Support drawing of RLE8-compressed bitmaps on the LCD. + CONFIG_I2C_EDID + + Enables an 'i2c edid' command which can read EDID + information over I2C from an attached LCD display. + - Splash Screen Support: CONFIG_SPLASH_SCREEN
common/cmd_i2c.c +39 -0
@@ -78,6 +78,7 @@#include <common.h> #include <command.h> +#include <edid.h> #include <environment.h> #include <i2c.h> #include <malloc.h>
@@ -1246,6 +1247,38 @@ static int do_sdram (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) }#endif +/* +* Syntax: +* i2c edid {i2c_chip} +*/ +#if defined(CONFIG_I2C_EDID ) +int do_edid (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +u_char chip; +struct edid1_info edid; + +if (argc <2 ) { +cmd_usage (cmdtp); +return 1 ; + } + + chip =simple_strtoul (argv[1 ],NULL ,16 ); +if (i2c_read (chip,0 ,1 , (uchar *)&edid,sizeof (edid)) !=0 ) { +puts ("Error reading EDID content.\n" ); +return 1 ; + } + +if (edid_check_info (&edid)) { +puts ("Content isn't valid EDID.\n" ); +return 1 ; + } + +edid_print_info (&edid); +return 0 ; + +} +#endif /* CONFIG_I2C_EDID */ +#if defined(CONFIG_I2C_MUX )static int do_i2c_add_bus (cmd_tbl_t * cmdtp,int flag,int argc,char *const argv[]) {
@@ -1335,6 +1368,9 @@ static cmd_tbl_t cmd_i2c_sub[] = {#if defined(CONFIG_I2C_MULTI_BUS ) U_BOOT_CMD_MKENT(dev, 1, 1, do_i2c_bus_num, "", ""),#endif /* CONFIG_I2C_MULTI_BUS */ +#if defined(CONFIG_I2C_EDID ) +U_BOOT_CMD_MKENT (edid,1 ,1 , do_edid,"" ,"" ), +#endif /* CONFIG_I2C_EDID */U_BOOT_CMD_MKENT (loop,3 ,1 , do_i2c_loop,"" ,"" ),U_BOOT_CMD_MKENT (md,3 ,1 , do_i2c_md,"" ,"" ), U_BOOT_CMD_MKENT(mm, 2, 1, do_i2c_mm, "", ""),
@@ -1385,6 +1421,9 @@ static char i2c_help_text[] =#if defined(CONFIG_I2C_MULTI_BUS ) "i2c dev [dev] - show or set current I2C bus\n"#endif /* CONFIG_I2C_MULTI_BUS */ +#if defined(CONFIG_I2C_EDID ) + "i2c edid chip - print EDID configuration information\n" +#endif /* CONFIG_I2C_EDID */ "i2c loop chip address[.0, .1, .2] [# of objects] - looping read of device\n" "i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device\n" "i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing)\n"
Signature · 1 line
1.7.7.3
A message that is not in the archive (sent off-list or not yet received): 1353611587-18186-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org
PATCH v2 15/23 fdt: edid: Enable fdt_add_edid() function when CONFIG_LCD defined
From: Tom Wai-Hong Tam <[email protected]>
This function can be used for LCDs as well as monitors.
---
Changes in v2: None
common/fdt_support.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
common/fdt_support.c +1 -1
@@ -1315,7 +1315,7 @@ int fdt_set_status_by_alias(void *fdt, const char* alias,return fdt_set_node_status (fdt, offset, status, error_code); } -#if defined(CONFIG_VIDEO ) +#if defined(CONFIG_VIDEO ) || defined(CONFIG_LCD )int fdt_add_edid (void *blob,const char *compat,unsigned char *edid_buf) {int noff;
Signature · 1 line
1.7.7.3
PATCH v2 16/23 mmc: Fix incorrect handling of 'read' & 'write' commands
In reply to Simon GlassFrom: Taylor Hutt <[email protected]>
If a malformed 'read' or 'write' command is issued, the Sandbox U-Boot can crash because the command-handling code does no error checking on the number of provided arguments.
This change makes the mmc 'erase', 'read' and 'write' commands only function if the proper number of arguments are supplied.
Also puts the else assignment at the beginning fo the if() statement to shortens the generated code. This removes an unnecessary jump from the generated code.
---
Changes in v2: None
common/cmd_mmc.c | 9 ++++----- 1 files changed, 4 insertions(+), 5 deletions(-)
common/cmd_mmc.c +4 -5
@@ -250,14 +250,13 @@ static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])return 0 ; } -if (strcmp (argv[1 ],"read" ) ==0 ) + state =MMC_INVALID ; +if (argc ==5 &&strcmp (argv[1 ],"read" ) ==0 ) state =MMC_READ ; -else if (strcmp (argv[1 ],"write" ) ==0 ) +else if (argc ==5 &&strcmp (argv[1 ],"write" ) ==0 ) state =MMC_WRITE ; -else if (strcmp (argv[1 ],"erase" ) ==0 ) +else if (argc ==4 &&strcmp (argv[1 ],"erase" ) ==0 ) state =MMC_ERASE ; -else - state =MMC_INVALID ;if (state !=MMC_INVALID ) {struct mmc *mmc =find_mmc_device (curr_device);
Signature · 1 line
1.7.7.3
PATCH v2 17/23 Add console command to access io space registers
In reply to Simon GlassFrom: Vadim Bendebury <[email protected]>
Provide u-boot console functions to access IO space registers. A no thrills implementation, accessing one register at a time.
For example:
boot > iod 80
0080: 00000094
boot > iod.w 80
0080: 0094
boot > iod.b 80
0080: 94
boot > iow.b 0x80 12
boot > iod 0x80
0080: 00000012---
Changes in v2: None
common/Makefile | 1 + common/cmd_io.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++ include/command.h | 8 ++-- include/config_cmd_all.h | 1 + 4 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 common/cmd_io.c
common/Makefile +1 -0
@@ -120,6 +120,7 @@ COBJS-$(CONFIG_LOGBUFFER) += cmd_log.o COBJS-$(CONFIG_ID_EEPROM) += cmd_mac.o COBJS-$(CONFIG_CMD_MD5SUM) += cmd_md5sum.o COBJS-$(CONFIG_CMD_MEMORY) += cmd_mem.o +COBJS-$(CONFIG_CMD_IO) += cmd_io.o COBJS-$(CONFIG_CMD_MFSL) += cmd_mfsl.o COBJS-$(CONFIG_MII) += miiphyutil.o COBJS-$(CONFIG_CMD_MII) += miiphyutil.o
common/cmd_io.c new file +93 -0
93 lines not on this page · raw message
include/command.h +4 -4
@@ -89,10 +89,10 @@ extern int cmd_auto_complete(const char *const prompt, char *buf, int *np, int **/ #if defined(CONFIG_CMD_MEMORY ) \ - || defined(CONFIG_CMD_I2C ) \ - || defined(CONFIG_CMD_ITEST ) \ - || defined(CONFIG_CMD_PCI ) \ - || defined(CONFIG_CMD_PORTIO ) + || defined(CONFIG_CMD_I2C ) \ + || defined(CONFIG_CMD_ITEST ) \ + || defined(CONFIG_CMD_PCI ) \ + || defined(CONFIG_CMD_PORTIO )#define CMD_DATA_SIZE extern int cmd_get_data_size (char * arg,int default_size);#endif
include/config_cmd_all.h +1 -0
@@ -48,6 +48,7 @@#define CONFIG_CMD_IMI /* iminfo */ #define CONFIG_CMD_IMLS /* List all found images */ #define CONFIG_CMD_IMMAP /* IMMR dump support */ +#define CONFIG_CMD_IO /* Access to X86 IO space */ #define CONFIG_CMD_IRQ /* irqinfo */ #define CONFIG_CMD_ITEST /* Integer (and string) test */ #define CONFIG_CMD_JFFS2 /* JFFS2 Support */
Signature · 1 line
1.7.7.3
PATCH v2 18/23 console: Enable function to display console info
In reply to Simon GlassThe CONFIG_SYS_CONSOLE_INFO_QUIET option should suppress the console information, but allow boards to display it later if required. Adjust the code to support this.
This is used to avoid printing the information while the LCD display is not ready, since it only becomes ready when stdio init is complete.
---
Changes in v2: None
common/console.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
common/console.c +4 -2
@@ -591,7 +591,6 @@ int console_init_f(void)void stdio_print_current_devices (void ) { -#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET /* Print information */ puts ("In: " );if (stdio_devices[stdin] ==NULL ) {
@@ -613,7 +612,6 @@ void stdio_print_current_devices(void) }else {printf ("%s\n" , stdio_devices[stderr]->name); } -#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */ }#ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV
@@ -685,7 +683,9 @@ done: gd->flags |=GD_FLG_DEVINIT ;/* device initialization completed */ +#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET stdio_print_current_devices (); +#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */ #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE /* set the environment variables (will overwrite previous env settings) */
@@ -760,7 +760,9 @@ int console_init_r(void) gd->flags |=GD_FLG_DEVINIT ;/* device initialization completed */ +#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET stdio_print_current_devices (); +#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */ /* Setting environment variables */ for (i =0 ; i <3 ; i++) {
Signature · 1 line
1.7.7.3
PATCH v2 19/23 tpm: Add TPM stress test
In reply to Simon GlassFrom: Luigi Semenzato <[email protected]>
Add a simple command to stress-test a TPM (Trusted Platform Module).
---
Changes in v2: None
common/cmd_tpm.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 87 insertions(+), 6 deletions(-)
common/cmd_tpm.c +87 -6
@@ -63,19 +63,68 @@ static int tpm_process(int argc, char * const argv[], cmd_tbl_t *cmdtp)return rv; } -static int do_tpm (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +#define CHECK (exp) do { \ + int _rv = exp; \ + if (_rv) { \ + printf("CHECK: %s %d %x\n", #exp, __LINE__, _rv);\ + } \ + } while (0) + +static int tpm_process_stress (int repeat_count) { +int i;int rv =0 ; +u8 request[] = {0x0 ,0xc1 , +0x0 ,0x0 ,0x0 ,0x16 , +0x0 ,0x0 ,0x0 ,0x65 , +0x0 ,0x0 ,0x0 ,0x4 , +0x0 ,0x0 ,0x0 ,0x4 , +0x0 ,0x0 ,0x1 ,0x9 }; +u8 response[MAX_TRANSACTION_SIZE ]; +u32 rlength =MAX_TRANSACTION_SIZE ; + +CHECK (tis_init ()); + +for (i =0 ; i < repeat_count; i++) { +CHECK (tis_open ()); + rv =tis_sendrecv (request,sizeof (request), response, &rlength); +if (rv) { +printf ("tpm test failed at step %d with 0x%x\n" , i, rv); +CHECK (tis_close ()); +break ; + } +CHECK (tis_close ()); +if ((response[6 ] || response[7 ] || response[8 ] || response[9 ]) + && response[9 ] !=0x26 ) { +/* Ignore postinit errors */ +printf ("tpm command failed at step %d\n" +"tpm error code: %02x%02x%02x%02x\n" , i, + response[6 ], response[7 ], + response[8 ], response[9 ]); + rv =-1 ; +break ; + } + } +return rv; +} -/* -* Verify that in case it is present, the first argument, it is -* exactly one character in size. -*/ -if (argc <7 ) { + +static int do_tpm_many (cmd_tbl_t *cmdtp,int flag, +int argc,char *const argv[],int repeat_count) + +{ +int rv =0 ; + +if (argc <7 && repeat_count ==0 ) {puts ("command should be@least six bytes in size\n" );return -1 ; } +if (repeat_count >0 ) { + rv =tpm_process_stress (repeat_count); +return rv; + } +if (tis_init ()) {puts ("tis_init() failed!\n" );return -1 ;
@@ -96,8 +145,40 @@ static int do_tpm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])return rv; } + +static int do_tpm (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +return do_tpm_many (cmdtp, flag, argc, argv,0 ); +} + +U_BOOT_CMD (tpm,MAX_TRANSACTION_SIZE ,1 , do_tpm,"<byte> [<byte> ...] - write data and read response" ,"send arbitrary data (at least 6 bytes) to the TPM " "device and read the response" ); + +static int do_tpm_stress (cmd_tbl_t *cmdtp,int flag, +int argc,char *const argv[]) +{ +long unsigned int n; +int rv; + +if (argc !=2 ) { +puts ("usage: tpm_stress <count>\n" ); +return -1 ; + } + + rv =strict_strtoul (argv[1 ],10 , &n); +if (rv) { +puts ("tpm_stress: bad count" ); +return -1 ; + } + +return do_tpm_many (cmdtp, flag, argc, argv, n); +} + +U_BOOT_CMD (tpm_stress,2 ,1 , do_tpm_stress, +"<n> - stress-test communication with TPM" , +"Repeat a TPM transaction (request-response) N times" +);
Signature · 1 line
1.7.7.3
PATCH v2 20/23 Add command to show DRAM configuration
In reply to Simon GlassThe new meminfo command shows details memory information. It is implemented by board_show_dram(), which should be implemented by the board.
This is a rewrite of the patch:
arm: Add option to display customised memory information
according to feedback on the mailing list.
---
Changes in v2:
- Rework DRAM info feature to use a command instead of updating arm code
README | 8 ++++++++ common/cmd_mem.c | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 0 deletions(-)
README +8 -0
@@ -2414,6 +2414,14 @@ CBFS (Coreboot Filesystem) support Note: There is also a sha1sum command, which should perhaps be deprecated in favour of 'hash sha1'. +- Detailed memory information + CONFIG_CMD_MEMINFO + + Define this to provide a 'meminfo' command. This prints + information on system memory. You can provide a + board-specific function board_show_dram() to print this + information if the standard message is insufficient. + - Show boot progress: CONFIG_SHOW_BOOT_PROGRESS
common/cmd_mem.c +25 -0
@@ -33,6 +33,9 @@#include <dataflash.h> #endif #include <watchdog.h> +#include <linux/compiler.h> + +DECLARE_GLOBAL_DATA_PTR ;static int mod_mem (cmd_tbl_t *,int ,int ,int ,char *const []);
@@ -1243,3 +1246,25 @@ U_BOOT_CMD("[.b, .w, .l] address value delay(ms)" );#endif /* CONFIG_MX_CYCLIC */ + +#ifdef CONFIG_CMD_MEMINFO +__weak void board_show_dram (ulong size) +{ +puts ("DRAM: " ); +print_size (size,"\n" ); +} + +static int do_mem_info (cmd_tbl_t *cmdtp,int flag,int argc, +char *const argv[]) +{ +board_show_dram (gd->ram_size); + +return 0 ; +} + +U_BOOT_CMD ( + meminfo,3 ,1 , do_mem_info, +"display memory information" , +"" +); +#endif
Signature · 1 line
1.7.7.3
PATCH v2 20/23 Add command to show DRAM configuration
Hi,
Quoted 10 lines · Simon Glass
The new meminfo command shows details memory information. It is implemented by
board_show_dram(), which should be implemented by the board.This is a rewrite of the patch:
arm: Add option to display customised memory information
according to feedback on the mailing list.
Signed-off-by Simon Glass <[email protected]>
I have ended up with two of these patches since I neglected to drop it from the arm series. So I would like to drop this one please. I will mark it superseded in patchwork.
Regards,
Simon
PATCH v2 21/23 exynos: Enable hashing functions and EDID for smdk5250
In reply to Simon GlassEnable SHA1/SHA256 hashing and the hash command. Also enable EDID support for reading from an LCD.
---
Changes in v2:
- Add patch to enable hashing and EDID on smdk5250
include/configs/smdk5250.h | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
include/configs/smdk5250.h +7 -0
@@ -203,6 +203,7 @@#define CONFIG_I2C_MULTI_BUS #define CONFIG_MAX_I2C_NUM 8#define CONFIG_SYS_I2C_SLAVE 0x0 +#define CONFIG_I2C_EDID /* Ethernet Controllor Driver */ #ifdef CONFIG_CMD_NET
@@ -215,4 +216,10 @@/* Enable devicetree support */ #define CONFIG_OF_LIBFDT +/* SHA hashing */ +#define CONFIG_CMD_HASH +#define CONFIG_HASH_VERIFY +#define CONFIG_SHA1 +#define CONFIG_SHA256 +#endif /* __CONFIG_H */
Signature · 1 line
1.7.7.3
PATCH v2 22/23 x86: coreboot: Enable io command
In reply to Simon GlassEnable the io command for x86 on coreboot.
---
Changes in v2:
- Add x86 patch to enable io command for coreboot
include/configs/coreboot.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
include/configs/coreboot.h +1 -0
@@ -138,6 +138,7 @@#define CONFIG_CMD_FPGA #define CONFIG_CMD_IMI #undef CONFIG_CMD_IMLS +#define CONFIG_CMD_IO #define CONFIG_CMD_IRQ #define CONFIG_CMD_ITEST #define CONFIG_CMD_LOADB
Signature · 1 line
1.7.7.3
PATCH v2 23/23 x86: Add coreboot version to u-boot's version command
In reply to Simon GlassFrom: Stefan Reinauer <[email protected]>
Since U-Boot runs from coreboot on x86, the Coreboot version is an important part of the boot state. This version information is available in the coreboot tables, so print it when the 'version' command is used.
---
Changes in v2:
- Add x86 tag to version command patch
common/cmd_version.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
common/cmd_version.c +6 -1
@@ -25,6 +25,9 @@#include <command.h> #include <version.h> #include <linux/compiler.h> +#ifdef CONFIG_SYS_COREBOOT +#include <asm/arch/sysinfo.h> +#endif const char __weak version_string[] =U_BOOT_VERSION_STRING ;
@@ -37,7 +40,9 @@ static int do_version(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])#ifdef LD_VERSION_STRING puts (LD_VERSION_STRING "\n" );#endif - +#ifdef CONFIG_SYS_COREBOOT +printf ("coreboot-%s (%s)\n" , lib_sysinfo.version, lib_sysinfo.build); +#endif return 0 ; }
Signature · 1 line
1.7.7.3