From 90a9901764d71308192c96ecd7d735531fe9cc30 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 1 Nov 2020 14:15:35 -0700 Subject: test: Add some tests for setexpr This command currently has no tests. Add some for basic assignment and the integer operations. Note that the default size for setexpr is ulong, which varies depending on the build machine. So for sandbox on a 64-bit host, this means that the default size is 64 bits. Signed-off-by: Simon Glass --- include/test/suites.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/test/suites.h b/include/test/suites.h index ab7b3bd9cad..5c97846e7f5 100644 --- a/include/test/suites.h +++ b/include/test/suites.h @@ -38,6 +38,8 @@ int do_ut_mem(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_optee(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_overlay(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); +int do_ut_setexpr(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]); int do_ut_str(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_time(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_unicode(struct cmd_tbl *cmdtp, int flag, int argc, -- cgit v1.3.1 From 7526deec7e52da92dee25aaf3a47514e639c2bb0 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 1 Nov 2020 14:15:36 -0700 Subject: command: Add constants for cmd_get_data_size string / error At present these values are open-coded in a few places. Add constants so the meaning is clear. Also add a comment to cmd_get_data_size() Signed-off-by: Simon Glass --- cmd/itest.c | 4 ++-- cmd/mem.c | 2 +- common/command.c | 4 ++-- include/command.h | 26 +++++++++++++++++++++++++- 4 files changed, 30 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/cmd/itest.c b/cmd/itest.c index a0cf4bee041..9a441ce9b8a 100644 --- a/cmd/itest.c +++ b/cmd/itest.c @@ -197,10 +197,10 @@ static int do_itest(struct cmd_tbl *cmdtp, int flag, int argc, #endif value = binary_test (argv[2], argv[1], argv[3], w); break; - case -2: + case CMD_DATA_SIZE_STR: value = binary_test (argv[2], argv[1], argv[3], 0); break; - case -1: + case CMD_DATA_SIZE_ERR: default: puts("Invalid data width specifier\n"); value = 0; diff --git a/cmd/mem.c b/cmd/mem.c index 56e1d0755b6..1d4f2bab2f9 100644 --- a/cmd/mem.c +++ b/cmd/mem.c @@ -393,7 +393,7 @@ static int do_mem_search(struct cmd_tbl *cmdtp, int flag, int argc, * Defaults to long if no or incorrect specification. */ size = cmd_get_data_size(argv[0], 4); - if (size < 0 && size != -2 /* string */) + if (size < 0 && size != CMD_DATA_SIZE_STR) return 1; argc--; diff --git a/common/command.c b/common/command.c index 2c491e20a74..068cb55b4cd 100644 --- a/common/command.c +++ b/common/command.c @@ -475,13 +475,13 @@ int cmd_get_data_size(char* arg, int default_size) case 'l': return 4; case 's': - return -2; + return CMD_DATA_SIZE_STR; case 'q': if (MEM_SUPPORT_64BIT_DATA) return 8; /* no break */ default: - return -1; + return CMD_DATA_SIZE_ERR; } } return default_size; diff --git a/include/command.h b/include/command.h index b9b5ec1afa0..e900f97df33 100644 --- a/include/command.h +++ b/include/command.h @@ -117,7 +117,31 @@ int cmd_process_error(struct cmd_tbl *cmdtp, int err); defined(CONFIG_CMD_PCI) || \ defined(CONFIG_CMD_SETEXPR) #define CMD_DATA_SIZE -extern int cmd_get_data_size(char* arg, int default_size); +#define CMD_DATA_SIZE_ERR (-1) +#define CMD_DATA_SIZE_STR (-2) + +/** + * cmd_get_data_size() - Get the data-size specifier from a command + * + * This reads a '.x' size specifier appended to a command. For example 'md.b' + * is the 'md' command with a '.b' specifier, meaning that the command should + * use bytes. + * + * Valid characters are: + * + * b - byte + * w - word (16 bits) + * l - long (32 bits) + * q - quad (64 bits) + * s - string + * + * @arg: Pointers to the command to check. If a valid specifier is present it + * will be the last character of the string, following a '.' + * @default_size: Default size to return if there is no specifier + * @return data size in bytes (1, 2, 4, 8) or CMD_DATA_SIZE_ERR for an invalid + * character, or CMD_DATA_SIZE_STR for a string + */ +int cmd_get_data_size(char *arg, int default_size); #endif #ifdef CONFIG_CMD_BOOTD -- cgit v1.3.1 From d422c77ae8e0cb1211b34eb4af442600b0da8d5b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 1 Nov 2020 14:15:40 -0700 Subject: setexpr: Add some tests for buffer overflow and backref Add tests to check for buffer overflow using simple replacement as well as back references. At present these don't fully pass. Signed-off-by: Simon Glass --- cmd/setexpr.c | 21 +++---------- include/command.h | 17 +++++++++++ test/cmd/setexpr.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 17 deletions(-) (limited to 'include') diff --git a/cmd/setexpr.c b/cmd/setexpr.c index fe3435b4d99..dbb43b3be2f 100644 --- a/cmd/setexpr.c +++ b/cmd/setexpr.c @@ -134,22 +134,8 @@ static char *substitute(char *string, int *slen, int ssize, return p + nlen; } -/** - * regex_sub() - Replace a regex pattern with a string - * - * @data: Buffer containing the string to update - * @data_size: Size of buffer (must be large enough for the new string) - * @nbuf: Back-reference buffer - * @nbuf_size: Size of back-reference buffer (must be larger enough for @s plus - * all back-reference expansions) - * @r: Regular expression to find - * @s: String to replace with - * @global: true to replace all matches in @data, false to replace just the - * first - * @return 0 if OK, 1 on error - */ -static int regex_sub(char *data, uint data_size, char *nbuf, uint nbuf_size, - const char *r, const char *s, bool global) +int setexpr_regex_sub(char *data, uint data_size, char *nbuf, uint nbuf_size, + const char *r, const char *s, bool global) { struct slre slre; char *datap = data; @@ -325,7 +311,8 @@ static int regex_sub_var(const char *name, const char *r, const char *s, strcpy(data, t); - ret = regex_sub(data, SLRE_BUFSZ, nbuf, SLRE_PATSZ, r, s, global); + ret = setexpr_regex_sub(data, SLRE_BUFSZ, nbuf, SLRE_PATSZ, r, s, + global); if (ret) return 1; diff --git a/include/command.h b/include/command.h index e900f97df33..e229bf2825c 100644 --- a/include/command.h +++ b/include/command.h @@ -183,6 +183,23 @@ extern int do_env_set_efi(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); #endif +/** + * setexpr_regex_sub() - Replace a regex pattern with a string + * + * @data: Buffer containing the string to update + * @data_size: Size of buffer (must be large enough for the new string) + * @nbuf: Back-reference buffer + * @nbuf_size: Size of back-reference buffer (must be larger enough for @s plus + * all back-reference expansions) + * @r: Regular expression to find + * @s: String to replace with + * @global: true to replace all matches in @data, false to replace just the + * first + * @return 0 if OK, 1 on error + */ +int setexpr_regex_sub(char *data, uint data_size, char *nbuf, uint nbuf_size, + const char *r, const char *s, bool global); + /* * Error codes that commands return to cmd_process(). We use the standard 0 * and 1 for success and failure, but add one more case - failure with a diff --git a/test/cmd/setexpr.c b/test/cmd/setexpr.c index de54561917c..a6940fd82dd 100644 --- a/test/cmd/setexpr.c +++ b/test/cmd/setexpr.c @@ -209,6 +209,95 @@ static int setexpr_test_regex_inc(struct unit_test_state *uts) } SETEXPR_TEST(setexpr_test_regex_inc, UT_TESTF_CONSOLE_REC); +/* Test setexpr_regex_sub() directly to check buffer usage */ +static int setexpr_test_sub(struct unit_test_state *uts) +{ + char *buf, *nbuf; + int i; + + buf = map_sysmem(0, BUF_SIZE); + nbuf = map_sysmem(0x1000, BUF_SIZE); + + /* Add a pattern so we can check the buffer limits */ + memset(buf, '\xff', BUF_SIZE); + memset(nbuf, '\xff', BUF_SIZE); + for (i = BUF_SIZE; i < 0x1000; i++) { + buf[i] = i & 0xff; + nbuf[i] = i & 0xff; + } + strcpy(buf, "this is a test"); + + /* + * This is a regression test, since a bug was found in the use of + * memmove() in setexpr + */ + ut_assertok(setexpr_regex_sub(buf, BUF_SIZE, nbuf, BUF_SIZE, "is", + "us it is longer", true)); + ut_asserteq_str("thus it is longer us it is longer a test", buf); + + /* The following checks fail at present due to a bug in setexpr */ + return 0; + for (i = BUF_SIZE; i < 0x1000; i++) { + ut_assertf(buf[i] == (char)i, + "buf byte at %x should be %02x, got %02x)\n", + i, i & 0xff, (u8)buf[i]); + ut_assertf(nbuf[i] == (char)i, + "nbuf byte at %x should be %02x, got %02x)\n", + i, i & 0xff, (u8)nbuf[i]); + } + + unmap_sysmem(buf); + + return 0; +} +SETEXPR_TEST(setexpr_test_sub, UT_TESTF_CONSOLE_REC); + +/* Test setexpr_regex_sub() with back references */ +static int setexpr_test_backref(struct unit_test_state *uts) +{ + char *buf, *nbuf; + int i; + + buf = map_sysmem(0, BUF_SIZE); + nbuf = map_sysmem(0x1000, BUF_SIZE); + + /* Add a pattern so we can check the buffer limits */ + memset(buf, '\xff', BUF_SIZE); + memset(nbuf, '\xff', BUF_SIZE); + for (i = BUF_SIZE; i < 0x1000; i++) { + buf[i] = i & 0xff; + nbuf[i] = i & 0xff; + } + strcpy(buf, "this is surely a test is it? yes this is indeed a test"); + + /* + * This is a regression test, since a bug was found in the use of + * memmove() in setexpr + */ + ut_assertok(setexpr_regex_sub(buf, BUF_SIZE, nbuf, BUF_SIZE, + "(this) (is) (surely|indeed)", + "us \\1 \\2 \\3!", true)); + + /* The following checks fail at present due to bugs in setexpr */ + return 0; + ut_asserteq_str("us this is surely! a test is it? yes us this is indeed! a test", + buf); + + for (i = BUF_SIZE; i < 0x1000; i++) { + ut_assertf(buf[i] == (char)i, + "buf byte at %x should be %02x, got %02x)\n", + i, i & 0xff, (u8)buf[i]); + ut_assertf(nbuf[i] == (char)i, + "nbuf byte at %x should be %02x, got %02x)\n", + i, i & 0xff, (u8)nbuf[i]); + } + + unmap_sysmem(buf); + + return 0; +} +SETEXPR_TEST(setexpr_test_backref, UT_TESTF_CONSOLE_REC); + int do_ut_setexpr(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct unit_test *tests = ll_entry_start(struct unit_test, -- cgit v1.3.1 From 310f285e788dbc77fe804261ff5d016cd56ad523 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Mon, 26 Oct 2020 09:31:41 +0100 Subject: hush: Remove default CONFIG_SYS_PROMPT_HUSH_PS2 setting from board files There is no reason to define default option for this macro which is already done in common/cli_hush.c. 87 #ifndef CONFIG_SYS_PROMPT_HUSH_PS2 88 #define CONFIG_SYS_PROMPT_HUSH_PS2 "> " 89 #endif Signed-off-by: Patrick Delaunay Acked-by: Oleksandr Andrushchenko --- include/configs/apalis-imx8.h | 1 - include/configs/colibri-imx8x.h | 1 - include/configs/imx8mm_beacon.h | 1 - include/configs/imx8mm_evk.h | 1 - include/configs/imx8mn_evk.h | 1 - include/configs/imx8mp_evk.h | 1 - include/configs/imx8mq_evk.h | 1 - include/configs/imx8mq_phanbell.h | 1 - include/configs/s5p4418_nanopi2.h | 4 ---- include/configs/verdin-imx8mm.h | 1 - include/configs/xenguest_arm64.h | 1 - 11 files changed, 14 deletions(-) (limited to 'include') diff --git a/include/configs/apalis-imx8.h b/include/configs/apalis-imx8.h index db4e9011c0b..b474b2f5226 100644 --- a/include/configs/apalis-imx8.h +++ b/include/configs/apalis-imx8.h @@ -98,7 +98,6 @@ #define PHYS_SDRAM_2_SIZE SZ_2G /* 2 GB */ /* Monitor Command Prompt */ -#define CONFIG_SYS_PROMPT_HUSH_PS2 "> " #define CONFIG_SYS_CBSIZE SZ_2K #define CONFIG_SYS_MAXARGS 64 #define CONFIG_SYS_BARGSIZE CONFIG_SYS_CBSIZE diff --git a/include/configs/colibri-imx8x.h b/include/configs/colibri-imx8x.h index 29a37ed44fd..fc2c1915942 100644 --- a/include/configs/colibri-imx8x.h +++ b/include/configs/colibri-imx8x.h @@ -132,7 +132,6 @@ #define PHYS_SDRAM_2_SIZE 0x00000000 /* 0 GB */ /* Monitor Command Prompt */ -#define CONFIG_SYS_PROMPT_HUSH_PS2 "> " #define CONFIG_SYS_CBSIZE SZ_2K #define CONFIG_SYS_MAXARGS 64 #define CONFIG_SYS_BARGSIZE CONFIG_SYS_CBSIZE diff --git a/include/configs/imx8mm_beacon.h b/include/configs/imx8mm_beacon.h index 3c9541187f8..9a93dba1c59 100644 --- a/include/configs/imx8mm_beacon.h +++ b/include/configs/imx8mm_beacon.h @@ -119,7 +119,6 @@ #define CONFIG_MXC_UART_BASE UART2_BASE_ADDR /* Monitor Command Prompt */ -#define CONFIG_SYS_PROMPT_HUSH_PS2 "> " #define CONFIG_SYS_CBSIZE 2048 #define CONFIG_SYS_MAXARGS 64 #define CONFIG_SYS_BARGSIZE CONFIG_SYS_CBSIZE diff --git a/include/configs/imx8mm_evk.h b/include/configs/imx8mm_evk.h index 83521ad401d..92eb85553e5 100644 --- a/include/configs/imx8mm_evk.h +++ b/include/configs/imx8mm_evk.h @@ -120,7 +120,6 @@ #define CONFIG_MXC_UART_BASE UART2_BASE_ADDR /* Monitor Command Prompt */ -#define CONFIG_SYS_PROMPT_HUSH_PS2 "> " #define CONFIG_SYS_CBSIZE 2048 #define CONFIG_SYS_MAXARGS 64 #define CONFIG_SYS_BARGSIZE CONFIG_SYS_CBSIZE diff --git a/include/configs/imx8mn_evk.h b/include/configs/imx8mn_evk.h index a6333085fe2..cda8fc2ef76 100644 --- a/include/configs/imx8mn_evk.h +++ b/include/configs/imx8mn_evk.h @@ -124,7 +124,6 @@ #define CONFIG_MXC_UART_BASE UART2_BASE_ADDR /* Monitor Command Prompt */ -#define CONFIG_SYS_PROMPT_HUSH_PS2 "> " #define CONFIG_SYS_CBSIZE 2048 #define CONFIG_SYS_MAXARGS 64 #define CONFIG_SYS_BARGSIZE CONFIG_SYS_CBSIZE diff --git a/include/configs/imx8mp_evk.h b/include/configs/imx8mp_evk.h index 8253c6aa2f3..92091dfd6ba 100644 --- a/include/configs/imx8mp_evk.h +++ b/include/configs/imx8mp_evk.h @@ -135,7 +135,6 @@ #define CONFIG_MXC_UART_BASE UART2_BASE_ADDR /* Monitor Command Prompt */ -#define CONFIG_SYS_PROMPT_HUSH_PS2 "> " #define CONFIG_SYS_CBSIZE 2048 #define CONFIG_SYS_MAXARGS 64 #define CONFIG_SYS_BARGSIZE CONFIG_SYS_CBSIZE diff --git a/include/configs/imx8mq_evk.h b/include/configs/imx8mq_evk.h index 3f9a3bc100b..96bfff749cf 100644 --- a/include/configs/imx8mq_evk.h +++ b/include/configs/imx8mq_evk.h @@ -175,7 +175,6 @@ /* Monitor Command Prompt */ #undef CONFIG_SYS_PROMPT #define CONFIG_SYS_PROMPT "u-boot=> " -#define CONFIG_SYS_PROMPT_HUSH_PS2 "> " #define CONFIG_SYS_CBSIZE 1024 #define CONFIG_SYS_MAXARGS 64 #define CONFIG_SYS_BARGSIZE CONFIG_SYS_CBSIZE diff --git a/include/configs/imx8mq_phanbell.h b/include/configs/imx8mq_phanbell.h index e8b65a4ba5c..66c2c3a8d87 100644 --- a/include/configs/imx8mq_phanbell.h +++ b/include/configs/imx8mq_phanbell.h @@ -169,7 +169,6 @@ #define CONFIG_MXC_UART_BASE UART1_BASE_ADDR /* Monitor Command Prompt */ -#define CONFIG_SYS_PROMPT_HUSH_PS2 "> " #define CONFIG_SYS_CBSIZE 1024 #define CONFIG_SYS_MAXARGS 64 #define CONFIG_SYS_BARGSIZE CONFIG_SYS_CBSIZE diff --git a/include/configs/s5p4418_nanopi2.h b/include/configs/s5p4418_nanopi2.h index 6dd1f3bc049..1e2180b970d 100644 --- a/include/configs/s5p4418_nanopi2.h +++ b/include/configs/s5p4418_nanopi2.h @@ -102,10 +102,6 @@ /* Boot Argument Buffer Size */ #define CONFIG_SYS_BARGSIZE CONFIG_SYS_CBSIZE -#ifdef CONFIG_HUSH_PARSER -#define CONFIG_SYS_PROMPT_HUSH_PS2 "> " -#endif - /*----------------------------------------------------------------------- * Etc Command definition */ diff --git a/include/configs/verdin-imx8mm.h b/include/configs/verdin-imx8mm.h index fd8405433dd..4751bf5a5af 100644 --- a/include/configs/verdin-imx8mm.h +++ b/include/configs/verdin-imx8mm.h @@ -98,7 +98,6 @@ #define CONFIG_MXC_UART_BASE UART1_BASE_ADDR /* Monitor Command Prompt */ -#define CONFIG_SYS_PROMPT_HUSH_PS2 "> " #define CONFIG_SYS_CBSIZE SZ_2K #define CONFIG_SYS_MAXARGS 64 #define CONFIG_SYS_BARGSIZE CONFIG_SYS_CBSIZE diff --git a/include/configs/xenguest_arm64.h b/include/configs/xenguest_arm64.h index c44381e966c..d76ce13d14e 100644 --- a/include/configs/xenguest_arm64.h +++ b/include/configs/xenguest_arm64.h @@ -27,7 +27,6 @@ #define CONFIG_SYS_MALLOC_LEN (32 * 1024 * 1024) /* Monitor Command Prompt */ -#define CONFIG_SYS_PROMPT_HUSH_PS2 "> " #define CONFIG_SYS_CBSIZE 1024 #define CONFIG_SYS_MAXARGS 64 #define CONFIG_SYS_BARGSIZE CONFIG_SYS_CBSIZE -- cgit v1.3.1 From 7292a18256252e41970eceacd5ccd3ed79ea64f0 Mon Sep 17 00:00:00 2001 From: Holger Brunck Date: Fri, 30 Oct 2020 12:45:49 +0100 Subject: km/arm: coding style clean up Address most of the checkpatch issues we found in km_arm and common km code. CC: Stefan Roese CC: Valentin Longchamp Signed-off-by: Holger Brunck Reviewed-by: Stefan Roese --- board/keymile/common/common.c | 44 ++++++++++--------- board/keymile/common/ivm.c | 84 ++++++++++++++++++------------------- board/keymile/km_arm/fpga_config.c | 16 +++---- board/keymile/km_arm/km_arm.c | 41 +++++++++--------- include/configs/km/keymile-common.h | 4 +- include/configs/km/km_arm.h | 2 +- 6 files changed, 96 insertions(+), 95 deletions(-) (limited to 'include') diff --git a/board/keymile/common/common.c b/board/keymile/common/common.c index 03c7ce9da7d..df507e27907 100644 --- a/board/keymile/common/common.c +++ b/board/keymile/common/common.c @@ -56,7 +56,7 @@ int set_km_env(void) /* try to read rootfssize (ram image) from environment */ p = env_get("rootfssize"); - if (p != NULL) + if (p) strict_strtoul(p, 16, &rootfssize); pram = (rootfssize + CONFIG_KM_RESERVED_PRAM + CONFIG_KM_PHRAM + CONFIG_KM_PNVRAM) / 0x400; @@ -165,7 +165,7 @@ static int do_setboardid(struct cmd_tbl *cmdtp, int flag, int argc, char *p; p = get_local_var("IVM_BoardId"); - if (p == NULL) { + if (!p) { printf("can't get the IVM_Boardid\n"); return 1; } @@ -174,7 +174,7 @@ static int do_setboardid(struct cmd_tbl *cmdtp, int flag, int argc, printf("set boardid=%s\n", buf); p = get_local_var("IVM_HWKey"); - if (p == NULL) { + if (!p) { printf("can't get the IVM_HWKey\n"); return 1; } @@ -186,8 +186,8 @@ static int do_setboardid(struct cmd_tbl *cmdtp, int flag, int argc, return 0; } -U_BOOT_CMD(km_setboardid, 1, 0, do_setboardid, "setboardid", "read out bid and " - "hwkey from IVM and set in environment"); +U_BOOT_CMD(km_setboardid, 1, 0, do_setboardid, "setboardid", + "read out bid and hwkey from IVM and set in environment"); /* * command km_checkbidhwk @@ -218,14 +218,14 @@ static int do_checkboardidhwk(struct cmd_tbl *cmdtp, int flag, int argc, * already stored in the local hush variables */ p = get_local_var("IVM_BoardId"); - if (p == NULL) { + if (!p) { printf("can't get the IVM_Boardid\n"); return 1; } rc = strict_strtoul(p, 16, &ivmbid); p = get_local_var("IVM_HWKey"); - if (p == NULL) { + if (!p) { printf("can't get the IVM_HWKey\n"); return 1; } @@ -238,10 +238,10 @@ static int do_checkboardidhwk(struct cmd_tbl *cmdtp, int flag, int argc, /* now try to read values from environment if available */ p = env_get("boardid"); - if (p != NULL) + if (p) rc = strict_strtoul(p, 16, &envbid); p = env_get("hwkey"); - if (p != NULL) + if (p) rc = strict_strtoul(p, 16, &envhwkey); if (rc != 0) { @@ -263,9 +263,8 @@ static int do_checkboardidhwk(struct cmd_tbl *cmdtp, int flag, int argc, if (verbose) { printf("IVM_BoardId: %ld, IVM_HWKey=%ld\n", - ivmbid, ivmhwkey); - printf("boardIdHwKeyList: %s\n", - bidhwklist); + ivmbid, ivmhwkey); + printf("boardIdHwKeyList: %s\n", bidhwklist); } while (!found) { /* loop over each bid/hwkey pair in the list */ @@ -291,13 +290,13 @@ static int do_checkboardidhwk(struct cmd_tbl *cmdtp, int flag, int argc, while (*rest && !isxdigit(*rest)) rest++; } - if ((!bid) || (!hwkey)) { + if (!bid || !hwkey) { /* end of list */ break; } if (verbose) { printf("trying bid=0x%lX, hwkey=%ld\n", - bid, hwkey); + bid, hwkey); } /* * Compare the values of the found entry in the @@ -305,7 +304,7 @@ static int do_checkboardidhwk(struct cmd_tbl *cmdtp, int flag, int argc, * in the inventory eeprom. If they are equal * set the values in environment variables. */ - if ((bid == ivmbid) && (hwkey == ivmhwkey)) { + if (bid == ivmbid && hwkey == ivmhwkey) { char buf[10]; found = 1; @@ -321,12 +320,12 @@ static int do_checkboardidhwk(struct cmd_tbl *cmdtp, int flag, int argc, } /* compare now the values */ - if ((ivmbid == envbid) && (ivmhwkey == envhwkey)) { + if (ivmbid == envbid && ivmhwkey == envhwkey) { printf("boardid=0x%3lX, hwkey=%ld\n", envbid, envhwkey); rc = 0; /* match */ } else { printf("Error: env boardid=0x%3lX, hwkey=%ld\n", envbid, - envhwkey); + envhwkey); printf(" IVM bId=0x%3lX, hwKey=%ld\n", ivmbid, ivmhwkey); rc = 1; /* don't match */ } @@ -334,10 +333,8 @@ static int do_checkboardidhwk(struct cmd_tbl *cmdtp, int flag, int argc, } U_BOOT_CMD(km_checkbidhwk, 2, 0, do_checkboardidhwk, - "check boardid and hwkey", - "[v]\n - check environment parameter "\ - "\"boardIdListHex\" against stored boardid and hwkey "\ - "from the IVM\n v: verbose output" + "check boardid and hwkey", + "[v]\n - check environment parameter \"boardIdListHex\" against stored boardid and hwkey from the IVM\n v: verbose output" ); /* @@ -356,6 +353,7 @@ static int do_checktestboot(struct cmd_tbl *cmdtp, int flag, int argc, #if defined(CONFIG_POST) testpin = post_hotkeys_pressed(); #endif + s = env_get("test_bank"); /* when test_bank is not set, act as if testpin is not asserted */ testboot = (testpin != 0) && (s); @@ -370,6 +368,6 @@ static int do_checktestboot(struct cmd_tbl *cmdtp, int flag, int argc, } U_BOOT_CMD(km_checktestboot, 2, 0, do_checktestboot, - "check if testpin is asserted", - "[v]\n v - verbose output" + "check if testpin is asserted", + "[v]\n v - verbose output" ); diff --git a/board/keymile/common/ivm.c b/board/keymile/common/ivm.c index 60b89fe348c..e989bf609fe 100644 --- a/board/keymile/common/ivm.c +++ b/board/keymile/common/ivm.c @@ -46,28 +46,27 @@ static int ivm_set_value(char *name, char *value) { char tempbuf[256]; - if (value != NULL) { + if (value) { sprintf(tempbuf, "%s=%s", name, value); return set_local_var(tempbuf, 0); - } else { - unset_local_var(name); } + unset_local_var(name); return 0; } static int ivm_get_value(unsigned char *buf, int len, char *name, int off, - int check) + int check) { unsigned short val; unsigned char valbuf[30]; - if ((buf[off + 0] != buf[off + 2]) && - (buf[off + 2] != buf[off + 4])) { + if (buf[off + 0] != buf[off + 2] && + buf[off + 2] != buf[off + 4]) { printf("%s Error corrupted %s\n", __func__, name); val = -1; } else { val = buf[off + 0] + (buf[off + 1] << 8); - if ((val == 0) && (check == 1)) + if (val == 0 && check == 1) val = -1; } sprintf((char *)valbuf, "%x", val); @@ -98,9 +97,9 @@ static char convert_char(char c) } static int ivm_findinventorystring(int type, - unsigned char *const string, - unsigned long maxlen, - unsigned char *buf) + unsigned char *const string, + unsigned long maxlen, + unsigned char *buf) { int xcode = 0; unsigned long cr = 0; @@ -133,12 +132,12 @@ static int ivm_findinventorystring(int type, */ if (addr < INVENTORYDATASIZE) { /* Copy the IVM string in the corresponding string */ - for (; (buf[addr] != '\r') && - ((buf[addr] != ';') || (!stop)) && - (size < (maxlen - 1) && - (addr < INVENTORYDATASIZE)); addr++) { + for (; (buf[addr] != '\r') && + ((buf[addr] != ';') || (!stop)) && + (size < (maxlen - 1) && + (addr < INVENTORYDATASIZE)); addr++) { size += sprintf((char *)string + size, "%c", - convert_char (buf[addr])); + convert_char (buf[addr])); } /* @@ -176,12 +175,12 @@ static int ivm_check_crc(unsigned char *buf, int block) unsigned long crceeprom; crc = ivm_calc_crc(buf, CONFIG_SYS_IVM_EEPROM_PAGE_LEN - 2); - crceeprom = (buf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN - 1] + \ + crceeprom = (buf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN - 1] + buf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN - 2] * 256); if (crc != crceeprom) { if (block == 0) - printf("Error CRC Block: %d EEprom: calculated: \ - %lx EEprom: %lx\n", block, crc, crceeprom); + printf("Error CRC Block: %d EEprom: calculated: %lx EEprom: %lx\n", + block, crc, crceeprom); return -1; } return 0; @@ -189,7 +188,7 @@ static int ivm_check_crc(unsigned char *buf, int block) /* take care of the possible MAC address offset and the IVM content offset */ static int process_mac(unsigned char *valbuf, unsigned char *buf, - int offset, bool unique) + int offset, bool unique) { unsigned char mac[6]; unsigned long val = (buf[4] << 16) + (buf[5] << 8) + buf[6]; @@ -197,9 +196,9 @@ static int process_mac(unsigned char *valbuf, unsigned char *buf, /* use an intermediate buffer, to not change IVM content * MAC address is at offset 1 */ - memcpy(mac, buf+1, 6); + memcpy(mac, buf + 1, 6); - /* MAC adress can be set to locally administred, this is only allowed + /* MAC address can be set to locally administred, this is only allowed * for interfaces which have now connection to the outside. For these * addresses we need to set the second bit in the first byte. */ @@ -222,7 +221,7 @@ static int ivm_analyze_block2(unsigned char *buf, int len) unsigned char valbuf[MAC_STR_SZ]; unsigned long count; - /* IVM_MAC Adress begins at offset 1 */ + /* IVM_MAC Address begins at offset 1 */ sprintf((char *)valbuf, "%pM", buf + 1); ivm_set_value("IVM_MacAddress", (char *)valbuf); /* IVM_MacCount */ @@ -247,9 +246,9 @@ int ivm_analyze_eeprom(unsigned char *buf, int len) return -1; ivm_get_value(buf, CONFIG_SYS_IVM_EEPROM_PAGE_LEN, - "IVM_BoardId", 0, 1); + "IVM_BoardId", 0, 1); val = ivm_get_value(buf, CONFIG_SYS_IVM_EEPROM_PAGE_LEN, - "IVM_HWKey", 6, 1); + "IVM_HWKey", 6, 1); if (val != 0xffff) { sprintf((char *)valbuf, "%x", ((val / 100) % 10)); ivm_set_value("IVM_HWVariant", (char *)valbuf); @@ -257,7 +256,7 @@ int ivm_analyze_eeprom(unsigned char *buf, int len) ivm_set_value("IVM_HWVersion", (char *)valbuf); } ivm_get_value(buf, CONFIG_SYS_IVM_EEPROM_PAGE_LEN, - "IVM_Functions", 12, 0); + "IVM_Functions", 12, 0); GET_STRING("IVM_Symbol", IVM_POS_SYMBOL_ONLY, 8) GET_STRING("IVM_DeviceName", IVM_POS_SHORT_TEXT, 64) @@ -269,7 +268,7 @@ int ivm_analyze_eeprom(unsigned char *buf, int len) while (i < len) { if (tmp[i] == ';') { ivm_set_value("IVM_ShortText", - (char *)&tmp[i + 1]); + (char *)&tmp[i + 1]); break; } i++; @@ -292,7 +291,7 @@ int ivm_analyze_eeprom(unsigned char *buf, int len) if (ivm_check_crc(&buf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN * 2], 2) != 0) return 0; ivm_analyze_block2(&buf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN * 2], - CONFIG_SYS_IVM_EEPROM_PAGE_LEN); + CONFIG_SYS_IVM_EEPROM_PAGE_LEN); return 0; } @@ -305,22 +304,23 @@ static int ivm_populate_env(unsigned char *buf, int len, int mac_address_offset) /* do we have the page 2 filled ? if not return */ if (ivm_check_crc(buf, 2)) return 0; - page2 = &buf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN*2]; + page2 = &buf[CONFIG_SYS_IVM_EEPROM_PAGE_LEN * 2]; -#ifndef CONFIG_KMTEGR1 - /* if an offset is defined, add it */ - process_mac(valbuf, page2, mac_address_offset, true); - env_set((char *)"ethaddr", (char *)valbuf); -#else -/* KMTEGR1 has a special setup. eth0 has no connection to the outside and - * gets an locally administred MAC address, eth1 is the debug interface and - * gets the official MAC address from the IVM - */ - process_mac(valbuf, page2, mac_address_offset, false); - env_set((char *)"ethaddr", (char *)valbuf); - process_mac(valbuf, page2, mac_address_offset, true); - env_set((char *)"eth1addr", (char *)valbuf); -#endif + if (!IS_ENABLED(CONFIG_KMTEGR1)) { + /* if an offset is defined, add it */ + process_mac(valbuf, page2, mac_address_offset, true); + env_set((char *)"ethaddr", (char *)valbuf); + } else { + /* KMTEGR1 has a special setup. eth0 has no connection to the + * outside and gets an locally administred MAC address, eth1 is + * the debug interface and gets the official MAC address from + * the IVM + */ + process_mac(valbuf, page2, mac_address_offset, false); + env_set((char *)"ethaddr", (char *)valbuf); + process_mac(valbuf, page2, mac_address_offset, true); + env_set((char *)"eth1addr", (char *)valbuf); + } return 0; } diff --git a/board/keymile/km_arm/fpga_config.c b/board/keymile/km_arm/fpga_config.c index abb5b7d60d0..839b162eea1 100644 --- a/board/keymile/km_arm/fpga_config.c +++ b/board/keymile/km_arm/fpga_config.c @@ -40,14 +40,14 @@ static int boco_clear_bits(u8 reg, u8 flags) ret = i2c_read(BOCO_ADDR, reg, 1, ®val, 1); if (ret) { printf("%s: error reading the BOCO @%#x !!\n", - __func__, reg); + __func__, reg); return ret; } regval &= ~flags; ret = i2c_write(BOCO_ADDR, reg, 1, ®val, 1); if (ret) { printf("%s: error writing the BOCO @%#x !!\n", - __func__, reg); + __func__, reg); return ret; } @@ -63,14 +63,14 @@ static int boco_set_bits(u8 reg, u8 flags) ret = i2c_read(BOCO_ADDR, reg, 1, ®val, 1); if (ret) { printf("%s: error reading the BOCO @%#x !!\n", - __func__, reg); + __func__, reg); return ret; } regval |= flags; ret = i2c_write(BOCO_ADDR, reg, 1, ®val, 1); if (ret) { printf("%s: error writing the BOCO @%#x !!\n", - __func__, reg); + __func__, reg); return ret; } @@ -113,7 +113,8 @@ int trigger_fpga_config(void) skip = 0; #ifndef CONFIG_KM_FPGA_FORCE_CONFIG /* if the FPGA is already configured, we do not want to - * reconfigure it */ + * reconfigure it + */ skip = 0; if (fpga_done()) { printf("PCIe FPGA config: skipped\n"); @@ -179,7 +180,7 @@ int wait_for_fpga_config(void) ret = i2c_read(BOCO_ADDR, SPI_REG, 1, &spictrl, 1); if (ret) { printf("%s: error reading the BOCO spictrl !!\n", - __func__); + __func__); return ret; } if (timeout-- == 0) { @@ -235,7 +236,8 @@ int fpga_reset(void) #endif /* the FPGA was configured, we configure the BOCO2 so that the EEPROM - * is available from the Bobcat SPI bus */ + * is available from the Bobcat SPI bus + */ int toggle_eeprom_spi_bus(void) { int ret = 0; diff --git a/board/keymile/km_arm/km_arm.c b/board/keymile/km_arm/km_arm.c index 7d191ab860b..60187bd8d29 100644 --- a/board/keymile/km_arm/km_arm.c +++ b/board/keymile/km_arm/km_arm.c @@ -53,9 +53,9 @@ DECLARE_GLOBAL_DATA_PTR; #define PHY_MARVELL_88E1118R_LED_CTRL_REG 0x0010 #define PHY_MARVELL_88E1118R_LED_CTRL_RESERVED 0x1000 -#define PHY_MARVELL_88E1118R_LED_CTRL_LED0_1000MB (0x7<<0) -#define PHY_MARVELL_88E1118R_LED_CTRL_LED1_ACT (0x3<<4) -#define PHY_MARVELL_88E1118R_LED_CTRL_LED2_LINK (0x0<<8) +#define PHY_MARVELL_88E1118R_LED_CTRL_LED0_1000MB (0x7 << 0) +#define PHY_MARVELL_88E1118R_LED_CTRL_LED1_ACT (0x3 << 4) +#define PHY_MARVELL_88E1118R_LED_CTRL_LED2_LINK (0x0 << 8) /* I/O pin to erase flash RGPP09 = MPP43 */ #define KM_FLASH_ERASE_ENABLE 43 @@ -169,6 +169,7 @@ static void set_bootcount_addr(void) { uchar buf[32]; unsigned int bootcountaddr; + bootcountaddr = gd->ram_size - BOOTCOUNT_ADDR; sprintf((char *)buf, "0x%x", bootcountaddr); env_set("bootcountaddr", (char *)buf); @@ -192,7 +193,7 @@ int board_early_init_f(void) /* set the 2 bitbang i2c pins as output gpios */ tmp = readl(MVEBU_GPIO0_BASE + 4); - writel(tmp & (~KM_KIRKWOOD_SOFT_I2C_GPIOS) , MVEBU_GPIO0_BASE + 4); + writel(tmp & (~KM_KIRKWOOD_SOFT_I2C_GPIOS), MVEBU_GPIO0_BASE + 4); #endif /* adjust SDRAM size for bank 0 */ mvebu_sdram_size_adjust(0); @@ -292,11 +293,11 @@ int mvebu_board_spi_release_bus(struct udevice *dev) #define PHY_LED_SEL_REG 0x18 #define PHY_LED0_LINK (0x5) -#define PHY_LED1_ACT (0x8<<4) -#define PHY_LED2_INT (0xe<<8) +#define PHY_LED1_ACT (0x8 << 4) +#define PHY_LED2_INT (0xe << 8) #define PHY_SPEC_CTRL_REG 0x1c -#define PHY_RGMII_CLK_STABLE (0x1<<10) -#define PHY_CLSA (0x1<<1) +#define PHY_RGMII_CLK_STABLE (0x1 << 10) +#define PHY_CLSA (0x1 << 1) /* Configure and enable MV88E3018 PHY */ void reset_phy(void) @@ -407,8 +408,8 @@ void reset_phy(void) return; /* check for Marvell 88E1118R Gigabit PHY (PIGGY3) */ - if ((oui == PHY_MARVELL_OUI) && - (model == PHY_MARVELL_88E1118R_MODEL)) { + if (oui == PHY_MARVELL_OUI && + model == PHY_MARVELL_88E1118R_MODEL) { /* set page register to 3 */ if (miiphy_write(name, CONFIG_PHY_BASE_ADR, PHY_MARVELL_PAGE_REG, @@ -438,7 +439,6 @@ void reset_phy(void) } #endif - #if defined(CONFIG_HUSH_INIT_VAR) int hush_init_var(void) { @@ -478,22 +478,23 @@ int get_scl(void) int post_hotkeys_pressed(void) { -#if defined(CONFIG_KM_COGE5UN) - return kw_gpio_get_value(KM_POST_EN_L); -#else - return !kw_gpio_get_value(KM_POST_EN_L); -#endif + if (IS_ENABLED(CONFIG_KM_COGE5UN)) + return kw_gpio_get_value(KM_POST_EN_L); + else + return !kw_gpio_get_value(KM_POST_EN_L); } ulong post_word_load(void) { - void* addr = (void *) (gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF); + void *addr = (void *)(gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF); + return in_le32(addr); } void post_word_store(ulong value) { - void* addr = (void *) (gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF); + void *addr = (void *)(gd->ram_size - BOOTCOUNT_ADDR + POST_WORD_OFF); + out_le32(addr, value); } @@ -502,14 +503,14 @@ int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset) *vstart = CONFIG_SYS_SDRAM_BASE; /* we go up to relocation plus a 1 MB margin */ - *size = CONFIG_SYS_TEXT_BASE - (1<<20); + *size = CONFIG_SYS_TEXT_BASE - (1 << 20); return 0; } #endif #if defined(CONFIG_SYS_EEPROM_WREN) -int eeprom_write_enable(unsigned dev_addr, int state) +int eeprom_write_enable(unsigned int dev_addr, int state) { kw_gpio_set_value(KM_KIRKWOOD_ENV_WP, !state); diff --git a/include/configs/km/keymile-common.h b/include/configs/km/keymile-common.h index 851b13e063d..e0848625181 100644 --- a/include/configs/km/keymile-common.h +++ b/include/configs/km/keymile-common.h @@ -184,9 +184,9 @@ "cramfsloadfdt=" \ "cramfsload ${fdt_addr_r} " \ "fdt_0x${IVM_BoardId}_0x${IVM_HWKey}.dtb\0" \ - "fdt_addr_r="__stringify(CONFIG_KM_FDT_ADDR) "\0" \ + "fdt_addr_r=" __stringify(CONFIG_KM_FDT_ADDR) "\0" \ "init=/sbin/init-overlay.sh\0" \ - "load_addr_r="__stringify(CONFIG_KM_KERNEL_ADDR) "\0" \ + "load_addr_r=" __stringify(CONFIG_KM_KERNEL_ADDR) "\0" \ "load=tftpboot ${load_addr_r} ${u-boot}\0" \ "mtdids=" CONFIG_MTDIDS_DEFAULT "\0" \ "mtdparts=" CONFIG_MTDPARTS_DEFAULT "\0" \ diff --git a/include/configs/km/km_arm.h b/include/configs/km/km_arm.h index 98e0ce1c240..29060fa96b3 100644 --- a/include/configs/km/km_arm.h +++ b/include/configs/km/km_arm.h @@ -48,7 +48,7 @@ " boardid=0x${IVM_BoardId} hwkey=0x${IVM_HWKey}" #define CONFIG_KM_DEF_ENV_CPU \ - "u-boot="CONFIG_HOSTNAME "/u-boot.kwb\0" \ + "u-boot=" CONFIG_HOSTNAME "/u-boot.kwb\0" \ CONFIG_KM_UPDATE_UBOOT \ "set_fdthigh=setenv fdt_high ${kernelmem}\0" \ "checkfdt=" \ -- cgit v1.3.1