Improve env var handling for net stack
Subsystems (3)
cover Improve env var handling for net stack
This includes moving CONFIG_REGEX to Kconfig and adding support for regex to the env_attr lists (when CONFIG_REGEX is enabled).
This allows ethaddrs to all be checked for access and format by default. Also use callbacks to keep network stack variables up to date instead of polling them on each call to net_loop.
This is a step in the right direction to refactoring the network stack to be similar to that of barebox.
Joe Hershberger (11):
sandbox: Enable some ENV commands
kconfig: Move REGEX to Kconfig
sandbox: Enable regex support
env: Fix return values in env_attr_lookup()
env: Simplify the reverse_strstr() interface
env: Allow env_attr_walk to pass a priv * to callback
env: Add regex support to env_attrs
env: Distinguish finer between source of env change
net: Apply default format rules to all ethaddr
net: Use env callbacks for net variables
net: Add default flags for common net env vars
common/cmd_nvedit.c | 36 +++++--- common/env_attr.c | 179 ++++++++++++++++++++++++++++--------- common/env_callback.c | 6 +- common/env_flags.c | 6 +- configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sandbox_defconfig | 1 + configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/sandbox.h | 5 ++ include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 - include/env_attr.h | 10 +-- include/env_callback.h | 32 ++++++- include/env_flags.h | 23 ++++- include/search.h | 2 + lib/Kconfig | 8 ++ net/net.c | 105 ++++++++++++++++++---- test/dm/eth.c | 1 + 51 files changed, 358 insertions(+), 94 deletions(-)
Signature · 1 line
1.7.11.5
PATCH 1/11 sandbox: Enable some ENV commands
Enable some additional ENV commands in sandbox to aid in build testing and run testing.
---
include/configs/sandbox.h | 5 +++++ 1 file changed, 5 insertions(+)
include/configs/sandbox.h +5 -0
@@ -151,6 +151,11 @@#define CONFIG_CMD_SANDBOX +#define CONFIG_CMD_ENV_FLAGS +#define CONFIG_CMD_ENV_CALLBACK +#define CONFIG_CMD_GREPENV +#define CONFIG_CMD_ASKENV +#define CONFIG_BOOTARGS ""#define CONFIG_BOARD_LATE_INIT
Signature · 1 line
1.7.11.5
PATCH 1/11 sandbox: Enable some ENV commands
Quoted 8 lines · Joe Hershberger
Enable some additional ENV commands in sandbox to aid in build testing and run testing.
Signed-off-by Joe Hershberger <[email protected]>---
include/configs/sandbox.h | 5 +++++ 1 file changed, 5 insertions(+)
PATCH 2/11 kconfig: Move REGEX to Kconfig
In reply to Joe HershbergerHaving this as a Kconfig allows it to be a dependent feature.
---
configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 - lib/Kconfig | 8 ++++++++ 39 files changed, 40 insertions(+), 6 deletions(-)
configs/acadia_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_ACADIA=y +CONFIG_REGEX=y
configs/bamboo_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_BAMBOO=y +CONFIG_REGEX=y
configs/bubinga_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_BUBINGA=y +CONFIG_REGEX=y
configs/canyonlands_defconfig +1 -0
@@ -5,3 +5,4 @@ CONFIG_CANYONLANDS=y CONFIG_DEFAULT_DEVICE_TREE="canyonlands" CONFIG_OF_CONTROL=y CONFIG_OF_EMBED=y +CONFIG_REGEX=y
configs/dlvision-10g_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_DLVISION_10G=y +CONFIG_REGEX=y
configs/dlvision_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_DLVISION=y +CONFIG_REGEX=y
configs/ebony_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_EBONY=y +CONFIG_REGEX=y
configs/gdppc440etx_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_GDPPC440ETX=y +CONFIG_REGEX=y
configs/icon_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_ICON=y +CONFIG_REGEX=y
configs/intip_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="INTIB" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_INTIP=y +CONFIG_REGEX=y
configs/io64_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IO64=y +CONFIG_REGEX=y
configs/io_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IO=y +CONFIG_REGEX=y
configs/iocon_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IOCON=y +CONFIG_REGEX=y
configs/katmai_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_KATMAI=y +CONFIG_REGEX=y
configs/kilauea_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="KILAUEA" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_KILAUEA=y +CONFIG_REGEX=y
configs/luan_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_LUAN=y +CONFIG_REGEX=y
configs/m28evk_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_SPL=y CONFIG_ARM=y CONFIG_TARGET_M28EVK=y +CONFIG_REGEX=y
configs/m53evk_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SPL=y CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/denx/m53evk/imximage.cfg" CONFIG_ARM=y CONFIG_TARGET_M53EVK=y +CONFIG_REGEX=y
configs/makalu_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_MAKALU=y +CONFIG_REGEX=y
configs/neo_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_NEO=y +CONFIG_REGEX=y
configs/novena_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SPL=y CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=arch/arm/imx-common/spl_sd.cfg,MX6Q" CONFIG_ARM=y CONFIG_TARGET_KOSAGI_NOVENA=y +CONFIG_REGEX=y
configs/ocotea_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_OCOTEA=y +CONFIG_REGEX=y
configs/redwood_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_REDWOOD=y +CONFIG_REGEX=y
configs/sequoia_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="SEQUOIA" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_SEQUOIA=y +CONFIG_REGEX=y
configs/socfpga_arria5_defconfig +1 -0
@@ -3,3 +3,4 @@ CONFIG_ARM=y CONFIG_TARGET_SOCFPGA_ARRIA5=y CONFIG_OF_CONTROL=y CONFIG_DEFAULT_DEVICE_TREE="socfpga_arria5_socdk" +CONFIG_REGEX=y
configs/socfpga_cyclone5_defconfig +1 -0
@@ -6,3 +6,4 @@ CONFIG_DEFAULT_DEVICE_TREE="socfpga_cyclone5_socdk" CONFIG_ETH_DESIGNWARE=y CONFIG_NETDEVICES=y CONFIG_NET=y +CONFIG_REGEX=y
configs/t3corp_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_T3CORP=y +CONFIG_REGEX=y
configs/taihu_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_TAIHU=y +CONFIG_REGEX=y
configs/taishan_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_TAISHAN=y +CONFIG_REGEX=y
configs/walnut_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_WALNUT=y +CONFIG_REGEX=y
configs/yosemite_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="YOSEMITE" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_YOSEMITE=y +CONFIG_REGEX=y
configs/yucca_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_YUCCA=y +CONFIG_REGEX=y
include/configs/amcc-common.h +0 -1
@@ -106,7 +106,6 @@#define CONFIG_LOADS_ECHO /* echo on for serial download */ #define CONFIG_SYS_LOADS_BAUD_CHANGE /* allow baudrate change */ -#define CONFIG_REGEX /* Enable regular expression support */ /* * BOOTP options */
include/configs/m28evk.h +0 -1
@@ -49,7 +49,6 @@#define CONFIG_CMD_USB #define CONFIG_VIDEO -#define CONFIG_REGEX /* Enable regular expression support */ /* Memory configuration */ #define CONFIG_NR_DRAM_BANKS 1/* 1 bank of DRAM */
include/configs/m53evk.h +0 -1
@@ -51,7 +51,6 @@#define CONFIG_CMD_USB #define CONFIG_VIDEO -#define CONFIG_REGEX /* Enable regular expression support */ /* * Memory configurations
include/configs/novena.h +0 -1
@@ -22,7 +22,6 @@#define CONFIG_KEYBOARD #define CONFIG_MXC_GPIO #define CONFIG_OF_LIBFDT -#define CONFIG_REGEX #define CONFIG_SYS_GENERIC_BOARD #define CONFIG_SYS_NO_FLASH
include/configs/socfpga_arria5.h +0 -1
@@ -37,7 +37,6 @@#define CONFIG_CMD_USB #define CONFIG_CMD_USB_MASS_STORAGE -#define CONFIG_REGEX /* Enable regular expression support */ /* Memory configurations */ #define PHYS_SDRAM_1_SIZE 0x40000000/* 1GiB on SoCDK */
include/configs/socfpga_cyclone5.h +0 -1
@@ -37,7 +37,6 @@#define CONFIG_CMD_USB #define CONFIG_CMD_USB_MASS_STORAGE -#define CONFIG_REGEX /* Enable regular expression support */ /* Memory configurations */ #define PHYS_SDRAM_1_SIZE 0x40000000/* 1GiB on SoCDK */
lib/Kconfig +8 -0
@@ -36,6 +36,14 @@ config SYS_VSNPRINTF Thumb-2, about 420 bytes). Enable this option for safety when using sprintf() with data you do not control. +config REGEX + bool "Enable regular expression support" + help + If this variable is defined, U-Boot is linked against the + SLRE (Super Light Regular Expression) library, which adds + regex support to some commands, for example "env grep" and + "setexpr". + source lib/rsa/Kconfig menu "Hashing Support"
Signature · 1 line
1.7.11.5
PATCH 2/11 kconfig: Move REGEX to Kconfig
Quoted 37 lines · Joe Hershberger
Having this as a
Kconfigallows it to be a dependent feature.Signed-off-by Joe Hershberger <[email protected]>---
configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 +
Quoted 8 lines
include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 - lib/Kconfig | 8 ++++++++ 39 files changed, 40 insertions(+), 6 deletions(-)
PATCH 2/11 kconfig: Move REGEX to Kconfig
In reply to Joe HershbergerQuoted 4 lines · Joe Hershberger
Having this as a
Kconfigallows it to be a dependent feature.Signed-off-by Joe Hershberger <[email protected]>Reviewed-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150510/439d2474/attachment.sig>
PATCH 2/11 kconfig: Move REGEX to Kconfig
Hi Tom,
Quoted 8 lines · Tom Rini
Quoted 4 lines · Joe Hershberger
Having this as a
Kconfigallows it to be a dependent feature.Signed-off-by Joe Hershberger <[email protected]>Reviewed-by Simon Glass <[email protected]>Applied to u-boot/master, thanks!
What about the rest of the series (v4)?
Thanks,
-Joe
PATCH 2/11 kconfig: Move REGEX to Kconfig
Quoted 5 lines · Joe Hershberger
Hi Tom,
Quoted 2 lines · Tom Rini
On Tue, Apr 21, 2015 at 05:02:42PM -0500, Joe Hershberger wrote:
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Having this as a
Kconfigallows it to be a dependent feature.Signed-off-by Joe Hershberger <[email protected]>Reviewed-by Simon Glass <[email protected]>Applied to u-boot/master, thanks!
What about the rest of the series (v4)?
I think this one got out of sync with the rest of the series :|
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150510/58a67952/attachment.sig>
PATCH 3/11 sandbox: Enable regex support
In reply to Joe HershbergerEnable regex support on sandbox.
---
configs/sandbox_defconfig | 1 + 1 file changed, 1 insertion(+)
configs/sandbox_defconfig +1 -0
@@ -26,3 +26,4 @@ CONFIG_TPM_TIS_SANDBOX=y CONFIG_SOUND=y CONFIG_CMD_SOUND=y CONFIG_SOUND_SANDBOX=y +CONFIG_REGEX=y
Signature · 1 line
1.7.11.5
PATCH 3/11 sandbox: Enable regex support
Quoted 7 lines · Joe Hershberger
Enable regex support on sandbox.
Signed-off-by Joe Hershberger <[email protected]>---
configs/sandbox_defconfig | 1 + 1 file changed, 1 insertion(+)
PATCH 4/11 env: Fix return values in env_attr_lookup()
In reply to Joe HershbergerThis function returned numbers for error codes. Change them to error codes.
---
common/env_attr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
common/env_attr.c +3 -3
@@ -148,10 +148,10 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes)if (!attributes)/* bad parameter */ -return -1 ; +return -EINVAL ;if (!attr_list)/* list not found */ -return 1 ; +return -EINVAL ; entry =reverse_strstr (attr_list, name,NULL );while (entry !=NULL ) {
@@ -209,5 +209,5 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes) }/* not found in list */ -return 2 ; +return -ENOENT ; }
Signature · 1 line
1.7.11.5
PATCH 4/11 env: Fix return values in env_attr_lookup()
Quoted 8 lines · Joe Hershberger
This function returned numbers for error codes. Change them to error codes.
Signed-off-by Joe Hershberger <[email protected]>---
common/env_attr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
PATCH 5/11 env: Simplify the reverse_strstr() interface
In reply to Joe HershbergerThe logic to find the whole matching name was split needlessly between the reverse_strstr function and its caller. Fully contain it to make the interface for calling it more consistent.
---
common/env_attr.c | 79 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 38 deletions(-)
common/env_attr.c +41 -38
@@ -109,33 +109,55 @@ int env_attr_walk(const char *attr_list, }/* -* Search for the last matching string in another string with the option to -* start looking at a certain point (i.e. ignore anything beyond that point). +* Search for the last exactly matching name in an attribute list */ -static char *reverse_strstr (const char *searched,const char *search_for, -const char *searched_start) +static int reverse_name_search (const char *searched,const char *search_for, +const char **result) { -char *result =NULL ; +int result_size =0 ; +const char *cur_searched = searched; + +if (result) + *result =NULL ;if (*search_for =='\0' )return (char *)searched;for (;;) { -char *match =strstr (searched, search_for); - -/* -* Stop looking if no new match is found or looking past the -* searched_start pointer -*/ -if (match ==NULL || (searched_start !=NULL && - match +strlen (search_for) > searched_start)) +const char *match =strstr (cur_searched, search_for); +const char *prevch; +const char *nextch; + +/* Stop looking if no new match is found */ +if (match ==NULL )break ; - result = match; - searched = match +1 ; + prevch = match -1 ; + nextch = match +strlen (search_for); + +/* Skip spaces */ +while (*prevch ==' ' ) + prevch--; +while (*nextch ==' ' ) + nextch++; + +/* Start looking past the current match so last is found */ + cur_searched = match +1 ; + +/* Check for an exact match */ +if (match != searched && + *prevch !=ENV_ATTR_LIST_DELIM ) +continue ; +if (*nextch !=ENV_ATTR_SEP && + *nextch !=ENV_ATTR_LIST_DELIM && + *nextch !='\0' ) +continue ; + + *result = match; + result_size =strlen (search_for); } -return result; +return result_size; }/*
@@ -145,6 +167,7 @@ static char *reverse_strstr(const char *searched, const char *search_for,int env_attr_lookup (const char *attr_list,const char *name,char *attributes) {const char *entry =NULL ; +int entry_len;if (!attributes)/* bad parameter */
@@ -153,32 +176,12 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes)/* list not found */ return -EINVAL ; - entry =reverse_strstr (attr_list, name,NULL ); -while (entry !=NULL ) { -const char *prevch = entry -1 ; -const char *nextch = entry +strlen (name); - -/* Skip spaces */ -while (*prevch ==' ' ) - prevch--; -while (*nextch ==' ' ) - nextch++; - -/* check for an exact match */ -if ((entry == attr_list || - *prevch ==ENV_ATTR_LIST_DELIM ) && - (*nextch ==ENV_ATTR_SEP || - *nextch ==ENV_ATTR_LIST_DELIM || - *nextch =='\0' )) -break ; - - entry =reverse_strstr (attr_list, name, entry); - } + entry_len =reverse_name_search (attr_list, name, &entry);if (entry !=NULL ) {int len;/* skip the name */ - entry +=strlen (name); + entry += entry_len;/* skip spaces */ while (*entry ==' ' ) entry++;
Signature · 1 line
1.7.11.5
PATCH 5/11 env: Simplify the reverse_strstr() interface
Hi Joe,
Quoted 10 lines · Joe Hershberger
The logic to find the whole matching name was split needlessly between the
reverse_strstrfunction and its caller. Fully contain it to make the interface for calling it more consistent.Signed-off-by Joe Hershberger <[email protected]>---
common/env_attr.c | 79 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 38 deletions(-)
You could perhaps add some environment tests in test/ for this function, or access it through getenv(), etc.
Quoted 120 lines
common/env_attr.c +41
-39@@ -109,33 +109,55 @@ int env_attr_walk(const char *attr_list, }/* -* Search for the last matching string in another string with the option to -* start looking at a certain point (i.e. ignore anything beyond that point). +* Search for the last exactly matching name in an attribute list */ -static char *reverse_strstr (const char *searched,const char *search_for, -const char *searched_start) +static int reverse_name_search (const char *searched,const char *search_for, +const char **result) { -char *result =NULL ; +int result_size =0 ; +const char *cur_searched = searched; + +if (result) + *result =NULL ;if (*search_for =='\0' )return (char *)searched;for (;;) { -char *match =strstr (searched, search_for); - -/* -* Stop looking if no new match is found or looking past the -* searched_start pointer -*/ -if (match ==NULL || (searched_start !=NULL && - match +strlen (search_for) > searched_start)) +const char *match =strstr (cur_searched, search_for); +const char *prevch; +const char *nextch; + +/* Stop looking if no new match is found */ +if (match ==NULL )break ; - result = match; - searched = match +1 ; + prevch = match -1 ; + nextch = match +strlen (search_for); + +/* Skip spaces */ +while (*prevch ==' ' ) + prevch--; +while (*nextch ==' ' ) + nextch++; + +/* Start looking past the current match so last is found */ + cur_searched = match +1 ; + +/* Check for an exact match */ +if (match != searched && + *prevch !=ENV_ATTR_LIST_DELIM ) +continue ; +if (*nextch !=ENV_ATTR_SEP && + *nextch !=ENV_ATTR_LIST_DELIM && + *nextch !='\0' ) +continue ; + + *result = match; + result_size =strlen (search_for); } -return result; +return result_size; }/* @@ -145,6 +167,7 @@ static char *reverse_strstr(const char *searched, const char *search_for,int env_attr_lookup (const char *attr_list,const char *name,char *attributes) {const char *entry =NULL ; +int entry_len;if (!attributes)/* bad parameter */ @@ -153,32 +176,12 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes)/* list not found */ return -EINVAL ; - entry =reverse_strstr (attr_list, name,NULL ); -while (entry !=NULL ) { -const char *prevch = entry -1 ; -const char *nextch = entry +strlen (name); - -/* Skip spaces */ -while (*prevch ==' ' ) - prevch--; -while (*nextch ==' ' ) - nextch++; - -/* check for an exact match */ -if ((entry == attr_list || - *prevch ==ENV_ATTR_LIST_DELIM ) && - (*nextch ==ENV_ATTR_SEP || - *nextch ==ENV_ATTR_LIST_DELIM || - *nextch =='\0' )) -break ; - - entry =reverse_strstr (attr_list, name, entry); - } + entry_len =reverse_name_search (attr_list, name, &entry);if (entry !=NULL ) {int len;/* skip the name */ - entry +=strlen (name); + entry += entry_len;/* skip spaces */ while (*entry ==' ' ) entry++; --
Quoted 1 line
1.7.11.5
Regards,
Simon
PATCH 5/11 env: Simplify the reverse_strstr() interface
Hi Simon,
Quoted 10 lines · Simon Glass
Hi Joe,
Quoted 7 lines · Joe Hershberger
The logic to find the whole matching name was split needlessly between the
reverse_strstrfunction and its caller. Fully contain it to make the interface for calling it more consistent.Signed-off-by Joe Hershberger <[email protected]>---
Quoted 6 lines
Quoted 3 lines
common/env_attr.c | 79 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 38 deletions(-)You could perhaps add some environment tests in test/ for this function, or access it through
getenv(), etc.
I'll look into adding some unit tests for the env stuff.
Cheers,
-Joe
PATCH 5/11 env: Simplify the reverse_strstr() interface
Hi Simon,
Quoted 13 lines · Joe Hershberger
Hi Simon,
Quoted 10 lines · Simon Glass
Hi Joe,
Quoted 7 lines · Joe Hershberger
The logic to find the whole matching name was split needlessly between the
reverse_strstrfunction and its caller. Fully contain it to make the interface for calling it more consistent.Signed-off-by Joe Hershberger <[email protected]>---
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
common/env_attr.c | 79 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 38 deletions(-)You could perhaps add some environment tests in test/ for this function, or access it through
getenv(), etc.I'll look into adding some unit tests for the env stuff.
I'd like to reuse a bit of the unit test code from DM tests... do you have any plans to generalize some of it? Or should I take a crack at some of it (that I want to reuse)?
Thanks,
-Joe
PATCH 5/11 env: Simplify the reverse_strstr() interface
Hi Joe,
Quoted 21 lines · Joe Hershberger
Hi Simon,
Quoted 17 lines · Joe Hershberger
Hi Simon,
Quoted 14 lines · Simon Glass
Hi Joe,
Quoted 10 lines · Joe Hershberger
The logic to find the whole matching name was split needlessly between the
reverse_strstrfunction and its caller. Fully contain it to make the interface for calling it more consistent.Signed-off-by Joe Hershberger <[email protected]>---
common/env_attr.c | 79 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 38 deletions(-)
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
You could perhaps add some environment tests in test/ for this function, or access it through
getenv(), etc.I'll look into adding some unit tests for the env stuff.
I'd like to reuse a bit of the unit test code from DM tests... do you have any plans to generalize some of it? Or should I take a crack at some of it (that I want to reuse)?
No plans, please go ahead!
Regards,
Simon
PATCH 6/11 env: Allow env_attr_walk to pass a priv * to callback
In reply to Joe HershbergerIn some cases it can be helpful to have context in the callback about the calling situation. This is needed for following patches.
---
common/cmd_nvedit.c | 10 ++++++---- common/env_attr.c | 15 ++++++++++----- common/env_callback.c | 6 +++--- common/env_flags.c | 6 +++--- include/env_attr.h | 10 +++++----- 5 files changed, 27 insertions(+), 20 deletions(-)
common/cmd_nvedit.c +6 -4
@@ -427,7 +427,8 @@ int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])#endif #if defined(CONFIG_CMD_ENV_CALLBACK ) -static int print_static_binding (const char *var_name,const char *callback_name) +static int print_static_binding (const char *var_name,const char *callback_name, +void *priv) {printf ("\t%-20s %-20s\n" , var_name, callback_name);
@@ -489,7 +490,7 @@ int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])puts ("Static callback bindings:\n" );printf ("\t%-20s %-20s\n" ,"Variable Name" ,"Callback Name" );printf ("\t%-20s %-20s\n" ,"-------------" ,"-------------" ); -env_attr_walk (ENV_CALLBACK_LIST_STATIC , print_static_binding); +env_attr_walk (ENV_CALLBACK_LIST_STATIC , print_static_binding,NULL );puts ("\n" );/* walk through each variable and print the callback if it has one */
@@ -502,7 +503,8 @@ int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])#endif #if defined(CONFIG_CMD_ENV_FLAGS ) -static int print_static_flags (const char *var_name,const char *flags) +static int print_static_flags (const char *var_name,const char *flags, +void *priv) {enum env_flags_vartype type =env_flags_parse_vartype (flags);enum env_flags_varaccess access =env_flags_parse_varaccess (flags);
@@ -559,7 +561,7 @@ int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) "Variable Access");printf ("\t%-20s %-20s %-20s\n" ,"-------------" ,"-------------" ,"---------------" ); -env_attr_walk (ENV_FLAGS_LIST_STATIC , print_static_flags); +env_attr_walk (ENV_FLAGS_LIST_STATIC , print_static_flags,NULL );puts ("\n" );/* walk through each variable and print the flags if non-default */
common/env_attr.c +10 -5
@@ -26,7 +26,8 @@* list = entry[,list] */ int env_attr_walk (const char *attr_list, -int (*callback)(const char *name,const char *attributes)) +int (*callback)(const char *name,const char *attributes,void *priv), +void *priv) {const char *entry, *entry_end;char *name, *attributes;
@@ -93,7 +94,7 @@ int env_attr_walk(const char *attr_list,if (strlen (name) !=0 ) {int retval =0 ; - retval =callback (name, attributes); + retval =callback (name, attributes, priv);if (retval) {free (entry_cpy);return retval;
@@ -120,8 +121,11 @@ static int reverse_name_search(const char *searched, const char *search_for,if (result) *result =NULL ; -if (*search_for =='\0' ) -return (char *)searched; +if (*search_for =='\0' ) { +if (result) + *result = searched; +return strlen (searched); + }for (;;) {const char *match =strstr (cur_searched, search_for);
@@ -153,7 +157,8 @@ static int reverse_name_search(const char *searched, const char *search_for, *nextch != '\0')continue ; - *result = match; +if (result) + *result = match; result_size =strlen (search_for); }
common/env_callback.c +3 -3
@@ -90,7 +90,7 @@ static int clear_callback(ENTRY *entry)/* * Call for each element in the list that associates variables to callbacks */ -static int set_callback (const char *name,const char *value) +static int set_callback (const char *name,const char *value,void *priv) {ENTRY e, *ep;struct env_clbk_tbl *clbkp;
@@ -126,9 +126,9 @@ static int on_callbacks(const char *name, const char *value, enum env_op op,hwalk_r (&env_htab, clear_callback);/* configure any static callback bindings */ -env_attr_walk (ENV_CALLBACK_LIST_STATIC , set_callback); +env_attr_walk (ENV_CALLBACK_LIST_STATIC , set_callback,NULL );/* configure any dynamic callback bindings */ -env_attr_walk (value, set_callback); +env_attr_walk (value, set_callback,NULL );return 0 ; }
common/env_flags.c +3 -3
@@ -435,7 +435,7 @@ static int clear_flags(ENTRY *entry)/* * Call for each element in the list that defines flags for a variable */ -static int set_flags (const char *name,const char *value) +static int set_flags (const char *name,const char *value,void *priv) {ENTRY e, *ep;
@@ -463,9 +463,9 @@ static int on_flags(const char *name, const char *value, enum env_op op,hwalk_r (&env_htab, clear_flags);/* configure any static flags */ -env_attr_walk (ENV_FLAGS_LIST_STATIC , set_flags); +env_attr_walk (ENV_FLAGS_LIST_STATIC , set_flags,NULL );/* configure any dynamic flags */ -env_attr_walk (value, set_flags); +env_attr_walk (value, set_flags,NULL );return 0 ; }
include/env_attr.h +5 -5
@@ -16,13 +16,14 @@* attributes = [^,:\s]* * entry = name[:attributes] * list = entry[,list] -* It will call the "callback" function with the "name" and attribute as "value" +* It will call the "callback" function with the "name" and "attributes" * The callback may return a non-0 to abort the list walk. * This return value will be passed through to the caller. * 0 is returned on success. */ -extern int env_attr_walk (const char *attr_list, -int (*callback)(const char *name,const char *value)); +int env_attr_walk (const char *attr_list, +int (*callback)(const char *name,const char *attributes,void *priv), +void *priv);/* * env_attr_lookup takes as input an "attr_list" with the same form as above.
@@ -33,7 +34,6 @@ extern int env_attr_walk(const char *attr_list,* "attr_list" is NULL. * Returns 0 on success. */ -extern int env_attr_lookup (const char *attr_list,const char *name, -char *attributes); +int env_attr_lookup (const char *attr_list,const char *name,char *attributes);#endif /* __ENV_ATTR_H__ */
Signature · 1 line
1.7.11.5
PATCH 6/11 env: Allow env_attr_walk to pass a priv * to callback
Hi All,
Quoted 5 lines · Joe Hershberger
In some cases it can be helpful to have context in the callback about the calling situation. This is needed for following patches.
Signed-off-by Joe Hershberger <[email protected]>---
8<--snip-->8
Quoted 24 lines
common/env_attr.c +3
-2@@ -26,7 +26,8 @@* list = entry[,list] */ int env_attr_walk (const char *attr_list, -int (*callback)(const char *name,const char *attributes)) +int (*callback)(const char *name,const char *attributes,void *priv), +void *priv) {const char *entry, *entry_end;char *name, *attributes;@@ -93,7 +94,7 @@ int env_attr_walk(const char *attr_list,if (strlen (name) !=0 ) {int retval =0 ; - retval =callback (name, attributes); + retval =callback (name, attributes, priv);if (retval) {free (entry_cpy);return retval;
common/env_attr.c static int reverse_name_search(const char *searched, const char *search_for, · line 128
Quoted 10 lines
common/env_attr.c +5
-2@@ -120,8 +121,11 @@ static int reverse_name_search(const char *searched, const char *search_for,if (result) *result =NULL ; -if (*search_for =='\0' ) -return (char *)searched; +if (*search_for =='\0' ) { +if (result) + *result = searched; +return strlen (searched); + }
I noticed shortly after sending this that this hunk belongs in the previous patch.
common/env_attr.c static int reverse_name_search(const char *searched, const char *search_for, · line 161
Quoted 10 lines
common/env_attr.c +2
-1for (;;) {const char *match =strstr (cur_searched, search_for);@@ -153,7 +157,8 @@ static int reverse_name_search(const char *searched, const char *search_for, *nextch != '\0')continue ; - *result = match; +if (result) + *result = match;
As does this hunk.
common/env_attr.c static int reverse_name_search(const char *searched, const char *search_for, · line 164
Quoted 3 lines
common/env_attr.c +0
-0result_size =strlen (search_for); }
8<--snip-->8
My apologies... I'll resend after any other comments. Please do not apply as is, Tom.
Thanks,
-Joe
PATCH 6/11 env: Allow env_attr_walk to pass a priv * to callback
Quoted 66 lines · Joe Hershberger
Hi All,
Quoted 5 lines · Joe Hershberger
In some cases it can be helpful to have context in the callback about the calling situation. This is needed for following patches.
Signed-off-by Joe Hershberger <[email protected]>---
8<--snip-->8
Quoted 24 lines
common/env_attr.c +3
-2@@ -26,7 +26,8 @@* list = entry[,list] */ int env_attr_walk (const char *attr_list, -int (*callback)(const char *name,const char *attributes)) +int (*callback)(const char *name,const char *attributes,void *priv), +void *priv) {const char *entry, *entry_end;char *name, *attributes;@@ -93,7 +94,7 @@ int env_attr_walk(const char *attr_list,if (strlen (name) !=0 ) {int retval =0 ; - retval =callback (name, attributes); + retval =callback (name, attributes, priv);if (retval) {free (entry_cpy);return retval;common/env_attr.c static int reverse_name_search(const char *searched, const char *search_for, · line 128
Quoted 10 lines
common/env_attr.c +5
-2@@ -120,8 +121,11 @@ static int reverse_name_search(const char *searched, const char *search_for,if (result) *result =NULL ; -if (*search_for =='\0' ) -return (char *)searched; +if (*search_for =='\0' ) { +if (result) + *result = searched; +return strlen (searched); + }I noticed shortly after sending this that this hunk belongs in the previous patch.
common/env_attr.c static int reverse_name_search(const char *searched, const char *search_for, · line 161
Quoted 10 lines
common/env_attr.c +2
-1for (;;) {const char *match =strstr (cur_searched, search_for);@@ -153,7 +157,8 @@ static int reverse_name_search(const char *searched, const char *search_for, *nextch != '\0')continue ; - *result = match; +if (result) + *result = match;As does this hunk.
common/env_attr.c static int reverse_name_search(const char *searched, const char *search_for, · line 164
Quoted 3 lines
common/env_attr.c +0
-0result_size =strlen (search_for); }
Quoted 7 lines
8<--snip-->8
My apologies... I'll resend after any other comments. Please do not apply as is, Tom.
Thanks,
-Joe
PATCH 7/11 env: Add regex support to env_attrs
In reply to Joe HershbergerAllow the features that use env_attrs to specify regexs for the name
---
common/env_attr.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/env_callback.h | 10 ++++-- 2 files changed, 93 insertions(+), 2 deletions(-)
common/env_attr.c +85 -0
@@ -11,6 +11,7 @@#include <linux/linux_string.h> #else #include <common.h> +#include <slre.h> #endif #include <env_attr.h>
@@ -109,6 +110,89 @@ int env_attr_walk(const char *attr_list,return 0 ; } +#if defined(CONFIG_REGEX ) +struct regex_callback_priv { +const char *searched_for; +char *regex; +char *attributes; +}; + +static int regex_callback (const char *name,const char *attributes,void *priv) +{ +int retval =0 ; +struct regex_callback_priv *cbp = (struct regex_callback_priv *)priv; +struct slre slre; +char regex[strlen (name) +3 ]; + +/* Require the whole string to be described by the regex */ +sprintf (regex,"^%s$" , name); +if (slre_compile (&slre, regex)) { +struct cap caps[slre.num_caps +2 ]; + +if (slre_match (&slre, cbp->searched_for, +strlen (cbp->searched_for), caps)) { +free (cbp->regex); + cbp->regex =malloc (strlen (regex) +1 ); +if (cbp->regex) { +strcpy (cbp->regex, regex); + }else { + retval = -ENOMEM ; + goto done; + } + +free (cbp->attributes); + cbp->attributes =malloc (strlen (attributes) +1 ); +if (cbp->attributes) { +strcpy (cbp->attributes, attributes); + }else { + retval = -ENOMEM ; +free (cbp->regex); + cbp->regex =NULL ; + goto done; + } + } + }else { +printf ("Error compiling regex: %s\n" , slre.err_str); + retval =EINVAL ; + } +done: +return retval; +} + +/* +* Retrieve the attributes string associated with a single name in the list +* There is no protection on attributes being too small for the value +*/ +int env_attr_lookup (const char *attr_list,const char *name,char *attributes) +{ +if (!attributes) +/* bad parameter */ +return -EINVAL ; +if (!attr_list) +/* list not found */ +return -EINVAL ; + +struct regex_callback_priv priv; +int retval; + + priv.searched_for = name; + priv.regex =NULL ; + priv.attributes =NULL ; + retval =env_attr_walk (attr_list, regex_callback, &priv); +if (retval) +return retval;/* error */ + +if (priv.regex) { +strcpy (attributes, priv.attributes); +free (priv.attributes); +free (priv.regex); +/* success */ +return 0 ; + } +return -ENOENT ;/* not found in list */ +} +#else +/* * Search for the last exactly matching name in an attribute list */
@@ -219,3 +303,4 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes)/* not found in list */ return -ENOENT; } +#endif
include/env_callback.h +8 -2
@@ -31,12 +31,18 @@#define SPLASHIMAGE_CALLBACK #endif +#ifdef CONFIG_REGEX +#define ENV_DOT_ESCAPE "\\" +#else +#define ENV_DOT_ESCAPE +#endif +/* * This list of callback bindings is static, but may be overridden by defining * a new association in the ".callbacks" environment variable. */ -#define ENV_CALLBACK_LIST_STATIC ENV_CALLBACK_VAR ":callbacks," \ - ENV_FLAGS_VAR ":flags," \ +#define ENV_CALLBACK_LIST_STATIC ENV_DOT_ESCAPE ENV_CALLBACK_VAR ":callbacks," \ + ENV_DOT_ESCAPE ENV_FLAGS_VAR ":flags," \ "baudrate:baudrate," \ "bootfile:bootfile," \ "loadaddr:loadaddr," \
Signature · 1 line
1.7.11.5
PATCH 7/11 env: Add regex support to env_attrs
Quoted 8 lines · Joe Hershberger
Allow the features that use
env_attrsto specify regexs for the nameSigned-off-by Joe Hershberger <[email protected]>---
common/env_attr.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/env_callback.h | 10 ++++-- 2 files changed, 93 insertions(+), 2 deletions(-)
PATCH 8/11 env: Distinguish finer between source of env change
In reply to Joe HershbergerWe already could tell the difference in the callback between an import and "other" which we called interactive. Now add further distinction between interactive (i.e. running env set / env edit / env ask / etc. from the U-Boot command line) and programmatic (i.e. when u-boot source calls any variant of setenv() ).
---
common/cmd_nvedit.c | 26 +++++++++++++++++++------- include/search.h | 2 ++ 2 files changed, 21 insertions(+), 7 deletions(-)
common/cmd_nvedit.c +19 -7
@@ -208,12 +208,11 @@ DONE:* Set a new environment variable, * or replace or delete an existing one. */ -static int _do_env_set (int flag,int argc,char *const argv[]) +static int _do_env_set (int flag,int argc,char *const argv[],int env_flag) {int i, len;char *name, *value, *s;ENTRY e, *ep; -int env_flag =H_INTERACTIVE ;debug ("Initial value for argc=%d\n" , argc);while (argc >1 && **(argv +1 ) =='-' ) {
@@ -291,9 +290,9 @@ int setenv(const char *varname, const char *varvalue)return 1 ;if (varvalue ==NULL || varvalue[0 ] =='\0' ) -return _do_env_set (0 ,2 , (char *const *)argv); +return _do_env_set (0 ,2 , (char *const *)argv,H_PROGRAMMATIC );else -return _do_env_set (0 ,3 , (char *const *)argv); +return _do_env_set (0 ,3 , (char *const *)argv,H_PROGRAMMATIC ); }/**
@@ -347,7 +346,7 @@ static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])if (argc <2 )return CMD_RET_USAGE ; -return _do_env_set (flag, argc, argv); +return _do_env_set (flag, argc, argv,H_INTERACTIVE ); }/*
@@ -422,7 +421,7 @@ int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) }/* Continue calling setenv code */ -return _do_env_set (flag, len, local_args); +return _do_env_set (flag, len, local_args,H_INTERACTIVE ); }#endif
@@ -588,6 +587,10 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,if (argc <2 )return CMD_RET_USAGE ; +/* before import into hashtable */ +if (!(gd->flags &GD_FLG_ENV_READY )) +return 1 ; +/* Set read buffer to initial value or empty sting */ init_val =getenv (argv[1 ]);if (init_val)
@@ -598,7 +601,16 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,if (cli_readline_into_buffer ("edit: " , buffer,0 ) <0 )return 1 ; -return setenv (argv[1 ], buffer); +if (buffer[0 ] =='\0' ) { +const char *const _argv[3 ] = {"setenv" , argv[1 ],NULL }; + +return _do_env_set (0 ,2 , (char *const *)_argv,H_INTERACTIVE ); + }else { +const char *const _argv[4 ] = {"setenv" , argv[1 ], buffer, +NULL }; + +return _do_env_set (0 ,3 , (char *const *)_argv,H_INTERACTIVE ); + } }#endif /* CONFIG_CMD_EDITENV */ #endif /* CONFIG_SPL_BUILD */
include/search.h +2 -0
@@ -120,5 +120,7 @@ extern int hwalk_r(struct hsearch_data *__htab, int (*callback)(ENTRY *));#define H_MATCH_SUBSTR (1 << 7)/* search for substring matches */ #define H_MATCH_REGEX (1 << 8)/* search for regular expression matches */ #define H_MATCH_METHOD (H_MATCH_IDENT | H_MATCH_SUBSTR | H_MATCH_REGEX) +#define H_PROGRAMMATIC (1 << 9)/* indicate that an import is from setenv() */ +#define H_ORIGIN_FLAGS (H_INTERACTIVE | H_PROGRAMMATIC)#endif /* search.h */
Signature · 1 line
1.7.11.5
PATCH 8/11 env: Distinguish finer between source of env change
Quoted 6 lines · Joe Hershberger
We already could tell the difference in the callback between an import and "other" which we called interactive. Now add further distinction between interactive (i.e. running env set / env edit / env ask / etc. from the U-Boot command line) and programmatic (i.e. when u-boot source calls any variant of
setenv()).
Quoted 6 lines
Signed-off-by Joe Hershberger <[email protected]>---
common/cmd_nvedit.c | 26 +++++++++++++++++++------- include/search.h | 2 ++ 2 files changed, 21 insertions(+), 7 deletions(-)
PATCH 9/11 net: Apply default format rules to all ethaddr
In reply to Joe HershbergerUse a regular expression to apply the default formatting flags for all ethaddr env vars.
---
include/env_flags.h | 11 ++++++++--- test/dm/eth.c | 1 + 2 files changed, 9 insertions(+), 3 deletions(-)
include/env_flags.h +8 -3
@@ -38,13 +38,18 @@ enum env_flags_varaccess {#endif #ifdef CONFIG_CMD_NET +#ifdef CONFIG_REGEX +#define ETHADDR_WILDCARD "\\d?" +#else +#define ETHADDR_WILDCARD +#endif #ifdef CONFIG_ENV_OVERWRITE -#define ETHADDR_FLAGS "ethaddr:ma," +#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:ma,"#else #ifdef CONFIG_OVERWRITE_ETHADDR_ONCE -#define ETHADDR_FLAGS "ethaddr:mc," +#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mc,"#else -#define ETHADDR_FLAGS "ethaddr:mo," +#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"#endif #endif #else
test/dm/eth.c +1 -0
@@ -89,6 +89,7 @@ static int dm_test_eth_rotate(struct dm_test_state *dms)/* Invalidate eth1's MAC address */ net_ping_ip =string_to_ip ("1.1.2.2" );strcpy (ethaddr,getenv ("eth1addr" )); +setenv (".flags" ,"eth1addr" );setenv ("eth1addr" ,NULL );/* Make sure that the default is to rotate to the next interface */
Signature · 1 line
1.7.11.5
PATCH 9/11 net: Apply default format rules to all ethaddr
Quoted 9 lines · Joe Hershberger
Use a regular expression to apply the default formatting flags for all ethaddr env vars.
Signed-off-by Joe Hershberger <[email protected]>---
include/env_flags.h | 11 ++++++++--- test/dm/eth.c | 1 + 2 files changed, 9 insertions(+), 3 deletions(-)
Q below.
Quoted 32 lines
include/env_flags.h +8
-3@@ -38,13 +38,18 @@ enum env_flags_varaccess {#endif #ifdef CONFIG_CMD_NET +#ifdef CONFIG_REGEX +#define ETHADDR_WILDCARD "\\d?" +#else +#define ETHADDR_WILDCARD +#endif #ifdef CONFIG_ENV_OVERWRITE -#define ETHADDR_FLAGS "ethaddr:ma," +#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:ma,"#else #ifdef CONFIG_OVERWRITE_ETHADDR_ONCE -#define ETHADDR_FLAGS "ethaddr:mc," +#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mc,"#else -#define ETHADDR_FLAGS "ethaddr:mo," +#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"#endif #endif #else test/dm/eth.c +0
-0
test/dm/eth.c static int dm_test_eth_rotate(struct dm_test_state *dms) · line 91
Quoted 3 lines
test/dm/eth.c +0
-0@@ -89,6 +89,7 @@ static int dm_test_eth_rotate(struct dm_test_state *dms)/* Invalidate eth1's MAC address */ net_ping_ip =string_to_ip ("1.1.2.2" );strcpy (ethaddr,getenv ("eth1addr" ));
Can you explain this next line, please?
Quoted 7 lines
test/dm/eth.c +1
-1+setenv (".flags" ,"eth1addr" );setenv ("eth1addr" ,NULL );/* Make sure that the default is to rotate to the next interface */ --1.7.11.5
Regards,
Simon
PATCH 9/11 net: Apply default format rules to all ethaddr
Hi Simon,
Quoted 44 lines · Simon Glass
Quoted 9 lines · Joe Hershberger
Use a regular expression to apply the default formatting flags for all ethaddr env vars.
Signed-off-by Joe Hershberger <[email protected]>---
include/env_flags.h | 11 ++++++++--- test/dm/eth.c | 1 + 2 files changed, 9 insertions(+), 3 deletions(-)Reviewed-by Simon Glass <[email protected]>Q below.
Quoted 29 lines
include/env_flags.h +8
-3@@ -38,13 +38,18 @@ enum env_flags_varaccess {#endif #ifdef CONFIG_CMD_NET +#ifdef CONFIG_REGEX +#define ETHADDR_WILDCARD "\\d?" +#else +#define ETHADDR_WILDCARD +#endif #ifdef CONFIG_ENV_OVERWRITE -#define ETHADDR_FLAGS "ethaddr:ma," +#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:ma,"#else #ifdef CONFIG_OVERWRITE_ETHADDR_ONCE -#define ETHADDR_FLAGS "ethaddr:mc," +#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mc,"#else -#define ETHADDR_FLAGS "ethaddr:mo," +#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"#endif #endif #else test/dm/eth.c +0
-0
Quoted 10 lines
test/dm/eth.c static int dm_test_eth_rotate(struct dm_test_state *dms) · line 91
Quoted 6 lines
test/dm/eth.c +0
-0@@ -89,6 +89,7 @@ static int dm_test_eth_rotate(struct dm_test_state *dms)/* Invalidate eth1's MAC address */ net_ping_ip =string_to_ip ("1.1.2.2" );strcpy (ethaddr,getenv ("eth1addr" ));Can you explain this next line, please?
Quoted 1 line
test/dm/eth.c +1
-0+setenv (".flags" ,"eth1addr" );
This is now needed to allow the eth1addr to be modified. The env variable ".flags" overrides the static list that is compiled in. Since the regex now applies the ethaddr rules to eth\d?addr all of the ethaddr vars are restricted to write-once by default. You'll notice in another test where this was already overridden for "ethaddr" since it already had the flags applied.
This line has the effect of changing the flags for that variable to be "default" (i.e. unrestricted).
Quoted 13 lines
Quoted 6 lines
test/dm/eth.c +0
-1setenv ("eth1addr" ,NULL );/* Make sure that the default is to rotate to the next interface */ --1.7.11.5
Regards,
Simon
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot
PATCH 9/11 net: Apply default format rules to all ethaddr
Hi Joe,
Quoted 65 lines · Joe Hershberger
Hi Simon,
Quoted 44 lines · Simon Glass
Quoted 9 lines · Joe Hershberger
Use a regular expression to apply the default formatting flags for all ethaddr env vars.
Signed-off-by Joe Hershberger <[email protected]>---
include/env_flags.h | 11 ++++++++--- test/dm/eth.c | 1 + 2 files changed, 9 insertions(+), 3 deletions(-)Reviewed-by Simon Glass <[email protected]>Q below.
Quoted 29 lines
include/env_flags.h +8
-3@@ -38,13 +38,18 @@ enum env_flags_varaccess {#endif #ifdef CONFIG_CMD_NET +#ifdef CONFIG_REGEX +#define ETHADDR_WILDCARD "\\d?" +#else +#define ETHADDR_WILDCARD +#endif #ifdef CONFIG_ENV_OVERWRITE -#define ETHADDR_FLAGS "ethaddr:ma," +#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:ma,"#else #ifdef CONFIG_OVERWRITE_ETHADDR_ONCE -#define ETHADDR_FLAGS "ethaddr:mc," +#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mc,"#else -#define ETHADDR_FLAGS "ethaddr:mo," +#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"#endif #endif #else test/dm/eth.c +0
-0Quoted 10 lines
test/dm/eth.c static int dm_test_eth_rotate(struct dm_test_state *dms) · line 91
Quoted 6 lines
test/dm/eth.c +0
-0@@ -89,6 +89,7 @@ static int dm_test_eth_rotate(struct dm_test_state *dms)/* Invalidate eth1's MAC address */ net_ping_ip =string_to_ip ("1.1.2.2" );strcpy (ethaddr,getenv ("eth1addr" ));Can you explain this next line, please?
Quoted 1 line
test/dm/eth.c +1
-0+setenv (".flags" ,"eth1addr" );This is now needed to allow the eth1addr to be modified. The env variable ".flags" overrides the static list that is compiled in. Since the regex now applies the ethaddr rules to eth\d?addr all of the ethaddr vars are restricted to write-once by default. You'll notice in another test where this was already overridden for "ethaddr" since it already had the flags applied.
Quoted 2 lines
This line has the effect of changing the flags for that variable to be "default" (i.e. unrestricted).
OK I see. Would you mind adding this comment here in the code?
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
test/dm/eth.c +0
-1setenv ("eth1addr" ,NULL );/* Make sure that the default is to rotate to the next interface */ --1.7.11.5
Regards,
Simon
PATCH 10/11 net: Use env callbacks for net variables
In reply to Joe HershbergerInstead of checking for changes to the env each time we enter the net_loop, use the env callbacks to update the values of the variables. Don't update the variables when the source was programmatic, since the variables were the source of the new value.
---
include/env_callback.h | 22 ++++++++++- net/net.c | 105 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 110 insertions(+), 17 deletions(-)
include/env_callback.h +21 -1
@@ -37,6 +37,26 @@#define ENV_DOT_ESCAPE #endif +#ifdef CONFIG_CMD_DNS +#define DNS_CALLBACK "dnsip:dnsip," +#else +#define DNS_CALLBACK +#endif + +#ifdef CONFIG_NET +#define NET_CALLBACKS \ + "bootfile:bootfile," \ + "ipaddr:ipaddr," \ + "gatewayip:gatewayip," \ + "netmask:netmask," \ + "serverip:serverip," \ + "nvlan:nvlan," \ + "vlan:vlan," \ + DNS_CALLBACK +#else +#define NET_CALLBACKS +#endif +/* * This list of callback bindings is static, but may be overridden by defining * a new association in the ".callbacks" environment variable.
@@ -44,7 +64,7 @@#define ENV_CALLBACK_LIST_STATIC ENV_DOT_ESCAPE ENV_CALLBACK_VAR ":callbacks," \ ENV_DOT_ESCAPE ENV_FLAGS_VAR ":flags," \ "baudrate:baudrate," \ - "bootfile:bootfile," \ + NET_CALLBACKS \ "loadaddr:loadaddr," \ SILENT_CALLBACK \ SPLASHIMAGE_CALLBACK \
net/net.c +89 -16
123 lines not on this page · raw message
Signature · 1 line
1.7.11.5
PATCH 10/11 net: Use env callbacks for net variables
Hi Joe,
Quoted 11 lines · Joe Hershberger
Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables. Don't update the variables when the source was programmatic, since the variables were the source of the new value.Signed-off-by Joe Hershberger <[email protected]>---
include/env_callback.h | 22 ++++++++++- net/net.c | 105 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 110 insertions(+), 17 deletions(-)
Q below.
Quoted 56 lines
include/env_callback.h +21
-1@@ -37,6 +37,26 @@#define ENV_DOT_ESCAPE #endif +#ifdef CONFIG_CMD_DNS +#define DNS_CALLBACK "dnsip:dnsip," +#else +#define DNS_CALLBACK +#endif + +#ifdef CONFIG_NET +#define NET_CALLBACKS \ + "bootfile:bootfile," \ + "ipaddr:ipaddr," \ + "gatewayip:gatewayip," \ + "netmask:netmask," \ + "serverip:serverip," \ + "nvlan:nvlan," \ + "vlan:vlan," \ + DNS_CALLBACK +#else +#define NET_CALLBACKS +#endif +/* * This list of callback bindings is static, but may be overridden by defining * a new association in the ".callbacks" environment variable. @@ -44,7 +64,7 @@#define ENV_CALLBACK_LIST_STATIC ENV_DOT_ESCAPE ENV_CALLBACK_VAR ":callbacks," \ ENV_DOT_ESCAPE ENV_FLAGS_VAR ":flags," \ "baudrate:baudrate," \ - "bootfile:bootfile," \ + NET_CALLBACKS \ "loadaddr:loadaddr," \ SILENT_CALLBACK \ SPLASHIMAGE_CALLBACK \net/net.c +3
-0@@ -208,6 +208,9 @@ int __maybe_unused net_busy_flag;static int on_bootfile (const char *name,const char *value,enum env_op op,int flags) { +if ((flags &H_ORIGIN_FLAGS ) ==H_PROGRAMMATIC ) +return 0 ; +switch (op) {case env_op_create:case env_op_overwrite:
net/net.c static int on_bootfile(const char *name, const char *value, enum env_op op, · line 231
Quoted 7 lines
net/net.c +4
-0@@ -222,6 +225,92 @@ static int on_bootfile(const char *name, const char *value, enum env_op op, }U_BOOT_ENV_CALLBACK (bootfile, on_bootfile); +static int on_ipaddr (const char *name,const char *value,enum env_op op, +int flags) +{ +if ((flags &H_ORIGIN_FLAGS ) ==H_PROGRAMMATIC )
Can you just do this?
if (flags & H_PROGRAMMATIC)
Quoted 97 lines
net/net.c +82
-8+return 0 ; + + net_ip =string_to_ip (value); + +return 0 ; +} +U_BOOT_ENV_CALLBACK (ipaddr, on_ipaddr); + +static int on_gatewayip (const char *name,const char *value,enum env_op op, +int flags) +{ +if ((flags &H_ORIGIN_FLAGS ) ==H_PROGRAMMATIC ) +return 0 ; + + net_gateway =string_to_ip (value); + +return 0 ; +} +U_BOOT_ENV_CALLBACK (gatewayip, on_gatewayip); + +static int on_netmask (const char *name,const char *value,enum env_op op, +int flags) +{ +if ((flags &H_ORIGIN_FLAGS ) ==H_PROGRAMMATIC ) +return 0 ; + + net_netmask =string_to_ip (value); + +return 0 ; +} +U_BOOT_ENV_CALLBACK (netmask, on_netmask); + +static int on_serverip (const char *name,const char *value,enum env_op op, +int flags) +{ +if ((flags &H_ORIGIN_FLAGS ) ==H_PROGRAMMATIC ) +return 0 ; + + net_server_ip =string_to_ip (value); + +return 0 ; +} +U_BOOT_ENV_CALLBACK (serverip, on_serverip); + +static int on_nvlan (const char *name,const char *value,enum env_op op, +int flags) +{ +if ((flags &H_ORIGIN_FLAGS ) ==H_PROGRAMMATIC ) +return 0 ; + + net_native_vlan =string_to_vlan (value); + +return 0 ; +} +U_BOOT_ENV_CALLBACK (nvlan, on_nvlan); + +static int on_vlan (const char *name,const char *value,enum env_op op, +int flags) +{ +if ((flags &H_ORIGIN_FLAGS ) ==H_PROGRAMMATIC ) +return 0 ; + + net_our_vlan =string_to_vlan (value); + +return 0 ; +} +U_BOOT_ENV_CALLBACK (vlan, on_vlan); + +#if defined(CONFIG_CMD_DNS ) +static int on_dnsip (const char *name,const char *value,enum env_op op, +int flags) +{ +if ((flags &H_ORIGIN_FLAGS ) ==H_PROGRAMMATIC ) +return 0 ; + + net_dns_server =string_to_ip (value); + +return 0 ; +} +U_BOOT_ENV_CALLBACK (dnsip, on_dnsip); +#endif +/* * Check if autoload is enabled. If so, use either NFS or TFTP to download * the boot file. @@ -252,22 +341,6 @@ void net_auto_load(void)static void net_init_loop (void ) { -static int env_changed_id; -int env_id =get_env_id (); - -/* update only when the environment has changed */ -if (env_changed_id != env_id) { - net_ip =getenv_ip ("ipaddr" ); - net_gateway =getenv_ip ("gatewayip" ); - net_netmask =getenv_ip ("netmask" );
net/net.c void net_auto_load(void) · line 345
Quoted 10 lines
net/net.c +0
-8- net_server_ip =getenv_ip ("serverip" ); - net_native_vlan =getenv_vlan ("nvlan" ); - net_our_vlan =getenv_vlan ("vlan" ); -#if defined(CONFIG_CMD_DNS ) - net_dns_server =getenv_ip ("dnsip" ); -#endif - env_changed_id = env_id; - }if (eth_get_dev ())memcpy (net_ethaddr,eth_get_ethaddr (),6 );
Regards,
Simon
PATCH 10/11 net: Use env callbacks for net variables
Hi Simon,
Quoted 78 lines · Simon Glass
Hi Joe,
Quoted 11 lines · Joe Hershberger
Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables. Don't update the variables when the source was programmatic, since the variables were the source of the new value.Signed-off-by Joe Hershberger <[email protected]>---
include/env_callback.h | 22 ++++++++++- net/net.c | 105 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 110 insertions(+), 17 deletions(-)Reviewed-by Simon Glass <[email protected]>Q below.
Quoted 59 lines
include/env_callback.h +21
-1@@ -37,6 +37,26 @@#define ENV_DOT_ESCAPE #endif +#ifdef CONFIG_CMD_DNS +#define DNS_CALLBACK "dnsip:dnsip," +#else +#define DNS_CALLBACK +#endif + +#ifdef CONFIG_NET +#define NET_CALLBACKS \ + "bootfile:bootfile," \ + "ipaddr:ipaddr," \ + "gatewayip:gatewayip," \ + "netmask:netmask," \ + "serverip:serverip," \ + "nvlan:nvlan," \ + "vlan:vlan," \ + DNS_CALLBACK +#else +#define NET_CALLBACKS +#endif +/* * This list of callback bindings is static, but may be overridden by defining * a new association in the ".callbacks" environment variable. @@ -44,7 +64,7 @@#define ENV_CALLBACK_LIST_STATIC ENV_DOT_ESCAPE ENV_CALLBACK_VAR ":callbacks," \ ENV_DOT_ESCAPE ENV_FLAGS_VAR ":flags," \ "baudrate:baudrate," \ - "bootfile:bootfile," \ + NET_CALLBACKS \ "loadaddr:loadaddr," \ SILENT_CALLBACK \ SPLASHIMAGE_CALLBACK \net/net.c +3
-0@@ -208,6 +208,9 @@ int __maybe_unused net_busy_flag;static int on_bootfile (const char *name,const char *value,enum env_op op,int flags) { +if ((flags &H_ORIGIN_FLAGS ) ==H_PROGRAMMATIC ) +return 0 ; +switch (op) {case env_op_create:case env_op_overwrite:@@ -222,6 +225,92 @@ static int on_bootfile(const char *name, const char *value, enum env_op op, }U_BOOT_ENV_CALLBACK (bootfile, on_bootfile);
Quoted 8 lines
net/net.c static int on_bootfile(const char *name, const char *value, enum env_op op, · line 231
Quoted 4 lines
net/net.c +4
-0+static int on_ipaddr (const char *name,const char *value,enum env_op op, +int flags) +{ +if ((flags &H_ORIGIN_FLAGS ) ==H_PROGRAMMATIC )Can you just do this?
if (flags &
H_PROGRAMMATIC)
Probably so, since it's not likely that we'll make a 4th state that combines these "flags" even though they are all mutually exclusive.
Quoted 114 lines
Quoted 97 lines
net/net.c +82
-8+return 0 ; + + net_ip =string_to_ip (value); + +return 0 ; +} +U_BOOT_ENV_CALLBACK (ipaddr, on_ipaddr); + +static int on_gatewayip (const char *name,const char *value,enum env_op op, +int flags) +{ +if ((flags &H_ORIGIN_FLAGS ) ==H_PROGRAMMATIC ) +return 0 ; + + net_gateway =string_to_ip (value); + +return 0 ; +} +U_BOOT_ENV_CALLBACK (gatewayip, on_gatewayip); + +static int on_netmask (const char *name,const char *value,enum env_op op, +int flags) +{ +if ((flags &H_ORIGIN_FLAGS ) ==H_PROGRAMMATIC ) +return 0 ; + + net_netmask =string_to_ip (value); + +return 0 ; +} +U_BOOT_ENV_CALLBACK (netmask, on_netmask); + +static int on_serverip (const char *name,const char *value,enum env_op op, +int flags) +{ +if ((flags &H_ORIGIN_FLAGS ) ==H_PROGRAMMATIC ) +return 0 ; + + net_server_ip =string_to_ip (value); + +return 0 ; +} +U_BOOT_ENV_CALLBACK (serverip, on_serverip); + +static int on_nvlan (const char *name,const char *value,enum env_op op, +int flags) +{ +if ((flags &H_ORIGIN_FLAGS ) ==H_PROGRAMMATIC ) +return 0 ; + + net_native_vlan =string_to_vlan (value); + +return 0 ; +} +U_BOOT_ENV_CALLBACK (nvlan, on_nvlan); + +static int on_vlan (const char *name,const char *value,enum env_op op, +int flags) +{ +if ((flags &H_ORIGIN_FLAGS ) ==H_PROGRAMMATIC ) +return 0 ; + + net_our_vlan =string_to_vlan (value); + +return 0 ; +} +U_BOOT_ENV_CALLBACK (vlan, on_vlan); + +#if defined(CONFIG_CMD_DNS ) +static int on_dnsip (const char *name,const char *value,enum env_op op, +int flags) +{ +if ((flags &H_ORIGIN_FLAGS ) ==H_PROGRAMMATIC ) +return 0 ; + + net_dns_server =string_to_ip (value); + +return 0 ; +} +U_BOOT_ENV_CALLBACK (dnsip, on_dnsip); +#endif +/* * Check if autoload is enabled. If so, use either NFS or TFTP to download * the boot file. @@ -252,22 +341,6 @@ void net_auto_load(void)static void net_init_loop (void ) { -static int env_changed_id; -int env_id =get_env_id (); - -/* update only when the environment has changed */ -if (env_changed_id != env_id) { - net_ip =getenv_ip ("ipaddr" ); - net_gateway =getenv_ip ("gatewayip" ); - net_netmask =getenv_ip ("netmask" );net/net.c void net_auto_load(void) · line 345
Quoted 10 lines
net/net.c +0
-8- net_server_ip =getenv_ip ("serverip" ); - net_native_vlan =getenv_vlan ("nvlan" ); - net_our_vlan =getenv_vlan ("vlan" ); -#if defined(CONFIG_CMD_DNS ) - net_dns_server =getenv_ip ("dnsip" ); -#endif - env_changed_id = env_id; - }if (eth_get_dev ())memcpy (net_ethaddr,eth_get_ethaddr (),6 );Regards,
Simon
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot
PATCH 11/11 net: Add default flags for common net env vars
In reply to Joe HershbergerCheck that the common network stack's env vars conform to the proper format for IP addresses.
---
include/env_flags.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
include/env_flags.h +11 -1
@@ -52,8 +52,17 @@ enum env_flags_varaccess {#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"#endif #endif +#define NET_FLAGS \ + "ipaddr:i," \ + "gatewayip:i," \ + "netmask:i," \ + "serverip:i," \ + "nvlan:i," \ + "vlan:i," \ + "dnsip:i,"#else -#define ETHADDR_FLAGS "" +#define ETHADDR_FLAGS +#define NET_FLAGS #endif #ifndef CONFIG_ENV_OVERWRITE
@@ -64,6 +73,7 @@ enum env_flags_varaccess {#define ENV_FLAGS_LIST_STATIC \ ETHADDR_FLAGS \ + NET_FLAGS \ SERIAL_FLAGS \ CONFIG_ENV_FLAGS_LIST_STATIC
Signature · 1 line
1.7.11.5
PATCH 11/11 net: Add default flags for common net env vars
Quoted 8 lines · Joe Hershberger
Check that the common network stack's env vars conform to the proper format for IP addresses.
Signed-off-by Joe Hershberger <[email protected]>---
include/env_flags.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
cover Improve env var handling for net stack
In reply to Joe HershbergerHi Joe,
Quoted 68 lines · Joe Hershberger
This includes moving
CONFIG_REGEXtoKconfigand adding support for regex to theenv_attrlists (whenCONFIG_REGEXis enabled).This allows ethaddrs to all be checked for access and format by default. Also use callbacks to keep network stack variables up to date instead of polling them on each call to
net_loop.This is a step in the right direction to refactoring the network stack to be similar to that of barebox.
Joe Hershberger (11):
sandbox: Enable some ENV commands
kconfig: Move REGEX toKconfig
sandbox: Enable regex support
env: Fix return values inenv_attr_lookup()
env: Simplify thereverse_strstr()interface
env: Allowenv_attr_walkto pass a priv * to callback
env: Add regex support toenv_attrs
env: Distinguish finer between source of env change
net: Apply default format rules to all ethaddr
net: Use env callbacks for net variables
net: Add default flags for common net env varscommon/cmd_nvedit.c | 36 +++++--- common/env_attr.c | 179 ++++++++++++++++++++++++++++--------- common/env_callback.c | 6 +- common/env_flags.c | 6 +- configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sandbox_defconfig | 1 + configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/sandbox.h | 5 ++ include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 -
Quoted 8 lines
include/env_attr.h | 10 +-- include/env_callback.h | 32 ++++++- include/env_flags.h | 23 ++++- include/search.h | 2 + lib/Kconfig | 8 ++ net/net.c | 105 ++++++++++++++++++---- test/dm/eth.c | 1 + 51 files changed, 358 insertions(+), 94 deletions(-)
Looks good! I wonder if you could update a README somewhere to explain how it works?
If I understand correctly, you need to enable CONFIG_REGEX for the eth1addr variable to work (for example). Is that right? If so, what is the code size impact?
Regards,
Simon
cover Improve env var handling for net stack
Hi Simon,
Quoted 80 lines · Simon Glass
Hi Joe,
Quoted 68 lines · Joe Hershberger
This includes moving
CONFIG_REGEXtoKconfigand adding support for regex to theenv_attrlists (whenCONFIG_REGEXis enabled).This allows ethaddrs to all be checked for access and format by default. Also use callbacks to keep network stack variables up to date instead of polling them on each call to
net_loop.This is a step in the right direction to refactoring the network stack to be similar to that of barebox.
Joe Hershberger (11):
sandbox: Enable some ENV commands
kconfig: Move REGEX toKconfig
sandbox: Enable regex support
env: Fix return values inenv_attr_lookup()
env: Simplify thereverse_strstr()interface
env: Allowenv_attr_walkto pass a priv * to callback
env: Add regex support toenv_attrs
env: Distinguish finer between source of env change
net: Apply default format rules to all ethaddr
net: Use env callbacks for net variables
net: Add default flags for common net env varscommon/cmd_nvedit.c | 36 +++++--- common/env_attr.c | 179 ++++++++++++++++++++++++++++--------- common/env_callback.c | 6 +- common/env_flags.c | 6 +- configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sandbox_defconfig | 1 + configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/sandbox.h | 5 ++ include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 -Quoted 8 lines
include/env_attr.h | 10 +-- include/env_callback.h | 32 ++++++- include/env_flags.h | 23 ++++- include/search.h | 2 + lib/Kconfig | 8 ++ net/net.c | 105 ++++++++++++++++++---- test/dm/eth.c | 1 + 51 files changed, 358 insertions(+), 94 deletions(-)
Quoted 2 lines
Looks good! I wonder if you could update a README somewhere to explain how it works?
I'll update README to describe it.
Quoted 3 lines
If I understand correctly, you need to enable
CONFIG_REGEXfor the eth1addr variable to work (for example). Is that right? If so, what is the code size impact?
That's sort-of correct. Before the regex, only the "ethaddr" was checked for format, though the eth1addr, etc. all "worked", just were unverified.
I did some build tests...
Without CONFIG_REGEX, the total size grew by 295 bytes (due to the other global changes).
With CONFIG_REGEX enabled, the total size grew by 378 bytes. Enabling CONFIG_REGEX now adds 3633 bytes total.
This test was on BB Black (ARM).
Raw data:
text data bss dec hex filename
W/ patch W/O regex
394014 13324 305876 713214 ae1fe /tmp/u-boot-build/arm/u-boot
W/ patch W/ regex
397651 13324 305872 716847 af02f /tmp/u-boot-build/arm/u-boot
W/O patch W/O regex
393811 13276 305832 712919 ae0d7 /tmp/u-boot-build/arm/u-boot
W/O patch W/ regex
397333 13276 305860 716469 aeeb5 /tmp/u-boot-build/arm/u-boot
Cheers,
-Joe
cover Improve env var handling for net stack
Hi Joe,
Quoted 96 lines · Joe Hershberger
Hi Simon,
Quoted 80 lines · Simon Glass
Hi Joe,
Quoted 68 lines · Joe Hershberger
This includes moving
CONFIG_REGEXtoKconfigand adding support for regex to theenv_attrlists (whenCONFIG_REGEXis enabled).This allows ethaddrs to all be checked for access and format by default. Also use callbacks to keep network stack variables up to date instead of polling them on each call to
net_loop.This is a step in the right direction to refactoring the network stack to be similar to that of barebox.
Joe Hershberger (11):
sandbox: Enable some ENV commands
kconfig: Move REGEX toKconfig
sandbox: Enable regex support
env: Fix return values inenv_attr_lookup()
env: Simplify thereverse_strstr()interface
env: Allowenv_attr_walkto pass a priv * to callback
env: Add regex support toenv_attrs
env: Distinguish finer between source of env change
net: Apply default format rules to all ethaddr
net: Use env callbacks for net variables
net: Add default flags for common net env varscommon/cmd_nvedit.c | 36 +++++--- common/env_attr.c | 179 ++++++++++++++++++++++++++++--------- common/env_callback.c | 6 +- common/env_flags.c | 6 +- configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sandbox_defconfig | 1 + configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/sandbox.h | 5 ++ include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 -Quoted 8 lines
include/env_attr.h | 10 +-- include/env_callback.h | 32 ++++++- include/env_flags.h | 23 ++++- include/search.h | 2 + lib/Kconfig | 8 ++ net/net.c | 105 ++++++++++++++++++---- test/dm/eth.c | 1 + 51 files changed, 358 insertions(+), 94 deletions(-)Quoted 2 lines
Looks good! I wonder if you could update a README somewhere to explain how it works?
I'll update README to describe it.
Quoted 3 lines
If I understand correctly, you need to enable
CONFIG_REGEXfor the eth1addr variable to work (for example). Is that right? If so, what is the code size impact?That's sort-of correct. Before the regex, only the "ethaddr" was checked for format, though the eth1addr, etc. all "worked", just were unverified.
Quoted 6 lines
I did some build tests...
Without
CONFIG_REGEX, the total size grew by 295 bytes (due to the other global changes).
WithCONFIG_REGEXenabled, the total size grew by 378 bytes. EnablingCONFIG_REGEXnow adds 3633 bytes total.
Probably because it is now actually being used?
This is definitely a size increase but IMO it is worth it and those using networking are likely less size-sensitive.
Quoted 15 lines
This test was on BB Black (ARM).
Raw data:
text data bss dec hex filename
W/ patch W/O regex
394014 13324 305876 713214 ae1fe/tmp/u-boot-build/arm/u-boot
W/ patch W/ regex
397651 13324 305872 716847 af02f/tmp/u-boot-build/arm/u-boot
W/O patch W/O regex
393811 13276 305832 712919 ae0d7/tmp/u-boot-build/arm/u-boot
W/O patch W/ regex
397333 13276 305860 716469 aeeb5/tmp/u-boot-build/arm/u-boot
Quoted 2 lines
Cheers,
-Joe
Regards,
Simon
cover Improve env var handling for net stack
Quoted 99 lines · Simon Glass
Hi Joe,
Quoted 96 lines · Joe Hershberger
Hi Simon,
Quoted 80 lines · Simon Glass
Hi Joe,
Quoted 68 lines · Joe Hershberger
This includes moving
CONFIG_REGEXtoKconfigand adding support for regex to theenv_attrlists (whenCONFIG_REGEXis enabled).This allows ethaddrs to all be checked for access and format by default. Also use callbacks to keep network stack variables up to date instead of polling them on each call to
net_loop.This is a step in the right direction to refactoring the network stack to be similar to that of barebox.
Joe Hershberger (11):
sandbox: Enable some ENV commands
kconfig: Move REGEX toKconfig
sandbox: Enable regex support
env: Fix return values inenv_attr_lookup()
env: Simplify thereverse_strstr()interface
env: Allowenv_attr_walkto pass a priv * to callback
env: Add regex support toenv_attrs
env: Distinguish finer between source of env change
net: Apply default format rules to all ethaddr
net: Use env callbacks for net variables
net: Add default flags for common net env varscommon/cmd_nvedit.c | 36 +++++--- common/env_attr.c | 179 ++++++++++++++++++++++++++++--------- common/env_callback.c | 6 +- common/env_flags.c | 6 +- configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sandbox_defconfig | 1 + configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/sandbox.h | 5 ++ include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 -Quoted 8 lines
include/env_attr.h | 10 +-- include/env_callback.h | 32 ++++++- include/env_flags.h | 23 ++++- include/search.h | 2 + lib/Kconfig | 8 ++ net/net.c | 105 ++++++++++++++++++---- test/dm/eth.c | 1 + 51 files changed, 358 insertions(+), 94 deletions(-)Quoted 2 lines
Looks good! I wonder if you could update a README somewhere to explain how it works?
I'll update README to describe it.
Quoted 3 lines
If I understand correctly, you need to enable
CONFIG_REGEXfor the eth1addr variable to work (for example). Is that right? If so, what is the code size impact?That's sort-of correct. Before the regex, only the "ethaddr" was checked for format, though the eth1addr, etc. all "worked", just were unverified.
Quoted 8 lines
Quoted 6 lines
I did some build tests...
Without
CONFIG_REGEX, the total size grew by 295 bytes (due to the other global changes).
WithCONFIG_REGEXenabled, the total size grew by 378 bytes. EnablingCONFIG_REGEXnow adds 3633 bytes total.Probably because it is now actually being used?
Perhaps I was unclear... Enabling CONFIG_REGEX for a target used to add 3550 bytes total (it was already used in env grep command and setexpr sub/gsub). So that means the code for using that lib on the env_attr names is only 83 bytes.
Quoted 2 lines
This is definitely a size increase but IMO it is worth it and those using networking are likely less size-sensitive.
I agree.
Quoted 20 lines
Quoted 15 lines
This test was on BB Black (ARM).
Raw data:
text data bss dec hex filename
W/ patch W/O regex
394014 13324 305876 713214 ae1fe/tmp/u-boot-build/arm/u-boot
W/ patch W/ regex
397651 13324 305872 716847 af02f/tmp/u-boot-build/arm/u-boot
W/O patch W/O regex
393811 13276 305832 712919 ae0d7/tmp/u-boot-build/arm/u-boot
W/O patch W/ regex
397333 13276 305860 716469 aeeb5/tmp/u-boot-build/arm/u-bootQuoted 2 lines
Cheers,
-JoeRegards,
Simon
v2 cover Improve env var handling for net stack
In reply to Joe HershbergerThis includes moving CONFIG_REGEX to Kconfig and adding support for regex to the env_attr lists (when CONFIG_REGEX is enabled).
This allows ethaddrs to all be checked for access and format by default. Also use callbacks to keep network stack variables up to date instead of polling them on each call to net_loop.
This is a step in the right direction to refactoring the network stack to be similar to that of barebox.
Also added a test command to host unit tests for the env functions.
Changes in v2:
-Added comments about the use of .flags in the dm eth test -Added description to README
-Fix bisectability issue
-Fix corner case in reverse_name_search() where searched starts with ' ' -New for version 2
-Simplified test for H_PROGRAMMATIC
Joe Hershberger (19):
sandbox: Enable some ENV commands
kconfig: Move REGEX to Kconfig
sandbox: Enable regex support
env: Fix return values in env_attr_lookup()
env: Simplify the reverse_strstr() interface
env: Allow env_attr_walk to pass a priv * to callback
env: Add regex support to env_attrs
env: Distinguish finer between source of env change
net: Apply default format rules to all ethaddr
net: Use env callbacks for net variables
net: Add default flags for common net env vars
test: Generalize the unit test framework
test: dm: Don't bail on all tests if one test fails
test: Return values from the asserts compatible with cmds
test: env: Add test framework for env
test: env: Add test for verifying env attrs
test: env: Add a test of the new regex behavior for attrs
sandbox: Cleanup order and extra defines in defconfig
sandbox: Enable env unit tests
Makefile | 1 +
README | 8 ++
common/cmd_nvedit.c | 46 +++++++---
common/env_attr.c | 181 ++++++++++++++++++++++++++++---------
common/env_callback.c | 6 +-
common/env_flags.c | 6 +-
configs/acadia_defconfig | 1 +
configs/bamboo_defconfig | 1 +
configs/bubinga_defconfig | 1 +
configs/canyonlands_defconfig | 1 +
configs/dlvision-10g_defconfig | 1 +
configs/dlvision_defconfig | 1 +
configs/ebony_defconfig | 1 +
configs/gdppc440etx_defconfig | 1 +
configs/icon_defconfig | 1 +
configs/intip_defconfig | 1 +
configs/io64_defconfig | 1 +
configs/io_defconfig | 1 +
configs/iocon_defconfig | 1 +
configs/katmai_defconfig | 1 +
configs/kilauea_defconfig | 1 +
configs/luan_defconfig | 1 +
configs/m28evk_defconfig | 1 +
configs/m53evk_defconfig | 1 +
configs/makalu_defconfig | 1 +
configs/neo_defconfig | 1 +
configs/novena_defconfig | 1 +
configs/ocotea_defconfig | 1 +
configs/redwood_defconfig | 1 +
configs/sandbox_defconfig | 38 ++++----
configs/sequoia_defconfig | 1 +
configs/socfpga_arria5_defconfig | 1 +
configs/socfpga_cyclone5_defconfig | 1 +
configs/t3corp_defconfig | 1 +
configs/taihu_defconfig | 1 +
configs/taishan_defconfig | 1 +
configs/walnut_defconfig | 1 +
configs/yosemite_defconfig | 1 +
configs/yucca_defconfig | 1 +
include/configs/amcc-common.h | 1 -
include/configs/m28evk.h | 1 -
include/configs/m53evk.h | 1 -
include/configs/novena.h | 1 -
include/configs/sandbox.h | 5 +
include/configs/socfpga_arria5.h | 1 -
include/configs/socfpga_cyclone5.h | 1 -
include/dm/test.h | 35 ++-----
include/env_attr.h | 10 +-
include/env_callback.h | 32 ++++++-
include/env_flags.h | 23 ++++-
include/env_test.h | 18 ++++
include/search.h | 2 +
include/test/test.h | 47 ++++++++++
include/{dm => test}/ut.h | 40 ++++----
lib/Kconfig | 8 ++
net/net.c | 105 +++++++++++++++++----
test/Kconfig | 4 +
test/Makefile | 1 +
test/dm/Kconfig | 1 +
test/dm/Makefile | 2 -
test/dm/bus.c | 39 ++++----
test/dm/core.c | 74 ++++++++-------
test/dm/eth.c | 17 ++--
test/dm/gpio.c | 22 ++---
test/dm/i2c.c | 20 ++--
test/dm/pci.c | 6 +-
test/dm/sf.c | 4 +-
test/dm/spi.c | 8 +-
test/dm/test-driver.c | 6 +-
test/dm/test-fdt.c | 16 ++--
test/dm/test-main.c | 37 ++++----
test/dm/test-uclass.c | 7 +-
test/dm/usb.c | 6 +-
test/env/Kconfig | 8 ++
test/env/Makefile | 8 ++
test/env/attr.c | 89 ++++++++++++++++++
test/env/cmd_env_test.c | 36 ++++++++
test/{dm => }/ut.c | 16 ++--
78 files changed, 780 insertions(+), 296 deletions(-)
create mode 100644 include/env_test.h
create mode 100644 include/test/test.h
rename include/{dm => test}/ut.h (73%)
create mode 100644 test/env/Kconfig
create mode 100644 test/env/Makefile
create mode 100644 test/env/attr.c
create mode 100644 test/env/cmd_env_test.c
rename test/{dm => }/ut.c (59%)Signature · 1 line
1.7.11.5
PATCH v2 1/19 sandbox: Enable some ENV commands
Enable some additional ENV commands in sandbox to aid in build testing and run testing.
---
Changes in v2: None
include/configs/sandbox.h | 5 +++++ 1 file changed, 5 insertions(+)
include/configs/sandbox.h +5 -0
@@ -151,6 +151,11 @@#define CONFIG_CMD_SANDBOX +#define CONFIG_CMD_ENV_FLAGS +#define CONFIG_CMD_ENV_CALLBACK +#define CONFIG_CMD_GREPENV +#define CONFIG_CMD_ASKENV +#define CONFIG_BOOTARGS ""#define CONFIG_BOARD_LATE_INIT
Signature · 1 line
1.7.11.5
PATCH v2 2/19 kconfig: Move REGEX to Kconfig
In reply to Joe HershbergerHaving this as a Kconfig allows it to be a dependent feature.
---
Changes in v2: None
configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 - lib/Kconfig | 8 ++++++++ 39 files changed, 40 insertions(+), 6 deletions(-)
configs/acadia_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_ACADIA=y +CONFIG_REGEX=y
configs/bamboo_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_BAMBOO=y +CONFIG_REGEX=y
configs/bubinga_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_BUBINGA=y +CONFIG_REGEX=y
configs/canyonlands_defconfig +1 -0
@@ -5,3 +5,4 @@ CONFIG_CANYONLANDS=y CONFIG_DEFAULT_DEVICE_TREE="canyonlands" CONFIG_OF_CONTROL=y CONFIG_OF_EMBED=y +CONFIG_REGEX=y
configs/dlvision-10g_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_DLVISION_10G=y +CONFIG_REGEX=y
configs/dlvision_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_DLVISION=y +CONFIG_REGEX=y
configs/ebony_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_EBONY=y +CONFIG_REGEX=y
configs/gdppc440etx_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_GDPPC440ETX=y +CONFIG_REGEX=y
configs/icon_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_ICON=y +CONFIG_REGEX=y
configs/intip_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="INTIB" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_INTIP=y +CONFIG_REGEX=y
configs/io64_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IO64=y +CONFIG_REGEX=y
configs/io_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IO=y +CONFIG_REGEX=y
configs/iocon_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IOCON=y +CONFIG_REGEX=y
configs/katmai_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_KATMAI=y +CONFIG_REGEX=y
configs/kilauea_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="KILAUEA" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_KILAUEA=y +CONFIG_REGEX=y
configs/luan_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_LUAN=y +CONFIG_REGEX=y
configs/m28evk_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_SPL=y CONFIG_ARM=y CONFIG_TARGET_M28EVK=y +CONFIG_REGEX=y
configs/m53evk_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SPL=y CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/denx/m53evk/imximage.cfg" CONFIG_ARM=y CONFIG_TARGET_M53EVK=y +CONFIG_REGEX=y
configs/makalu_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_MAKALU=y +CONFIG_REGEX=y
configs/neo_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_NEO=y +CONFIG_REGEX=y
configs/novena_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SPL=y CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=arch/arm/imx-common/spl_sd.cfg,MX6Q" CONFIG_ARM=y CONFIG_TARGET_KOSAGI_NOVENA=y +CONFIG_REGEX=y
configs/ocotea_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_OCOTEA=y +CONFIG_REGEX=y
configs/redwood_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_REDWOOD=y +CONFIG_REGEX=y
configs/sequoia_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="SEQUOIA" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_SEQUOIA=y +CONFIG_REGEX=y
configs/socfpga_arria5_defconfig +1 -0
@@ -3,3 +3,4 @@ CONFIG_ARM=y CONFIG_TARGET_SOCFPGA_ARRIA5=y CONFIG_OF_CONTROL=y CONFIG_DEFAULT_DEVICE_TREE="socfpga_arria5_socdk" +CONFIG_REGEX=y
configs/socfpga_cyclone5_defconfig +1 -0
@@ -6,3 +6,4 @@ CONFIG_DEFAULT_DEVICE_TREE="socfpga_cyclone5_socdk" CONFIG_ETH_DESIGNWARE=y CONFIG_NETDEVICES=y CONFIG_NET=y +CONFIG_REGEX=y
configs/t3corp_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_T3CORP=y +CONFIG_REGEX=y
configs/taihu_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_TAIHU=y +CONFIG_REGEX=y
configs/taishan_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_TAISHAN=y +CONFIG_REGEX=y
configs/walnut_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_WALNUT=y +CONFIG_REGEX=y
configs/yosemite_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="YOSEMITE" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_YOSEMITE=y +CONFIG_REGEX=y
configs/yucca_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_YUCCA=y +CONFIG_REGEX=y
include/configs/amcc-common.h +0 -1
@@ -106,7 +106,6 @@#define CONFIG_LOADS_ECHO /* echo on for serial download */ #define CONFIG_SYS_LOADS_BAUD_CHANGE /* allow baudrate change */ -#define CONFIG_REGEX /* Enable regular expression support */ /* * BOOTP options */
include/configs/m28evk.h +0 -1
@@ -49,7 +49,6 @@#define CONFIG_CMD_USB #define CONFIG_VIDEO -#define CONFIG_REGEX /* Enable regular expression support */ /* Memory configuration */ #define CONFIG_NR_DRAM_BANKS 1/* 1 bank of DRAM */
include/configs/m53evk.h +0 -1
@@ -51,7 +51,6 @@#define CONFIG_CMD_USB #define CONFIG_VIDEO -#define CONFIG_REGEX /* Enable regular expression support */ /* * Memory configurations
include/configs/novena.h +0 -1
@@ -22,7 +22,6 @@#define CONFIG_KEYBOARD #define CONFIG_MXC_GPIO #define CONFIG_OF_LIBFDT -#define CONFIG_REGEX #define CONFIG_SYS_GENERIC_BOARD #define CONFIG_SYS_NO_FLASH
include/configs/socfpga_arria5.h +0 -1
@@ -37,7 +37,6 @@#define CONFIG_CMD_USB #define CONFIG_CMD_USB_MASS_STORAGE -#define CONFIG_REGEX /* Enable regular expression support */ /* Memory configurations */ #define PHYS_SDRAM_1_SIZE 0x40000000/* 1GiB on SoCDK */
include/configs/socfpga_cyclone5.h +0 -1
@@ -37,7 +37,6 @@#define CONFIG_CMD_USB #define CONFIG_CMD_USB_MASS_STORAGE -#define CONFIG_REGEX /* Enable regular expression support */ /* Memory configurations */ #define PHYS_SDRAM_1_SIZE 0x40000000/* 1GiB on SoCDK */
lib/Kconfig +8 -0
@@ -36,6 +36,14 @@ config SYS_VSNPRINTF Thumb-2, about 420 bytes). Enable this option for safety when using sprintf() with data you do not control. +config REGEX + bool "Enable regular expression support" + help + If this variable is defined, U-Boot is linked against the + SLRE (Super Light Regular Expression) library, which adds + regex support to some commands, for example "env grep" and + "setexpr". + source lib/rsa/Kconfig menu "Hashing Support"
Signature · 1 line
1.7.11.5
PATCH v2 2/19 kconfig: Move REGEX to Kconfig
Quoted 4 lines · Joe Hershberger
Having this as a
Kconfigallows it to be a dependent feature.Signed-off-by Joe Hershberger <[email protected]>Reviewed-by Simon Glass <[email protected]>
Thanks,
Stefan
PATCH v2 3/19 sandbox: Enable regex support
In reply to Joe HershbergerEnable regex support on sandbox.
---
Changes in v2: None
configs/sandbox_defconfig | 1 + 1 file changed, 1 insertion(+)
configs/sandbox_defconfig +1 -0
@@ -26,3 +26,4 @@ CONFIG_TPM_TIS_SANDBOX=y CONFIG_SOUND=y CONFIG_CMD_SOUND=y CONFIG_SOUND_SANDBOX=y +CONFIG_REGEX=y
Signature · 1 line
1.7.11.5
PATCH v2 4/19 env: Fix return values in env_attr_lookup()
In reply to Joe HershbergerThis function returned numbers for error codes. Change them to error codes.
---
Changes in v2: None
common/env_attr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
common/env_attr.c +3 -3
@@ -148,10 +148,10 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes)if (!attributes)/* bad parameter */ -return -1 ; +return -EINVAL ;if (!attr_list)/* list not found */ -return 1 ; +return -EINVAL ; entry =reverse_strstr (attr_list, name,NULL );while (entry !=NULL ) {
@@ -209,5 +209,5 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes) }/* not found in list */ -return 2 ; +return -ENOENT ; }
Signature · 1 line
1.7.11.5
PATCH v2 5/19 env: Simplify the reverse_strstr() interface
In reply to Joe HershbergerThe logic to find the whole matching name was split needlessly between the reverse_strstr function and its caller. Fully contain it to make the interface for calling it more consistent.
---
Changes in v2:
-Fix bisectability issue
-Fix corner case in reverse_name_search() where searched starts with ' '
common/env_attr.c | 87 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 47 insertions(+), 40 deletions(-)
common/env_attr.c +47 -40
@@ -109,33 +109,59 @@ int env_attr_walk(const char *attr_list, }/* -* Search for the last matching string in another string with the option to -* start looking at a certain point (i.e. ignore anything beyond that point). +* Search for the last exactly matching name in an attribute list */ -static char *reverse_strstr (const char *searched,const char *search_for, -const char *searched_start) +static int reverse_name_search (const char *searched,const char *search_for, +const char **result) { -char *result =NULL ; +int result_size =0 ; +const char *cur_searched = searched; -if (*search_for =='\0' ) -return (char *)searched; +if (result) + *result =NULL ; + +if (*search_for =='\0' ) { +if (result) + *result = searched; +return strlen (searched); + }for (;;) { -char *match =strstr (searched, search_for); - -/* -* Stop looking if no new match is found or looking past the -* searched_start pointer -*/ -if (match ==NULL || (searched_start !=NULL && - match +strlen (search_for) > searched_start)) +const char *match =strstr (cur_searched, search_for); +const char *prevch; +const char *nextch; + +/* Stop looking if no new match is found */ +if (match ==NULL )break ; - result = match; - searched = match +1 ; + prevch = match -1 ; + nextch = match +strlen (search_for); + +/* Skip spaces */ +while (*prevch ==' ' && prevch >= searched) + prevch--; +while (*nextch ==' ' ) + nextch++; + +/* Start looking past the current match so last is found */ + cur_searched = match +1 ; +/* Check for an exact match */ +if (match != searched && + *prevch !=ENV_ATTR_LIST_DELIM && + prevch != searched -1 ) +continue ; +if (*nextch !=ENV_ATTR_SEP && + *nextch !=ENV_ATTR_LIST_DELIM && + *nextch !='\0' ) +continue ; + +if (result) + *result = match; + result_size =strlen (search_for); } -return result; +return result_size; }/*
@@ -145,6 +171,7 @@ static char *reverse_strstr(const char *searched, const char *search_for,int env_attr_lookup (const char *attr_list,const char *name,char *attributes) {const char *entry =NULL ; +int entry_len;if (!attributes)/* bad parameter */
@@ -153,32 +180,12 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes)/* list not found */ return -EINVAL ; - entry =reverse_strstr (attr_list, name,NULL ); -while (entry !=NULL ) { -const char *prevch = entry -1 ; -const char *nextch = entry +strlen (name); - -/* Skip spaces */ -while (*prevch ==' ' ) - prevch--; -while (*nextch ==' ' ) - nextch++; - -/* check for an exact match */ -if ((entry == attr_list || - *prevch ==ENV_ATTR_LIST_DELIM ) && - (*nextch ==ENV_ATTR_SEP || - *nextch ==ENV_ATTR_LIST_DELIM || - *nextch =='\0' )) -break ; - - entry =reverse_strstr (attr_list, name, entry); - } + entry_len =reverse_name_search (attr_list, name, &entry);if (entry !=NULL ) {int len;/* skip the name */ - entry +=strlen (name); + entry += entry_len;/* skip spaces */ while (*entry ==' ' ) entry++;
Signature · 1 line
1.7.11.5
PATCH v2 6/19 env: Allow env_attr_walk to pass a priv * to callback
In reply to Joe HershbergerIn some cases it can be helpful to have context in the callback about the calling situation. This is needed for following patches.
---
Changes in v2: None
common/cmd_nvedit.c | 10 ++++++---- common/env_attr.c | 5 +++-- common/env_callback.c | 6 +++--- common/env_flags.c | 6 +++--- include/env_attr.h | 10 +++++----- 5 files changed, 20 insertions(+), 17 deletions(-)
common/cmd_nvedit.c +6 -4
@@ -427,7 +427,8 @@ int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])#endif #if defined(CONFIG_CMD_ENV_CALLBACK ) -static int print_static_binding (const char *var_name,const char *callback_name) +static int print_static_binding (const char *var_name,const char *callback_name, +void *priv) {printf ("\t%-20s %-20s\n" , var_name, callback_name);
@@ -489,7 +490,7 @@ int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])puts ("Static callback bindings:\n" );printf ("\t%-20s %-20s\n" ,"Variable Name" ,"Callback Name" );printf ("\t%-20s %-20s\n" ,"-------------" ,"-------------" ); -env_attr_walk (ENV_CALLBACK_LIST_STATIC , print_static_binding); +env_attr_walk (ENV_CALLBACK_LIST_STATIC , print_static_binding,NULL );puts ("\n" );/* walk through each variable and print the callback if it has one */
@@ -502,7 +503,8 @@ int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])#endif #if defined(CONFIG_CMD_ENV_FLAGS ) -static int print_static_flags (const char *var_name,const char *flags) +static int print_static_flags (const char *var_name,const char *flags, +void *priv) {enum env_flags_vartype type =env_flags_parse_vartype (flags);enum env_flags_varaccess access =env_flags_parse_varaccess (flags);
@@ -559,7 +561,7 @@ int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) "Variable Access");printf ("\t%-20s %-20s %-20s\n" ,"-------------" ,"-------------" ,"---------------" ); -env_attr_walk (ENV_FLAGS_LIST_STATIC , print_static_flags); +env_attr_walk (ENV_FLAGS_LIST_STATIC , print_static_flags,NULL );puts ("\n" );/* walk through each variable and print the flags if non-default */
common/env_attr.c +3 -2
@@ -26,7 +26,8 @@* list = entry[,list] */ int env_attr_walk (const char *attr_list, -int (*callback)(const char *name,const char *attributes)) +int (*callback)(const char *name,const char *attributes,void *priv), +void *priv) {const char *entry, *entry_end;char *name, *attributes;
@@ -93,7 +94,7 @@ int env_attr_walk(const char *attr_list,if (strlen (name) !=0 ) {int retval =0 ; - retval =callback (name, attributes); + retval =callback (name, attributes, priv);if (retval) {free (entry_cpy);return retval;
common/env_callback.c +3 -3
@@ -90,7 +90,7 @@ static int clear_callback(ENTRY *entry)/* * Call for each element in the list that associates variables to callbacks */ -static int set_callback (const char *name,const char *value) +static int set_callback (const char *name,const char *value,void *priv) {ENTRY e, *ep;struct env_clbk_tbl *clbkp;
@@ -126,9 +126,9 @@ static int on_callbacks(const char *name, const char *value, enum env_op op,hwalk_r (&env_htab, clear_callback);/* configure any static callback bindings */ -env_attr_walk (ENV_CALLBACK_LIST_STATIC , set_callback); +env_attr_walk (ENV_CALLBACK_LIST_STATIC , set_callback,NULL );/* configure any dynamic callback bindings */ -env_attr_walk (value, set_callback); +env_attr_walk (value, set_callback,NULL );return 0 ; }
common/env_flags.c +3 -3
@@ -435,7 +435,7 @@ static int clear_flags(ENTRY *entry)/* * Call for each element in the list that defines flags for a variable */ -static int set_flags (const char *name,const char *value) +static int set_flags (const char *name,const char *value,void *priv) {ENTRY e, *ep;
@@ -463,9 +463,9 @@ static int on_flags(const char *name, const char *value, enum env_op op,hwalk_r (&env_htab, clear_flags);/* configure any static flags */ -env_attr_walk (ENV_FLAGS_LIST_STATIC , set_flags); +env_attr_walk (ENV_FLAGS_LIST_STATIC , set_flags,NULL );/* configure any dynamic flags */ -env_attr_walk (value, set_flags); +env_attr_walk (value, set_flags,NULL );return 0 ; }
include/env_attr.h +5 -5
@@ -16,13 +16,14 @@* attributes = [^,:\s]* * entry = name[:attributes] * list = entry[,list] -* It will call the "callback" function with the "name" and attribute as "value" +* It will call the "callback" function with the "name" and "attributes" * The callback may return a non-0 to abort the list walk. * This return value will be passed through to the caller. * 0 is returned on success. */ -extern int env_attr_walk (const char *attr_list, -int (*callback)(const char *name,const char *value)); +int env_attr_walk (const char *attr_list, +int (*callback)(const char *name,const char *attributes,void *priv), +void *priv);/* * env_attr_lookup takes as input an "attr_list" with the same form as above.
@@ -33,7 +34,6 @@ extern int env_attr_walk(const char *attr_list,* "attr_list" is NULL. * Returns 0 on success. */ -extern int env_attr_lookup (const char *attr_list,const char *name, -char *attributes); +int env_attr_lookup (const char *attr_list,const char *name,char *attributes);#endif /* __ENV_ATTR_H__ */
Signature · 1 line
1.7.11.5
PATCH v2 7/19 env: Add regex support to env_attrs
In reply to Joe HershbergerAllow the features that use env_attrs to specify regexs for the name
---
Changes in v2:
-Added description to README
README | 8 +++++ common/env_attr.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/env_callback.h | 10 ++++-- 3 files changed, 101 insertions(+), 2 deletions(-)
README +8 -0
@@ -4157,6 +4157,10 @@ Configuration Settings: list, simply add an entry for the same variable name to the ".flags" variable. + If CONFIG_REGEX is defined, the variable_name above is evaluated as a + regular expression. This allows multiple variables to define the same + flags without explicitly listing them for each variable. + - CONFIG_ENV_ACCESS_IGNORE_FORCE If defined, don't allow the -f switch to env set override variable access flags.
@@ -5555,6 +5559,10 @@ override any association in the static list. You can define CONFIG_ENV_CALLBACK_LIST_DEFAULT to a list (string) to define the ".callbacks" environment variable in the default or embedded environment. +If CONFIG_REGEX is defined, the variable_name above is evaluated as a +regular expression. This allows multiple variables to be connected to +the same callback without explicitly listing them all out. + Command Line Parsing: =====================
common/env_attr.c +85 -0
100 lines not on this page · raw message
include/env_callback.h +8 -2
@@ -31,12 +31,18 @@#define SPLASHIMAGE_CALLBACK #endif +#ifdef CONFIG_REGEX +#define ENV_DOT_ESCAPE "\\" +#else +#define ENV_DOT_ESCAPE +#endif +/* * This list of callback bindings is static, but may be overridden by defining * a new association in the ".callbacks" environment variable. */ -#define ENV_CALLBACK_LIST_STATIC ENV_CALLBACK_VAR ":callbacks," \ - ENV_FLAGS_VAR ":flags," \ +#define ENV_CALLBACK_LIST_STATIC ENV_DOT_ESCAPE ENV_CALLBACK_VAR ":callbacks," \ + ENV_DOT_ESCAPE ENV_FLAGS_VAR ":flags," \ "baudrate:baudrate," \ "bootfile:bootfile," \ "loadaddr:loadaddr," \
Signature · 1 line
1.7.11.5
PATCH v2 8/19 env: Distinguish finer between source of env change
In reply to Joe HershbergerWe already could tell the difference in the callback between an import and "other" which we called interactive. Now add further distinction between interactive (i.e. running env set / env edit / env ask / etc. from the U-Boot command line) and programmatic (i.e. when u-boot source calls any variant of setenv() ).
---
Changes in v2: None
common/cmd_nvedit.c | 26 +++++++++++++++++++------- include/search.h | 2 ++ 2 files changed, 21 insertions(+), 7 deletions(-)
common/cmd_nvedit.c +19 -7
@@ -208,12 +208,11 @@ DONE:* Set a new environment variable, * or replace or delete an existing one. */ -static int _do_env_set (int flag,int argc,char *const argv[]) +static int _do_env_set (int flag,int argc,char *const argv[],int env_flag) {int i, len;char *name, *value, *s;ENTRY e, *ep; -int env_flag =H_INTERACTIVE ;debug ("Initial value for argc=%d\n" , argc);while (argc >1 && **(argv +1 ) =='-' ) {
@@ -291,9 +290,9 @@ int setenv(const char *varname, const char *varvalue)return 1 ;if (varvalue ==NULL || varvalue[0 ] =='\0' ) -return _do_env_set (0 ,2 , (char *const *)argv); +return _do_env_set (0 ,2 , (char *const *)argv,H_PROGRAMMATIC );else -return _do_env_set (0 ,3 , (char *const *)argv); +return _do_env_set (0 ,3 , (char *const *)argv,H_PROGRAMMATIC ); }/**
@@ -347,7 +346,7 @@ static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])if (argc <2 )return CMD_RET_USAGE ; -return _do_env_set (flag, argc, argv); +return _do_env_set (flag, argc, argv,H_INTERACTIVE ); }/*
@@ -422,7 +421,7 @@ int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) }/* Continue calling setenv code */ -return _do_env_set (flag, len, local_args); +return _do_env_set (flag, len, local_args,H_INTERACTIVE ); }#endif
@@ -588,6 +587,10 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,if (argc <2 )return CMD_RET_USAGE ; +/* before import into hashtable */ +if (!(gd->flags &GD_FLG_ENV_READY )) +return 1 ; +/* Set read buffer to initial value or empty sting */ init_val =getenv (argv[1 ]);if (init_val)
@@ -598,7 +601,16 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,if (cli_readline_into_buffer ("edit: " , buffer,0 ) <0 )return 1 ; -return setenv (argv[1 ], buffer); +if (buffer[0 ] =='\0' ) { +const char *const _argv[3 ] = {"setenv" , argv[1 ],NULL }; + +return _do_env_set (0 ,2 , (char *const *)_argv,H_INTERACTIVE ); + }else { +const char *const _argv[4 ] = {"setenv" , argv[1 ], buffer, +NULL }; + +return _do_env_set (0 ,3 , (char *const *)_argv,H_INTERACTIVE ); + } }#endif /* CONFIG_CMD_EDITENV */ #endif /* CONFIG_SPL_BUILD */
include/search.h +2 -0
@@ -120,5 +120,7 @@ extern int hwalk_r(struct hsearch_data *__htab, int (*callback)(ENTRY *));#define H_MATCH_SUBSTR (1 << 7)/* search for substring matches */ #define H_MATCH_REGEX (1 << 8)/* search for regular expression matches */ #define H_MATCH_METHOD (H_MATCH_IDENT | H_MATCH_SUBSTR | H_MATCH_REGEX) +#define H_PROGRAMMATIC (1 << 9)/* indicate that an import is from setenv() */ +#define H_ORIGIN_FLAGS (H_INTERACTIVE | H_PROGRAMMATIC)#endif /* search.h */
Signature · 1 line
1.7.11.5
PATCH v2 9/19 net: Apply default format rules to all ethaddr
In reply to Joe HershbergerUse a regular expression to apply the default formatting flags for all ethaddr env vars.
---
Changes in v2:
-Added comments about the use of .flags in the dm eth test
include/env_flags.h | 11 ++++++++--- test/dm/eth.c | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-)
include/env_flags.h +8 -3
@@ -38,13 +38,18 @@ enum env_flags_varaccess {#endif #ifdef CONFIG_CMD_NET +#ifdef CONFIG_REGEX +#define ETHADDR_WILDCARD "\\d?" +#else +#define ETHADDR_WILDCARD +#endif #ifdef CONFIG_ENV_OVERWRITE -#define ETHADDR_FLAGS "ethaddr:ma," +#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:ma,"#else #ifdef CONFIG_OVERWRITE_ETHADDR_ONCE -#define ETHADDR_FLAGS "ethaddr:mc," +#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mc,"#else -#define ETHADDR_FLAGS "ethaddr:mo," +#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"#endif #endif #else
test/dm/eth.c +3 -0
@@ -89,6 +89,8 @@ static int dm_test_eth_rotate(struct dm_test_state *dms)/* Invalidate eth1's MAC address */ net_ping_ip =string_to_ip ("1.1.2.2" );strcpy (ethaddr,getenv ("eth1addr" )); +/* Must disable access protection for eth1addr before clearing */ +setenv (".flags" ,"eth1addr" );setenv ("eth1addr" ,NULL );/* Make sure that the default is to rotate to the next interface */
@@ -108,6 +110,7 @@ static int dm_test_eth_rotate(struct dm_test_state *dms)/* Invalidate eth0's MAC address */ strcpy (ethaddr,getenv ("ethaddr" )); +/* Must disable access protection for ethaddr before clearing */ setenv (".flags" ,"ethaddr" );setenv ("ethaddr" ,NULL );
Signature · 1 line
1.7.11.5
PATCH v2 10/19 net: Use env callbacks for net variables
In reply to Joe HershbergerInstead of checking for changes to the env each time we enter the net_loop, use the env callbacks to update the values of the variables. Don't update the variables when the source was programmatic, since the variables were the source of the new value.
---
Changes in v2:
-Simplified test for H_PROGRAMMATIC
include/env_callback.h | 22 ++++++++++- net/net.c | 105 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 110 insertions(+), 17 deletions(-)
include/env_callback.h +21 -1
@@ -37,6 +37,26 @@#define ENV_DOT_ESCAPE #endif +#ifdef CONFIG_CMD_DNS +#define DNS_CALLBACK "dnsip:dnsip," +#else +#define DNS_CALLBACK +#endif + +#ifdef CONFIG_NET +#define NET_CALLBACKS \ + "bootfile:bootfile," \ + "ipaddr:ipaddr," \ + "gatewayip:gatewayip," \ + "netmask:netmask," \ + "serverip:serverip," \ + "nvlan:nvlan," \ + "vlan:vlan," \ + DNS_CALLBACK +#else +#define NET_CALLBACKS +#endif +/* * This list of callback bindings is static, but may be overridden by defining * a new association in the ".callbacks" environment variable.
@@ -44,7 +64,7 @@#define ENV_CALLBACK_LIST_STATIC ENV_DOT_ESCAPE ENV_CALLBACK_VAR ":callbacks," \ ENV_DOT_ESCAPE ENV_FLAGS_VAR ":flags," \ "baudrate:baudrate," \ - "bootfile:bootfile," \ + NET_CALLBACKS \ "loadaddr:loadaddr," \ SILENT_CALLBACK \ SPLASHIMAGE_CALLBACK \
net/net.c +89 -16
123 lines not on this page · raw message
Signature · 1 line
1.7.11.5
PATCH v2 11/19 net: Add default flags for common net env vars
In reply to Joe HershbergerCheck that the common network stack's env vars conform to the proper format for IP addresses.
---
Changes in v2: None
include/env_flags.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
include/env_flags.h +11 -1
@@ -52,8 +52,17 @@ enum env_flags_varaccess {#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"#endif #endif +#define NET_FLAGS \ + "ipaddr:i," \ + "gatewayip:i," \ + "netmask:i," \ + "serverip:i," \ + "nvlan:i," \ + "vlan:i," \ + "dnsip:i,"#else -#define ETHADDR_FLAGS "" +#define ETHADDR_FLAGS +#define NET_FLAGS #endif #ifndef CONFIG_ENV_OVERWRITE
@@ -64,6 +73,7 @@ enum env_flags_varaccess {#define ENV_FLAGS_LIST_STATIC \ ETHADDR_FLAGS \ + NET_FLAGS \ SERIAL_FLAGS \ CONFIG_ENV_FLAGS_LIST_STATIC
Signature · 1 line
1.7.11.5
PATCH v2 12/19 test: Generalize the unit test framework
In reply to Joe HershbergerSeparate the ability to define tests and assert status of test functions from the dm tests so they can be used more consistenly throughout all tests.
---
Changes in v2:
-New for version 2
include/dm/test.h | 35 +++++-----------------
include/test/test.h | 47 ++++++++++++++++++++++++++++++
include/{dm => test}/ut.h | 28 +++++++++---------
test/Kconfig | 3 ++
test/Makefile | 1 +
test/dm/Kconfig | 1 +
test/dm/Makefile | 2 --
test/dm/bus.c | 39 +++++++++++++------------
test/dm/core.c | 74 +++++++++++++++++++++++++----------------------
test/dm/eth.c | 14 ++++-----
test/dm/gpio.c | 22 +++++++-------
test/dm/i2c.c | 20 ++++++-------
test/dm/pci.c | 6 ++--
test/dm/sf.c | 4 +--
test/dm/spi.c | 8 ++---
test/dm/test-driver.c | 6 ++--
test/dm/test-fdt.c | 16 +++++-----
test/dm/test-main.c | 36 +++++++++++++----------
test/dm/test-uclass.c | 7 +++--
test/dm/usb.c | 6 ++--
test/{dm => }/ut.c | 16 +++++-----
21 files changed, 217 insertions(+), 174 deletions(-)
create mode 100644 include/test/test.h
rename include/{dm => test}/ut.h (79%)
rename test/{dm => }/ut.c (59%)include/dm/test.h +7 -28
@@ -8,7 +8,7 @@#define __DM_TEST_H#include <dm.h> -#include <malloc.h> +#include <test/test.h> /** * struct dm_test_cdata - configuration data for test instance
@@ -124,7 +124,7 @@ struct dm_test_perdev_uc_pdata {*/ extern int dm_testdrv_op_count[DM_TEST_OP_COUNT ]; -extern struct dm_test_state global_test_state; +extern struct unit_test_state global_dm_test_state;/* * struct dm_test_state - Entire state of dm test system
@@ -133,7 +133,6 @@ extern struct dm_test_state global_test_state;* * @root: Root device * @testdev: Test device -* @fail_count: Number of tests that failed * @force_fail_alloc: Force all memory allocs to fail * @skip_post_probe: Skip uclass post-probe processing * @removed: Used to keep track of a device that was removed
@@ -141,11 +140,9 @@ extern struct dm_test_state global_test_state;struct dm_test_state {struct udevice *root;struct udevice *testdev; -int fail_count;int force_fail_alloc;int skip_post_probe;struct udevice *removed; -struct mallinfo start; };/* Test flags for each test */
@@ -155,26 +152,8 @@ enum { DM_TESTF_SCAN_FDT = 1 << 2, /* scan device tree */ }; -/** -* struct dm_test - Information about a driver model test -* -* @name: Name of test -* @func: Function to call to perform test -* @flags: Flags indicated pre-conditions for test -*/ -struct dm_test { -const char *name; -int (*func)(struct dm_test_state *dms); -int flags; -}; -/* Declare a new driver model test */ -#define DM_TEST (_name, _flags) \ - ll_entry_declare(struct dm_test, _name, dm_test) = { \ - .name = #_name, \ - .flags = _flags, \ - .func = _name, \ - } +#define DM_TEST (_name, _flags) UNIT_TEST(_name, _flags, dm_test)/* Declare ping methods for the drivers */ int test_ping (struct udevice *dev,int pingval,int *pingret);
@@ -191,7 +170,7 @@ int testfdt_ping(struct udevice *dev, int pingval, int *pingret);* @priv: Pointer to private test information * @return 0 if OK, -ve on error */ -int dm_check_operations (struct dm_test_state *dms,struct udevice *dev, +int dm_check_operations (struct unit_test_state *uts,struct udevice *dev,uint32_t base,struct dm_test_priv *priv);/**
@@ -201,7 +180,7 @@ int dm_check_operations(struct dm_test_state *dms, struct udevice *dev,* @num_devices: Number of test devices to check * @return 0 if OK, -ve on error */ -int dm_check_devices (struct dm_test_state *dms,int num_devices); +int dm_check_devices (struct unit_test_state *uts,int num_devices);/** * dm_leak_check_start() - Prepare to check for a memory leak
@@ -211,7 +190,7 @@ int dm_check_devices(struct dm_test_state *dms, int num_devices);* * @dms: Overall test state */ -void dm_leak_check_start (struct dm_test_state *dms); +void dm_leak_check_start (struct unit_test_state *uts);/** * dm_leak_check_end() - Check that no memory has leaked
@@ -221,7 +200,7 @@ void dm_leak_check_start(struct dm_test_state *dms);* it sees a different amount of total memory allocated than before. * * @dms: Overall test state -*/ int dm_leak_check_end (struct dm_test_state *dms); +*/ int dm_leak_check_end (struct unit_test_state *uts);/**
include/test/test.h new file +47 -0
47 lines not on this page · raw message
include/test/ut.h renamed from include/dm/ut.h +14 -14
@@ -1,39 +1,39 @@/* -* Simple unit test library for driver model +* Simple unit test library * * Copyright (c) 2013 Google, Inc * * SPDX-License-Identifier: GPL-2.0+ */ -#ifndef __DM_UT_H -#define __DM_UT_H +#ifndef __TEST_UT_H +#define __TEST_UT_H -struct dm_test_state ; +struct unit_test_state ;/** * ut_fail() - Record failure of a unit test * -* @dms: Test state +* @uts: Test state * @fname: Filename where the error occured * @line: Line number where the error occured * @func: Function name where the error occured * @cond: The condition that failed */ -void ut_fail (struct dm_test_state *dms,const char *fname,int line, +void ut_fail (struct unit_test_state *uts,const char *fname,int line,const char *func,const char *cond);/** * ut_failf() - Record failure of a unit test * -* @dms: Test state +* @uts: Test state * @fname: Filename where the error occured * @line: Line number where the error occured * @func: Function name where the error occured * @cond: The condition that failed * @fmt: printf() format string for the error, followed by args */ -void ut_failf (struct dm_test_state *dms,const char *fname,int line, +void ut_failf (struct unit_test_state *uts,const char *fname,int line,const char *func,const char *cond,const char *fmt, ...) __attribute__ ((format (__printf__,6 ,7 )));
@@ -41,14 +41,14 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,/* Assert that a condition is non-zero */ #define ut_assert (cond) \ if (!(cond)) { \ - ut_fail(dms, __FILE__, __LINE__, __func__, #cond); \ + ut_fail(uts, __FILE__, __LINE__, __func__, #cond); \ return -1; \ }/* Assert that a condition is non-zero, with printf() string */ #define ut_assertf(cond, fmt, args...) \ if (!(cond)) { \ - ut_failf(dms, __FILE__, __LINE__, __func__, #cond, \ + ut_failf(uts, __FILE__, __LINE__, __func__, #cond, \ fmt, ##args); \ return -1; \ }
@@ -58,7 +58,7 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,unsigned int val1 = (expr1), val2 = (expr2); \ \if (val1 != val2) { \ -ut_failf (dms, __FILE__, __LINE__, __func__, \ +ut_failf (uts, __FILE__, __LINE__, __func__, \ #expr1 " == " #expr2, \"Expected %d, got %d" , val1, val2); \return -1 ; \
@@ -70,7 +70,7 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,const char *val1 = (expr1), *val2 = (expr2); \ \if (strcmp (val1, val2)) { \ -ut_failf (dms, __FILE__, __LINE__, __func__, \ +ut_failf (uts, __FILE__, __LINE__, __func__, \ #expr1 " = " #expr2, \"Expected \"%s\", got \"%s\"" , val1, val2); \return -1 ; \
@@ -82,7 +82,7 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,const void *val1 = (expr1), *val2 = (expr2); \ \if (val1 != val2) { \ -ut_failf (dms, __FILE__, __LINE__, __func__, \ +ut_failf (uts, __FILE__, __LINE__, __func__, \ #expr1 " = " #expr2, \"Expected %p, got %p" , val1, val2); \return -1 ; \
@@ -94,7 +94,7 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,const void *val = (expr); \ \if (val ==NULL ) { \ -ut_failf (dms, __FILE__, __LINE__, __func__, \ +ut_failf (uts, __FILE__, __LINE__, __func__, \ #expr " = NULL", \"Expected non-null, got NULL" ); \return -1 ; \
test/Kconfig +3 -0
@@ -1 +1,4 @@ +config UNIT_TEST + bool + source "test/dm/Kconfig"
test/Makefile +1 -0
@@ -4,5 +4,6 @@ # SPDX-License-Identifier: GPL-2.0+ # +obj-$(CONFIG_UNIT_TEST) += ut.o obj-$(CONFIG_SANDBOX) += command_ut.o obj-$(CONFIG_SANDBOX) += compression.o
test/dm/Kconfig +1 -0
@@ -1,6 +1,7 @@ config DM_TEST bool "Enable driver model test command" depends on SANDBOX && CMD_DM + select UNIT_TEST help This enables the 'dm test' command which runs a series of unit tests on the driver model code. Each subsystem (uclass) is tested.
test/dm/Makefile +0 -2
@@ -10,12 +10,10 @@ obj-$(CONFIG_DM_TEST) += test-driver.o obj-$(CONFIG_DM_TEST) += test-fdt.o obj-$(CONFIG_DM_TEST) += test-main.o obj-$(CONFIG_DM_TEST) += test-uclass.o -obj-$(CONFIG_DM_TEST) += ut.o # Tests for particular subsystems - when enabling driver model for a new # subsystem you must add sandbox tests here. obj-$(CONFIG_DM_TEST) += core.o -obj-$(CONFIG_DM_TEST) += ut.o ifneq ($(CONFIG_SANDBOX),) obj-$(CONFIG_DM_ETH) += eth.o obj-$(CONFIG_DM_GPIO) += gpio.o
test/dm/bus.c +20 -19
@@ -10,8 +10,8 @@#include <dm/root.h> #include <dm/test.h> #include <dm/uclass-internal.h> -#include <dm/ut.h> #include <dm/util.h> +#include <test/ut.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -104,7 +104,7 @@ UCLASS_DRIVER(testbus) = { };/* Test that we can probe for children */ -static int dm_test_bus_children (struct dm_test_state *dms) +static int dm_test_bus_children (struct unit_test_state *uts) {int num_devices =6 ;struct udevice *bus;
@@ -120,14 +120,14 @@ static int dm_test_bus_children(struct dm_test_state *dms)ut_assertok (uclass_get (UCLASS_TEST_FDT , &uc));ut_asserteq (num_devices,list_count_items (&uc->dev_head)); -ut_assert (!dm_check_devices (dms, num_devices)); +ut_assert (!dm_check_devices (uts, num_devices));return 0 ; }DM_TEST (dm_test_bus_children,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test our functions for accessing children */ -static int dm_test_bus_children_funcs (struct dm_test_state *dms) +static int dm_test_bus_children_funcs (struct unit_test_state *uts) {const void *blob = gd->fdt_blob;struct udevice *bus, *dev;
@@ -173,7 +173,7 @@ static int dm_test_bus_children_funcs(struct dm_test_state *dms)DM_TEST (dm_test_bus_children_funcs,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test that we can iterate through children */ -static int dm_test_bus_children_iterators (struct dm_test_state *dms) +static int dm_test_bus_children_iterators (struct unit_test_state *uts) {struct udevice *bus, *dev, *child;
@@ -204,7 +204,7 @@ DM_TEST(dm_test_bus_children_iterators, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);/* Test that the bus can store data about each child */ -static int test_bus_parent_data (struct dm_test_state *dms) +static int test_bus_parent_data (struct unit_test_state *uts) {struct dm_test_parent_data *parent_data;struct udevice *bus, *dev;
@@ -264,14 +264,14 @@ static int test_bus_parent_data(struct dm_test_state *dms)return 0 ; }/* Test that the bus can store data about each child */ -static int dm_test_bus_parent_data (struct dm_test_state *dms) +static int dm_test_bus_parent_data (struct unit_test_state *uts) { -return test_bus_parent_data (dms); +return test_bus_parent_data (uts); }DM_TEST (dm_test_bus_parent_data,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* As above but the size is controlled by the uclass */ -static int dm_test_bus_parent_data_uclass (struct dm_test_state *dms) +static int dm_test_bus_parent_data_uclass (struct unit_test_state *uts) {struct driver *drv;struct udevice *bus;
@@ -284,7 +284,7 @@ static int dm_test_bus_parent_data_uclass(struct dm_test_state *dms) size = drv->per_child_auto_alloc_size; bus->uclass->uc_drv->per_child_auto_alloc_size = size; drv->per_child_auto_alloc_size =0 ; - ret =test_bus_parent_data (dms); + ret =test_bus_parent_data (uts);if (ret)return ret; bus->uclass->uc_drv->per_child_auto_alloc_size =0 ;
@@ -296,9 +296,10 @@ DM_TEST(dm_test_bus_parent_data_uclass, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);/* Test that the bus ops are called when a child is probed/removed */ -static int dm_test_bus_parent_ops (struct dm_test_state *dms) +static int dm_test_bus_parent_ops (struct unit_test_state *uts) {struct dm_test_parent_data *parent_data; +struct dm_test_state *dms = uts->priv;struct udevice *bus, *dev;struct uclass *uc;
@@ -333,7 +334,7 @@ static int dm_test_bus_parent_ops(struct dm_test_state *dms) }DM_TEST (dm_test_bus_parent_ops,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); -static int test_bus_parent_platdata (struct dm_test_state *dms) +static int test_bus_parent_platdata (struct unit_test_state *uts) {struct dm_test_parent_platdata *plat;struct udevice *bus, *dev;
@@ -406,14 +407,14 @@ static int test_bus_parent_platdata(struct dm_test_state *dms) }/* Test that the bus can store platform data about each child */ -static int dm_test_bus_parent_platdata (struct dm_test_state *dms) +static int dm_test_bus_parent_platdata (struct unit_test_state *uts) { -return test_bus_parent_platdata (dms); +return test_bus_parent_platdata (uts); }DM_TEST (dm_test_bus_parent_platdata,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* As above but the size is controlled by the uclass */ -static int dm_test_bus_parent_platdata_uclass (struct dm_test_state *dms) +static int dm_test_bus_parent_platdata_uclass (struct unit_test_state *uts) {struct udevice *bus;struct driver *drv;
@@ -426,7 +427,7 @@ static int dm_test_bus_parent_platdata_uclass(struct dm_test_state *dms) size = drv->per_child_platdata_auto_alloc_size; bus->uclass->uc_drv->per_child_platdata_auto_alloc_size = size; drv->per_child_platdata_auto_alloc_size =0 ; - ret =test_bus_parent_platdata (dms); + ret =test_bus_parent_platdata (uts);if (ret)return ret; bus->uclass->uc_drv->per_child_platdata_auto_alloc_size =0 ;
@@ -438,7 +439,7 @@ DM_TEST(dm_test_bus_parent_platdata_uclass, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);/* Test that the child post_bind method is called */ -static int dm_test_bus_child_post_bind (struct dm_test_state *dms) +static int dm_test_bus_child_post_bind (struct unit_test_state *uts) {struct dm_test_parent_platdata *plat;struct udevice *bus, *dev;
@@ -461,7 +462,7 @@ static int dm_test_bus_child_post_bind(struct dm_test_state *dms)DM_TEST (dm_test_bus_child_post_bind,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test that the child post_bind method is called */ -static int dm_test_bus_child_post_bind_uclass (struct dm_test_state *dms) +static int dm_test_bus_child_post_bind_uclass (struct unit_test_state *uts) {struct dm_test_parent_platdata *plat;struct udevice *bus, *dev;
@@ -488,7 +489,7 @@ DM_TEST(dm_test_bus_child_post_bind_uclass,* Test that the bus' uclass' child_pre_probe() is called before the * device's probe() method */ -static int dm_test_bus_child_pre_probe_uclass (struct dm_test_state *dms) +static int dm_test_bus_child_pre_probe_uclass (struct unit_test_state *uts) {struct udevice *bus, *dev;int child_count;
test/dm/core.c +40 -34
259 lines not on this page · raw message
test/dm/eth.c +7 -7
@@ -9,16 +9,16 @@#include <common.h> #include <dm.h> -#include <dm/test.h> -#include <dm/ut.h> #include <fdtdec.h> #include <malloc.h> #include <net.h> +#include <dm/test.h> #include <asm/eth.h> +#include <test/ut.h> DECLARE_GLOBAL_DATA_PTR ; -static int dm_test_eth (struct dm_test_state *dms) +static int dm_test_eth (struct unit_test_state *uts) { net_ping_ip =string_to_ip ("1.1.2.2" );
@@ -38,7 +38,7 @@ static int dm_test_eth(struct dm_test_state *dms) }DM_TEST (dm_test_eth,DM_TESTF_SCAN_FDT ); -static int dm_test_eth_alias (struct dm_test_state *dms) +static int dm_test_eth_alias (struct unit_test_state *uts) { net_ping_ip =string_to_ip ("1.1.2.2" );setenv ("ethact" ,"eth0" );
@@ -62,7 +62,7 @@ static int dm_test_eth_alias(struct dm_test_state *dms) }DM_TEST (dm_test_eth_alias,DM_TESTF_SCAN_FDT ); -static int dm_test_eth_prime (struct dm_test_state *dms) +static int dm_test_eth_prime (struct unit_test_state *uts) { net_ping_ip =string_to_ip ("1.1.2.2" );
@@ -82,7 +82,7 @@ static int dm_test_eth_prime(struct dm_test_state *dms) }DM_TEST (dm_test_eth_prime,DM_TESTF_SCAN_FDT ); -static int dm_test_eth_rotate (struct dm_test_state *dms) +static int dm_test_eth_rotate (struct unit_test_state *uts) {char ethaddr[18 ];
@@ -127,7 +127,7 @@ static int dm_test_eth_rotate(struct dm_test_state *dms) }DM_TEST (dm_test_eth_rotate,DM_TESTF_SCAN_FDT ); -static int dm_test_net_retry (struct dm_test_state *dms) +static int dm_test_net_retry (struct unit_test_state *uts) { net_ping_ip =string_to_ip ("1.1.2.2" );
test/dm/gpio.c +11 -11
@@ -8,15 +8,15 @@#include <fdtdec.h> #include <dm.h> #include <dm/root.h> -#include <dm/ut.h> #include <dm/test.h> #include <dm/util.h> #include <asm/gpio.h> +#include <test/ut.h> DECLARE_GLOBAL_DATA_PTR ;/* Test that sandbox GPIOs work correctly */ -static int dm_test_gpio (struct dm_test_state *dms) +static int dm_test_gpio (struct unit_test_state *uts) {unsigned int offset, gpio;struct dm_gpio_ops *ops;
@@ -103,7 +103,7 @@ static int dm_test_gpio(struct dm_test_state *dms)DM_TEST (dm_test_gpio,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test that sandbox anonymous GPIOs work correctly */ -static int dm_test_gpio_anon (struct dm_test_state *dms) +static int dm_test_gpio_anon (struct unit_test_state *uts) {unsigned int offset, gpio;struct udevice *dev;
@@ -125,7 +125,7 @@ static int dm_test_gpio_anon(struct dm_test_state *dms)DM_TEST (dm_test_gpio_anon,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test that gpio_requestf() works as expected */ -static int dm_test_gpio_requestf (struct dm_test_state *dms) +static int dm_test_gpio_requestf (struct unit_test_state *uts) {unsigned int offset, gpio;struct udevice *dev;
@@ -143,7 +143,7 @@ static int dm_test_gpio_requestf(struct dm_test_state *dms)DM_TEST (dm_test_gpio_requestf,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test that gpio_request() copies its string */ -static int dm_test_gpio_copy (struct dm_test_state *dms) +static int dm_test_gpio_copy (struct unit_test_state *uts) {unsigned int offset, gpio;struct udevice *dev;
@@ -165,19 +165,19 @@ static int dm_test_gpio_copy(struct dm_test_state *dms)DM_TEST (dm_test_gpio_copy,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test that we don't leak memory with GPIOs */ -static int dm_test_gpio_leak (struct dm_test_state *dms) +static int dm_test_gpio_leak (struct unit_test_state *uts) { -ut_assertok (dm_test_gpio (dms)); -ut_assertok (dm_test_gpio_anon (dms)); -ut_assertok (dm_test_gpio_requestf (dms)); -ut_assertok (dm_leak_check_end (dms)); +ut_assertok (dm_test_gpio (uts)); +ut_assertok (dm_test_gpio_anon (uts)); +ut_assertok (dm_test_gpio_requestf (uts)); +ut_assertok (dm_leak_check_end (uts));return 0 ; }DM_TEST (dm_test_gpio_leak,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test that we can find GPIOs using phandles */ -static int dm_test_gpio_phandles (struct dm_test_state *dms) +static int dm_test_gpio_phandles (struct unit_test_state *uts) {struct gpio_desc desc, desc_list[8 ], desc_list2[8 ];struct udevice *dev, *gpio_a, *gpio_b;
test/dm/i2c.c +10 -10
@@ -10,19 +10,19 @@#include <dm.h> #include <fdtdec.h> #include <i2c.h> +#include <asm/state.h> +#include <asm/test.h> #include <dm/device-internal.h> #include <dm/test.h> #include <dm/uclass-internal.h> -#include <dm/ut.h> #include <dm/util.h> -#include <asm/state.h> -#include <asm/test.h> +#include <test/ut.h> static const int busnum;static const int chip =0x2c ;/* Test that we can find buses and chips */ -static int dm_test_i2c_find (struct dm_test_state *dms) +static int dm_test_i2c_find (struct unit_test_state *uts) {struct udevice *bus, *dev;const int no_chip =0x10 ;
@@ -43,7 +43,7 @@ static int dm_test_i2c_find(struct dm_test_state *dms) }DM_TEST (dm_test_i2c_find,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); -static int dm_test_i2c_read_write (struct dm_test_state *dms) +static int dm_test_i2c_read_write (struct unit_test_state *uts) {struct udevice *bus, *dev;uint8_t buf[5 ];
@@ -60,7 +60,7 @@ static int dm_test_i2c_read_write(struct dm_test_state *dms) }DM_TEST (dm_test_i2c_read_write,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); -static int dm_test_i2c_speed (struct dm_test_state *dms) +static int dm_test_i2c_speed (struct unit_test_state *uts) {struct udevice *bus, *dev;uint8_t buf[5 ];
@@ -78,7 +78,7 @@ static int dm_test_i2c_speed(struct dm_test_state *dms) }DM_TEST (dm_test_i2c_speed,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); -static int dm_test_i2c_offset_len (struct dm_test_state *dms) +static int dm_test_i2c_offset_len (struct unit_test_state *uts) {struct udevice *bus, *dev;uint8_t buf[5 ];
@@ -95,7 +95,7 @@ static int dm_test_i2c_offset_len(struct dm_test_state *dms) }DM_TEST (dm_test_i2c_offset_len,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); -static int dm_test_i2c_probe_empty (struct dm_test_state *dms) +static int dm_test_i2c_probe_empty (struct unit_test_state *uts) {struct udevice *bus, *dev;
@@ -106,7 +106,7 @@ static int dm_test_i2c_probe_empty(struct dm_test_state *dms) }DM_TEST (dm_test_i2c_probe_empty,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); -static int dm_test_i2c_bytewise (struct dm_test_state *dms) +static int dm_test_i2c_bytewise (struct unit_test_state *uts) {struct udevice *bus, *dev;struct udevice *eeprom;
@@ -161,7 +161,7 @@ static int dm_test_i2c_bytewise(struct dm_test_state *dms) }DM_TEST (dm_test_i2c_bytewise,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); -static int dm_test_i2c_offset (struct dm_test_state *dms) +static int dm_test_i2c_offset (struct unit_test_state *uts) {struct udevice *eeprom;struct udevice *dev;
test/dm/pci.c +3 -3
@@ -8,10 +8,10 @@#include <dm.h> #include <asm/io.h> #include <dm/test.h> -#include <dm/ut.h> +#include <test/ut.h> /* Test that sandbox PCI works correctly */ -static int dm_test_pci_base (struct dm_test_state *dms) +static int dm_test_pci_base (struct unit_test_state *uts) {struct udevice *bus;
@@ -22,7 +22,7 @@ static int dm_test_pci_base(struct dm_test_state *dms)DM_TEST (dm_test_pci_base,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test that we can use the swapcase device correctly */ -static int dm_test_pci_swapcase (struct dm_test_state *dms) +static int dm_test_pci_swapcase (struct unit_test_state *uts) {pci_dev_t pci_dev =PCI_BDF (0 ,0x1f ,0 );struct pci_controller *hose;
test/dm/sf.c +2 -2
@@ -10,12 +10,12 @@#include <spi.h> #include <spi_flash.h> #include <asm/state.h> -#include <dm/ut.h> #include <dm/test.h> #include <dm/util.h> +#include <test/ut.h> /* Test that sandbox SPI flash works correctly */ -static int dm_test_spi_flash (struct dm_test_state *dms) +static int dm_test_spi_flash (struct unit_test_state *uts) {/* * Create an empty test file and run the SPI flash tests. This is a
test/dm/spi.c +4 -4
@@ -9,15 +9,15 @@#include <fdtdec.h> #include <spi.h> #include <spi_flash.h> +#include <asm/state.h> #include <dm/device-internal.h> #include <dm/test.h> #include <dm/uclass-internal.h> -#include <dm/ut.h> #include <dm/util.h> -#include <asm/state.h> +#include <test/ut.h> /* Test that we can find buses and chip-selects */ -static int dm_test_spi_find (struct dm_test_state *dms) +static int dm_test_spi_find (struct unit_test_state *uts) {struct sandbox_state *state =state_get_current ();struct spi_slave *slave;
@@ -95,7 +95,7 @@ static int dm_test_spi_find(struct dm_test_state *dms)DM_TEST (dm_test_spi_find,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test that sandbox SPI works correctly */ -static int dm_test_spi_xfer (struct dm_test_state *dms) +static int dm_test_spi_xfer (struct unit_test_state *uts) {struct spi_slave *slave;struct udevice *bus;
test/dm/test-driver.c +4 -2
@@ -12,11 +12,11 @@#include <errno.h> #include <malloc.h> #include <dm/test.h> -#include <dm/ut.h> +#include <test/ut.h> #include <asm/io.h> int dm_testdrv_op_count[DM_TEST_OP_COUNT ]; -static struct dm_test_state *dms = &global_test_state; +static struct unit_test_state *uts = &global_dm_test_state;static int testdrv_ping (struct udevice *dev,int pingval,int *pingret) {
@@ -114,6 +114,8 @@ static int test_manual_bind(struct udevice *dev)static int test_manual_probe (struct udevice *dev) { +struct dm_test_state *dms = uts->priv; + dm_testdrv_op_count[DM_TEST_OP_PROBE ]++;if (!dms->force_fail_alloc) dev->priv =calloc (1 ,sizeof (struct dm_test_priv ));
test/dm/test-fdt.c +8 -8
@@ -12,9 +12,9 @@#include <asm/io.h> #include <dm/test.h> #include <dm/root.h> -#include <dm/ut.h> #include <dm/uclass-internal.h> #include <dm/util.h> +#include <test/ut.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -99,7 +99,7 @@ UCLASS_DRIVER(testfdt) = { .flags = DM_UC_FLAG_SEQ_ALIAS, }; -int dm_check_devices (struct dm_test_state *dms,int num_devices) +int dm_check_devices (struct unit_test_state *uts,int num_devices) {struct udevice *dev;int ret;
@@ -126,7 +126,7 @@ int dm_check_devices(struct dm_test_state *dms, int num_devices)debug ("dev=%d, base=%d: %s\n" , i, base,fdt_get_name (gd->fdt_blob, dev->of_offset,NULL )); -ut_assert (!dm_check_operations (dms, dev, base, +ut_assert (!dm_check_operations (uts, dev, base,dev_get_priv (dev))); }
@@ -134,7 +134,7 @@ int dm_check_devices(struct dm_test_state *dms, int num_devices) }/* Test that FDT-based binding works correctly */ -static int dm_test_fdt (struct dm_test_state *dms) +static int dm_test_fdt (struct unit_test_state *uts) {const int num_devices =6 ;struct udevice *dev;
@@ -159,13 +159,13 @@ static int dm_test_fdt(struct dm_test_state *dms)ut_assert (dev->platdata); } -ut_assertok (dm_check_devices (dms, num_devices)); +ut_assertok (dm_check_devices (uts, num_devices));return 0 ; }DM_TEST (dm_test_fdt,0 ); -static int dm_test_fdt_pre_reloc (struct dm_test_state *dms) +static int dm_test_fdt_pre_reloc (struct unit_test_state *uts) {struct uclass *uc;int ret;
@@ -184,7 +184,7 @@ static int dm_test_fdt_pre_reloc(struct dm_test_state *dms)DM_TEST (dm_test_fdt_pre_reloc,0 );/* Test that sequence numbers are allocated properly */ -static int dm_test_fdt_uclass_seq (struct dm_test_state *dms) +static int dm_test_fdt_uclass_seq (struct unit_test_state *uts) {struct udevice *dev;
@@ -239,7 +239,7 @@ static int dm_test_fdt_uclass_seq(struct dm_test_state *dms)DM_TEST (dm_test_fdt_uclass_seq,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test that we can find a device by device tree offset */ -static int dm_test_fdt_offset (struct dm_test_state *dms) +static int dm_test_fdt_offset (struct unit_test_state *uts) {const void *blob = gd->fdt_blob;struct udevice *dev;
test/dm/test-main.c +21 -15
@@ -11,15 +11,20 @@#include <dm/test.h> #include <dm/root.h> #include <dm/uclass-internal.h> -#include <dm/ut.h> +#include <test/ut.h> DECLARE_GLOBAL_DATA_PTR ; -struct dm_test_state global_test_state; +struct unit_test_state global_dm_test_state; +static struct dm_test_state _global_priv_dm_test_state;/* Get ready for testing */ -static int dm_test_init (struct dm_test_state *dms) +static int dm_test_init (struct unit_test_state *uts) { +struct dm_test_state *dms = uts->priv; + +memset (uts,'\0' ,sizeof (*uts)); + uts->priv = dms;memset (dms,'\0' ,sizeof (*dms)); gd->dm_root =NULL ;memset (dm_testdrv_op_count,'\0' ,sizeof (dm_testdrv_op_count));
@@ -31,7 +36,7 @@ static int dm_test_init(struct dm_test_state *dms) }/* Ensure all the test devices are probed */ -static int do_autoprobe (struct dm_test_state *dms) +static int do_autoprobe (struct unit_test_state *uts) {struct udevice *dev;int ret;
@@ -45,7 +50,7 @@ static int do_autoprobe(struct dm_test_state *dms)return ret; } -static int dm_test_destroy (struct dm_test_state *dms) +static int dm_test_destroy (struct unit_test_state *uts) {int id;
@@ -67,10 +72,11 @@ static int dm_test_destroy(struct dm_test_state *dms)int dm_test_main (const char *test_name) { - struct dm_test *tests = ll_entry_start(struct dm_test, dm_test); - const int n_ents = ll_entry_count(struct dm_test, dm_test); -struct dm_test_state *dms = &global_test_state; -struct dm_test *test; + struct unit_test *tests = ll_entry_start(struct unit_test, dm_test); + const int n_ents = ll_entry_count(struct unit_test, dm_test); +struct unit_test_state *uts = &global_dm_test_state; + uts->priv = &_global_priv_dm_test_state; +struct unit_test *test;/* * If we have no device tree, or it only has a root node, then these
@@ -90,23 +96,23 @@ int dm_test_main(const char *test_name)if (test_name &&strcmp (test_name, test->name))continue ;printf ("Test: %s\n" , test->name); -ut_assertok (dm_test_init (dms)); +ut_assertok (dm_test_init (uts)); - dms->start =mallinfo (); + uts->start =mallinfo ();if (test->flags &DM_TESTF_SCAN_PDATA )ut_assertok (dm_scan_platdata (false));if (test->flags &DM_TESTF_PROBE_TEST ) -ut_assertok (do_autoprobe (dms)); +ut_assertok (do_autoprobe (uts));if (test->flags &DM_TESTF_SCAN_FDT )ut_assertok (dm_scan_fdt (gd->fdt_blob, false)); -if (test->func (dms)) +if (test->func (uts))break ; -ut_assertok (dm_test_destroy (dms)); +ut_assertok (dm_test_destroy (uts)); } -printf ("Failures: %d\n" , dms->fail_count); +printf ("Failures: %d\n" , uts->fail_count);return 0 ; }
test/dm/test-uclass.c +4 -3
@@ -11,12 +11,12 @@#include <malloc.h> #include <dm.h> #include <errno.h> -#include <dm/test.h> -#include <dm/ut.h> #include <asm/io.h> +#include <dm/test.h> #include <linux/list.h> +#include <test/ut.h> -static struct dm_test_state *dms = &global_test_state; +static struct unit_test_state *uts = &global_dm_test_state;int test_ping (struct udevice *dev,int pingval,int *pingret) {
@@ -70,6 +70,7 @@ static int test_post_probe(struct udevice *dev)struct dm_test_uclass_perdev_priv *priv =dev_get_uclass_priv (dev);struct uclass *uc = dev->uclass; +struct dm_test_state *dms = uts->priv; dm_testdrv_op_count[DM_TEST_OP_POST_PROBE ]++;ut_assert (priv);
test/dm/usb.c +3 -3
@@ -9,10 +9,10 @@#include <usb.h> #include <asm/io.h> #include <dm/test.h> -#include <dm/ut.h> +#include <test/ut.h> /* Test that sandbox USB works correctly */ -static int dm_test_usb_base (struct dm_test_state *dms) +static int dm_test_usb_base (struct unit_test_state *uts) {struct udevice *bus;
@@ -29,7 +29,7 @@ DM_TEST(dm_test_usb_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);* covers scanning the bug, setting up a hub and a flash stick and reading * data from the flash stick. */ -static int dm_test_usb_flash (struct dm_test_state *dms) +static int dm_test_usb_flash (struct unit_test_state *uts) {struct udevice *dev;block_dev_desc_t *dev_desc;
test/ut.c renamed from test/dm/ut.c +7 -9
@@ -1,5 +1,5 @@/* -* Simple unit test library for driver model +* Simple unit test library * * Copyright (c) 2013 Google, Inc *
@@ -7,19 +7,17 @@*/ #include <common.h> -#include <dm/test.h> -#include <dm/ut.h> +#include <test/test.h> +#include <test/ut.h> -struct dm_test_state ; - -void ut_fail (struct dm_test_state *dms,const char *fname,int line, +void ut_fail (struct unit_test_state *uts,const char *fname,int line,const char *func,const char *cond) {printf ("%s:%d, %s(): %s\n" , fname, line, func, cond); - dms->fail_count++; + uts->fail_count++; } -void ut_failf (struct dm_test_state *dms,const char *fname,int line, +void ut_failf (struct unit_test_state *uts,const char *fname,int line,const char *func,const char *cond,const char *fmt, ...) {va_list args;
@@ -29,5 +27,5 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,vprintf (fmt, args);va_end (args);putc ('\n' ); - dms->fail_count++; + uts->fail_count++; }
Signature · 1 line
1.7.11.5
PATCH v2 12/19 test: Generalize the unit test framework
Quoted 27 lines · Joe Hershberger
Separate the ability to define tests and assert status of test functions from the dm tests so they can be used more consistenly throughout all tests.
Signed-off-by Joe Hershberger <[email protected]>---
Changes in v2:
-New for version 2include/dm/test.h | 35 +++++----------------- include/test/test.h | 47 ++++++++++++++++++++++++++++++ include/{dm => test}/ut.h | 28 +++++++++--------- test/Kconfig | 3 ++ test/Makefile | 1 + test/dm/Kconfig | 1 + test/dm/Makefile | 2 -- test/dm/bus.c | 39 +++++++++++++------------ test/dm/core.c | 74 +++++++++++++++++++++++++---------------------- test/dm/eth.c | 14 ++++----- test/dm/gpio.c | 22 +++++++------- test/dm/i2c.c | 20 ++++++------- test/dm/pci.c | 6 ++-- test/dm/sf.c | 4 +-- test/dm/spi.c | 8 ++--- test/dm/test-driver.c | 6 ++-- test/dm/test-fdt.c | 16 +++++-----
Quoted 8 lines
test/dm/test-main.c | 36 +++++++++++++----------
test/dm/test-uclass.c | 7 +++--
test/dm/usb.c | 6 ++--
test/{dm => }/ut.c | 16 +++++-----
21 files changed, 217 insertions(+), 174 deletions(-)
create mode 100644 include/test/test.h
rename include/{dm => test}/ut.h (79%)
rename test/{dm => }/ut.c (59%)PATCH v2 13/19 test: dm: Don't bail on all tests if one test fails
In reply to Joe HershbergerThere's not much point in having a failure count if we always give up on the first failure. Also stop clearing the entire state between tests.
Make sure that any failures are still passed out to the command line.
---
Changes in v2:
-New for version 2
test/dm/test-main.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
test/dm/test-main.c +2 -5
@@ -23,8 +23,6 @@ static int dm_test_init(struct unit_test_state *uts) {struct dm_test_state *dms = uts->priv; -memset (uts,'\0' ,sizeof (*uts)); - uts->priv = dms;memset (dms,'\0' ,sizeof (*dms)); gd->dm_root =NULL ;memset (dm_testdrv_op_count,'\0' ,sizeof (dm_testdrv_op_count));
@@ -106,13 +104,12 @@ int dm_test_main(const char *test_name)if (test->flags &DM_TESTF_SCAN_FDT )ut_assertok (dm_scan_fdt (gd->fdt_blob, false)); -if (test->func (uts)) -break ; + test->func (uts);ut_assertok (dm_test_destroy (uts)); }printf ("Failures: %d\n" , uts->fail_count); -return 0 ; +return uts->fail_count ?CMD_RET_FAILURE :0 ; }
Signature · 1 line
1.7.11.5
PATCH v2 13/19 test: dm: Don't bail on all tests if one test fails
Quoted 5 lines · Joe Hershberger
There's not much point in having a failure count if we always give up on the first failure. Also stop clearing the entire state between tests.
Make sure that any failures are still passed out to the command line.
Quoted 8 lines
Signed-off-by Joe Hershberger <[email protected]>---
Changes in v2:
-New for version 2test/dm/test-main.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
PATCH v2 14/19 test: Return values from the asserts compatible with cmds
In reply to Joe HershbergerThe asserts are sometimes called from the context of the test command itself so make sure that a return that happens as a result of a failure is compatible with that command return. When called within a test, the return value is ignored.
---
Changes in v2:
-New for version 2
include/test/ut.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
include/test/ut.h +6 -6
@@ -42,7 +42,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,#define ut_assert (cond) \ if (!(cond)) { \ ut_fail(uts, __FILE__, __LINE__, __func__, #cond); \ - return -1; \ + return CMD_RET_FAILURE; \ }/* Assert that a condition is non-zero, with printf() string */
@@ -50,7 +50,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,if (!(cond)) { \ ut_failf(uts, __FILE__, __LINE__, __func__, #cond, \ fmt, ##args); \ -return -1 ; \ +return CMD_RET_FAILURE ; \ }/* Assert that two int expressions are equal */
@@ -61,7 +61,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,ut_failf (uts, __FILE__, __LINE__, __func__, \ #expr1 " == " #expr2, \"Expected %d, got %d" , val1, val2); \ -return -1 ; \ +return CMD_RET_FAILURE ; \ } \ }
@@ -73,7 +73,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,ut_failf (uts, __FILE__, __LINE__, __func__, \ #expr1 " = " #expr2, \"Expected \"%s\", got \"%s\"" , val1, val2); \ -return -1 ; \ +return CMD_RET_FAILURE ; \ } \ }
@@ -85,7 +85,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,ut_failf (uts, __FILE__, __LINE__, __func__, \ #expr1 " = " #expr2, \"Expected %p, got %p" , val1, val2); \ -return -1 ; \ +return CMD_RET_FAILURE ; \ } \ }
@@ -97,7 +97,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,ut_failf (uts, __FILE__, __LINE__, __func__, \ #expr " = NULL", \"Expected non-null, got NULL" ); \ -return -1 ; \ +return CMD_RET_FAILURE ; \ } \ }
Signature · 1 line
1.7.11.5
PATCH v2 14/19 test: Return values from the asserts compatible with cmds
Quoted 5 lines · Joe Hershberger
The asserts are sometimes called from the context of the test command itself so make sure that a return that happens as a result of a failure is compatible with that command return. When called within a test, the return value is ignored.
Quoted 8 lines
Signed-off-by Joe Hershberger <[email protected]>---
Changes in v2:
-New for version 2include/test/ut.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
PATCH v2 15/19 test: env: Add test framework for env
In reply to Joe HershbergerAdd a new "test" subcommand to the env command.
This will run unit tests on the env code. This should be targetable to any device that supports the env features needed for the tests.
---
Changes in v2:
-New for version 2
Makefile | 1 + common/cmd_nvedit.c | 10 +++++++++- include/env_test.h | 18 ++++++++++++++++++ test/Kconfig | 1 + test/env/Kconfig | 8 ++++++++ test/env/Makefile | 7 +++++++ test/env/cmd_env_test.c | 36 ++++++++++++++++++++++++++++++++++++ 7 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 include/env_test.h create mode 100644 test/env/Kconfig create mode 100644 test/env/Makefile create mode 100644 test/env/cmd_env_test.c
Makefile +1 -0
@@ -665,6 +665,7 @@ libs-$(CONFIG_API) += api/ libs-$(CONFIG_HAS_POST) += post/ libs-y += test/ libs-y += test/dm/ +libs-$(CONFIG_ENV_TEST) += test/env/ libs-y += $(if $(BOARDDIR),board/$(BOARDDIR)/)
common/cmd_nvedit.c +9 -1
@@ -28,6 +28,7 @@#include <cli.h> #include <command.h> #include <environment.h> +#include <env_test.h> #include <search.h> #include <errno.h> #include <malloc.h>
@@ -1147,6 +1148,9 @@ static cmd_tbl_t cmd_env_sub[] = {#if defined(CONFIG_CMD_ENV_EXISTS ) U_BOOT_CMD_MKENT(exists, 2, 0, do_env_exists, "", ""),#endif +#if defined(CONFIG_ENV_TEST ) + U_BOOT_CMD_MKENT(test, 1, 0, do_env_test, "", ""), +#endif };#if defined(CONFIG_NEEDS_MANUAL_RELOC )
@@ -1215,7 +1219,11 @@ static char env_help_text[] = #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE) "env save - save environment\n" #endif -"env set [-f] name [arg ...]\n" ; + "env set [-f] name [arg ...]\n" +#if defined(CONFIG_ENV_TEST) + "env test - run unit tests on the env commands" +#endif + ; #endif U_BOOT_CMD(
include/env_test.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* (C) Copyright 2015 +* Joe Hershberger, National Instruments, joe.hershberger at ni.com +* +* SPDX-License-Identifier: GPL-2.0 +*/ + +#ifndef __ENV_TEST_H__ +#define __ENV_TEST_H__ + +#include <test/test.h> + +int do_env_test (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]); + +/* Declare a new environment test */ +#define ENV_TEST (_name, _flags) UNIT_TEST(_name, _flags, env_test) + +#endif /* __ENV_TEST_H__ */
test/Kconfig +1 -0
@@ -2,3 +2,4 @@ config UNIT_TEST bool source "test/dm/Kconfig" +source "test/env/Kconfig"
test/env/Kconfig new file +8 -0
@@ -0,0 +1,8 @@ +config ENV_TEST + bool "Enable env test command" + select UNIT_TEST + help + This enables the 'env test' command which runs a series of unit + tests on the env code. + If all is well then all tests pass although there will be a few + messages printed along the way.
test/env/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# +# Copyright (c) 2015 National Instruments, Inc +# +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-y += cmd_env_test.o
test/env/cmd_env_test.c new file +36 -0
@@ -0,0 +1,36 @@ +/* +* (C) Copyright 2015 +* Joe Hershberger, National Instruments, joe.hershberger at ni.com +* +* SPDX-License-Identifier: GPL-2.0 +*/ + +#include <common.h> +#include <command.h> +#include <env_test.h> +#include <test/ut.h> + +int do_env_test (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ + struct unit_test *tests = ll_entry_start(struct unit_test, env_test); + const int n_ents = ll_entry_count(struct unit_test, env_test); +struct unit_test_state uts = { .fail_count =0 }; +struct unit_test *test; + +if (argc ==1 ) +printf ("Running %d environment tests\n" , n_ents); + +for (test = tests; test < tests + n_ents; test++) { +if (argc >1 &&strcmp (argv[1 ], test->name)) +continue ; +printf ("Test: %s\n" , test->name); + + uts.start =mallinfo (); + + test->func (&uts); + } + +printf ("Failures: %d\n" , uts.fail_count); + +return uts.fail_count ?CMD_RET_FAILURE :0 ; +}
Signature · 1 line
1.7.11.5
PATCH v2 15/19 test: env: Add test framework for env
Quoted 11 lines · Joe Hershberger
Add a new "test" subcommand to the env command.
This will run unit tests on the env code. This should be targetable to any device that supports the env features needed for the tests.
Signed-off-by Joe Hershberger <[email protected]>---
Changes in v2:
-New for version 2
Quoted 12 lines
Makefile | 1 + common/cmd_nvedit.c | 10 +++++++++- include/env_test.h | 18 ++++++++++++++++++ test/Kconfig | 1 + test/env/Kconfig | 8 ++++++++ test/env/Makefile | 7 +++++++ test/env/cmd_env_test.c | 36 ++++++++++++++++++++++++++++++++++++ 7 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 include/env_test.h create mode 100644 test/env/Kconfig create mode 100644 test/env/Makefile create mode 100644 test/env/cmd_env_test.c
PATCH v2 16/19 test: env: Add test for verifying env attrs
In reply to Joe HershbergerAdd a test of the env_attr_lookup() function.
---
Changes in v2:
-New for version 2
test/env/Makefile | 1 + test/env/attr.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 test/env/attr.c
test/env/Makefile +1 -0
@@ -5,3 +5,4 @@ # obj-y += cmd_env_test.o +obj-y += attr.o
test/env/attr.c new file +62 -0
62 lines not on this page · raw message
Signature · 1 line
1.7.11.5
PATCH v2 16/19 test: env: Add test for verifying env attrs
Hi Joe,
Quoted 5 lines · Joe Hershberger
Add a test of the
env_attr_lookup()function.Signed-off-by Joe Hershberger <[email protected]>---
Quoted 7 lines
Changes in v2:
-New for version 2test/env/Makefile | 1 + test/env/attr.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 test/env/attr.c
I don't know how much it matters, but I was trying to make test commands start with 'ut_' (unit test) so they would all appear in the same place when you type 'help'.
Regards,
Simon
PATCH v2 16/19 test: env: Add test for verifying env attrs
Hi Simon,
Quoted 16 lines · Simon Glass
Hi Joe,
Quoted 5 lines · Joe Hershberger
Add a test of the
env_attr_lookup()function.Signed-off-by Joe Hershberger <[email protected]>---
Quoted 7 lines
Changes in v2:
-New for version 2test/env/Makefile | 1 + test/env/attr.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 test/env/attr.c
Quoted 5 lines
Reviewed-by Simon Glass <[email protected]>I don't know how much it matters, but I was trying to make test commands start with '
ut_' (unit test) so they would all appear in the same place when you type 'help'.
I took it one step further by creating a ut command that can have sub-commands that are test suites. This also should help address Tom's concerns about ease of running.
Cheers,
-Joe
PATCH v2 17/19 test: env: Add a test of the new regex behavior for attrs
In reply to Joe HershbergerThe behavior of the env attrs depends on CONFIG_REGEX. Add an additional test if that variable is set.
---
Changes in v2:
-New for version 2
test/env/attr.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
test/env/attr.c +27 -0
@@ -60,3 +60,30 @@ static int env_test_attrs_lookup(struct unit_test_state *uts)return 0 ; }ENV_TEST (env_test_attrs_lookup,0 ); + +#ifdef CONFIG_REGEX +static int env_test_attrs_lookup_regex (struct unit_test_state *uts) +{ +char attrs[32 ]; + +ut_assertok (env_attr_lookup ("foo1?:bar" ,"foo" , attrs)); +ut_asserteq_str ("bar" , attrs); + +ut_assertok (env_attr_lookup ("foo1?:bar" ,"foo1" , attrs)); +ut_asserteq_str ("bar" , attrs); + +ut_assertok (env_attr_lookup (".foo:bar" ,".foo" , attrs)); +ut_asserteq_str ("bar" , attrs); + +ut_assertok (env_attr_lookup (".foo:bar" ,"ufoo" , attrs)); +ut_asserteq_str ("bar" , attrs); + +ut_assertok (env_attr_lookup ("\\.foo:bar" ,".foo" , attrs)); +ut_asserteq_str ("bar" , attrs); + +ut_asserteq (-ENOENT ,env_attr_lookup ("\\.foo:bar" ,"ufoo" , attrs)); + +return 0 ; +} +ENV_TEST (env_test_attrs_lookup_regex,0 ); +#endif
Signature · 1 line
1.7.11.5
PATCH v2 17/19 test: env: Add a test of the new regex behavior for attrs
Quoted 11 lines · Joe Hershberger
The behavior of the env attrs depends on
CONFIG_REGEX. Add an additional test if that variable is set.Signed-off-by Joe Hershberger <[email protected]>---
Changes in v2:
-New for version 2test/env/attr.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
PATCH v2 18/19 sandbox: Cleanup order and extra defines in defconfig
In reply to Joe HershbergerThe defconfigs should not be edited directly. They should be generated by editing the .config (through menuconfig or whatever) and then run make savedefconfig to have the Kconfig system generate a clean defconfig
I did this for sandbox here with no actual changes.
---
Changes in v2:
-New for version 2
configs/sandbox_defconfig | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
configs/sandbox_defconfig +18 -18
@@ -1,29 +1,29 @@ -CONFIG_OF_CONTROL=y -CONFIG_OF_HOSTFILE=y +CONFIG_DM_USB=y +CONFIG_PCI=y +CONFIG_SYS_VSNPRINTF=y +CONFIG_DEFAULT_DEVICE_TREE="sandbox" +CONFIG_BOOTSTAGE=y +CONFIG_BOOTSTAGE_REPORT=y CONFIG_FIT=y CONFIG_FIT_VERBOSE=y CONFIG_FIT_SIGNATURE=y -CONFIG_DEFAULT_DEVICE_TREE="sandbox" +CONFIG_CMD_SOUND=y +CONFIG_OF_CONTROL=y +CONFIG_OF_HOSTFILE=y +CONFIG_DM_PCI=y +CONFIG_PCI_SANDBOX=y +CONFIG_SPI_FLASH_SANDBOX=y +CONFIG_CMD_CROS_EC=y CONFIG_CROS_EC=y CONFIG_CROS_EC_SANDBOX=y CONFIG_CROS_EC_KEYB=y -CONFIG_CMD_CROS_EC=y -CONFIG_PCI=y -CONFIG_DM_PCI=y -CONFIG_PCI_SANDBOX=y -CONFIG_USB=y -CONFIG_DM_USB=y -CONFIG_USB_EMUL=y -CONFIG_USB_STORAGE=y -CONFIG_BOOTSTAGE=y -CONFIG_BOOTSTAGE_REPORT=y -CONFIG_SANDBOX_GPIO=y -CONFIG_SYS_VSNPRINTF=y +CONFIG_TPM_TIS_SANDBOX=y CONFIG_SYS_I2C_SANDBOX=y CONFIG_SANDBOX_SPI=y -CONFIG_SPI_FLASH_SANDBOX=y -CONFIG_TPM_TIS_SANDBOX=y +CONFIG_SANDBOX_GPIO=y CONFIG_SOUND=y -CONFIG_CMD_SOUND=y CONFIG_SOUND_SANDBOX=y +CONFIG_USB=y +CONFIG_USB_EMUL=y +CONFIG_USB_STORAGE=y CONFIG_REGEX=y
Signature · 1 line
1.7.11.5
PATCH v2 18/19 sandbox: Cleanup order and extra defines in defconfig
Quoted 6 lines · Joe Hershberger
The defconfigs should not be edited directly. They should be generated by editing the .config (through menuconfig or whatever) and then run make savedefconfig to have the
Kconfigsystem generate a clean defconfigI did this for sandbox here with no actual changes.
Quoted 8 lines
Signed-off-by Joe Hershberger <[email protected]>---
Changes in v2:
-New for version 2configs/sandbox_defconfig | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
PATCH v2 19/19 sandbox: Enable env unit tests
In reply to Joe HershbergerEnable the new env unit tests on sandbox.
---
Changes in v2:
-New for version 2
configs/sandbox_defconfig | 1 + 1 file changed, 1 insertion(+)
configs/sandbox_defconfig +1 -0
@@ -27,3 +27,4 @@ CONFIG_USB=y CONFIG_USB_EMUL=y CONFIG_USB_STORAGE=y CONFIG_REGEX=y +CONFIG_ENV_TEST=y
Signature · 1 line
1.7.11.5
PATCH v2 19/19 sandbox: Enable env unit tests
Quoted 10 lines · Joe Hershberger
Enable the new env unit tests on sandbox.
Signed-off-by Joe Hershberger <[email protected]>---
Changes in v2:
-New for version 2configs/sandbox_defconfig | 1 + 1 file changed, 1 insertion(+)
Quoted 13 lines
configs/sandbox_defconfig +1
-1@@ -27,3 +27,4 @@ CONFIG_USB=y CONFIG_USB_EMUL=y CONFIG_USB_STORAGE=y CONFIG_REGEX=y +CONFIG_ENV_TEST=y --1.7.11.5
v3 cover Improve env var handling for net stack
In reply to Joe HershbergerThis includes moving CONFIG_REGEX to Kconfig and adding support for regex to the env_attr lists (when CONFIG_REGEX is enabled).
This allows ethaddrs to all be checked for access and format by default. Also use callbacks to keep network stack variables up to date instead of polling them on each call to net_loop.
This is a step in the right direction to refactoring the network stack to be similar to that of barebox.
Also added a test command to host unit tests for the env functions.
Changes in v3:
-Moved test from env subcommand to ut subcommand
-New for version 3
Changes in v2:
-Added comments about the use of .flags in the dm eth test -Added description to README
-Fix bisectability issue
-Fix corner case in reverse_name_search() where searched starts with ' ' -New for version 2
-Simplified test for H_PROGRAMMATIC
Joe Hershberger (26):
sandbox: Enable some ENV commands
kconfig: Move REGEX to Kconfig
sandbox: Enable regex support
env: Fix return values in env_attr_lookup()
env: Simplify the reverse_strstr() interface
env: Allow env_attr_walk to pass a priv * to callback
env: Add regex support to env_attrs
env: Distinguish finer between source of env change
net: Apply default format rules to all ethaddr
net: Use env callbacks for net variables
net: Add default flags for common net env vars
net: Remove duplicate bootfile syncing functionality
net: Handle ethaddr changes as an env callback
test: Generalize the unit test framework
test: Add a common unit test command
test: Move the unit tests to their own menu
test: dm: Don't bail on all tests if one test fails
test: dm: eth: Handle failed test env cleanup
test: Return values from the asserts compatible with cmds
test: dm: Recover the driver model tree after tests
test: env: Add test framework for env
test: env: Add test for verifying env attrs
test: env: Add a test of the new regex behavior for attrs
test: dm: Move the dm tests over to the ut command
sandbox: Cleanup order and extra defines in defconfig
sandbox: Enable env unit tests
Makefile | 1 +
README | 8 ++
arch/sandbox/Kconfig | 5 +-
common/cmd_nvedit.c | 36 +++++---
common/env_attr.c | 181 ++++++++++++++++++++++++++++---------
common/env_callback.c | 6 +-
common/env_flags.c | 6 +-
configs/acadia_defconfig | 1 +
configs/bamboo_defconfig | 1 +
configs/bubinga_defconfig | 1 +
configs/canyonlands_defconfig | 1 +
configs/dlvision-10g_defconfig | 1 +
configs/dlvision_defconfig | 1 +
configs/ebony_defconfig | 1 +
configs/gdppc440etx_defconfig | 1 +
configs/icon_defconfig | 1 +
configs/intip_defconfig | 1 +
configs/io64_defconfig | 1 +
configs/io_defconfig | 1 +
configs/iocon_defconfig | 1 +
configs/katmai_defconfig | 1 +
configs/kilauea_defconfig | 1 +
configs/luan_defconfig | 1 +
configs/m28evk_defconfig | 1 +
configs/m53evk_defconfig | 1 +
configs/makalu_defconfig | 1 +
configs/neo_defconfig | 1 +
configs/novena_defconfig | 1 +
configs/ocotea_defconfig | 1 +
configs/redwood_defconfig | 1 +
configs/sandbox_defconfig | 37 ++++----
configs/sequoia_defconfig | 1 +
configs/socfpga_arria5_defconfig | 1 +
configs/socfpga_cyclone5_defconfig | 1 +
configs/t3corp_defconfig | 1 +
configs/taihu_defconfig | 1 +
configs/taishan_defconfig | 1 +
configs/walnut_defconfig | 1 +
configs/yosemite_defconfig | 1 +
configs/yucca_defconfig | 1 +
include/configs/amcc-common.h | 1 -
include/configs/m28evk.h | 1 -
include/configs/m53evk.h | 1 -
include/configs/novena.h | 1 -
include/configs/sandbox.h | 5 +
include/configs/socfpga_arria5.h | 1 -
include/configs/socfpga_cyclone5.h | 1 -
include/dm/test.h | 46 ++--------
include/env_attr.h | 10 +-
include/env_callback.h | 33 ++++++-
include/env_flags.h | 23 ++++-
include/search.h | 2 +
include/test/env.h | 16 ++++
include/test/suites.h | 14 +++
include/test/test.h | 47 ++++++++++
include/{dm => test}/ut.h | 40 ++++----
lib/Kconfig | 8 ++
net/Kconfig | 1 +
net/eth.c | 95 ++++++++++++-------
net/net.c | 105 +++++++++++++++++----
test/Kconfig | 7 ++
test/Makefile | 2 +
test/cmd_ut.c | 74 +++++++++++++++
test/dm/Kconfig | 8 +-
test/dm/Makefile | 14 ++-
test/dm/bus.c | 39 ++++----
test/dm/cmd_dm.c | 21 -----
test/dm/core.c | 74 ++++++++-------
test/dm/eth.c | 86 ++++++++++++------
test/dm/gpio.c | 22 ++---
test/dm/i2c.c | 20 ++--
test/dm/pci.c | 6 +-
test/dm/sf.c | 4 +-
test/dm/spi.c | 8 +-
test/dm/test-dm.sh | 2 +-
test/dm/test-driver.c | 6 +-
test/dm/test-fdt.c | 16 ++--
test/dm/test-main.c | 55 +++++++----
test/dm/test-uclass.c | 7 +-
test/dm/usb.c | 6 +-
test/env/Kconfig | 8 ++
test/env/Makefile | 8 ++
test/env/attr.c | 89 ++++++++++++++++++
test/env/cmd_ut_env.c | 37 ++++++++
test/{dm => }/ut.c | 16 ++--
85 files changed, 1004 insertions(+), 394 deletions(-)
create mode 100644 include/test/env.h
create mode 100644 include/test/suites.h
create mode 100644 include/test/test.h
rename include/{dm => test}/ut.h (73%)
create mode 100644 test/cmd_ut.c
create mode 100644 test/env/Kconfig
create mode 100644 test/env/Makefile
create mode 100644 test/env/attr.c
create mode 100644 test/env/cmd_ut_env.c
rename test/{dm => }/ut.c (59%)Signature · 1 line
1.7.11.5
PATCH v3 1/26 sandbox: Enable some ENV commands
Enable some additional ENV commands in sandbox to aid in build testing and run testing.
---
Changes in v3: None
Changes in v2: None
include/configs/sandbox.h | 5 +++++ 1 file changed, 5 insertions(+)
include/configs/sandbox.h +5 -0
@@ -151,6 +151,11 @@#define CONFIG_CMD_SANDBOX +#define CONFIG_CMD_ENV_FLAGS +#define CONFIG_CMD_ENV_CALLBACK +#define CONFIG_CMD_GREPENV +#define CONFIG_CMD_ASKENV +#define CONFIG_BOOTARGS ""#define CONFIG_BOARD_LATE_INIT
Signature · 1 line
1.7.11.5
PATCH v3 2/26 kconfig: Move REGEX to Kconfig
In reply to Joe HershbergerHaving this as a Kconfig allows it to be a dependent feature.
---
Changes in v3: None
Changes in v2: None
configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 - lib/Kconfig | 8 ++++++++ 39 files changed, 40 insertions(+), 6 deletions(-)
configs/acadia_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_ACADIA=y +CONFIG_REGEX=y
configs/bamboo_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_BAMBOO=y +CONFIG_REGEX=y
configs/bubinga_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_BUBINGA=y +CONFIG_REGEX=y
configs/canyonlands_defconfig +1 -0
@@ -5,3 +5,4 @@ CONFIG_CANYONLANDS=y CONFIG_DEFAULT_DEVICE_TREE="canyonlands" CONFIG_OF_CONTROL=y CONFIG_OF_EMBED=y +CONFIG_REGEX=y
configs/dlvision-10g_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_DLVISION_10G=y +CONFIG_REGEX=y
configs/dlvision_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_DLVISION=y +CONFIG_REGEX=y
configs/ebony_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_EBONY=y +CONFIG_REGEX=y
configs/gdppc440etx_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_GDPPC440ETX=y +CONFIG_REGEX=y
configs/icon_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_ICON=y +CONFIG_REGEX=y
configs/intip_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="INTIB" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_INTIP=y +CONFIG_REGEX=y
configs/io64_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IO64=y +CONFIG_REGEX=y
configs/io_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IO=y +CONFIG_REGEX=y
configs/iocon_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IOCON=y +CONFIG_REGEX=y
configs/katmai_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_KATMAI=y +CONFIG_REGEX=y
configs/kilauea_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="KILAUEA" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_KILAUEA=y +CONFIG_REGEX=y
configs/luan_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_LUAN=y +CONFIG_REGEX=y
configs/m28evk_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_SPL=y CONFIG_ARM=y CONFIG_TARGET_M28EVK=y +CONFIG_REGEX=y
configs/m53evk_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SPL=y CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/denx/m53evk/imximage.cfg" CONFIG_ARM=y CONFIG_TARGET_M53EVK=y +CONFIG_REGEX=y
configs/makalu_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_MAKALU=y +CONFIG_REGEX=y
configs/neo_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_NEO=y +CONFIG_REGEX=y
configs/novena_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SPL=y CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=arch/arm/imx-common/spl_sd.cfg,MX6Q" CONFIG_ARM=y CONFIG_TARGET_KOSAGI_NOVENA=y +CONFIG_REGEX=y
configs/ocotea_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_OCOTEA=y +CONFIG_REGEX=y
configs/redwood_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_REDWOOD=y +CONFIG_REGEX=y
configs/sequoia_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="SEQUOIA" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_SEQUOIA=y +CONFIG_REGEX=y
configs/socfpga_arria5_defconfig +1 -0
@@ -3,3 +3,4 @@ CONFIG_ARM=y CONFIG_TARGET_SOCFPGA_ARRIA5=y CONFIG_OF_CONTROL=y CONFIG_DEFAULT_DEVICE_TREE="socfpga_arria5_socdk" +CONFIG_REGEX=y
configs/socfpga_cyclone5_defconfig +1 -0
@@ -6,3 +6,4 @@ CONFIG_DEFAULT_DEVICE_TREE="socfpga_cyclone5_socdk" CONFIG_ETH_DESIGNWARE=y CONFIG_NETDEVICES=y CONFIG_NET=y +CONFIG_REGEX=y
configs/t3corp_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_T3CORP=y +CONFIG_REGEX=y
configs/taihu_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_TAIHU=y +CONFIG_REGEX=y
configs/taishan_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_TAISHAN=y +CONFIG_REGEX=y
configs/walnut_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_WALNUT=y +CONFIG_REGEX=y
configs/yosemite_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="YOSEMITE" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_YOSEMITE=y +CONFIG_REGEX=y
configs/yucca_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_YUCCA=y +CONFIG_REGEX=y
include/configs/amcc-common.h +0 -1
@@ -106,7 +106,6 @@#define CONFIG_LOADS_ECHO /* echo on for serial download */ #define CONFIG_SYS_LOADS_BAUD_CHANGE /* allow baudrate change */ -#define CONFIG_REGEX /* Enable regular expression support */ /* * BOOTP options */
include/configs/m28evk.h +0 -1
@@ -49,7 +49,6 @@#define CONFIG_CMD_USB #define CONFIG_VIDEO -#define CONFIG_REGEX /* Enable regular expression support */ /* Memory configuration */ #define CONFIG_NR_DRAM_BANKS 1/* 1 bank of DRAM */
include/configs/m53evk.h +0 -1
@@ -51,7 +51,6 @@#define CONFIG_CMD_USB #define CONFIG_VIDEO -#define CONFIG_REGEX /* Enable regular expression support */ /* * Memory configurations
include/configs/novena.h +0 -1
@@ -22,7 +22,6 @@#define CONFIG_KEYBOARD #define CONFIG_MXC_GPIO #define CONFIG_OF_LIBFDT -#define CONFIG_REGEX #define CONFIG_SYS_GENERIC_BOARD #define CONFIG_SYS_NO_FLASH
include/configs/socfpga_arria5.h +0 -1
@@ -37,7 +37,6 @@#define CONFIG_CMD_USB #define CONFIG_CMD_USB_MASS_STORAGE -#define CONFIG_REGEX /* Enable regular expression support */ /* Memory configurations */ #define PHYS_SDRAM_1_SIZE 0x40000000/* 1GiB on SoCDK */
include/configs/socfpga_cyclone5.h +0 -1
@@ -37,7 +37,6 @@#define CONFIG_CMD_USB #define CONFIG_CMD_USB_MASS_STORAGE -#define CONFIG_REGEX /* Enable regular expression support */ /* Memory configurations */ #define PHYS_SDRAM_1_SIZE 0x40000000/* 1GiB on SoCDK */
lib/Kconfig +8 -0
@@ -36,6 +36,14 @@ config SYS_VSNPRINTF Thumb-2, about 420 bytes). Enable this option for safety when using sprintf() with data you do not control. +config REGEX + bool "Enable regular expression support" + help + If this variable is defined, U-Boot is linked against the + SLRE (Super Light Regular Expression) library, which adds + regex support to some commands, for example "env grep" and + "setexpr". + source lib/rsa/Kconfig menu "Hashing Support"
Signature · 1 line
1.7.11.5
PATCH v3 2/26 kconfig: Move REGEX to Kconfig
Quoted 5 lines · Joe Hershberger
Having this as a
Kconfigallows it to be a dependent feature.Signed-off-by Joe Hershberger <[email protected]>Reviewed-by Simon Glass <[email protected]>Acked-by Stefan Roese <[email protected]>
configs/socfpga_cyclone5_defconfig CONFIG_DEFAULT_DEVICE_TREE="socfpga_cyclone5_socdk" · line 9
Quoted 9 lines
configs/socfpga_cyclone5_defconfig +1
-0@@ -6,3 +6,4 @@ CONFIG_DEFAULT_DEVICE_TREE="socfpga_cyclone5_socdk" CONFIG_ETH_DESIGNWARE=y CONFIG_NETDEVICES=y CONFIG_NET=y +CONFIG_REGEX=y
Unfortunately, this is going to cause rejects on the config fixes pending. Oh well. Just apply it ASAP :-).
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
PATCH v3 3/26 sandbox: Enable regex support
In reply to Joe HershbergerEnable regex support on sandbox.
---
Changes in v3: None
Changes in v2: None
configs/sandbox_defconfig | 1 + 1 file changed, 1 insertion(+)
configs/sandbox_defconfig +1 -0
@@ -26,3 +26,4 @@ CONFIG_TPM_TIS_SANDBOX=y CONFIG_SOUND=y CONFIG_CMD_SOUND=y CONFIG_SOUND_SANDBOX=y +CONFIG_REGEX=y
Signature · 1 line
1.7.11.5
PATCH v3 4/26 env: Fix return values in env_attr_lookup()
In reply to Joe HershbergerThis function returned numbers for error codes. Change them to error codes.
---
Changes in v3: None
Changes in v2: None
common/env_attr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
common/env_attr.c +3 -3
@@ -148,10 +148,10 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes)if (!attributes)/* bad parameter */ -return -1 ; +return -EINVAL ;if (!attr_list)/* list not found */ -return 1 ; +return -EINVAL ; entry =reverse_strstr (attr_list, name,NULL );while (entry !=NULL ) {
@@ -209,5 +209,5 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes) }/* not found in list */ -return 2 ; +return -ENOENT ; }
Signature · 1 line
1.7.11.5
PATCH v3 5/26 env: Simplify the reverse_strstr() interface
In reply to Joe HershbergerThe logic to find the whole matching name was split needlessly between the reverse_strstr function and its caller. Fully contain it to make the interface for calling it more consistent.
---
Changes in v3: None
Changes in v2:
-Fix bisectability issue
-Fix corner case in reverse_name_search() where searched starts with ' '
common/env_attr.c | 87 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 47 insertions(+), 40 deletions(-)
common/env_attr.c +47 -40
@@ -109,33 +109,59 @@ int env_attr_walk(const char *attr_list, }/* -* Search for the last matching string in another string with the option to -* start looking at a certain point (i.e. ignore anything beyond that point). +* Search for the last exactly matching name in an attribute list */ -static char *reverse_strstr (const char *searched,const char *search_for, -const char *searched_start) +static int reverse_name_search (const char *searched,const char *search_for, +const char **result) { -char *result =NULL ; +int result_size =0 ; +const char *cur_searched = searched; -if (*search_for =='\0' ) -return (char *)searched; +if (result) + *result =NULL ; + +if (*search_for =='\0' ) { +if (result) + *result = searched; +return strlen (searched); + }for (;;) { -char *match =strstr (searched, search_for); - -/* -* Stop looking if no new match is found or looking past the -* searched_start pointer -*/ -if (match ==NULL || (searched_start !=NULL && - match +strlen (search_for) > searched_start)) +const char *match =strstr (cur_searched, search_for); +const char *prevch; +const char *nextch; + +/* Stop looking if no new match is found */ +if (match ==NULL )break ; - result = match; - searched = match +1 ; + prevch = match -1 ; + nextch = match +strlen (search_for); + +/* Skip spaces */ +while (*prevch ==' ' && prevch >= searched) + prevch--; +while (*nextch ==' ' ) + nextch++; + +/* Start looking past the current match so last is found */ + cur_searched = match +1 ; +/* Check for an exact match */ +if (match != searched && + *prevch !=ENV_ATTR_LIST_DELIM && + prevch != searched -1 ) +continue ; +if (*nextch !=ENV_ATTR_SEP && + *nextch !=ENV_ATTR_LIST_DELIM && + *nextch !='\0' ) +continue ; + +if (result) + *result = match; + result_size =strlen (search_for); } -return result; +return result_size; }/*
@@ -145,6 +171,7 @@ static char *reverse_strstr(const char *searched, const char *search_for,int env_attr_lookup (const char *attr_list,const char *name,char *attributes) {const char *entry =NULL ; +int entry_len;if (!attributes)/* bad parameter */
@@ -153,32 +180,12 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes)/* list not found */ return -EINVAL ; - entry =reverse_strstr (attr_list, name,NULL ); -while (entry !=NULL ) { -const char *prevch = entry -1 ; -const char *nextch = entry +strlen (name); - -/* Skip spaces */ -while (*prevch ==' ' ) - prevch--; -while (*nextch ==' ' ) - nextch++; - -/* check for an exact match */ -if ((entry == attr_list || - *prevch ==ENV_ATTR_LIST_DELIM ) && - (*nextch ==ENV_ATTR_SEP || - *nextch ==ENV_ATTR_LIST_DELIM || - *nextch =='\0' )) -break ; - - entry =reverse_strstr (attr_list, name, entry); - } + entry_len =reverse_name_search (attr_list, name, &entry);if (entry !=NULL ) {int len;/* skip the name */ - entry +=strlen (name); + entry += entry_len;/* skip spaces */ while (*entry ==' ' ) entry++;
Signature · 1 line
1.7.11.5
PATCH v3 6/26 env: Allow env_attr_walk to pass a priv * to callback
In reply to Joe HershbergerIn some cases it can be helpful to have context in the callback about the calling situation. This is needed for following patches.
---
Changes in v3: None
Changes in v2: None
common/cmd_nvedit.c | 10 ++++++---- common/env_attr.c | 5 +++-- common/env_callback.c | 6 +++--- common/env_flags.c | 6 +++--- include/env_attr.h | 10 +++++----- 5 files changed, 20 insertions(+), 17 deletions(-)
common/cmd_nvedit.c +6 -4
@@ -427,7 +427,8 @@ int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])#endif #if defined(CONFIG_CMD_ENV_CALLBACK ) -static int print_static_binding (const char *var_name,const char *callback_name) +static int print_static_binding (const char *var_name,const char *callback_name, +void *priv) {printf ("\t%-20s %-20s\n" , var_name, callback_name);
@@ -489,7 +490,7 @@ int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])puts ("Static callback bindings:\n" );printf ("\t%-20s %-20s\n" ,"Variable Name" ,"Callback Name" );printf ("\t%-20s %-20s\n" ,"-------------" ,"-------------" ); -env_attr_walk (ENV_CALLBACK_LIST_STATIC , print_static_binding); +env_attr_walk (ENV_CALLBACK_LIST_STATIC , print_static_binding,NULL );puts ("\n" );/* walk through each variable and print the callback if it has one */
@@ -502,7 +503,8 @@ int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])#endif #if defined(CONFIG_CMD_ENV_FLAGS ) -static int print_static_flags (const char *var_name,const char *flags) +static int print_static_flags (const char *var_name,const char *flags, +void *priv) {enum env_flags_vartype type =env_flags_parse_vartype (flags);enum env_flags_varaccess access =env_flags_parse_varaccess (flags);
@@ -559,7 +561,7 @@ int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) "Variable Access");printf ("\t%-20s %-20s %-20s\n" ,"-------------" ,"-------------" ,"---------------" ); -env_attr_walk (ENV_FLAGS_LIST_STATIC , print_static_flags); +env_attr_walk (ENV_FLAGS_LIST_STATIC , print_static_flags,NULL );puts ("\n" );/* walk through each variable and print the flags if non-default */
common/env_attr.c +3 -2
@@ -26,7 +26,8 @@* list = entry[,list] */ int env_attr_walk (const char *attr_list, -int (*callback)(const char *name,const char *attributes)) +int (*callback)(const char *name,const char *attributes,void *priv), +void *priv) {const char *entry, *entry_end;char *name, *attributes;
@@ -93,7 +94,7 @@ int env_attr_walk(const char *attr_list,if (strlen (name) !=0 ) {int retval =0 ; - retval =callback (name, attributes); + retval =callback (name, attributes, priv);if (retval) {free (entry_cpy);return retval;
common/env_callback.c +3 -3
@@ -90,7 +90,7 @@ static int clear_callback(ENTRY *entry)/* * Call for each element in the list that associates variables to callbacks */ -static int set_callback (const char *name,const char *value) +static int set_callback (const char *name,const char *value,void *priv) {ENTRY e, *ep;struct env_clbk_tbl *clbkp;
@@ -126,9 +126,9 @@ static int on_callbacks(const char *name, const char *value, enum env_op op,hwalk_r (&env_htab, clear_callback);/* configure any static callback bindings */ -env_attr_walk (ENV_CALLBACK_LIST_STATIC , set_callback); +env_attr_walk (ENV_CALLBACK_LIST_STATIC , set_callback,NULL );/* configure any dynamic callback bindings */ -env_attr_walk (value, set_callback); +env_attr_walk (value, set_callback,NULL );return 0 ; }
common/env_flags.c +3 -3
@@ -435,7 +435,7 @@ static int clear_flags(ENTRY *entry)/* * Call for each element in the list that defines flags for a variable */ -static int set_flags (const char *name,const char *value) +static int set_flags (const char *name,const char *value,void *priv) {ENTRY e, *ep;
@@ -463,9 +463,9 @@ static int on_flags(const char *name, const char *value, enum env_op op,hwalk_r (&env_htab, clear_flags);/* configure any static flags */ -env_attr_walk (ENV_FLAGS_LIST_STATIC , set_flags); +env_attr_walk (ENV_FLAGS_LIST_STATIC , set_flags,NULL );/* configure any dynamic flags */ -env_attr_walk (value, set_flags); +env_attr_walk (value, set_flags,NULL );return 0 ; }
include/env_attr.h +5 -5
@@ -16,13 +16,14 @@* attributes = [^,:\s]* * entry = name[:attributes] * list = entry[,list] -* It will call the "callback" function with the "name" and attribute as "value" +* It will call the "callback" function with the "name" and "attributes" * The callback may return a non-0 to abort the list walk. * This return value will be passed through to the caller. * 0 is returned on success. */ -extern int env_attr_walk (const char *attr_list, -int (*callback)(const char *name,const char *value)); +int env_attr_walk (const char *attr_list, +int (*callback)(const char *name,const char *attributes,void *priv), +void *priv);/* * env_attr_lookup takes as input an "attr_list" with the same form as above.
@@ -33,7 +34,6 @@ extern int env_attr_walk(const char *attr_list,* "attr_list" is NULL. * Returns 0 on success. */ -extern int env_attr_lookup (const char *attr_list,const char *name, -char *attributes); +int env_attr_lookup (const char *attr_list,const char *name,char *attributes);#endif /* __ENV_ATTR_H__ */
Signature · 1 line
1.7.11.5
PATCH v3 7/26 env: Add regex support to env_attrs
In reply to Joe HershbergerAllow the features that use env_attrs to specify regexs for the name
---
Changes in v3: None
Changes in v2:
-Added description to README
README | 8 +++++ common/env_attr.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/env_callback.h | 10 ++++-- 3 files changed, 101 insertions(+), 2 deletions(-)
README +8 -0
@@ -4157,6 +4157,10 @@ Configuration Settings: list, simply add an entry for the same variable name to the ".flags" variable. + If CONFIG_REGEX is defined, the variable_name above is evaluated as a + regular expression. This allows multiple variables to define the same + flags without explicitly listing them for each variable. + - CONFIG_ENV_ACCESS_IGNORE_FORCE If defined, don't allow the -f switch to env set override variable access flags.
@@ -5555,6 +5559,10 @@ override any association in the static list. You can define CONFIG_ENV_CALLBACK_LIST_DEFAULT to a list (string) to define the ".callbacks" environment variable in the default or embedded environment. +If CONFIG_REGEX is defined, the variable_name above is evaluated as a +regular expression. This allows multiple variables to be connected to +the same callback without explicitly listing them all out. + Command Line Parsing: =====================
common/env_attr.c +85 -0
100 lines not on this page · raw message
include/env_callback.h +8 -2
@@ -31,12 +31,18 @@#define SPLASHIMAGE_CALLBACK #endif +#ifdef CONFIG_REGEX +#define ENV_DOT_ESCAPE "\\" +#else +#define ENV_DOT_ESCAPE +#endif +/* * This list of callback bindings is static, but may be overridden by defining * a new association in the ".callbacks" environment variable. */ -#define ENV_CALLBACK_LIST_STATIC ENV_CALLBACK_VAR ":callbacks," \ - ENV_FLAGS_VAR ":flags," \ +#define ENV_CALLBACK_LIST_STATIC ENV_DOT_ESCAPE ENV_CALLBACK_VAR ":callbacks," \ + ENV_DOT_ESCAPE ENV_FLAGS_VAR ":flags," \ "baudrate:baudrate," \ "bootfile:bootfile," \ "loadaddr:loadaddr," \
Signature · 1 line
1.7.11.5
PATCH v3 8/26 env: Distinguish finer between source of env change
In reply to Joe HershbergerWe already could tell the difference in the callback between an import and "other" which we called interactive. Now add further distinction between interactive (i.e. running env set / env edit / env ask / etc. from the U-Boot command line) and programmatic (i.e. when u-boot source calls any variant of setenv() ).
---
Changes in v3: None
Changes in v2: None
common/cmd_nvedit.c | 26 +++++++++++++++++++------- include/search.h | 2 ++ 2 files changed, 21 insertions(+), 7 deletions(-)
common/cmd_nvedit.c +19 -7
@@ -208,12 +208,11 @@ DONE:* Set a new environment variable, * or replace or delete an existing one. */ -static int _do_env_set (int flag,int argc,char *const argv[]) +static int _do_env_set (int flag,int argc,char *const argv[],int env_flag) {int i, len;char *name, *value, *s;ENTRY e, *ep; -int env_flag =H_INTERACTIVE ;debug ("Initial value for argc=%d\n" , argc);while (argc >1 && **(argv +1 ) =='-' ) {
@@ -291,9 +290,9 @@ int setenv(const char *varname, const char *varvalue)return 1 ;if (varvalue ==NULL || varvalue[0 ] =='\0' ) -return _do_env_set (0 ,2 , (char *const *)argv); +return _do_env_set (0 ,2 , (char *const *)argv,H_PROGRAMMATIC );else -return _do_env_set (0 ,3 , (char *const *)argv); +return _do_env_set (0 ,3 , (char *const *)argv,H_PROGRAMMATIC ); }/**
@@ -347,7 +346,7 @@ static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])if (argc <2 )return CMD_RET_USAGE ; -return _do_env_set (flag, argc, argv); +return _do_env_set (flag, argc, argv,H_INTERACTIVE ); }/*
@@ -422,7 +421,7 @@ int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) }/* Continue calling setenv code */ -return _do_env_set (flag, len, local_args); +return _do_env_set (flag, len, local_args,H_INTERACTIVE ); }#endif
@@ -588,6 +587,10 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,if (argc <2 )return CMD_RET_USAGE ; +/* before import into hashtable */ +if (!(gd->flags &GD_FLG_ENV_READY )) +return 1 ; +/* Set read buffer to initial value or empty sting */ init_val =getenv (argv[1 ]);if (init_val)
@@ -598,7 +601,16 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,if (cli_readline_into_buffer ("edit: " , buffer,0 ) <0 )return 1 ; -return setenv (argv[1 ], buffer); +if (buffer[0 ] =='\0' ) { +const char *const _argv[3 ] = {"setenv" , argv[1 ],NULL }; + +return _do_env_set (0 ,2 , (char *const *)_argv,H_INTERACTIVE ); + }else { +const char *const _argv[4 ] = {"setenv" , argv[1 ], buffer, +NULL }; + +return _do_env_set (0 ,3 , (char *const *)_argv,H_INTERACTIVE ); + } }#endif /* CONFIG_CMD_EDITENV */ #endif /* CONFIG_SPL_BUILD */
include/search.h +2 -0
@@ -120,5 +120,7 @@ extern int hwalk_r(struct hsearch_data *__htab, int (*callback)(ENTRY *));#define H_MATCH_SUBSTR (1 << 7)/* search for substring matches */ #define H_MATCH_REGEX (1 << 8)/* search for regular expression matches */ #define H_MATCH_METHOD (H_MATCH_IDENT | H_MATCH_SUBSTR | H_MATCH_REGEX) +#define H_PROGRAMMATIC (1 << 9)/* indicate that an import is from setenv() */ +#define H_ORIGIN_FLAGS (H_INTERACTIVE | H_PROGRAMMATIC)#endif /* search.h */
Signature · 1 line
1.7.11.5
PATCH v3 9/26 net: Apply default format rules to all ethaddr
In reply to Joe HershbergerUse a regular expression to apply the default formatting flags for all ethaddr env vars.
---
Changes in v3: None
Changes in v2:
-Added comments about the use of .flags in the dm eth test
include/env_flags.h | 11 ++++++++--- test/dm/eth.c | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-)
include/env_flags.h +8 -3
@@ -38,13 +38,18 @@ enum env_flags_varaccess {#endif #ifdef CONFIG_CMD_NET +#ifdef CONFIG_REGEX +#define ETHADDR_WILDCARD "\\d?" +#else +#define ETHADDR_WILDCARD +#endif #ifdef CONFIG_ENV_OVERWRITE -#define ETHADDR_FLAGS "ethaddr:ma," +#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:ma,"#else #ifdef CONFIG_OVERWRITE_ETHADDR_ONCE -#define ETHADDR_FLAGS "ethaddr:mc," +#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mc,"#else -#define ETHADDR_FLAGS "ethaddr:mo," +#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"#endif #endif #else
test/dm/eth.c +3 -0
@@ -89,6 +89,8 @@ static int dm_test_eth_rotate(struct dm_test_state *dms)/* Invalidate eth1's MAC address */ net_ping_ip =string_to_ip ("1.1.2.2" );strcpy (ethaddr,getenv ("eth1addr" )); +/* Must disable access protection for eth1addr before clearing */ +setenv (".flags" ,"eth1addr" );setenv ("eth1addr" ,NULL );/* Make sure that the default is to rotate to the next interface */
@@ -108,6 +110,7 @@ static int dm_test_eth_rotate(struct dm_test_state *dms)/* Invalidate eth0's MAC address */ strcpy (ethaddr,getenv ("ethaddr" )); +/* Must disable access protection for ethaddr before clearing */ setenv (".flags" ,"ethaddr" );setenv ("ethaddr" ,NULL );
Signature · 1 line
1.7.11.5
PATCH v3 10/26 net: Use env callbacks for net variables
In reply to Joe HershbergerInstead of checking for changes to the env each time we enter the net_loop, use the env callbacks to update the values of the variables. Don't update the variables when the source was programmatic, since the variables were the source of the new value.
---
Changes in v3: None
Changes in v2:
-Simplified test for H_PROGRAMMATIC
include/env_callback.h | 22 ++++++++++- net/net.c | 105 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 110 insertions(+), 17 deletions(-)
include/env_callback.h +21 -1
@@ -37,6 +37,26 @@#define ENV_DOT_ESCAPE #endif +#ifdef CONFIG_CMD_DNS +#define DNS_CALLBACK "dnsip:dnsip," +#else +#define DNS_CALLBACK +#endif + +#ifdef CONFIG_NET +#define NET_CALLBACKS \ + "bootfile:bootfile," \ + "ipaddr:ipaddr," \ + "gatewayip:gatewayip," \ + "netmask:netmask," \ + "serverip:serverip," \ + "nvlan:nvlan," \ + "vlan:vlan," \ + DNS_CALLBACK +#else +#define NET_CALLBACKS +#endif +/* * This list of callback bindings is static, but may be overridden by defining * a new association in the ".callbacks" environment variable.
@@ -44,7 +64,7 @@#define ENV_CALLBACK_LIST_STATIC ENV_DOT_ESCAPE ENV_CALLBACK_VAR ":callbacks," \ ENV_DOT_ESCAPE ENV_FLAGS_VAR ":flags," \ "baudrate:baudrate," \ - "bootfile:bootfile," \ + NET_CALLBACKS \ "loadaddr:loadaddr," \ SILENT_CALLBACK \ SPLASHIMAGE_CALLBACK \
net/net.c +89 -16
123 lines not on this page · raw message
Signature · 1 line
1.7.11.5
PATCH v3 11/26 net: Add default flags for common net env vars
In reply to Joe HershbergerCheck that the common network stack's env vars conform to the proper format for IP addresses.
---
Changes in v3: None
Changes in v2: None
include/env_flags.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
include/env_flags.h +11 -1
@@ -52,8 +52,17 @@ enum env_flags_varaccess {#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"#endif #endif +#define NET_FLAGS \ + "ipaddr:i," \ + "gatewayip:i," \ + "netmask:i," \ + "serverip:i," \ + "nvlan:i," \ + "vlan:i," \ + "dnsip:i,"#else -#define ETHADDR_FLAGS "" +#define ETHADDR_FLAGS +#define NET_FLAGS #endif #ifndef CONFIG_ENV_OVERWRITE
@@ -64,6 +73,7 @@ enum env_flags_varaccess {#define ENV_FLAGS_LIST_STATIC \ ETHADDR_FLAGS \ + NET_FLAGS \ SERIAL_FLAGS \ CONFIG_ENV_FLAGS_LIST_STATIC
Signature · 1 line
1.7.11.5
PATCH v3 12/26 net: Remove duplicate bootfile syncing functionality
In reply to Joe HershbergerThe bootfile env var is already kept up to date by the callback in net.c so there is no need to poll it too.
---
Changes in v3:
-New for version 3
Changes in v2: None
net/eth.c | 12 ------------ 1 file changed, 12 deletions(-)
net/eth.c +0 -12
@@ -60,16 +60,6 @@ static inline int eth_setenv_enetaddr_by_index(const char *base_name, int index,return eth_setenv_enetaddr (enetvar, enetaddr); } -static void eth_env_init (void ) -{ -const char *s; - - s =getenv ("bootfile" ); -if (s !=NULL ) -copy_filename (net_boot_file_name, s, -sizeof (net_boot_file_name)); -} -static int eth_mac_skip (int index) {char enetvar[15 ];
@@ -104,8 +94,6 @@ static void eth_common_init(void)phy_init ();#endif -eth_env_init (); -/* * If board-specific initialization exists, call it. * If not, call a CPU-specific one
Signature · 1 line
1.7.11.5
PATCH v3 13/26 net: Handle ethaddr changes as an env callback
In reply to Joe HershbergerWhen the ethaddr is changed in the env, update the device pdata at the same time (only if it is probed for the DM case; only if registered for the non-DM case). Again this gets us closer to completely non-polled env needed to simplify the net_loop.
This requires that the NET feature select the REGEX feature.
---
Changes in v3:
-New for version 3
Changes in v2: None
configs/sandbox_defconfig | 1 - include/env_callback.h | 3 +- net/Kconfig | 1 + net/eth.c | 83 ++++++++++++++++++++++++++++++++++------------- 4 files changed, 63 insertions(+), 25 deletions(-)
configs/sandbox_defconfig +0 -1
@@ -26,4 +26,3 @@ CONFIG_TPM_TIS_SANDBOX=y CONFIG_SOUND=y CONFIG_CMD_SOUND=y CONFIG_SOUND_SANDBOX=y -CONFIG_REGEX=y
include/env_callback.h +2 -1
@@ -52,7 +52,8 @@"serverip:serverip," \"nvlan:nvlan," \"vlan:vlan," \ - DNS_CALLBACK +DNS_CALLBACK \ + "eth\\d?addr:ethaddr,"#else #define NET_CALLBACKS #endif
net/Kconfig +1 -0
@@ -4,6 +4,7 @@ menuconfig NET bool "Networking support" + select REGEX if NET
net/eth.c +60 -23
124 lines not on this page · raw message
Signature · 1 line
1.7.11.5
PATCH v3 14/26 test: Generalize the unit test framework
In reply to Joe HershbergerSeparate the ability to define tests and assert status of test functions from the dm tests so they can be used more consistenly throughout all tests.
---
Changes in v3: None
Changes in v2:
-New for version 2
include/dm/test.h | 35 +++++-----------------
include/test/test.h | 47 ++++++++++++++++++++++++++++++
include/{dm => test}/ut.h | 28 +++++++++---------
test/Kconfig | 3 ++
test/Makefile | 1 +
test/dm/Kconfig | 1 +
test/dm/Makefile | 2 --
test/dm/bus.c | 39 +++++++++++++------------
test/dm/core.c | 74 +++++++++++++++++++++++++----------------------
test/dm/eth.c | 14 ++++-----
test/dm/gpio.c | 22 +++++++-------
test/dm/i2c.c | 20 ++++++-------
test/dm/pci.c | 6 ++--
test/dm/sf.c | 4 +--
test/dm/spi.c | 8 ++---
test/dm/test-driver.c | 6 ++--
test/dm/test-fdt.c | 16 +++++-----
test/dm/test-main.c | 36 +++++++++++++----------
test/dm/test-uclass.c | 7 +++--
test/dm/usb.c | 6 ++--
test/{dm => }/ut.c | 16 +++++-----
21 files changed, 217 insertions(+), 174 deletions(-)
create mode 100644 include/test/test.h
rename include/{dm => test}/ut.h (79%)
rename test/{dm => }/ut.c (59%)include/dm/test.h +7 -28
@@ -8,7 +8,7 @@#define __DM_TEST_H#include <dm.h> -#include <malloc.h> +#include <test/test.h> /** * struct dm_test_cdata - configuration data for test instance
@@ -124,7 +124,7 @@ struct dm_test_perdev_uc_pdata {*/ extern int dm_testdrv_op_count[DM_TEST_OP_COUNT ]; -extern struct dm_test_state global_test_state; +extern struct unit_test_state global_dm_test_state;/* * struct dm_test_state - Entire state of dm test system
@@ -133,7 +133,6 @@ extern struct dm_test_state global_test_state;* * @root: Root device * @testdev: Test device -* @fail_count: Number of tests that failed * @force_fail_alloc: Force all memory allocs to fail * @skip_post_probe: Skip uclass post-probe processing * @removed: Used to keep track of a device that was removed
@@ -141,11 +140,9 @@ extern struct dm_test_state global_test_state;struct dm_test_state {struct udevice *root;struct udevice *testdev; -int fail_count;int force_fail_alloc;int skip_post_probe;struct udevice *removed; -struct mallinfo start; };/* Test flags for each test */
@@ -155,26 +152,8 @@ enum { DM_TESTF_SCAN_FDT = 1 << 2, /* scan device tree */ }; -/** -* struct dm_test - Information about a driver model test -* -* @name: Name of test -* @func: Function to call to perform test -* @flags: Flags indicated pre-conditions for test -*/ -struct dm_test { -const char *name; -int (*func)(struct dm_test_state *dms); -int flags; -}; -/* Declare a new driver model test */ -#define DM_TEST (_name, _flags) \ - ll_entry_declare(struct dm_test, _name, dm_test) = { \ - .name = #_name, \ - .flags = _flags, \ - .func = _name, \ - } +#define DM_TEST (_name, _flags) UNIT_TEST(_name, _flags, dm_test)/* Declare ping methods for the drivers */ int test_ping (struct udevice *dev,int pingval,int *pingret);
@@ -191,7 +170,7 @@ int testfdt_ping(struct udevice *dev, int pingval, int *pingret);* @priv: Pointer to private test information * @return 0 if OK, -ve on error */ -int dm_check_operations (struct dm_test_state *dms,struct udevice *dev, +int dm_check_operations (struct unit_test_state *uts,struct udevice *dev,uint32_t base,struct dm_test_priv *priv);/**
@@ -201,7 +180,7 @@ int dm_check_operations(struct dm_test_state *dms, struct udevice *dev,* @num_devices: Number of test devices to check * @return 0 if OK, -ve on error */ -int dm_check_devices (struct dm_test_state *dms,int num_devices); +int dm_check_devices (struct unit_test_state *uts,int num_devices);/** * dm_leak_check_start() - Prepare to check for a memory leak
@@ -211,7 +190,7 @@ int dm_check_devices(struct dm_test_state *dms, int num_devices);* * @dms: Overall test state */ -void dm_leak_check_start (struct dm_test_state *dms); +void dm_leak_check_start (struct unit_test_state *uts);/** * dm_leak_check_end() - Check that no memory has leaked
@@ -221,7 +200,7 @@ void dm_leak_check_start(struct dm_test_state *dms);* it sees a different amount of total memory allocated than before. * * @dms: Overall test state -*/ int dm_leak_check_end (struct dm_test_state *dms); +*/ int dm_leak_check_end (struct unit_test_state *uts);/**
include/test/test.h new file +47 -0
47 lines not on this page · raw message
include/test/ut.h renamed from include/dm/ut.h +14 -14
@@ -1,39 +1,39 @@/* -* Simple unit test library for driver model +* Simple unit test library * * Copyright (c) 2013 Google, Inc * * SPDX-License-Identifier: GPL-2.0+ */ -#ifndef __DM_UT_H -#define __DM_UT_H +#ifndef __TEST_UT_H +#define __TEST_UT_H -struct dm_test_state ; +struct unit_test_state ;/** * ut_fail() - Record failure of a unit test * -* @dms: Test state +* @uts: Test state * @fname: Filename where the error occured * @line: Line number where the error occured * @func: Function name where the error occured * @cond: The condition that failed */ -void ut_fail (struct dm_test_state *dms,const char *fname,int line, +void ut_fail (struct unit_test_state *uts,const char *fname,int line,const char *func,const char *cond);/** * ut_failf() - Record failure of a unit test * -* @dms: Test state +* @uts: Test state * @fname: Filename where the error occured * @line: Line number where the error occured * @func: Function name where the error occured * @cond: The condition that failed * @fmt: printf() format string for the error, followed by args */ -void ut_failf (struct dm_test_state *dms,const char *fname,int line, +void ut_failf (struct unit_test_state *uts,const char *fname,int line,const char *func,const char *cond,const char *fmt, ...) __attribute__ ((format (__printf__,6 ,7 )));
@@ -41,14 +41,14 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,/* Assert that a condition is non-zero */ #define ut_assert (cond) \ if (!(cond)) { \ - ut_fail(dms, __FILE__, __LINE__, __func__, #cond); \ + ut_fail(uts, __FILE__, __LINE__, __func__, #cond); \ return -1; \ }/* Assert that a condition is non-zero, with printf() string */ #define ut_assertf(cond, fmt, args...) \ if (!(cond)) { \ - ut_failf(dms, __FILE__, __LINE__, __func__, #cond, \ + ut_failf(uts, __FILE__, __LINE__, __func__, #cond, \ fmt, ##args); \ return -1; \ }
@@ -58,7 +58,7 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,unsigned int val1 = (expr1), val2 = (expr2); \ \if (val1 != val2) { \ -ut_failf (dms, __FILE__, __LINE__, __func__, \ +ut_failf (uts, __FILE__, __LINE__, __func__, \ #expr1 " == " #expr2, \"Expected %d, got %d" , val1, val2); \return -1 ; \
@@ -70,7 +70,7 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,const char *val1 = (expr1), *val2 = (expr2); \ \if (strcmp (val1, val2)) { \ -ut_failf (dms, __FILE__, __LINE__, __func__, \ +ut_failf (uts, __FILE__, __LINE__, __func__, \ #expr1 " = " #expr2, \"Expected \"%s\", got \"%s\"" , val1, val2); \return -1 ; \
@@ -82,7 +82,7 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,const void *val1 = (expr1), *val2 = (expr2); \ \if (val1 != val2) { \ -ut_failf (dms, __FILE__, __LINE__, __func__, \ +ut_failf (uts, __FILE__, __LINE__, __func__, \ #expr1 " = " #expr2, \"Expected %p, got %p" , val1, val2); \return -1 ; \
@@ -94,7 +94,7 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,const void *val = (expr); \ \if (val ==NULL ) { \ -ut_failf (dms, __FILE__, __LINE__, __func__, \ +ut_failf (uts, __FILE__, __LINE__, __func__, \ #expr " = NULL", \"Expected non-null, got NULL" ); \return -1 ; \
test/Kconfig +3 -0
@@ -1 +1,4 @@ +config UNIT_TEST + bool + source "test/dm/Kconfig"
test/Makefile +1 -0
@@ -4,5 +4,6 @@ # SPDX-License-Identifier: GPL-2.0+ # +obj-$(CONFIG_UNIT_TEST) += ut.o obj-$(CONFIG_SANDBOX) += command_ut.o obj-$(CONFIG_SANDBOX) += compression.o
test/dm/Kconfig +1 -0
@@ -1,6 +1,7 @@ config DM_TEST bool "Enable driver model test command" depends on SANDBOX && CMD_DM + select UNIT_TEST help This enables the 'dm test' command which runs a series of unit tests on the driver model code. Each subsystem (uclass) is tested.
test/dm/Makefile +0 -2
@@ -10,12 +10,10 @@ obj-$(CONFIG_DM_TEST) += test-driver.o obj-$(CONFIG_DM_TEST) += test-fdt.o obj-$(CONFIG_DM_TEST) += test-main.o obj-$(CONFIG_DM_TEST) += test-uclass.o -obj-$(CONFIG_DM_TEST) += ut.o # Tests for particular subsystems - when enabling driver model for a new # subsystem you must add sandbox tests here. obj-$(CONFIG_DM_TEST) += core.o -obj-$(CONFIG_DM_TEST) += ut.o ifneq ($(CONFIG_SANDBOX),) obj-$(CONFIG_DM_ETH) += eth.o obj-$(CONFIG_DM_GPIO) += gpio.o
test/dm/bus.c +20 -19
@@ -10,8 +10,8 @@#include <dm/root.h> #include <dm/test.h> #include <dm/uclass-internal.h> -#include <dm/ut.h> #include <dm/util.h> +#include <test/ut.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -104,7 +104,7 @@ UCLASS_DRIVER(testbus) = { };/* Test that we can probe for children */ -static int dm_test_bus_children (struct dm_test_state *dms) +static int dm_test_bus_children (struct unit_test_state *uts) {int num_devices =6 ;struct udevice *bus;
@@ -120,14 +120,14 @@ static int dm_test_bus_children(struct dm_test_state *dms)ut_assertok (uclass_get (UCLASS_TEST_FDT , &uc));ut_asserteq (num_devices,list_count_items (&uc->dev_head)); -ut_assert (!dm_check_devices (dms, num_devices)); +ut_assert (!dm_check_devices (uts, num_devices));return 0 ; }DM_TEST (dm_test_bus_children,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test our functions for accessing children */ -static int dm_test_bus_children_funcs (struct dm_test_state *dms) +static int dm_test_bus_children_funcs (struct unit_test_state *uts) {const void *blob = gd->fdt_blob;struct udevice *bus, *dev;
@@ -173,7 +173,7 @@ static int dm_test_bus_children_funcs(struct dm_test_state *dms)DM_TEST (dm_test_bus_children_funcs,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test that we can iterate through children */ -static int dm_test_bus_children_iterators (struct dm_test_state *dms) +static int dm_test_bus_children_iterators (struct unit_test_state *uts) {struct udevice *bus, *dev, *child;
@@ -204,7 +204,7 @@ DM_TEST(dm_test_bus_children_iterators, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);/* Test that the bus can store data about each child */ -static int test_bus_parent_data (struct dm_test_state *dms) +static int test_bus_parent_data (struct unit_test_state *uts) {struct dm_test_parent_data *parent_data;struct udevice *bus, *dev;
@@ -264,14 +264,14 @@ static int test_bus_parent_data(struct dm_test_state *dms)return 0 ; }/* Test that the bus can store data about each child */ -static int dm_test_bus_parent_data (struct dm_test_state *dms) +static int dm_test_bus_parent_data (struct unit_test_state *uts) { -return test_bus_parent_data (dms); +return test_bus_parent_data (uts); }DM_TEST (dm_test_bus_parent_data,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* As above but the size is controlled by the uclass */ -static int dm_test_bus_parent_data_uclass (struct dm_test_state *dms) +static int dm_test_bus_parent_data_uclass (struct unit_test_state *uts) {struct driver *drv;struct udevice *bus;
@@ -284,7 +284,7 @@ static int dm_test_bus_parent_data_uclass(struct dm_test_state *dms) size = drv->per_child_auto_alloc_size; bus->uclass->uc_drv->per_child_auto_alloc_size = size; drv->per_child_auto_alloc_size =0 ; - ret =test_bus_parent_data (dms); + ret =test_bus_parent_data (uts);if (ret)return ret; bus->uclass->uc_drv->per_child_auto_alloc_size =0 ;
@@ -296,9 +296,10 @@ DM_TEST(dm_test_bus_parent_data_uclass, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);/* Test that the bus ops are called when a child is probed/removed */ -static int dm_test_bus_parent_ops (struct dm_test_state *dms) +static int dm_test_bus_parent_ops (struct unit_test_state *uts) {struct dm_test_parent_data *parent_data; +struct dm_test_state *dms = uts->priv;struct udevice *bus, *dev;struct uclass *uc;
@@ -333,7 +334,7 @@ static int dm_test_bus_parent_ops(struct dm_test_state *dms) }DM_TEST (dm_test_bus_parent_ops,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); -static int test_bus_parent_platdata (struct dm_test_state *dms) +static int test_bus_parent_platdata (struct unit_test_state *uts) {struct dm_test_parent_platdata *plat;struct udevice *bus, *dev;
@@ -406,14 +407,14 @@ static int test_bus_parent_platdata(struct dm_test_state *dms) }/* Test that the bus can store platform data about each child */ -static int dm_test_bus_parent_platdata (struct dm_test_state *dms) +static int dm_test_bus_parent_platdata (struct unit_test_state *uts) { -return test_bus_parent_platdata (dms); +return test_bus_parent_platdata (uts); }DM_TEST (dm_test_bus_parent_platdata,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* As above but the size is controlled by the uclass */ -static int dm_test_bus_parent_platdata_uclass (struct dm_test_state *dms) +static int dm_test_bus_parent_platdata_uclass (struct unit_test_state *uts) {struct udevice *bus;struct driver *drv;
@@ -426,7 +427,7 @@ static int dm_test_bus_parent_platdata_uclass(struct dm_test_state *dms) size = drv->per_child_platdata_auto_alloc_size; bus->uclass->uc_drv->per_child_platdata_auto_alloc_size = size; drv->per_child_platdata_auto_alloc_size =0 ; - ret =test_bus_parent_platdata (dms); + ret =test_bus_parent_platdata (uts);if (ret)return ret; bus->uclass->uc_drv->per_child_platdata_auto_alloc_size =0 ;
@@ -438,7 +439,7 @@ DM_TEST(dm_test_bus_parent_platdata_uclass, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);/* Test that the child post_bind method is called */ -static int dm_test_bus_child_post_bind (struct dm_test_state *dms) +static int dm_test_bus_child_post_bind (struct unit_test_state *uts) {struct dm_test_parent_platdata *plat;struct udevice *bus, *dev;
@@ -461,7 +462,7 @@ static int dm_test_bus_child_post_bind(struct dm_test_state *dms)DM_TEST (dm_test_bus_child_post_bind,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test that the child post_bind method is called */ -static int dm_test_bus_child_post_bind_uclass (struct dm_test_state *dms) +static int dm_test_bus_child_post_bind_uclass (struct unit_test_state *uts) {struct dm_test_parent_platdata *plat;struct udevice *bus, *dev;
@@ -488,7 +489,7 @@ DM_TEST(dm_test_bus_child_post_bind_uclass,* Test that the bus' uclass' child_pre_probe() is called before the * device's probe() method */ -static int dm_test_bus_child_pre_probe_uclass (struct dm_test_state *dms) +static int dm_test_bus_child_pre_probe_uclass (struct unit_test_state *uts) {struct udevice *bus, *dev;int child_count;
test/dm/core.c +40 -34
259 lines not on this page · raw message
test/dm/eth.c +7 -7
@@ -9,16 +9,16 @@#include <common.h> #include <dm.h> -#include <dm/test.h> -#include <dm/ut.h> #include <fdtdec.h> #include <malloc.h> #include <net.h> +#include <dm/test.h> #include <asm/eth.h> +#include <test/ut.h> DECLARE_GLOBAL_DATA_PTR ; -static int dm_test_eth (struct dm_test_state *dms) +static int dm_test_eth (struct unit_test_state *uts) { net_ping_ip =string_to_ip ("1.1.2.2" );
@@ -38,7 +38,7 @@ static int dm_test_eth(struct dm_test_state *dms) }DM_TEST (dm_test_eth,DM_TESTF_SCAN_FDT ); -static int dm_test_eth_alias (struct dm_test_state *dms) +static int dm_test_eth_alias (struct unit_test_state *uts) { net_ping_ip =string_to_ip ("1.1.2.2" );setenv ("ethact" ,"eth0" );
@@ -62,7 +62,7 @@ static int dm_test_eth_alias(struct dm_test_state *dms) }DM_TEST (dm_test_eth_alias,DM_TESTF_SCAN_FDT ); -static int dm_test_eth_prime (struct dm_test_state *dms) +static int dm_test_eth_prime (struct unit_test_state *uts) { net_ping_ip =string_to_ip ("1.1.2.2" );
@@ -82,7 +82,7 @@ static int dm_test_eth_prime(struct dm_test_state *dms) }DM_TEST (dm_test_eth_prime,DM_TESTF_SCAN_FDT ); -static int dm_test_eth_rotate (struct dm_test_state *dms) +static int dm_test_eth_rotate (struct unit_test_state *uts) {char ethaddr[18 ];
@@ -127,7 +127,7 @@ static int dm_test_eth_rotate(struct dm_test_state *dms) }DM_TEST (dm_test_eth_rotate,DM_TESTF_SCAN_FDT ); -static int dm_test_net_retry (struct dm_test_state *dms) +static int dm_test_net_retry (struct unit_test_state *uts) { net_ping_ip =string_to_ip ("1.1.2.2" );
test/dm/gpio.c +11 -11
@@ -8,15 +8,15 @@#include <fdtdec.h> #include <dm.h> #include <dm/root.h> -#include <dm/ut.h> #include <dm/test.h> #include <dm/util.h> #include <asm/gpio.h> +#include <test/ut.h> DECLARE_GLOBAL_DATA_PTR ;/* Test that sandbox GPIOs work correctly */ -static int dm_test_gpio (struct dm_test_state *dms) +static int dm_test_gpio (struct unit_test_state *uts) {unsigned int offset, gpio;struct dm_gpio_ops *ops;
@@ -103,7 +103,7 @@ static int dm_test_gpio(struct dm_test_state *dms)DM_TEST (dm_test_gpio,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test that sandbox anonymous GPIOs work correctly */ -static int dm_test_gpio_anon (struct dm_test_state *dms) +static int dm_test_gpio_anon (struct unit_test_state *uts) {unsigned int offset, gpio;struct udevice *dev;
@@ -125,7 +125,7 @@ static int dm_test_gpio_anon(struct dm_test_state *dms)DM_TEST (dm_test_gpio_anon,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test that gpio_requestf() works as expected */ -static int dm_test_gpio_requestf (struct dm_test_state *dms) +static int dm_test_gpio_requestf (struct unit_test_state *uts) {unsigned int offset, gpio;struct udevice *dev;
@@ -143,7 +143,7 @@ static int dm_test_gpio_requestf(struct dm_test_state *dms)DM_TEST (dm_test_gpio_requestf,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test that gpio_request() copies its string */ -static int dm_test_gpio_copy (struct dm_test_state *dms) +static int dm_test_gpio_copy (struct unit_test_state *uts) {unsigned int offset, gpio;struct udevice *dev;
@@ -165,19 +165,19 @@ static int dm_test_gpio_copy(struct dm_test_state *dms)DM_TEST (dm_test_gpio_copy,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test that we don't leak memory with GPIOs */ -static int dm_test_gpio_leak (struct dm_test_state *dms) +static int dm_test_gpio_leak (struct unit_test_state *uts) { -ut_assertok (dm_test_gpio (dms)); -ut_assertok (dm_test_gpio_anon (dms)); -ut_assertok (dm_test_gpio_requestf (dms)); -ut_assertok (dm_leak_check_end (dms)); +ut_assertok (dm_test_gpio (uts)); +ut_assertok (dm_test_gpio_anon (uts)); +ut_assertok (dm_test_gpio_requestf (uts)); +ut_assertok (dm_leak_check_end (uts));return 0 ; }DM_TEST (dm_test_gpio_leak,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test that we can find GPIOs using phandles */ -static int dm_test_gpio_phandles (struct dm_test_state *dms) +static int dm_test_gpio_phandles (struct unit_test_state *uts) {struct gpio_desc desc, desc_list[8 ], desc_list2[8 ];struct udevice *dev, *gpio_a, *gpio_b;
test/dm/i2c.c +10 -10
@@ -10,19 +10,19 @@#include <dm.h> #include <fdtdec.h> #include <i2c.h> +#include <asm/state.h> +#include <asm/test.h> #include <dm/device-internal.h> #include <dm/test.h> #include <dm/uclass-internal.h> -#include <dm/ut.h> #include <dm/util.h> -#include <asm/state.h> -#include <asm/test.h> +#include <test/ut.h> static const int busnum;static const int chip =0x2c ;/* Test that we can find buses and chips */ -static int dm_test_i2c_find (struct dm_test_state *dms) +static int dm_test_i2c_find (struct unit_test_state *uts) {struct udevice *bus, *dev;const int no_chip =0x10 ;
@@ -43,7 +43,7 @@ static int dm_test_i2c_find(struct dm_test_state *dms) }DM_TEST (dm_test_i2c_find,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); -static int dm_test_i2c_read_write (struct dm_test_state *dms) +static int dm_test_i2c_read_write (struct unit_test_state *uts) {struct udevice *bus, *dev;uint8_t buf[5 ];
@@ -60,7 +60,7 @@ static int dm_test_i2c_read_write(struct dm_test_state *dms) }DM_TEST (dm_test_i2c_read_write,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); -static int dm_test_i2c_speed (struct dm_test_state *dms) +static int dm_test_i2c_speed (struct unit_test_state *uts) {struct udevice *bus, *dev;uint8_t buf[5 ];
@@ -78,7 +78,7 @@ static int dm_test_i2c_speed(struct dm_test_state *dms) }DM_TEST (dm_test_i2c_speed,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); -static int dm_test_i2c_offset_len (struct dm_test_state *dms) +static int dm_test_i2c_offset_len (struct unit_test_state *uts) {struct udevice *bus, *dev;uint8_t buf[5 ];
@@ -95,7 +95,7 @@ static int dm_test_i2c_offset_len(struct dm_test_state *dms) }DM_TEST (dm_test_i2c_offset_len,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); -static int dm_test_i2c_probe_empty (struct dm_test_state *dms) +static int dm_test_i2c_probe_empty (struct unit_test_state *uts) {struct udevice *bus, *dev;
@@ -106,7 +106,7 @@ static int dm_test_i2c_probe_empty(struct dm_test_state *dms) }DM_TEST (dm_test_i2c_probe_empty,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); -static int dm_test_i2c_bytewise (struct dm_test_state *dms) +static int dm_test_i2c_bytewise (struct unit_test_state *uts) {struct udevice *bus, *dev;struct udevice *eeprom;
@@ -161,7 +161,7 @@ static int dm_test_i2c_bytewise(struct dm_test_state *dms) }DM_TEST (dm_test_i2c_bytewise,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); -static int dm_test_i2c_offset (struct dm_test_state *dms) +static int dm_test_i2c_offset (struct unit_test_state *uts) {struct udevice *eeprom;struct udevice *dev;
test/dm/pci.c +3 -3
@@ -8,10 +8,10 @@#include <dm.h> #include <asm/io.h> #include <dm/test.h> -#include <dm/ut.h> +#include <test/ut.h> /* Test that sandbox PCI works correctly */ -static int dm_test_pci_base (struct dm_test_state *dms) +static int dm_test_pci_base (struct unit_test_state *uts) {struct udevice *bus;
@@ -22,7 +22,7 @@ static int dm_test_pci_base(struct dm_test_state *dms)DM_TEST (dm_test_pci_base,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test that we can use the swapcase device correctly */ -static int dm_test_pci_swapcase (struct dm_test_state *dms) +static int dm_test_pci_swapcase (struct unit_test_state *uts) {pci_dev_t pci_dev =PCI_BDF (0 ,0x1f ,0 );struct pci_controller *hose;
test/dm/sf.c +2 -2
@@ -10,12 +10,12 @@#include <spi.h> #include <spi_flash.h> #include <asm/state.h> -#include <dm/ut.h> #include <dm/test.h> #include <dm/util.h> +#include <test/ut.h> /* Test that sandbox SPI flash works correctly */ -static int dm_test_spi_flash (struct dm_test_state *dms) +static int dm_test_spi_flash (struct unit_test_state *uts) {/* * Create an empty test file and run the SPI flash tests. This is a
test/dm/spi.c +4 -4
@@ -9,15 +9,15 @@#include <fdtdec.h> #include <spi.h> #include <spi_flash.h> +#include <asm/state.h> #include <dm/device-internal.h> #include <dm/test.h> #include <dm/uclass-internal.h> -#include <dm/ut.h> #include <dm/util.h> -#include <asm/state.h> +#include <test/ut.h> /* Test that we can find buses and chip-selects */ -static int dm_test_spi_find (struct dm_test_state *dms) +static int dm_test_spi_find (struct unit_test_state *uts) {struct sandbox_state *state =state_get_current ();struct spi_slave *slave;
@@ -95,7 +95,7 @@ static int dm_test_spi_find(struct dm_test_state *dms)DM_TEST (dm_test_spi_find,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test that sandbox SPI works correctly */ -static int dm_test_spi_xfer (struct dm_test_state *dms) +static int dm_test_spi_xfer (struct unit_test_state *uts) {struct spi_slave *slave;struct udevice *bus;
test/dm/test-driver.c +4 -2
@@ -12,11 +12,11 @@#include <errno.h> #include <malloc.h> #include <dm/test.h> -#include <dm/ut.h> +#include <test/ut.h> #include <asm/io.h> int dm_testdrv_op_count[DM_TEST_OP_COUNT ]; -static struct dm_test_state *dms = &global_test_state; +static struct unit_test_state *uts = &global_dm_test_state;static int testdrv_ping (struct udevice *dev,int pingval,int *pingret) {
@@ -114,6 +114,8 @@ static int test_manual_bind(struct udevice *dev)static int test_manual_probe (struct udevice *dev) { +struct dm_test_state *dms = uts->priv; + dm_testdrv_op_count[DM_TEST_OP_PROBE ]++;if (!dms->force_fail_alloc) dev->priv =calloc (1 ,sizeof (struct dm_test_priv ));
test/dm/test-fdt.c +8 -8
@@ -12,9 +12,9 @@#include <asm/io.h> #include <dm/test.h> #include <dm/root.h> -#include <dm/ut.h> #include <dm/uclass-internal.h> #include <dm/util.h> +#include <test/ut.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -99,7 +99,7 @@ UCLASS_DRIVER(testfdt) = { .flags = DM_UC_FLAG_SEQ_ALIAS, }; -int dm_check_devices (struct dm_test_state *dms,int num_devices) +int dm_check_devices (struct unit_test_state *uts,int num_devices) {struct udevice *dev;int ret;
@@ -126,7 +126,7 @@ int dm_check_devices(struct dm_test_state *dms, int num_devices)debug ("dev=%d, base=%d: %s\n" , i, base,fdt_get_name (gd->fdt_blob, dev->of_offset,NULL )); -ut_assert (!dm_check_operations (dms, dev, base, +ut_assert (!dm_check_operations (uts, dev, base,dev_get_priv (dev))); }
@@ -134,7 +134,7 @@ int dm_check_devices(struct dm_test_state *dms, int num_devices) }/* Test that FDT-based binding works correctly */ -static int dm_test_fdt (struct dm_test_state *dms) +static int dm_test_fdt (struct unit_test_state *uts) {const int num_devices =6 ;struct udevice *dev;
@@ -159,13 +159,13 @@ static int dm_test_fdt(struct dm_test_state *dms)ut_assert (dev->platdata); } -ut_assertok (dm_check_devices (dms, num_devices)); +ut_assertok (dm_check_devices (uts, num_devices));return 0 ; }DM_TEST (dm_test_fdt,0 ); -static int dm_test_fdt_pre_reloc (struct dm_test_state *dms) +static int dm_test_fdt_pre_reloc (struct unit_test_state *uts) {struct uclass *uc;int ret;
@@ -184,7 +184,7 @@ static int dm_test_fdt_pre_reloc(struct dm_test_state *dms)DM_TEST (dm_test_fdt_pre_reloc,0 );/* Test that sequence numbers are allocated properly */ -static int dm_test_fdt_uclass_seq (struct dm_test_state *dms) +static int dm_test_fdt_uclass_seq (struct unit_test_state *uts) {struct udevice *dev;
@@ -239,7 +239,7 @@ static int dm_test_fdt_uclass_seq(struct dm_test_state *dms)DM_TEST (dm_test_fdt_uclass_seq,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );/* Test that we can find a device by device tree offset */ -static int dm_test_fdt_offset (struct dm_test_state *dms) +static int dm_test_fdt_offset (struct unit_test_state *uts) {const void *blob = gd->fdt_blob;struct udevice *dev;
test/dm/test-main.c +21 -15
@@ -11,15 +11,20 @@#include <dm/test.h> #include <dm/root.h> #include <dm/uclass-internal.h> -#include <dm/ut.h> +#include <test/ut.h> DECLARE_GLOBAL_DATA_PTR ; -struct dm_test_state global_test_state; +struct unit_test_state global_dm_test_state; +static struct dm_test_state _global_priv_dm_test_state;/* Get ready for testing */ -static int dm_test_init (struct dm_test_state *dms) +static int dm_test_init (struct unit_test_state *uts) { +struct dm_test_state *dms = uts->priv; + +memset (uts,'\0' ,sizeof (*uts)); + uts->priv = dms;memset (dms,'\0' ,sizeof (*dms)); gd->dm_root =NULL ;memset (dm_testdrv_op_count,'\0' ,sizeof (dm_testdrv_op_count));
@@ -31,7 +36,7 @@ static int dm_test_init(struct dm_test_state *dms) }/* Ensure all the test devices are probed */ -static int do_autoprobe (struct dm_test_state *dms) +static int do_autoprobe (struct unit_test_state *uts) {struct udevice *dev;int ret;
@@ -45,7 +50,7 @@ static int do_autoprobe(struct dm_test_state *dms)return ret; } -static int dm_test_destroy (struct dm_test_state *dms) +static int dm_test_destroy (struct unit_test_state *uts) {int id;
@@ -67,10 +72,11 @@ static int dm_test_destroy(struct dm_test_state *dms)int dm_test_main (const char *test_name) { - struct dm_test *tests = ll_entry_start(struct dm_test, dm_test); - const int n_ents = ll_entry_count(struct dm_test, dm_test); -struct dm_test_state *dms = &global_test_state; -struct dm_test *test; + struct unit_test *tests = ll_entry_start(struct unit_test, dm_test); + const int n_ents = ll_entry_count(struct unit_test, dm_test); +struct unit_test_state *uts = &global_dm_test_state; + uts->priv = &_global_priv_dm_test_state; +struct unit_test *test;/* * If we have no device tree, or it only has a root node, then these
@@ -90,23 +96,23 @@ int dm_test_main(const char *test_name)if (test_name &&strcmp (test_name, test->name))continue ;printf ("Test: %s\n" , test->name); -ut_assertok (dm_test_init (dms)); +ut_assertok (dm_test_init (uts)); - dms->start =mallinfo (); + uts->start =mallinfo ();if (test->flags &DM_TESTF_SCAN_PDATA )ut_assertok (dm_scan_platdata (false));if (test->flags &DM_TESTF_PROBE_TEST ) -ut_assertok (do_autoprobe (dms)); +ut_assertok (do_autoprobe (uts));if (test->flags &DM_TESTF_SCAN_FDT )ut_assertok (dm_scan_fdt (gd->fdt_blob, false)); -if (test->func (dms)) +if (test->func (uts))break ; -ut_assertok (dm_test_destroy (dms)); +ut_assertok (dm_test_destroy (uts)); } -printf ("Failures: %d\n" , dms->fail_count); +printf ("Failures: %d\n" , uts->fail_count);return 0 ; }
test/dm/test-uclass.c +4 -3
@@ -11,12 +11,12 @@#include <malloc.h> #include <dm.h> #include <errno.h> -#include <dm/test.h> -#include <dm/ut.h> #include <asm/io.h> +#include <dm/test.h> #include <linux/list.h> +#include <test/ut.h> -static struct dm_test_state *dms = &global_test_state; +static struct unit_test_state *uts = &global_dm_test_state;int test_ping (struct udevice *dev,int pingval,int *pingret) {
@@ -70,6 +70,7 @@ static int test_post_probe(struct udevice *dev)struct dm_test_uclass_perdev_priv *priv =dev_get_uclass_priv (dev);struct uclass *uc = dev->uclass; +struct dm_test_state *dms = uts->priv; dm_testdrv_op_count[DM_TEST_OP_POST_PROBE ]++;ut_assert (priv);
test/dm/usb.c +3 -3
@@ -9,10 +9,10 @@#include <usb.h> #include <asm/io.h> #include <dm/test.h> -#include <dm/ut.h> +#include <test/ut.h> /* Test that sandbox USB works correctly */ -static int dm_test_usb_base (struct dm_test_state *dms) +static int dm_test_usb_base (struct unit_test_state *uts) {struct udevice *bus;
@@ -29,7 +29,7 @@ DM_TEST(dm_test_usb_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);* covers scanning the bug, setting up a hub and a flash stick and reading * data from the flash stick. */ -static int dm_test_usb_flash (struct dm_test_state *dms) +static int dm_test_usb_flash (struct unit_test_state *uts) {struct udevice *dev;block_dev_desc_t *dev_desc;
test/ut.c renamed from test/dm/ut.c +7 -9
@@ -1,5 +1,5 @@/* -* Simple unit test library for driver model +* Simple unit test library * * Copyright (c) 2013 Google, Inc *
@@ -7,19 +7,17 @@*/ #include <common.h> -#include <dm/test.h> -#include <dm/ut.h> +#include <test/test.h> +#include <test/ut.h> -struct dm_test_state ; - -void ut_fail (struct dm_test_state *dms,const char *fname,int line, +void ut_fail (struct unit_test_state *uts,const char *fname,int line,const char *func,const char *cond) {printf ("%s:%d, %s(): %s\n" , fname, line, func, cond); - dms->fail_count++; + uts->fail_count++; } -void ut_failf (struct dm_test_state *dms,const char *fname,int line, +void ut_failf (struct unit_test_state *uts,const char *fname,int line,const char *func,const char *cond,const char *fmt, ...) {va_list args;
@@ -29,5 +27,5 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,vprintf (fmt, args);va_end (args);putc ('\n' ); - dms->fail_count++; + uts->fail_count++; }
Signature · 1 line
1.7.11.5
PATCH v3 15/26 test: Add a common unit test command
In reply to Joe HershbergerAdd a command that all other unit tests should be a sub-command of. Also include a command that will run all tests.
---
Changes in v3:
-New for version 3
Changes in v2: None
include/test/suites.h | 11 +++++++++ test/Makefile | 1 + test/cmd_ut.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 include/test/suites.h create mode 100644 test/cmd_ut.c
include/test/suites.h new file +11 -0
@@ -0,0 +1,11 @@ +/* +* (C) Copyright 2015 +* Joe Hershberger, National Instruments, joe.hershberger at ni.com +* +* SPDX-License-Identifier: GPL-2.0 +*/ + +#ifndef __TEST_SUITES_H__ +#define __TEST_SUITES_H__ + +#endif /* __TEST_SUITES_H__ */
test/Makefile +1 -0
@@ -4,6 +4,7 @@ # SPDX-License-Identifier: GPL-2.0+ # +obj-$(CONFIG_UNIT_TEST) += cmd_ut.o obj-$(CONFIG_UNIT_TEST) += ut.o obj-$(CONFIG_SANDBOX) += command_ut.o obj-$(CONFIG_SANDBOX) += compression.o
test/cmd_ut.c new file +62 -0
62 lines not on this page · raw message
Signature · 1 line
1.7.11.5
PATCH v3 15/26 test: Add a common unit test command
Quoted 9 lines · Joe Hershberger
Add a command that all other unit tests should be a sub-command of. Also include a command that will run all tests.
Signed-off-by Joe Hershberger <[email protected]>---
Changes in v3:
-New for version 3
Quoted 8 lines
Changes in v2: None
include/test/suites.h | 11 +++++++++ test/Makefile | 1 + test/cmd_ut.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 include/test/suites.h create mode 100644 test/cmd_ut.c
PATCH v3 16/26 test: Move the unit tests to their own menu
In reply to Joe HershbergerMake all unit tests selectable as a menu of test suites instead of just sitting in the top-level menu individually.
---
Changes in v3:
-New for version 3
Changes in v2: None
test/Kconfig | 7 +++++-- test/dm/Kconfig | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-)
test/Kconfig +5 -2
@@ -1,4 +1,7 @@ -config UNIT_TEST - bool +menuconfig UNIT_TEST + bool "Unit tests" + help + Select this to compile in unit tests for various parts of + U-Boot. Test suites will be subcommands of the "ut" command. source "test/dm/Kconfig"
test/dm/Kconfig +1 -2
@@ -1,7 +1,6 @@ config DM_TEST bool "Enable driver model test command" - depends on SANDBOX && CMD_DM - select UNIT_TEST + depends on SANDBOX && CMD_DM && UNIT_TEST help This enables the 'dm test' command which runs a series of unit tests on the driver model code. Each subsystem (uclass) is tested.
Signature · 1 line
1.7.11.5
PATCH v3 16/26 test: Move the unit tests to their own menu
Quoted 6 lines · Joe Hershberger
Make all unit tests selectable as a menu of test suites instead of just sitting in the top-level menu individually.
Signed-off-by Joe Hershberger <[email protected]>---
Quoted 8 lines
Changes in v3:
-New for version 3Changes in v2: None
test/Kconfig | 7 +++++-- test/dm/Kconfig | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-)
PATCH v3 17/26 test: dm: Don't bail on all tests if one test fails
In reply to Joe HershbergerThere's not much point in having a failure count if we always give up on the first failure. Also stop clearing the entire state between tests.
Make sure that any failures are still passed out to the command line.
---
Changes in v3: None
Changes in v2:
-New for version 2
test/dm/test-main.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
test/dm/test-main.c +2 -5
@@ -23,8 +23,6 @@ static int dm_test_init(struct unit_test_state *uts) {struct dm_test_state *dms = uts->priv; -memset (uts,'\0' ,sizeof (*uts)); - uts->priv = dms;memset (dms,'\0' ,sizeof (*dms)); gd->dm_root =NULL ;memset (dm_testdrv_op_count,'\0' ,sizeof (dm_testdrv_op_count));
@@ -106,13 +104,12 @@ int dm_test_main(const char *test_name)if (test->flags &DM_TESTF_SCAN_FDT )ut_assertok (dm_scan_fdt (gd->fdt_blob, false)); -if (test->func (uts)) -break ; + test->func (uts);ut_assertok (dm_test_destroy (uts)); }printf ("Failures: %d\n" , uts->fail_count); -return 0 ; +return uts->fail_count ?CMD_RET_FAILURE :0 ; }
Signature · 1 line
1.7.11.5
PATCH v3 18/26 test: dm: eth: Handle failed test env cleanup
In reply to Joe HershbergerMake sure that the env gets cleaned up after a test fails so that other tests aren't affected.
---
Changes in v3:
-New for version 3
Changes in v2: None
test/dm/eth.c | 79 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 24 deletions(-)
test/dm/eth.c +55 -24
@@ -82,17 +82,9 @@ static int dm_test_eth_prime(struct unit_test_state *uts) }DM_TEST (dm_test_eth_prime,DM_TESTF_SCAN_FDT ); -static int dm_test_eth_rotate (struct unit_test_state *uts) +/* The asserts include a return on fail; cleanup in the caller */ +static int _dm_test_eth_rotate1 (struct unit_test_state *uts) { -char ethaddr[18 ]; - -/* Invalidate eth1's MAC address */ - net_ping_ip =string_to_ip ("1.1.2.2" ); -strcpy (ethaddr,getenv ("eth1addr" )); -/* Must disable access protection for eth1addr before clearing */ -setenv (".flags" ,"eth1addr" ); -setenv ("eth1addr" ,NULL ); -/* Make sure that the default is to rotate to the next interface */ setenv ("ethact" ,"eth at 10004000" );ut_assertok (net_loop (PING ));
@@ -104,33 +96,61 @@ static int dm_test_eth_rotate(struct unit_test_state *uts)ut_asserteq (-EINVAL ,net_loop (PING ));ut_asserteq_str ("eth at 10004000" ,getenv ("ethact" )); -/* Restore the env */ -setenv ("eth1addr" , ethaddr); -setenv ("ethrotate" ,NULL ); - -/* Invalidate eth0's MAC address */ -strcpy (ethaddr,getenv ("ethaddr" )); -/* Must disable access protection for ethaddr before clearing */ -setenv (".flags" ,"ethaddr" ); -setenv ("ethaddr" ,NULL ); +return 0 ; +} +static int _dm_test_eth_rotate2 (struct unit_test_state *uts) +{/* Make sure we can skip invalid devices */ setenv ("ethact" ,"eth at 10004000" );ut_assertok (net_loop (PING ));ut_asserteq_str ("eth at 10004000" ,getenv ("ethact" )); +return 0 ; +} + +static int dm_test_eth_rotate (struct unit_test_state *uts) +{ +char ethaddr[18 ]; +int retval; + +/* Set target IP to mock ping */ + net_ping_ip =string_to_ip ("1.1.2.2" ); + +/* Invalidate eth1's MAC address */ +strcpy (ethaddr,getenv ("eth1addr" )); +/* Must disable access protection for eth1addr before clearing */ +setenv (".flags" ,"eth1addr" ); +setenv ("eth1addr" ,NULL ); + + retval =_dm_test_eth_rotate1 (uts); + +/* Restore the env */ +setenv ("eth1addr" , ethaddr); +setenv ("ethrotate" ,NULL ); + +if (!retval) { +/* Invalidate eth0's MAC address */ +strcpy (ethaddr,getenv ("ethaddr" )); +/* Must disable access protection for ethaddr before clearing */ +setenv (".flags" ,"ethaddr" ); +setenv ("ethaddr" ,NULL ); + + retval =_dm_test_eth_rotate2 (uts); + +/* Restore the env */ +setenv ("ethaddr" , ethaddr); + }/* Restore the env */ -setenv ("ethaddr" , ethaddr);setenv (".flags" ,NULL ); -return 0 ; +return retval; }DM_TEST (dm_test_eth_rotate,DM_TESTF_SCAN_FDT ); -static int dm_test_net_retry (struct unit_test_state *uts) +/* The asserts include a return on fail; cleanup in the caller */ +static int _dm_test_net_retry (struct unit_test_state *uts) { - net_ping_ip =string_to_ip ("1.1.2.2" ); -/* * eth1 is disabled and netretry is yes, so the ping should succeed and * the active device should be eth0
@@ -150,6 +170,17 @@ static int dm_test_net_retry(struct unit_test_state *uts)ut_asserteq (-ETIMEDOUT ,net_loop (PING ));ut_asserteq_str ("eth at 10004000" ,getenv ("ethact" )); +return 0 ; +} + +static int dm_test_net_retry (struct unit_test_state *uts) +{ +int retval; + + net_ping_ip =string_to_ip ("1.1.2.2" ); + + retval =_dm_test_net_retry (uts); +/* Restore the env */ setenv ("netretry" ,NULL );sandbox_eth_disable_response (1 , false);
Signature · 1 line
1.7.11.5
PATCH v3 18/26 test: dm: eth: Handle failed test env cleanup
Hi Joe,
Quoted 6 lines · Joe Hershberger
Make sure that the env gets cleaned up after a test fails so that other tests aren't affected.
Signed-off-by Joe Hershberger <[email protected]>---
Quoted 7 lines
Changes in v3:
-New for version 3Changes in v2: None
test/dm/eth.c | 79 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 24 deletions(-)
With this commit I get quite a few errors, like:
19: test: dm: eth: Handle failed test env cleanup
sandbox: + sandbox
+ int retval;
+ ^+test/dm/built-in.o: In function `dm_test_bus_children':+build/../test/dm/bus.c:121: undefined reference to ut_failf' +build/../test/dm/bus.c:123: undefined reference to ut_fail' +test/dm/built-in.o: In function `dm_test_bus_children_funcs':+build/../test/dm/bus.c:143: undefined reference to ut_failf' +build/../test/dm/bus.c:168: undefined reference to ut_failf' +build/../test/dm/bus.c:169: undefined reference to `ut_fail'
Regards,
Simon
PATCH v3 18/26 test: dm: eth: Handle failed test env cleanup
Hi Simon,
Quoted 21 lines · Simon Glass
Hi Joe,
Quoted 6 lines · Joe Hershberger
Make sure that the env gets cleaned up after a test fails so that other tests aren't affected.
Signed-off-by Joe Hershberger <[email protected]>---
Quoted 7 lines
Changes in v3:
-New for version 3Changes in v2: None
test/dm/eth.c | 79 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 24 deletions(-)With this commit I get quite a few errors, like:
19: test: dm: eth: Handle failed test env cleanup
sandbox: + sandbox
Review
Quoted 9 lines
(quoted diff) +9
-0+ int retval; + ^ +test/dm/built-in.o: In function `dm_test_bus_children': +build/../test/dm/bus.c:121: undefined reference to `ut_failf' +build/../test/dm/bus.c:123: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_bus_children_funcs': +build/../test/dm/bus.c:143: undefined reference to `ut_failf' +build/../test/dm/bus.c:168: undefined reference to `ut_failf' +build/../test/dm/bus.c:169: undefined reference to `ut_fail'
Are you sure it's this commit? This touches nothing it test/dm/bus.c and nothing in test/ut.c (where those functions are defined). Is is maybe a dirty build error?
Thanks,
-Joe
PATCH v3 18/26 test: dm: eth: Handle failed test env cleanup
Hi Joe,
Quoted 22 lines · Joe Hershberger
Hi Simon,
Quoted 19 lines · Simon Glass
Hi Joe,
Quoted 6 lines · Joe Hershberger
Make sure that the env gets cleaned up after a test fails so that other tests aren't affected.
Signed-off-by Joe Hershberger <[email protected]>---
Quoted 7 lines
Changes in v3:
-New for version 3Changes in v2: None
test/dm/eth.c | 79 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 24 deletions(-)With this commit I get quite a few errors, like:
Quoted 15 lines
Review
Quoted 11 lines
19: test: dm: eth: Handle failed test env cleanup
sandbox: + sandbox(quoted diff) +9
-0+ int retval; + ^ +test/dm/built-in.o: In function `dm_test_bus_children': +build/../test/dm/bus.c:121: undefined reference to `ut_failf' +build/../test/dm/bus.c:123: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_bus_children_funcs': +build/../test/dm/bus.c:143: undefined reference to `ut_failf' +build/../test/dm/bus.c:168: undefined reference to `ut_failf' +build/../test/dm/bus.c:169: undefined reference to `ut_fail'Are you sure it's this commit? This touches nothing it
test/dm/bus.cand nothing intest/ut.c(where those functions are defined). Is is maybe a dirty build error?
buildman does not lie :-) Well, so far as I know...it retries if it sees any errors and warnings, after doing a full mrproper.
Just to be sure I tried a separate sandbox build and got the same errors.
I pushed the tree to u-boot-dm branch 'env-working' - perhaps I've applied something incorrectly?
Regards,
Simon
PATCH v3 18/26 test: dm: eth: Handle failed test env cleanup
Hi Simon,
Quoted 41 lines · Simon Glass
Hi Joe,
Quoted 22 lines · Joe Hershberger
Hi Simon,
Quoted 19 lines · Simon Glass
Hi Joe,
Quoted 6 lines · Joe Hershberger
Make sure that the env gets cleaned up after a test fails so that other tests aren't affected.
Signed-off-by Joe Hershberger <[email protected]>---
Quoted 7 lines
Changes in v3:
-New for version 3Changes in v2: None
test/dm/eth.c | 79 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 24 deletions(-)With this commit I get quite a few errors, like:
Quoted 15 lines
Review
Quoted 11 lines
19: test: dm: eth: Handle failed test env cleanup
sandbox: + sandbox(quoted diff) +9
-0+ int retval; + ^ +test/dm/built-in.o: In function `dm_test_bus_children': +build/../test/dm/bus.c:121: undefined reference to `ut_failf' +build/../test/dm/bus.c:123: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_bus_children_funcs': +build/../test/dm/bus.c:143: undefined reference to `ut_failf' +build/../test/dm/bus.c:168: undefined reference to `ut_failf' +build/../test/dm/bus.c:169: undefined reference to `ut_fail'Are you sure it's this commit? This touches nothing it
test/dm/bus.cand nothing intest/ut.c(where those functions are defined). Is is maybe a dirty build error?
Quoted 7 lines
buildman does not lie :-) Well, so far as I know...it retries if it sees any errors and warnings, after doing a full mrproper.
Just to be sure I tried a separate sandbox build and got the same errors.
I pushed the tree to u-boot-dm branch 'env-working' - perhaps I've applied something incorrectly?
I fetched down your branch and it builds fine for me. Can you paste the entire error log from your attempted build?
Thanks,
-Joe
PATCH v3 18/26 test: dm: eth: Handle failed test env cleanup
Hi Joe,
Quoted 48 lines · Joe Hershberger
Hi Simon,
Quoted 44 lines · Simon Glass
Hi Joe,
Quoted 22 lines · Joe Hershberger
Hi Simon,
Quoted 19 lines · Simon Glass
Hi Joe,
Quoted 6 lines · Joe Hershberger
Make sure that the env gets cleaned up after a test fails so that other tests aren't affected.
Signed-off-by Joe Hershberger <[email protected]>---
Quoted 7 lines
Changes in v3:
-New for version 3Changes in v2: None
test/dm/eth.c | 79 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 24 deletions(-)With this commit I get quite a few errors, like:
Quoted 15 lines
Review
Quoted 11 lines
19: test: dm: eth: Handle failed test env cleanup
sandbox: + sandbox(quoted diff) +9
-0+ int retval; + ^ +test/dm/built-in.o: In function `dm_test_bus_children': +build/../test/dm/bus.c:121: undefined reference to `ut_failf' +build/../test/dm/bus.c:123: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_bus_children_funcs': +build/../test/dm/bus.c:143: undefined reference to `ut_failf' +build/../test/dm/bus.c:168: undefined reference to `ut_failf' +build/../test/dm/bus.c:169: undefined reference to `ut_fail'Are you sure it's this commit? This touches nothing it
test/dm/bus.cand nothing intest/ut.c(where those functions are defined). Is is maybe a dirty build error?buildman does not lie :-) Well, so far as I know...it retries if it sees any errors and warnings, after doing a full mrproper.
Quoted 7 lines
Quoted 4 lines
Just to be sure I tried a separate sandbox build and got the same errors.
I pushed the tree to u-boot-dm branch 'env-working' - perhaps I've applied something incorrectly?
I fetched down your branch and it builds fine for me. Can you paste the entire error log from your attempted build?
Did you build this commit?
19: test: dm: eth: Handle failed test env cleanup
sandbox: + sandbox
+ int retval;
+ ^+test/dm/built-in.o: In function `dm_test_bus_children':+build/../test/dm/bus.c:121: undefined reference to ut_failf' +build/../test/dm/bus.c:123: undefined reference to ut_fail' +test/dm/built-in.o: In function `dm_test_bus_children_funcs':+build/../test/dm/bus.c:143: undefined reference to ut_failf' +build/../test/dm/bus.c:168: undefined reference to ut_failf' +build/../test/dm/bus.c:169: undefined reference to ut_fail' +test/dm/built-in.o: In function dm_test_bus_children_iterators':+build/../test/dm/bus.c:198: undefined reference to ut_failf' +build/../test/dm/bus.c:199: undefined reference to ut_failf' +test/dm/built-in.o: In function `dm_test_bus_child_post_bind':+build/../test/dm/bus.c:454: undefined reference to ut_fail' +build/../test/dm/bus.c:458: undefined reference to ut_failf' +test/dm/built-in.o: In function `dm_test_bus_child_post_bind_uclass':+build/../test/dm/bus.c:477: undefined reference to ut_fail' +build/../test/dm/bus.c:481: undefined reference to ut_failf' +test/dm/built-in.o: In function `test_bus_parent_data':+build/../test/dm/bus.c:217: undefined reference to ut_failf' +build/../test/dm/bus.c:232: undefined reference to ut_fail' +build/../test/dm/bus.c:242: undefined reference to ut_failf' +test/dm/built-in.o: In function dm_test_bus_parent_ops':+build/../test/dm/bus.c:308: undefined reference to ut_failf' +build/../test/dm/bus.c:329: undefined reference to ut_failf' +test/dm/built-in.o: In function `dm_test_bus_child_pre_probe_uclass':+build/../test/dm/bus.c:508: undefined reference to ut_failf' +build/../test/dm/bus.c:512: undefined reference to ut_fail' +build/../test/dm/bus.c:517: undefined reference to ut_failf' +test/dm/built-in.o: In function dm_test_bus_parent_data_uclass':+build/../test/dm/bus.c:282: undefined reference to ut_failf' +test/dm/built-in.o: In function test_bus_parent_platdata':+build/../test/dm/bus.c:366: undefined reference to ut_failf' +build/../test/dm/bus.c:400: undefined reference to ut_fail' +build/../test/dm/bus.c:404: undefined reference to ut_failf' +test/dm/built-in.o: In function dm_test_bus_parent_platdata_uclass':+build/../test/dm/bus.c:425: undefined reference to ut_failf' +test/dm/built-in.o: In function test_unbind':+build/../test/dm/test-driver.c:69: undefined reference to ut_fail' +test/dm/built-in.o: In function test_remove':+build/../test/dm/test-driver.c:60: undefined reference to ut_fail' +test/dm/built-in.o: In function test_probe':+build/../test/dm/test-driver.c:50: undefined reference to ut_fail' +test/dm/built-in.o: In function test_bind':+build/../test/dm/test-driver.c:39: undefined reference to ut_fail' +test/dm/built-in.o: In function dm_test_fdt_uclass_seq':+build/../test/dm/test-fdt.c:234: undefined reference to ut_failf' +build/../test/dm/test-fdt.c:235: undefined reference to ut_failf' +test/dm/built-in.o: In function `dm_test_fdt_offset':+build/../test/dm/test-fdt.c:252: undefined reference to ut_failf' +build/../test/dm/test-fdt.c:262: undefined reference to ut_fail' +build/../test/dm/test-fdt.c:263: undefined reference to ut_failf' +test/dm/built-in.o: In function dm_test_fdt_pre_reloc':+build/../test/dm/test-fdt.c:177: undefined reference to ut_fail' +build/../test/dm/test-fdt.c:180: undefined reference to ut_failf' +test/dm/built-in.o: In function `dm_check_devices':+build/../test/dm/test-fdt.c:129: undefined reference to ut_fail' +test/dm/built-in.o: In function dm_test_fdt':+build/../test/dm/test-fdt.c:159: undefined reference to ut_fail' +build/../test/dm/test-fdt.c:162: undefined reference to ut_failf' +test/dm/built-in.o: In function `dm_test_main':+build/../test/dm/test-main.c:87: undefined reference to ut_fail' +test/dm/built-in.o: In function dm_test_init':+build/../test/dm/test-main.c:30: undefined reference to ut_failf' +build/../test/dm/test-main.c:97: undefined reference to ut_failf' +test/dm/built-in.o: In function `dm_test_destroy':+build/../test/dm/test-main.c:65: undefined reference to ut_failf' +test/dm/built-in.o: In function test_post_probe':+build/../test/dm/test-uclass.c:87: undefined reference to ut_fail' +test/dm/built-in.o: In function test_init':+build/../test/dm/test-uclass.c:104: undefined reference to ut_fail' +test/dm/built-in.o: In function test_pre_probe':+build/../test/dm/test-uclass.c:61: undefined reference to ut_fail' +test/dm/built-in.o: In function test_post_bind':+build/../test/dm/test-uclass.c:39: undefined reference to ut_fail' +test/dm/built-in.o: In function dm_test_autobind':+build/../test/dm/core.c:120: undefined reference to ut_failf' +build/../test/dm/core.c:127: undefined reference to ut_fail' +test/dm/built-in.o: In function `dm_test_uclass':+build/../test/dm/core.c:505: undefined reference to ut_fail' +build/../test/dm/core.c:509: undefined reference to ut_failf' +test/dm/built-in.o: In function `dm_test_autobind_uclass_pdata_alloc':+build/../test/dm/core.c:140: undefined reference to ut_failf' +build/../test/dm/core.c:155: undefined reference to ut_fail' +test/dm/built-in.o: In function `dm_test_autobind_uclass_pdata_valid':+build/../test/dm/core.c:181: undefined reference to ut_fail' +test/dm/built-in.o: In function dm_test_autoprobe':+build/../test/dm/core.c:198: undefined reference to ut_fail' +build/../test/dm/core.c:215: undefined reference to ut_failf' +build/../test/dm/core.c:246: undefined reference to ut_failf' +test/dm/built-in.o: In function dm_test_pre_reloc':+build/../test/dm/core.c:643: undefined reference to ut_failf' +build/../test/dm/core.c:647: undefined reference to ut_failf' +test/dm/built-in.o: In function `dm_test_remove':+build/../test/dm/core.c:452: undefined reference to ut_fail' +build/../test/dm/core.c:455: undefined reference to ut_failf' +build/../test/dm/core.c:456: undefined reference to ut_failf' +test/dm/built-in.o: In function dm_test_lifecycle':+build/../test/dm/core.c:313: undefined reference to ut_fail' +build/../test/dm/core.c:324: undefined reference to ut_failf' +test/dm/built-in.o: In function `dm_test_ordering':+build/../test/dm/core.c:376: undefined reference to ut_fail' +build/../test/dm/core.c:380: undefined reference to ut_failf' +test/dm/built-in.o: In function `dm_test_uclass_before_ready':+build/../test/dm/core.c:658: undefined reference to ut_failf' +build/../test/dm/core.c:664: undefined reference to ut_failf' +test/dm/built-in.o: In function `dm_test_uclass_devices_find_by_name':+build/../test/dm/core.c:713: undefined reference to ut_failf' +build/../test/dm/core.c:714: undefined reference to ut_fail' +build/../test/dm/core.c:716: undefined reference to ut_failf' +test/dm/built-in.o: In function dm_test_uclass_devices_get_by_name':+build/../test/dm/core.c:773: undefined reference to ut_failf' +build/../test/dm/core.c:775: undefined reference to ut_fail' +build/../test/dm/core.c:777: undefined reference to ut_failf' +test/dm/built-in.o: In function dm_test_device_get_uclass_id':+build/../test/dm/core.c:789: undefined reference to ut_failf' +test/dm/built-in.o: In function dm_test_uclass_devices_find':+build/../test/dm/core.c:678: undefined reference to ut_fail' +test/dm/built-in.o: In function dm_test_platdata':+build/../test/dm/core.c:264: undefined reference to ut_failf' +build/../test/dm/core.c:265: undefined reference to ut_fail' +test/dm/built-in.o: In function `dm_test_uclass_devices_get':+build/../test/dm/core.c:733: undefined reference to ut_fail' +test/dm/built-in.o: In function create_children':+build/../test/dm/core.c:536: undefined reference to ut_failf' +test/dm/built-in.o: In function dm_test_children':+build/../test/dm/core.c:627: undefined reference to ut_failf' +build/../test/dm/core.c:629: undefined reference to ut_failf' +test/dm/built-in.o: In function `dm_leak_check_end':+build/../test/dm/core.c:93: undefined reference to ut_failf' +test/dm/built-in.o: In function dm_test_leak':+build/../test/dm/core.c:490: undefined reference to ut_failf' +test/dm/built-in.o: In function dm_check_operations':+build/../test/dm/core.c:396: undefined reference to ut_fail' +build/../test/dm/core.c:408: undefined reference to ut_failf' +test/dm/built-in.o: In function `dm_test_operations':+build/../test/dm/core.c:427: undefined reference to ut_failf' +build/../test/dm/core.c:437: undefined reference to ut_fail' +test/dm/built-in.o: In function `dm_test_eth':+build/../test/dm/eth.c:34: undefined reference to ut_failf' +build/../test/dm/eth.c:35: undefined reference to ut_failf' +test/dm/built-in.o: In function `dm_test_eth_alias':+build/../test/dm/eth.c:58: undefined reference to ut_failf' +build/../test/dm/eth.c:59: undefined reference to ut_failf' +test/dm/built-in.o: In function `dm_test_eth_prime':+build/../test/dm/eth.c:78: undefined reference to ut_failf' +test/dm/built-in.o:build/../test/dm/eth.c:79: more undefined references to ut_failf' follow+test/dm/built-in.o: In function `dm_test_gpio':+build/../test/dm/gpio.c:45: undefined reference to ut_fail' +build/../test/dm/gpio.c:98: undefined reference to ut_failf' +build/../test/dm/gpio.c:99: undefined reference to ut_failf' +test/dm/built-in.o: In function dm_test_gpio_requestf':+build/../test/dm/gpio.c:138: undefined reference to ut_failf' +build/../test/dm/gpio.c:139: undefined reference to ut_failf' +test/dm/built-in.o: In function `dm_test_gpio_copy':+build/../test/dm/gpio.c:160: undefined reference to ut_failf' +test/dm/built-in.o:build/../test/dm/gpio.c:161: more undefined references to ut_failf' follow+test/dm/built-in.o: In function `dm_test_rtc_reset':+build/../test/dm/rtc.c:130: undefined reference to ut_fail' +build/../test/dm/rtc.c:139: undefined reference to ut_failf' +test/dm/built-in.o: In function `dm_test_rtc_set_get':+build/../test/dm/rtc.c:62: undefined reference to ut_failf' +build/../test/dm/rtc.c:65: undefined reference to ut_fail' +test/dm/built-in.o: In function `dm_test_rtc_dual':+build/../test/dm/rtc.c:161: undefined reference to ut_fail' +build/../test/dm/rtc.c:171: undefined reference to ut_failf' +test/dm/built-in.o: In function `dm_test_spi_flash':+build/../test/dm/sf.c:31: undefined reference to ut_failf' +test/dm/built-in.o: In function dm_test_spi_find':+build/../test/dm/spi.c:36: undefined reference to ut_failf' +build/../test/dm/spi.c:84: undefined reference to ut_failf' +test/dm/built-in.o: In function `dm_test_spi_xfer':+build/../test/dm/spi.c:108: undefined reference to ut_failf' +test/dm/built-in.o:build/../test/dm/usb.c:21: more undefined references to ut_failf' follow
+collect2: error: ld returned 1 exit status
+make[1]: *** [u-boot] Error 1
+make: *** [sub-make] Error 2w+../test/dm/eth.c: In function ?dm_test_net_retry?:w+../test/dm/eth.c:180:6: warning: variable ?retval? set but not used [-Wunused-but-set-variable]
20: test: Return values from the asserts compatible with cmds
Regards,
Simon
PATCH 1/2 sandbox: Use defconfig to enable features
Stop using the sandbox arch Kconfig to override defaults for config options. This is a bit of abuse and may be causing build problems.
---
The errors you are seeing are the result of "CONFIG_UNIT_TEST" not being defined. That should not be at all related to that test/dm/eth.c patch. This is changing the way that CONFIG_UNIT_TEST is enabled to be more typical in case there is some bad behavior with all this override of defaults. I have seen some non-ideal behavior, so I want to move away from using it.
Please apply this on top of u-boot-dm/env-working and try it.
arch/sandbox/Kconfig | 18 ------------------ configs/sandbox_defconfig | 5 +++++ 2 files changed, 5 insertions(+), 18 deletions(-)
arch/sandbox/Kconfig +0 -18
@@ -10,12 +10,6 @@ config SYS_BOARD config SYS_CONFIG_NAME default "sandbox" -config UNIT_TEST - default y - -config UT_DM - default y - config PCI bool "PCI support" help
@@ -23,16 +17,4 @@ config PCI used on some devices to allow the CPU to communicate with its peripherals. -config NET - default y - -config NETDEVICES - default y - -config DM_ETH - default y - -config ETH_SANDBOX_RAW - default y - endmenu
configs/sandbox_defconfig +5 -0
@@ -10,12 +10,15 @@ CONFIG_FIT_SIGNATURE=y CONFIG_CMD_SOUND=y CONFIG_OF_CONTROL=y CONFIG_OF_HOSTFILE=y +CONFIG_NET=y CONFIG_DM_PCI=y CONFIG_PCI_SANDBOX=y CONFIG_SPI_FLASH_SANDBOX=y CONFIG_CMD_CROS_EC=y CONFIG_CROS_EC=y CONFIG_CROS_EC_SANDBOX=y +CONFIG_DM_ETH=y +CONFIG_NETDEVICES=y CONFIG_CROS_EC_KEYB=y CONFIG_TPM_TIS_SANDBOX=y CONFIG_SYS_I2C_SANDBOX=y
@@ -27,4 +30,6 @@ CONFIG_USB=y CONFIG_USB_EMUL=y CONFIG_USB_STORAGE=y CONFIG_DM_RTC=y +CONFIG_UNIT_TEST=y +CONFIG_UT_DM=y CONFIG_UT_ENV=y
Signature · 1 line
1.7.11.5
PATCH 2/2 fixup! test: dm: eth: Handle failed test env cleanup
---
This fixes the one warning that was listed in your buildman output. For whatever reason my older gcc does not throw this warning.
test/dm/eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
test/dm/eth.c +1 -1
@@ -187,6 +187,6 @@ static int dm_test_net_retry(struct unit_test_state *uts)setenv ("netretry" ,NULL );sandbox_eth_disable_response (1 , false); -return 0 ; +return retval; }DM_TEST (dm_test_net_retry,DM_TESTF_SCAN_FDT );
Signature · 1 line
1.7.11.5
PATCH 1/2 sandbox: Use defconfig to enable features
In reply to Joe HershbergerHi Joe,
Quoted 13 lines · Joe Hershberger
Stop using the sandbox arch
Kconfigto override defaults for config options. This is a bit of abuse and may be causing build problems.Signed-off-by Joe Hershberger <[email protected]>---
The errors you are seeing are the result of "CONFIG_UNIT_TEST" not being defined. That should not be at all related to thattest/dm/eth.cpatch. This is changing the way thatCONFIG_UNIT_TESTis enabled to be more typical in case there is some bad behavior with all this override of defaults. I have seen some non-ideal behavior, so I want to move away from using it.
Please apply this on top of u-boot-dm/env-working and try it.
Quoted 3 lines
arch/sandbox/Kconfig | 18 ------------------ configs/sandbox_defconfig | 5 +++++ 2 files changed, 5 insertions(+), 18 deletions(-)
I should have mentioned that the errors are fixed by a later patch:
61: test: dm: Move the dm tests over to the ut command
So should I merge this change into one of your existing patches for testing?
BTW this series does have some driver model things but most of it is not, so perhaps Tom plans to apply it?
Regards,
Simon
PATCH 1/2 sandbox: Use defconfig to enable features
Hi Simon,
Quoted 16 lines · Simon Glass
Hi Joe,
Quoted 13 lines · Joe Hershberger
Stop using the sandbox arch
Kconfigto override defaults for config options. This is a bit of abuse and may be causing build problems.Signed-off-by Joe Hershberger <[email protected]>---
The errors you are seeing are the result of "CONFIG_UNIT_TEST" not being defined. That should not be at all related to thattest/dm/eth.cpatch. This is changing the way thatCONFIG_UNIT_TESTis enabled to be more typical in case there is some bad behavior with all this override of defaults. I have seen some non-ideal behavior, so I want to move away from using it.
Please apply this on top of u-boot-dm/env-working and try it.
Quoted 5 lines
Quoted 3 lines
arch/sandbox/Kconfig | 18 ------------------ configs/sandbox_defconfig | 5 +++++ 2 files changed, 5 insertions(+), 18 deletions(-)I should have mentioned that the errors are fixed by a later patch:
I see. I didn't realize you were saying it was a bisectability issue. It's odd that on your machine buildman told you it broke at "test: dm:
eth: Handle failed test env cleanup"
When I bisect it the failure happens at "test: Move the unit tests to their own menu". I actually finally got my build machine in a state where buildman can run there and it also claims that this ("test: Move the unit tests to their own menu") is the patch that breaks.
Quoted 1 line
61: test: dm: Move the dm tests over to the ut command
This is the patch that fixes it for me also.
Quoted 1 line
So should I merge this change into one of your existing patches for testing?
No... I've reordered a few patches to fix the bisectability and also make the changes simpler. I'll send a new version that passes buildman on my machine. It's nice to finally have buildman working. I like it better than MAKEALL, but it is more complicated with more requirements that were surprising.
Quoted 2 lines
BTW this series does have some driver model things but most of it is not, so perhaps Tom plans to apply it?
I asked Tom in reply to the summary email of this series. Haven't heard back. It also has some net things (but not mostly) that instigated the series, so I could apply it too. Waiting to hear from Tom.
Thanks,
-Joe
PATCH v3 19/26 test: Return values from the asserts compatible with cmds
In reply to Joe HershbergerThe asserts are sometimes called from the context of the test command itself so make sure that a return that happens as a result of a failure is compatible with that command return. When called within a test, the return value is ignored.
---
Changes in v3: None
Changes in v2:
-New for version 2
include/test/ut.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
include/test/ut.h +6 -6
@@ -42,7 +42,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,#define ut_assert (cond) \ if (!(cond)) { \ ut_fail(uts, __FILE__, __LINE__, __func__, #cond); \ - return -1; \ + return CMD_RET_FAILURE; \ }/* Assert that a condition is non-zero, with printf() string */
@@ -50,7 +50,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,if (!(cond)) { \ ut_failf(uts, __FILE__, __LINE__, __func__, #cond, \ fmt, ##args); \ -return -1 ; \ +return CMD_RET_FAILURE ; \ }/* Assert that two int expressions are equal */
@@ -61,7 +61,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,ut_failf (uts, __FILE__, __LINE__, __func__, \ #expr1 " == " #expr2, \"Expected %d, got %d" , val1, val2); \ -return -1 ; \ +return CMD_RET_FAILURE ; \ } \ }
@@ -73,7 +73,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,ut_failf (uts, __FILE__, __LINE__, __func__, \ #expr1 " = " #expr2, \"Expected \"%s\", got \"%s\"" , val1, val2); \ -return -1 ; \ +return CMD_RET_FAILURE ; \ } \ }
@@ -85,7 +85,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,ut_failf (uts, __FILE__, __LINE__, __func__, \ #expr1 " = " #expr2, \"Expected %p, got %p" , val1, val2); \ -return -1 ; \ +return CMD_RET_FAILURE ; \ } \ }
@@ -97,7 +97,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,ut_failf (uts, __FILE__, __LINE__, __func__, \ #expr " = NULL", \"Expected non-null, got NULL" ); \ -return -1 ; \ +return CMD_RET_FAILURE ; \ } \ }
Signature · 1 line
1.7.11.5
PATCH v3 20/26 test: dm: Recover the driver model tree after tests
In reply to Joe HershbergerPut the driver model for the system back into a good state after completing the DM testing.
---
Changes in v3:
-New for version 3
Changes in v2: None
test/dm/test-main.c | 5 +++++ 1 file changed, 5 insertions(+)
test/dm/test-main.c +5 -0
@@ -111,5 +111,10 @@ int dm_test_main(const char *test_name)printf ("Failures: %d\n" , uts->fail_count); + gd->dm_root =NULL ; +ut_assertok (dm_init ()); +dm_scan_platdata (false); +dm_scan_fdt (gd->fdt_blob, false); +return uts->fail_count ?CMD_RET_FAILURE :0 ; }
Signature · 1 line
1.7.11.5
PATCH v3 20/26 test: dm: Recover the driver model tree after tests
Quoted 6 lines · Joe Hershberger
Put the driver model for the system back into a good state after completing the DM testing.
Signed-off-by Joe Hershberger <[email protected]>---
Quoted 7 lines
Changes in v3:
-New for version 3Changes in v2: None
test/dm/test-main.c | 5 +++++ 1 file changed, 5 insertions(+)
PATCH v3 21/26 test: env: Add test framework for env
In reply to Joe HershbergerAdd a new "env" subcommand to the ut command.
This will run unit tests on the env code. This should be targetable to any device that supports the env features needed for the tests.
---
Changes in v3:
-Moved test from env subcommand to ut subcommand
Changes in v2:
-New for version 2
Makefile | 1 + include/test/env.h | 16 ++++++++++++++++ include/test/suites.h | 2 ++ test/Kconfig | 1 + test/cmd_ut.c | 6 ++++++ test/env/Kconfig | 8 ++++++++ test/env/Makefile | 7 +++++++ test/env/cmd_ut_env.c | 37 +++++++++++++++++++++++++++++++++++++ 8 files changed, 78 insertions(+) create mode 100644 include/test/env.h create mode 100644 test/env/Kconfig create mode 100644 test/env/Makefile create mode 100644 test/env/cmd_ut_env.c
Makefile +1 -0
@@ -665,6 +665,7 @@ libs-$(CONFIG_API) += api/ libs-$(CONFIG_HAS_POST) += post/ libs-y += test/ libs-y += test/dm/ +libs-$(CONFIG_UT_ENV) += test/env/ libs-y += $(if $(BOARDDIR),board/$(BOARDDIR)/)
include/test/env.h new file +16 -0
@@ -0,0 +1,16 @@ +/* +* (C) Copyright 2015 +* Joe Hershberger, National Instruments, joe.hershberger at ni.com +* +* SPDX-License-Identifier: GPL-2.0 +*/ + +#ifndef __TEST_ENV_H__ +#define __TEST_ENV_H__ + +#include <test/test.h> + +/* Declare a new environment test */ +#define ENV_TEST (_name, _flags) UNIT_TEST(_name, _flags, env_test) + +#endif /* __TEST_ENV_H__ */
include/test/suites.h +2 -0
@@ -8,4 +8,6 @@#ifndef __TEST_SUITES_H__#define __TEST_SUITES_H__ +int do_ut_env (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]); +#endif /* __TEST_SUITES_H__ */
test/Kconfig +1 -0
@@ -5,3 +5,4 @@ menuconfig UNIT_TEST U-Boot. Test suites will be subcommands of the "ut" command. source "test/dm/Kconfig" +source "test/env/Kconfig"
test/cmd_ut.c +6 -0
@@ -13,6 +13,9 @@ static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);static cmd_tbl_t cmd_ut_sub[] = {U_BOOT_CMD_MKENT (all,CONFIG_SYS_MAXARGS ,1 , do_ut_all,"" ,"" ), +#if defined(CONFIG_UT_ENV) +U_BOOT_CMD_MKENT (env,CONFIG_SYS_MAXARGS ,1 , do_ut_env,"" ,"" ), +#endif };static int do_ut_all (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[])
@@ -53,6 +56,9 @@ static int do_ut(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])#ifdef CONFIG_SYS_LONGHELP static char ut_help_text[] ="all - execute all enabled tests\n" +#ifdef CONFIG_UT_ENV +"ut env [test-name]\n" +#endif ;#endif
test/env/Kconfig new file +8 -0
@@ -0,0 +1,8 @@ +config UT_ENV + bool "Enable env unit tests" + depends on UNIT_TEST + help + This enables the 'ut env' command which runs a series of unit + tests on the env code. + If all is well then all tests pass although there will be a few + messages printed along the way.
test/env/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# +# Copyright (c) 2015 National Instruments, Inc +# +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-y += cmd_ut_env.o
test/env/cmd_ut_env.c new file +37 -0
@@ -0,0 +1,37 @@ +/* +* (C) Copyright 2015 +* Joe Hershberger, National Instruments, joe.hershberger at ni.com +* +* SPDX-License-Identifier: GPL-2.0 +*/ + +#include <common.h> +#include <command.h> +#include <test/env.h> +#include <test/suites.h> +#include <test/ut.h> + +int do_ut_env (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ + struct unit_test *tests = ll_entry_start(struct unit_test, env_test); + const int n_ents = ll_entry_count(struct unit_test, env_test); +struct unit_test_state uts = { .fail_count =0 }; +struct unit_test *test; + +if (argc ==1 ) +printf ("Running %d environment tests\n" , n_ents); + +for (test = tests; test < tests + n_ents; test++) { +if (argc >1 &&strcmp (argv[1 ], test->name)) +continue ; +printf ("Test: %s\n" , test->name); + + uts.start =mallinfo (); + + test->func (&uts); + } + +printf ("Failures: %d\n" , uts.fail_count); + +return uts.fail_count ?CMD_RET_FAILURE :0 ; +}
Signature · 1 line
1.7.11.5
PATCH v3 22/26 test: env: Add test for verifying env attrs
In reply to Joe HershbergerAdd a test of the env_attr_lookup() function.
---
Changes in v3: None
Changes in v2:
-New for version 2
test/env/Makefile | 1 + test/env/attr.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 test/env/attr.c
test/env/Makefile +1 -0
@@ -5,3 +5,4 @@ # obj-y += cmd_ut_env.o +obj-y += attr.o
test/env/attr.c new file +62 -0
62 lines not on this page · raw message
Signature · 1 line
1.7.11.5
PATCH v3 23/26 test: env: Add a test of the new regex behavior for attrs
In reply to Joe HershbergerThe behavior of the env attrs depends on CONFIG_REGEX. Add an additional test if that variable is set.
---
Changes in v3: None
Changes in v2:
-New for version 2
test/env/attr.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
test/env/attr.c +27 -0
@@ -60,3 +60,30 @@ static int env_test_attrs_lookup(struct unit_test_state *uts)return 0 ; }ENV_TEST (env_test_attrs_lookup,0 ); + +#ifdef CONFIG_REGEX +static int env_test_attrs_lookup_regex (struct unit_test_state *uts) +{ +char attrs[32 ]; + +ut_assertok (env_attr_lookup ("foo1?:bar" ,"foo" , attrs)); +ut_asserteq_str ("bar" , attrs); + +ut_assertok (env_attr_lookup ("foo1?:bar" ,"foo1" , attrs)); +ut_asserteq_str ("bar" , attrs); + +ut_assertok (env_attr_lookup (".foo:bar" ,".foo" , attrs)); +ut_asserteq_str ("bar" , attrs); + +ut_assertok (env_attr_lookup (".foo:bar" ,"ufoo" , attrs)); +ut_asserteq_str ("bar" , attrs); + +ut_assertok (env_attr_lookup ("\\.foo:bar" ,".foo" , attrs)); +ut_asserteq_str ("bar" , attrs); + +ut_asserteq (-ENOENT ,env_attr_lookup ("\\.foo:bar" ,"ufoo" , attrs)); + +return 0 ; +} +ENV_TEST (env_test_attrs_lookup_regex,0 ); +#endif
Signature · 1 line
1.7.11.5
PATCH v3 24/26 test: dm: Move the dm tests over to the ut command
In reply to Joe HershbergerUnify the command for running unit tests further by moving the "dm test" command over to "ut dm".
---
Changes in v3:
-New for version 3
Changes in v2: None
arch/sandbox/Kconfig | 5 ++++- include/dm/test.h | 11 ----------- include/test/suites.h | 1 + test/cmd_ut.c | 6 ++++++ test/dm/Kconfig | 8 ++++---- test/dm/Makefile | 12 ++++++------ test/dm/cmd_dm.c | 21 --------------------- test/dm/test-dm.sh | 2 +- test/dm/test-main.c | 13 ++++++++++++- 9 files changed, 34 insertions(+), 45 deletions(-)
arch/sandbox/Kconfig +4 -1
@@ -10,7 +10,10 @@ config SYS_BOARD config SYS_CONFIG_NAME default "sandbox" -config DM_TEST +config UNIT_TEST + default y + +config UT_DM default y config PCI
include/dm/test.h +0 -11
@@ -202,15 +202,4 @@ void dm_leak_check_start(struct unit_test_state *uts);* @dms: Overall test state */ int dm_leak_check_end (struct unit_test_state *uts); - -/** -* dm_test_main() - Run all or one of the tests -* -* This runs all available driver model tests, or a selected one -* -* @test_name: Name of test to run, or NULL for all -* @return 0 if OK, -ve on error -*/ -int dm_test_main (const char *test_name); -#endif
include/test/suites.h +1 -0
@@ -8,6 +8,7 @@#ifndef __TEST_SUITES_H__#define __TEST_SUITES_H__ +int do_ut_dm (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]);int do_ut_env (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]);#endif /* __TEST_SUITES_H__ */
test/cmd_ut.c +6 -0
@@ -13,6 +13,9 @@ static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);static cmd_tbl_t cmd_ut_sub[] = {U_BOOT_CMD_MKENT (all,CONFIG_SYS_MAXARGS ,1 , do_ut_all,"" ,"" ), +#if defined(CONFIG_UT_DM) +U_BOOT_CMD_MKENT (dm,CONFIG_SYS_MAXARGS ,1 , do_ut_dm,"" ,"" ), +#endif #if defined(CONFIG_UT_ENV)U_BOOT_CMD_MKENT (env,CONFIG_SYS_MAXARGS ,1 , do_ut_env,"" ,"" ), #endif
@@ -56,6 +59,9 @@ static int do_ut(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])#ifdef CONFIG_SYS_LONGHELP static char ut_help_text[] ="all - execute all enabled tests\n" +#ifdef CONFIG_UT_DM + "ut dm [test-name]\n" +#endif #ifdef CONFIG_UT_ENV "ut env [test-name]\n" #endif
test/dm/Kconfig +4 -4
@@ -1,8 +1,8 @@ -config DM_TEST - bool "Enable driver model test command" - depends on SANDBOX && CMD_DM && UNIT_TEST +config UT_DM + bool "Enable driver model unit test command" + depends on SANDBOX && UNIT_TEST help - This enables the 'dm test' command which runs a series of unit + This enables the 'ut dm' command which runs a series of unit tests on the driver model code. Each subsystem (uclass) is tested. If all is well then all tests pass although there will be a few messages printed along the way.
test/dm/Makefile +6 -6
@@ -5,15 +5,15 @@ # obj-$(CONFIG_CMD_DM) += cmd_dm.o -obj-$(CONFIG_DM_TEST) += bus.o -obj-$(CONFIG_DM_TEST) += test-driver.o -obj-$(CONFIG_DM_TEST) += test-fdt.o -obj-$(CONFIG_DM_TEST) += test-main.o -obj-$(CONFIG_DM_TEST) += test-uclass.o +obj-$(CONFIG_UT_DM) += bus.o +obj-$(CONFIG_UT_DM) += test-driver.o +obj-$(CONFIG_UT_DM) += test-fdt.o +obj-$(CONFIG_UT_DM) += test-main.o +obj-$(CONFIG_UT_DM) += test-uclass.o # Tests for particular subsystems - when enabling driver model for a new # subsystem you must add sandbox tests here. -obj-$(CONFIG_DM_TEST) += core.o +obj-$(CONFIG_UT_DM) += core.o ifneq ($(CONFIG_SANDBOX),) obj-$(CONFIG_DM_ETH) += eth.o obj-$(CONFIG_DM_GPIO) += gpio.o
test/dm/cmd_dm.c +0 -21
@@ -14,7 +14,6 @@#include <errno.h> #include <asm/io.h> #include <dm/root.h> -#include <dm/test.h> #include <dm/uclass-internal.h> static void show_devices (struct udevice *dev,int depth,int last_flag)
@@ -109,28 +108,9 @@ static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc,return 0 ; } -#ifdef CONFIG_DM_TEST -static int do_dm_test (cmd_tbl_t *cmdtp,int flag,int argc, -char *const argv[]) -{ -const char *test_name =NULL ; - -if (argc >0 ) - test_name = argv[0 ]; - -return dm_test_main (test_name); -} -#define TEST_HELP "\ndm test Run tests" -#else -#define TEST_HELP -#endif -static cmd_tbl_t test_commands[] = {U_BOOT_CMD_MKENT (tree,0 ,1 , do_dm_dump_all,"" ,"" ),U_BOOT_CMD_MKENT (uclass,1 ,1 , do_dm_dump_uclass,"" ,"" ), -#ifdef CONFIG_DM_TEST -U_BOOT_CMD_MKENT (test,1 ,1 , do_dm_test,"" ,"" ), -#endif };static int do_dm (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[])
@@ -157,5 +137,4 @@ U_BOOT_CMD("Driver model low level access" ,"tree Dump driver model tree ('*' = activated)\n" "dm uclass Dump list of instances for each uclass" -TEST_HELP );
test/dm/test-dm.sh +1 -1
@@ -12,6 +12,6 @@ make O=sandbox -s -j${NUM_CPUS} || die "Cannot build U-Boot" dd if=/dev/zero of=spi.bin bs=1M count=2 echo -n "this is a test" > testflash.bin dd if=/dev/zero bs=1M count=4 >>testflash.bin -./sandbox/u-boot -d test/dm/test.dtb -c "dm test" +./sandbox/u-boot -d test/dm/test.dtb -c "ut dm" rm spi.bin rm testflash.bin
test/dm/test-main.c +12 -1
@@ -5,6 +5,7 @@*/ #include <common.h> +#include <command.h> #include <dm.h> #include <errno.h> #include <malloc.h>
@@ -68,7 +69,7 @@ static int dm_test_destroy(struct unit_test_state *uts)return 0 ; } -int dm_test_main (const char *test_name) +static int dm_test_main (const char *test_name) { struct unit_test *tests = ll_entry_start(struct unit_test, dm_test); const int n_ents = ll_entry_count(struct unit_test, dm_test);
@@ -118,3 +119,13 @@ int dm_test_main(const char *test_name)return uts->fail_count ?CMD_RET_FAILURE :0 ; } + +int do_ut_dm (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +const char *test_name =NULL ; + +if (argc >1 ) + test_name = argv[1 ]; + +return dm_test_main (test_name); +}
Signature · 1 line
1.7.11.5
PATCH v3 24/26 test: dm: Move the dm tests over to the ut command
Quoted 11 lines · Joe Hershberger
Unify the command for running unit tests further by moving the "dm test" command over to "ut dm".
Signed-off-by Joe Hershberger <[email protected]>---
Changes in v3:
-New for version 3Changes in v2: None
Quoted 10 lines
arch/sandbox/Kconfig | 5 ++++- include/dm/test.h | 11 ----------- include/test/suites.h | 1 + test/cmd_ut.c | 6 ++++++ test/dm/Kconfig | 8 ++++---- test/dm/Makefile | 12 ++++++------ test/dm/cmd_dm.c | 21 --------------------- test/dm/test-dm.sh | 2 +- test/dm/test-main.c | 13 ++++++++++++- 9 files changed, 34 insertions(+), 45 deletions(-)
PATCH v3 25/26 sandbox: Cleanup order and extra defines in defconfig
In reply to Joe HershbergerThe defconfigs should not be edited directly. They should be generated by editing the .config (through menuconfig or whatever) and then run make savedefconfig to have the Kconfig system generate a clean defconfig
I did this for sandbox here with no actual changes.
---
Changes in v3: None
Changes in v2:
-New for version 2
configs/sandbox_defconfig | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
configs/sandbox_defconfig +18 -18
@@ -1,28 +1,28 @@ -CONFIG_OF_CONTROL=y -CONFIG_OF_HOSTFILE=y +CONFIG_DM_USB=y +CONFIG_PCI=y +CONFIG_SYS_VSNPRINTF=y +CONFIG_DEFAULT_DEVICE_TREE="sandbox" +CONFIG_BOOTSTAGE=y +CONFIG_BOOTSTAGE_REPORT=y CONFIG_FIT=y CONFIG_FIT_VERBOSE=y CONFIG_FIT_SIGNATURE=y -CONFIG_DEFAULT_DEVICE_TREE="sandbox" +CONFIG_CMD_SOUND=y +CONFIG_OF_CONTROL=y +CONFIG_OF_HOSTFILE=y +CONFIG_DM_PCI=y +CONFIG_PCI_SANDBOX=y +CONFIG_SPI_FLASH_SANDBOX=y +CONFIG_CMD_CROS_EC=y CONFIG_CROS_EC=y CONFIG_CROS_EC_SANDBOX=y CONFIG_CROS_EC_KEYB=y -CONFIG_CMD_CROS_EC=y -CONFIG_PCI=y -CONFIG_DM_PCI=y -CONFIG_PCI_SANDBOX=y -CONFIG_USB=y -CONFIG_DM_USB=y -CONFIG_USB_EMUL=y -CONFIG_USB_STORAGE=y -CONFIG_BOOTSTAGE=y -CONFIG_BOOTSTAGE_REPORT=y -CONFIG_SANDBOX_GPIO=y -CONFIG_SYS_VSNPRINTF=y +CONFIG_TPM_TIS_SANDBOX=y CONFIG_SYS_I2C_SANDBOX=y CONFIG_SANDBOX_SPI=y -CONFIG_SPI_FLASH_SANDBOX=y -CONFIG_TPM_TIS_SANDBOX=y +CONFIG_SANDBOX_GPIO=y CONFIG_SOUND=y -CONFIG_CMD_SOUND=y CONFIG_SOUND_SANDBOX=y +CONFIG_USB=y +CONFIG_USB_EMUL=y +CONFIG_USB_STORAGE=y
Signature · 1 line
1.7.11.5
PATCH v3 26/26 sandbox: Enable env unit tests
In reply to Joe HershbergerEnable the new env unit tests on sandbox.
---
Changes in v3: None
Changes in v2:
-New for version 2
configs/sandbox_defconfig | 1 + 1 file changed, 1 insertion(+)
configs/sandbox_defconfig +1 -0
@@ -26,3 +26,4 @@ CONFIG_SOUND_SANDBOX=y CONFIG_USB=y CONFIG_USB_EMUL=y CONFIG_USB_STORAGE=y +CONFIG_UT_ENV=y
Signature · 1 line
1.7.11.5
v3 cover Improve env var handling for net stack
In reply to Joe HershbergerHi Tom,
Quoted 43 lines · Joe Hershberger
This includes moving
CONFIG_REGEXtoKconfigand adding support for regex to theenv_attrlists (whenCONFIG_REGEXis enabled).This allows ethaddrs to all be checked for access and format by default. Also use callbacks to keep network stack variables up to date instead of polling them on each call to
net_loop.This is a step in the right direction to refactoring the network stack to be similar to that of barebox.
Also added a test command to host unit tests for the env functions.
Changes in v3:
(quoted diff) +0
-2-Moved test from env subcommand to ut subcommand -New for version 3Changes in v2:
(quoted diff) +0
-6-Added comments about the use of .flags in the dm eth test -Added description to README -Fix bisectability issue -Fix corner case in reverse_name_search() where searched starts with ' ' -New for version 2 -Simplified test for H_PROGRAMMATICJoe Hershberger (26):
sandbox: Enable some ENV commands
kconfig: Move REGEX toKconfig
sandbox: Enable regex support
env: Fix return values inenv_attr_lookup()
env: Simplify thereverse_strstr()interface
env: Allowenv_attr_walkto pass a priv * to callback
env: Add regex support toenv_attrs
env: Distinguish finer between source of env change
net: Apply default format rules to all ethaddr
net: Use env callbacks for net variables
net: Add default flags for common net env vars
net: Remove duplicate bootfile syncing functionality
net: Handle ethaddr changes as an env callback
test: Generalize the unit test framework
test: Add a common unit test command
test: Move the unit tests to their own menu
test: dm: Don't bail on all tests if one test fails
test: dm: eth: Handle failed test env cleanup
Quoted 8 lines
test: Return values from the asserts compatible with cmds
test: dm: Recover the driver model tree after tests
test: env: Add test framework for env
test: env: Add test for verifying env attrs
test: env: Add a test of the new regex behavior for attrs
test: dm: Move the dm tests over to the ut command
sandbox: Cleanup order and extra defines in defconfig
sandbox: Enable env unit tests
Would you prefer this to go through u-boot/net or would you prefer to pull it in directly? It has a fair amount of env and test changes.
Speaking of, are you the maintainer of the "env" area of the code? Wolfgang used to comment on it primarily, so I don't know if that role went to you along with mainline.
Please let me know... Thanks,
-Joe
v4 cover Improve env var handling for net stack
In reply to Joe HershbergerThis includes moving CONFIG_REGEX to Kconfig and adding support for regex to the env_attr lists (when CONFIG_REGEX is enabled).
This allows ethaddrs to all be checked for access and format by default. Also use callbacks to keep network stack variables up to date instead of polling them on each call to net_loop.
This is a step in the right direction to refactoring the network stack to be similar to that of barebox.
Also added a test command to host unit tests for the env functions.
Changes in v4:
-Fixed bisectability issue
-New for version 4
Changes in v3:
-Moved test from env subcommand to ut subcommand
-New for version 3
Changes in v2:
-Added comments about the use of .flags in the dm eth test -Added description to README
-Fix bisectability issue
-Fix corner case in reverse_name_search() where searched starts with ' ' -New for version 2
-Simplified test for H_PROGRAMMATIC
Joe Hershberger (26):
sandbox: Cleanup order and extra defines in defconfig
sandbox: Use defconfig to enable features
sandbox: Enable some ENV commands
kconfig: Move REGEX to Kconfig
env: Fix return values in env_attr_lookup()
env: Simplify the reverse_strstr() interface
env: Allow env_attr_walk to pass a priv * to callback
env: Add regex support to env_attrs
env: Distinguish finer between source of env change
net: Apply default format rules to all ethaddr
net: Use env callbacks for net variables
net: Add default flags for common net env vars
net: Remove duplicate bootfile syncing functionality
net: Handle ethaddr changes as an env callback
test: Generalize the unit test framework
test: Add a common unit test command
test: dm: Move the dm tests over to the ut command
test: Move the unit tests to their own menu
test: dm: Don't bail on all tests if one test fails
test: dm: eth: Handle failed test env cleanup
test: Return values from the asserts compatible with cmds
test: dm: Recover the driver model tree after tests
test: env: Add test framework for env
test: env: Add test for verifying env attrs
test: env: Add a test of the new regex behavior for attrs
sandbox: Enable env unit tests
Makefile | 1 +
README | 8 ++
arch/sandbox/Kconfig | 15 ---
common/cmd_nvedit.c | 36 +++++---
common/env_attr.c | 181 ++++++++++++++++++++++++++++---------
common/env_callback.c | 6 +-
common/env_flags.c | 6 +-
configs/acadia_defconfig | 1 +
configs/bamboo_defconfig | 1 +
configs/bubinga_defconfig | 1 +
configs/canyonlands_defconfig | 1 +
configs/dlvision-10g_defconfig | 1 +
configs/dlvision_defconfig | 1 +
configs/ebony_defconfig | 1 +
configs/gdppc440etx_defconfig | 1 +
configs/icon_defconfig | 1 +
configs/intip_defconfig | 1 +
configs/io64_defconfig | 1 +
configs/io_defconfig | 1 +
configs/iocon_defconfig | 1 +
configs/katmai_defconfig | 1 +
configs/kilauea_defconfig | 1 +
configs/luan_defconfig | 1 +
configs/m28evk_defconfig | 1 +
configs/m53evk_defconfig | 1 +
configs/makalu_defconfig | 1 +
configs/neo_defconfig | 1 +
configs/novena_defconfig | 1 +
configs/ocotea_defconfig | 1 +
configs/redwood_defconfig | 1 +
configs/sandbox_defconfig | 42 +++++----
configs/sequoia_defconfig | 1 +
configs/socfpga_arria5_defconfig | 1 +
configs/socfpga_cyclone5_defconfig | 1 +
configs/t3corp_defconfig | 1 +
configs/taihu_defconfig | 1 +
configs/taishan_defconfig | 1 +
configs/walnut_defconfig | 1 +
configs/yosemite_defconfig | 1 +
configs/yucca_defconfig | 1 +
include/configs/amcc-common.h | 1 -
include/configs/m28evk.h | 1 -
include/configs/m53evk.h | 1 -
include/configs/novena.h | 1 -
include/configs/sandbox.h | 5 +
include/configs/socfpga_arria5.h | 1 -
include/configs/socfpga_cyclone5.h | 1 -
include/dm/test.h | 46 ++--------
include/env_attr.h | 10 +-
include/env_callback.h | 33 ++++++-
include/env_flags.h | 23 ++++-
include/search.h | 2 +
include/test/env.h | 16 ++++
include/test/suites.h | 14 +++
include/test/test.h | 47 ++++++++++
include/{dm => test}/ut.h | 40 ++++----
lib/Kconfig | 8 ++
net/Kconfig | 1 +
net/eth.c | 95 ++++++++++++-------
net/net.c | 105 +++++++++++++++++----
test/Kconfig | 7 ++
test/Makefile | 2 +
test/cmd_ut.c | 74 +++++++++++++++
test/dm/Kconfig | 8 +-
test/dm/Makefile | 14 ++-
test/dm/bus.c | 39 ++++----
test/dm/cmd_dm.c | 21 -----
test/dm/core.c | 74 ++++++++-------
test/dm/eth.c | 88 ++++++++++++------
test/dm/gpio.c | 22 ++---
test/dm/i2c.c | 20 ++--
test/dm/pci.c | 6 +-
test/dm/sf.c | 4 +-
test/dm/spi.c | 8 +-
test/dm/test-dm.sh | 2 +-
test/dm/test-driver.c | 6 +-
test/dm/test-fdt.c | 16 ++--
test/dm/test-main.c | 55 +++++++----
test/dm/test-uclass.c | 7 +-
test/dm/usb.c | 6 +-
test/env/Kconfig | 8 ++
test/env/Makefile | 8 ++
test/env/attr.c | 89 ++++++++++++++++++
test/env/cmd_ut_env.c | 37 ++++++++
test/{dm => }/ut.c | 16 ++--
85 files changed, 1006 insertions(+), 409 deletions(-)
create mode 100644 include/test/env.h
create mode 100644 include/test/suites.h
create mode 100644 include/test/test.h
rename include/{dm => test}/ut.h (73%)
create mode 100644 test/cmd_ut.c
create mode 100644 test/env/Kconfig
create mode 100644 test/env/Makefile
create mode 100644 test/env/attr.c
create mode 100644 test/env/cmd_ut_env.c
rename test/{dm => }/ut.c (59%)Signature · 1 line
1.7.11.5
PATCH v4 1/26 sandbox: Cleanup order and extra defines in defconfig
The defconfigs should not be edited directly. They should be generated by editing the .config (through menuconfig or whatever) and then run make savedefconfig to have the Kconfig system generate a clean defconfig
I did this for sandbox here with no actual changes.
---
Changes in v4: None
Changes in v3: None
Changes in v2:
-New for version 2
configs/sandbox_defconfig | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
configs/sandbox_defconfig +18 -18
@@ -1,28 +1,28 @@ -CONFIG_OF_CONTROL=y -CONFIG_OF_HOSTFILE=y +CONFIG_DM_USB=y +CONFIG_PCI=y +CONFIG_SYS_VSNPRINTF=y +CONFIG_DEFAULT_DEVICE_TREE="sandbox" +CONFIG_BOOTSTAGE=y +CONFIG_BOOTSTAGE_REPORT=y CONFIG_FIT=y CONFIG_FIT_VERBOSE=y CONFIG_FIT_SIGNATURE=y -CONFIG_DEFAULT_DEVICE_TREE="sandbox" +CONFIG_CMD_SOUND=y +CONFIG_OF_CONTROL=y +CONFIG_OF_HOSTFILE=y +CONFIG_DM_PCI=y +CONFIG_PCI_SANDBOX=y +CONFIG_SPI_FLASH_SANDBOX=y +CONFIG_CMD_CROS_EC=y CONFIG_CROS_EC=y CONFIG_CROS_EC_SANDBOX=y CONFIG_CROS_EC_KEYB=y -CONFIG_CMD_CROS_EC=y -CONFIG_PCI=y -CONFIG_DM_PCI=y -CONFIG_PCI_SANDBOX=y -CONFIG_USB=y -CONFIG_DM_USB=y -CONFIG_USB_EMUL=y -CONFIG_USB_STORAGE=y -CONFIG_BOOTSTAGE=y -CONFIG_BOOTSTAGE_REPORT=y -CONFIG_SANDBOX_GPIO=y -CONFIG_SYS_VSNPRINTF=y +CONFIG_TPM_TIS_SANDBOX=y CONFIG_SYS_I2C_SANDBOX=y CONFIG_SANDBOX_SPI=y -CONFIG_SPI_FLASH_SANDBOX=y -CONFIG_TPM_TIS_SANDBOX=y +CONFIG_SANDBOX_GPIO=y CONFIG_SOUND=y -CONFIG_CMD_SOUND=y CONFIG_SOUND_SANDBOX=y +CONFIG_USB=y +CONFIG_USB_EMUL=y +CONFIG_USB_STORAGE=y
Signature · 1 line
1.7.11.5
PATCH v4 2/26 sandbox: Use defconfig to enable features
In reply to Joe HershbergerStop using the sandbox arch Kconfig to override defaults for config options. This is a bit of abuse and may be causing build problems.
---
Changes in v4:
-New for version 4
Changes in v3: None
Changes in v2: None
arch/sandbox/Kconfig | 15 --------------- configs/sandbox_defconfig | 4 ++++ 2 files changed, 4 insertions(+), 15 deletions(-)
arch/sandbox/Kconfig +0 -15
@@ -10,9 +10,6 @@ config SYS_BOARD config SYS_CONFIG_NAME default "sandbox" -config DM_TEST - default y - config PCI bool "PCI support" help
@@ -20,16 +17,4 @@ config PCI used on some devices to allow the CPU to communicate with its peripherals. -config NET - default y - -config NETDEVICES - default y - -config DM_ETH - default y - -config ETH_SANDBOX_RAW - default y - endmenu
configs/sandbox_defconfig +4 -0
@@ -10,12 +10,15 @@ CONFIG_FIT_SIGNATURE=y CONFIG_CMD_SOUND=y CONFIG_OF_CONTROL=y CONFIG_OF_HOSTFILE=y +CONFIG_NET=y CONFIG_DM_PCI=y CONFIG_PCI_SANDBOX=y CONFIG_SPI_FLASH_SANDBOX=y CONFIG_CMD_CROS_EC=y CONFIG_CROS_EC=y CONFIG_CROS_EC_SANDBOX=y +CONFIG_DM_ETH=y +CONFIG_NETDEVICES=y CONFIG_CROS_EC_KEYB=y CONFIG_TPM_TIS_SANDBOX=y CONFIG_SYS_I2C_SANDBOX=y
@@ -26,3 +29,4 @@ CONFIG_SOUND_SANDBOX=y CONFIG_USB=y CONFIG_USB_EMUL=y CONFIG_USB_STORAGE=y +CONFIG_DM_TEST=y
Signature · 1 line
1.7.11.5
PATCH v4 2/26 sandbox: Use defconfig to enable features
Quoted 9 lines · Joe Hershberger
Stop using the sandbox arch
Kconfigto override defaults for config options. This is a bit of abuse and may be causing build problems.Signed-off-by Joe Hershberger <[email protected]>---
Changes in v4:
-New for version 4
Quoted 6 lines
Changes in v3: None
Changes in v2: Nonearch/sandbox/Kconfig | 15 --------------- configs/sandbox_defconfig | 4 ++++ 2 files changed, 4 insertions(+), 15 deletions(-)
PATCH v4 3/26 sandbox: Enable some ENV commands
In reply to Joe HershbergerEnable some additional ENV commands in sandbox to aid in build testing and run testing.
---
Changes in v4: None
Changes in v3: None
Changes in v2: None
include/configs/sandbox.h | 5 +++++ 1 file changed, 5 insertions(+)
include/configs/sandbox.h +5 -0
@@ -151,6 +151,11 @@#define CONFIG_CMD_SANDBOX +#define CONFIG_CMD_ENV_FLAGS +#define CONFIG_CMD_ENV_CALLBACK +#define CONFIG_CMD_GREPENV +#define CONFIG_CMD_ASKENV +#define CONFIG_BOOTARGS ""#define CONFIG_BOARD_LATE_INIT
Signature · 1 line
1.7.11.5
PATCH v4 4/26 kconfig: Move REGEX to Kconfig
In reply to Joe HershbergerHaving this as a Kconfig allows it to be a dependent feature.
---
Changes in v4: None
Changes in v3: None
Changes in v2: None
configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 - lib/Kconfig | 8 ++++++++ 39 files changed, 40 insertions(+), 6 deletions(-)
configs/acadia_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_ACADIA=y +CONFIG_REGEX=y
configs/bamboo_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_BAMBOO=y +CONFIG_REGEX=y
configs/bubinga_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_BUBINGA=y +CONFIG_REGEX=y
configs/canyonlands_defconfig +1 -0
@@ -5,3 +5,4 @@ CONFIG_CANYONLANDS=y CONFIG_DEFAULT_DEVICE_TREE="canyonlands" CONFIG_OF_CONTROL=y CONFIG_OF_EMBED=y +CONFIG_REGEX=y
configs/dlvision-10g_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_DLVISION_10G=y +CONFIG_REGEX=y
configs/dlvision_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_DLVISION=y +CONFIG_REGEX=y
configs/ebony_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_EBONY=y +CONFIG_REGEX=y
configs/gdppc440etx_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_GDPPC440ETX=y +CONFIG_REGEX=y
configs/icon_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_ICON=y +CONFIG_REGEX=y
configs/intip_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="INTIB" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_INTIP=y +CONFIG_REGEX=y
configs/io64_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IO64=y +CONFIG_REGEX=y
configs/io_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IO=y +CONFIG_REGEX=y
configs/iocon_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IOCON=y +CONFIG_REGEX=y
configs/katmai_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_KATMAI=y +CONFIG_REGEX=y
configs/kilauea_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="KILAUEA" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_KILAUEA=y +CONFIG_REGEX=y
configs/luan_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_LUAN=y +CONFIG_REGEX=y
configs/m28evk_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_SPL=y CONFIG_ARM=y CONFIG_TARGET_M28EVK=y +CONFIG_REGEX=y
configs/m53evk_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SPL=y CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/denx/m53evk/imximage.cfg" CONFIG_ARM=y CONFIG_TARGET_M53EVK=y +CONFIG_REGEX=y
configs/makalu_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_MAKALU=y +CONFIG_REGEX=y
configs/neo_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_NEO=y +CONFIG_REGEX=y
configs/novena_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SPL=y CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=arch/arm/imx-common/spl_sd.cfg,MX6Q" CONFIG_ARM=y CONFIG_TARGET_KOSAGI_NOVENA=y +CONFIG_REGEX=y
configs/ocotea_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_OCOTEA=y +CONFIG_REGEX=y
configs/redwood_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_REDWOOD=y +CONFIG_REGEX=y
configs/sequoia_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="SEQUOIA" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_SEQUOIA=y +CONFIG_REGEX=y
configs/socfpga_arria5_defconfig +1 -0
@@ -3,3 +3,4 @@ CONFIG_ARM=y CONFIG_TARGET_SOCFPGA_ARRIA5=y CONFIG_OF_CONTROL=y CONFIG_DEFAULT_DEVICE_TREE="socfpga_arria5_socdk" +CONFIG_REGEX=y
configs/socfpga_cyclone5_defconfig +1 -0
@@ -6,3 +6,4 @@ CONFIG_DEFAULT_DEVICE_TREE="socfpga_cyclone5_socdk" CONFIG_ETH_DESIGNWARE=y CONFIG_NETDEVICES=y CONFIG_NET=y +CONFIG_REGEX=y
configs/t3corp_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_T3CORP=y +CONFIG_REGEX=y
configs/taihu_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_TAIHU=y +CONFIG_REGEX=y
configs/taishan_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_TAISHAN=y +CONFIG_REGEX=y
configs/walnut_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_WALNUT=y +CONFIG_REGEX=y
configs/yosemite_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="YOSEMITE" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_YOSEMITE=y +CONFIG_REGEX=y
configs/yucca_defconfig +1 -0
@@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_YUCCA=y +CONFIG_REGEX=y
include/configs/amcc-common.h +0 -1
@@ -106,7 +106,6 @@#define CONFIG_LOADS_ECHO /* echo on for serial download */ #define CONFIG_SYS_LOADS_BAUD_CHANGE /* allow baudrate change */ -#define CONFIG_REGEX /* Enable regular expression support */ /* * BOOTP options */
include/configs/m28evk.h +0 -1
@@ -49,7 +49,6 @@#define CONFIG_CMD_USB #define CONFIG_VIDEO -#define CONFIG_REGEX /* Enable regular expression support */ /* Memory configuration */ #define CONFIG_NR_DRAM_BANKS 1/* 1 bank of DRAM */
include/configs/m53evk.h +0 -1
@@ -51,7 +51,6 @@#define CONFIG_CMD_USB #define CONFIG_VIDEO -#define CONFIG_REGEX /* Enable regular expression support */ /* * Memory configurations
include/configs/novena.h +0 -1
@@ -22,7 +22,6 @@#define CONFIG_KEYBOARD #define CONFIG_MXC_GPIO #define CONFIG_OF_LIBFDT -#define CONFIG_REGEX #define CONFIG_SYS_GENERIC_BOARD #define CONFIG_SYS_NO_FLASH
include/configs/socfpga_arria5.h +0 -1
@@ -37,7 +37,6 @@#define CONFIG_CMD_USB #define CONFIG_CMD_USB_MASS_STORAGE -#define CONFIG_REGEX /* Enable regular expression support */ /* Memory configurations */ #define PHYS_SDRAM_1_SIZE 0x40000000/* 1GiB on SoCDK */
include/configs/socfpga_cyclone5.h +0 -1
@@ -37,7 +37,6 @@#define CONFIG_CMD_USB #define CONFIG_CMD_USB_MASS_STORAGE -#define CONFIG_REGEX /* Enable regular expression support */ /* Memory configurations */ #define PHYS_SDRAM_1_SIZE 0x40000000/* 1GiB on SoCDK */
lib/Kconfig +8 -0
@@ -36,6 +36,14 @@ config SYS_VSNPRINTF Thumb-2, about 420 bytes). Enable this option for safety when using sprintf() with data you do not control. +config REGEX + bool "Enable regular expression support" + help + If this variable is defined, U-Boot is linked against the + SLRE (Super Light Regular Expression) library, which adds + regex support to some commands, for example "env grep" and + "setexpr". + source lib/rsa/Kconfig menu "Hashing Support"
Signature · 1 line
1.7.11.5
PATCH v4 5/26 env: Fix return values in env_attr_lookup()
In reply to Joe HershbergerThis function returned numbers for error codes. Change them to error codes.
---
Changes in v4: None
Changes in v3: None
Changes in v2: None
common/env_attr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
common/env_attr.c +3 -3
@@ -148,10 +148,10 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes)if (!attributes)/* bad parameter */ -return -1 ; +return -EINVAL ;if (!attr_list)/* list not found */ -return 1 ; +return -EINVAL ; entry =reverse_strstr (attr_list, name,NULL );while (entry !=NULL ) {
@@ -209,5 +209,5 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes) }/* not found in list */ -return 2 ; +return -ENOENT ; }
Signature · 1 line
1.7.11.5
PATCH v4 6/26 env: Simplify the reverse_strstr() interface
In reply to Joe HershbergerThe logic to find the whole matching name was split needlessly between the reverse_strstr function and its caller. Fully contain it to make the interface for calling it more consistent.
---
Changes in v4: None
Changes in v3: None
Changes in v2:
-Fix bisectability issue
-Fix corner case in reverse_name_search() where searched starts with ' '
common/env_attr.c | 87 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 47 insertions(+), 40 deletions(-)
common/env_attr.c +47 -40
@@ -109,33 +109,59 @@ int env_attr_walk(const char *attr_list, }/* -* Search for the last matching string in another string with the option to -* start looking at a certain point (i.e. ignore anything beyond that point). +* Search for the last exactly matching name in an attribute list */ -static char *reverse_strstr (const char *searched,const char *search_for, -const char *searched_start) +static int reverse_name_search (const char *searched,const char *search_for, +const char **result) { -char *result =NULL ; +int result_size =0 ; +const char *cur_searched = searched; -if (*search_for =='\0' ) -return (char *)searched; +if (result) + *result =NULL ; + +if (*search_for =='\0' ) { +if (result) + *result = searched; +return strlen (searched); + }for (;;) { -char *match =strstr (searched, search_for); - -/* -* Stop looking if no new match is found or looking past the -* searched_start pointer -*/ -if (match ==NULL || (searched_start !=NULL && - match +strlen (search_for) > searched_start)) +const char *match =strstr (cur_searched, search_for); +const char *prevch; +const char *nextch; + +/* Stop looking if no new match is found */ +if (match ==NULL )break ; - result = match; - searched = match +1 ; + prevch = match -1 ; + nextch = match +strlen (search_for); + +/* Skip spaces */ +while (*prevch ==' ' && prevch >= searched) + prevch--; +while (*nextch ==' ' ) + nextch++; + +/* Start looking past the current match so last is found */ + cur_searched = match +1 ; +/* Check for an exact match */ +if (match != searched && + *prevch !=ENV_ATTR_LIST_DELIM && + prevch != searched -1 ) +continue ; +if (*nextch !=ENV_ATTR_SEP && + *nextch !=ENV_ATTR_LIST_DELIM && + *nextch !='\0' ) +continue ; + +if (result) + *result = match; + result_size =strlen (search_for); } -return result; +return result_size; }/*
@@ -145,6 +171,7 @@ static char *reverse_strstr(const char *searched, const char *search_for,int env_attr_lookup (const char *attr_list,const char *name,char *attributes) {const char *entry =NULL ; +int entry_len;if (!attributes)/* bad parameter */
@@ -153,32 +180,12 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes)/* list not found */ return -EINVAL ; - entry =reverse_strstr (attr_list, name,NULL ); -while (entry !=NULL ) { -const char *prevch = entry -1 ; -const char *nextch = entry +strlen (name); - -/* Skip spaces */ -while (*prevch ==' ' ) - prevch--; -while (*nextch ==' ' ) - nextch++; - -/* check for an exact match */ -if ((entry == attr_list || - *prevch ==ENV_ATTR_LIST_DELIM ) && - (*nextch ==ENV_ATTR_SEP || - *nextch ==ENV_ATTR_LIST_DELIM || - *nextch =='\0' )) -break ; - - entry =reverse_strstr (attr_list, name, entry); - } + entry_len =reverse_name_search (attr_list, name, &entry);if (entry !=NULL ) {int len;/* skip the name */ - entry +=strlen (name); + entry += entry_len;/* skip spaces */ while (*entry ==' ' ) entry++;
Signature · 1 line
1.7.11.5
PATCH v4 7/26 env: Allow env_attr_walk to pass a priv * to callback
In reply to Joe HershbergerIn some cases it can be helpful to have context in the callback about the calling situation. This is needed for following patches.
---
Changes in v4: None
Changes in v3: None
Changes in v2: None
common/cmd_nvedit.c | 10 ++++++---- common/env_attr.c | 5 +++-- common/env_callback.c | 6 +++--- common/env_flags.c | 6 +++--- include/env_attr.h | 10 +++++----- 5 files changed, 20 insertions(+), 17 deletions(-)
common/cmd_nvedit.c +6 -4
@@ -427,7 +427,8 @@ int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])#endif #if defined(CONFIG_CMD_ENV_CALLBACK ) -static int print_static_binding (const char *var_name,const char *callback_name) +static int print_static_binding (const char *var_name,const char *callback_name, +void *priv) {printf ("\t%-20s %-20s\n" , var_name, callback_name);
@@ -489,7 +490,7 @@ int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])puts ("Static callback bindings:\n" );printf ("\t%-20s %-20s\n" ,"Variable Name" ,"Callback Name" );printf ("\t%-20s %-20s\n" ,"-------------" ,"-------------" ); -env_attr_walk (ENV_CALLBACK_LIST_STATIC , print_static_binding); +env_attr_walk (ENV_CALLBACK_LIST_STATIC , print_static_binding,NULL );puts ("\n" );/* walk through each variable and print the callback if it has one */
@@ -502,7 +503,8 @@ int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])#endif #if defined(CONFIG_CMD_ENV_FLAGS ) -static int print_static_flags (const char *var_name,const char *flags) +static int print_static_flags (const char *var_name,const char *flags, +void *priv) {enum env_flags_vartype type =env_flags_parse_vartype (flags);enum env_flags_varaccess access =env_flags_parse_varaccess (flags);
@@ -559,7 +561,7 @@ int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) "Variable Access");printf ("\t%-20s %-20s %-20s\n" ,"-------------" ,"-------------" ,"---------------" ); -env_attr_walk (ENV_FLAGS_LIST_STATIC , print_static_flags); +env_attr_walk (ENV_FLAGS_LIST_STATIC , print_static_flags,NULL );puts ("\n" );/* walk through each variable and print the flags if non-default */
common/env_attr.c +3 -2
@@ -26,7 +26,8 @@* list = entry[,list] */ int env_attr_walk (const char *attr_list, -int (*callback)(const char *name,const char *attributes)) +int (*callback)(const char *name,const char *attributes,void *priv), +void *priv) {const char *entry, *entry_end;char *name, *attributes;
@@ -93,7 +94,7 @@ int env_attr_walk(const char *attr_list,if (strlen (name) !=0 ) {int retval =0 ; - retval =callback (name, attributes); + retval =callback (name, attributes, priv);if (retval) {free (entry_cpy);return retval;
common/env_callback.c +3 -3
@@ -90,7 +90,7 @@ static int clear_callback(ENTRY *entry)/* * Call for each element in the list that associates variables to callbacks */ -static int set_callback (const char *name,const char *value) +static int set_callback (const char *name,const char *value,void *priv) {ENTRY e, *ep;struct env_clbk_tbl *clbkp;
@@ -126,9 +126,9 @@ static int on_callbacks(const char *name, const char *value, enum env_op op,hwalk_r (&env_htab, clear_callback);/* configure any static callback bindings */ -env_attr_walk (ENV_CALLBACK_LIST_STATIC , set_callback); +env_attr_walk (ENV_CALLBACK_LIST_STATIC , set_callback,NULL );/* configure any dynamic callback bindings */ -env_attr_walk (value, set_callback); +env_attr_walk (value, set_callback,NULL );return 0 ; }
common/env_flags.c +3 -3
@@ -435,7 +435,7 @@ static int clear_flags(ENTRY *entry)/* * Call for each element in the list that defines flags for a variable */ -static int set_flags (const char *name,const char *value) +static int set_flags (const char *name,const char *value,void *priv) {ENTRY e, *ep;
@@ -463,9 +463,9 @@ static int on_flags(const char *name, const char *value, enum env_op op,hwalk_r (&env_htab, clear_flags);/* configure any static flags */ -env_attr_walk (ENV_FLAGS_LIST_STATIC , set_flags); +env_attr_walk (ENV_FLAGS_LIST_STATIC , set_flags,NULL );/* configure any dynamic flags */ -env_attr_walk (value, set_flags); +env_attr_walk (value, set_flags,NULL );return 0 ; }
include/env_attr.h +5 -5
@@ -16,13 +16,14 @@* attributes = [^,:\s]* * entry = name[:attributes] * list = entry[,list] -* It will call the "callback" function with the "name" and attribute as "value" +* It will call the "callback" function with the "name" and "attributes" * The callback may return a non-0 to abort the list walk. * This return value will be passed through to the caller. * 0 is returned on success. */ -extern int env_attr_walk (const char *attr_list, -int (*callback)(const char *name,const char *value)); +int env_attr_walk (const char *attr_list, +int (*callback)(const char *name,const char *attributes,void *priv), +void *priv);/* * env_attr_lookup takes as input an "attr_list" with the same form as above.
@@ -33,7 +34,6 @@ extern int env_attr_walk(const char *attr_list,* "attr_list" is NULL. * Returns 0 on success. */ -extern int env_attr_lookup (const char *attr_list,const char *name, -char *attributes); +int env_attr_lookup (const char *attr_list,const char *name,char *attributes);#endif /* __ENV_ATTR_H__ */
Signature · 1 line
1.7.11.5
PATCH v4 8/26 env: Add regex support to env_attrs
In reply to Joe HershbergerAllow the features that use env_attrs to specify regexs for the name
---
Changes in v4: None
Changes in v3: None
Changes in v2:
-Added description to README
README | 8 +++++ common/env_attr.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/env_callback.h | 10 ++++-- 3 files changed, 101 insertions(+), 2 deletions(-)
README +8 -0
@@ -4151,6 +4151,10 @@ Configuration Settings: list, simply add an entry for the same variable name to the ".flags" variable. + If CONFIG_REGEX is defined, the variable_name above is evaluated as a + regular expression. This allows multiple variables to define the same + flags without explicitly listing them for each variable. + - CONFIG_ENV_ACCESS_IGNORE_FORCE If defined, don't allow the -f switch to env set override variable access flags.
@@ -5549,6 +5553,10 @@ override any association in the static list. You can define CONFIG_ENV_CALLBACK_LIST_DEFAULT to a list (string) to define the ".callbacks" environment variable in the default or embedded environment. +If CONFIG_REGEX is defined, the variable_name above is evaluated as a +regular expression. This allows multiple variables to be connected to +the same callback without explicitly listing them all out. + Command Line Parsing: =====================
common/env_attr.c +85 -0
100 lines not on this page · raw message
include/env_callback.h +8 -2
@@ -31,12 +31,18 @@#define SPLASHIMAGE_CALLBACK #endif +#ifdef CONFIG_REGEX +#define ENV_DOT_ESCAPE "\\" +#else +#define ENV_DOT_ESCAPE +#endif +/* * This list of callback bindings is static, but may be overridden by defining * a new association in the ".callbacks" environment variable. */ -#define ENV_CALLBACK_LIST_STATIC ENV_CALLBACK_VAR ":callbacks," \ - ENV_FLAGS_VAR ":flags," \ +#define ENV_CALLBACK_LIST_STATIC ENV_DOT_ESCAPE ENV_CALLBACK_VAR ":callbacks," \ + ENV_DOT_ESCAPE ENV_FLAGS_VAR ":flags," \ "baudrate:baudrate," \ "bootfile:bootfile," \ "loadaddr:loadaddr," \
Signature · 1 line
1.7.11.5
PATCH v4 9/26 env: Distinguish finer between source of env change
In reply to Joe HershbergerWe already could tell the difference in the callback between an import and "other" which we called interactive. Now add further distinction between interactive (i.e. running env set / env edit / env ask / etc. from the U-Boot command line) and programmatic (i.e. when u-boot source calls any variant of setenv() ).
---
Changes in v4: None
Changes in v3: None
Changes in v2: None
common/cmd_nvedit.c | 26 +++++++++++++++++++------- include/search.h | 2 ++ 2 files changed, 21 insertions(+), 7 deletions(-)
common/cmd_nvedit.c +19 -7
@@ -208,12 +208,11 @@ DONE:* Set a new environment variable, * or replace or delete an existing one. */ -static int _do_env_set (int flag,int argc,char *const argv[]) +static int _do_env_set (int flag,int argc,char *const argv[],int env_flag) {int i, len;char *name, *value, *s;ENTRY e, *ep; -int env_flag =H_INTERACTIVE ;debug ("Initial value for argc=%d\n" , argc);while (argc >1 && **(argv +1 ) =='-' ) {
@@ -291,9 +290,9 @@ int setenv(const char *varname, const char *varvalue)return 1 ;if (varvalue ==NULL || varvalue[0 ] =='\0' ) -return _do_env_set (0 ,2 , (char *const *)argv); +return _do_env_set (0 ,2 , (char *const *)argv,H_PROGRAMMATIC );else -return _do_env_set (0 ,3 , (char *const *)argv); +return _do_env_set (0 ,3 , (char *const *)argv,H_PROGRAMMATIC ); }/**
@@ -347,7 +346,7 @@ static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])if (argc <2 )return CMD_RET_USAGE ; -return _do_env_set (flag, argc, argv); +return _do_env_set (flag, argc, argv,H_INTERACTIVE ); }/*
@@ -422,7 +421,7 @@ int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) }/* Continue calling setenv code */ -return _do_env_set (flag, len, local_args); +return _do_env_set (flag, len, local_args,H_INTERACTIVE ); }#endif
@@ -588,6 +587,10 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,if (argc <2 )return CMD_RET_USAGE ; +/* before import into hashtable */ +if (!(gd->flags &GD_FLG_ENV_READY )) +return 1 ; +/* Set read buffer to initial value or empty sting */ init_val =getenv (argv[1 ]);if (init_val)
@@ -598,7 +601,16 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,if (cli_readline_into_buffer ("edit: " , buffer,0 ) <0 )return 1 ; -return setenv (argv[1 ], buffer); +if (buffer[0 ] =='\0' ) { +const char *const _argv[3 ] = {"setenv" , argv[1 ],NULL }; + +return _do_env_set (0 ,2 , (char *const *)_argv,H_INTERACTIVE ); + }else { +const char *const _argv[4 ] = {"setenv" , argv[1 ], buffer, +NULL }; + +return _do_env_set (0 ,3 , (char *const *)_argv,H_INTERACTIVE ); + } }#endif /* CONFIG_CMD_EDITENV */ #endif /* CONFIG_SPL_BUILD */
include/search.h +2 -0
@@ -120,5 +120,7 @@ extern int hwalk_r(struct hsearch_data *__htab, int (*callback)(ENTRY *));#define H_MATCH_SUBSTR (1 << 7)/* search for substring matches */ #define H_MATCH_REGEX (1 << 8)/* search for regular expression matches */ #define H_MATCH_METHOD (H_MATCH_IDENT | H_MATCH_SUBSTR | H_MATCH_REGEX) +#define H_PROGRAMMATIC (1 << 9)/* indicate that an import is from setenv() */ +#define H_ORIGIN_FLAGS (H_INTERACTIVE | H_PROGRAMMATIC)#endif /* search.h */
Signature · 1 line
1.7.11.5
PATCH v4 10/26 net: Apply default format rules to all ethaddr
In reply to Joe HershbergerUse a regular expression to apply the default formatting flags for all ethaddr env vars.
---
Changes in v4: None
Changes in v3: None
Changes in v2:
-Added comments about the use of .flags in the dm eth test
include/env_flags.h | 11 ++++++++--- test/dm/eth.c | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-)
include/env_flags.h +8 -3
@@ -38,13 +38,18 @@ enum env_flags_varaccess {#endif #ifdef CONFIG_CMD_NET +#ifdef CONFIG_REGEX +#define ETHADDR_WILDCARD "\\d?" +#else +#define ETHADDR_WILDCARD +#endif #ifdef CONFIG_ENV_OVERWRITE -#define ETHADDR_FLAGS "ethaddr:ma," +#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:ma,"#else #ifdef CONFIG_OVERWRITE_ETHADDR_ONCE -#define ETHADDR_FLAGS "ethaddr:mc," +#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mc,"#else -#define ETHADDR_FLAGS "ethaddr:mo," +#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"#endif #endif #else
test/dm/eth.c +3 -0
@@ -89,6 +89,8 @@ static int dm_test_eth_rotate(struct dm_test_state *dms)/* Invalidate eth1's MAC address */ net_ping_ip =string_to_ip ("1.1.2.2" );strcpy (ethaddr,getenv ("eth1addr" )); +/* Must disable access protection for eth1addr before clearing */ +setenv (".flags" ,"eth1addr" );setenv ("eth1addr" ,NULL );/* Make sure that the default is to rotate to the next interface */
@@ -108,6 +110,7 @@ static int dm_test_eth_rotate(struct dm_test_state *dms)/* Invalidate eth0's MAC address */ strcpy (ethaddr,getenv ("ethaddr" )); +/* Must disable access protection for ethaddr before clearing */ setenv (".flags" ,"ethaddr" );setenv ("ethaddr" ,NULL );
Signature · 1 line
1.7.11.5
PATCH v4 11/26 net: Use env callbacks for net variables
In reply to Joe HershbergerInstead of checking for changes to the env each time we enter the net_loop, use the env callbacks to update the values of the variables. Don't update the variables when the source was programmatic, since the variables were the source of the new value.
---
Changes in v4: None
Changes in v3: None
Changes in v2:
-Simplified test for H_PROGRAMMATIC
include/env_callback.h | 22 ++++++++++- net/net.c | 105 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 110 insertions(+), 17 deletions(-)
include/env_callback.h +21 -1
@@ -37,6 +37,26 @@#define ENV_DOT_ESCAPE #endif +#ifdef CONFIG_CMD_DNS +#define DNS_CALLBACK "dnsip:dnsip," +#else +#define DNS_CALLBACK +#endif + +#ifdef CONFIG_NET +#define NET_CALLBACKS \ + "bootfile:bootfile," \ + "ipaddr:ipaddr," \ + "gatewayip:gatewayip," \ + "netmask:netmask," \ + "serverip:serverip," \ + "nvlan:nvlan," \ + "vlan:vlan," \ + DNS_CALLBACK +#else +#define NET_CALLBACKS +#endif +/* * This list of callback bindings is static, but may be overridden by defining * a new association in the ".callbacks" environment variable.
@@ -44,7 +64,7 @@#define ENV_CALLBACK_LIST_STATIC ENV_DOT_ESCAPE ENV_CALLBACK_VAR ":callbacks," \ ENV_DOT_ESCAPE ENV_FLAGS_VAR ":flags," \ "baudrate:baudrate," \ - "bootfile:bootfile," \ + NET_CALLBACKS \ "loadaddr:loadaddr," \ SILENT_CALLBACK \ SPLASHIMAGE_CALLBACK \
net/net.c +89 -16
123 lines not on this page · raw message
Signature · 1 line
1.7.11.5
PATCH v4 12/26 net: Add default flags for common net env vars
In reply to Joe HershbergerCheck that the common network stack's env vars conform to the proper format for IP addresses.
---
Changes in v4: None
Changes in v3: None
Changes in v2: None
include/env_flags.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
include/env_flags.h +11 -1
@@ -52,8 +52,17 @@ enum env_flags_varaccess {#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"#endif #endif +#define NET_FLAGS \ + "ipaddr:i," \ + "gatewayip:i," \ + "netmask:i," \ + "serverip:i," \ + "nvlan:i," \ + "vlan:i," \ + "dnsip:i,"#else -#define ETHADDR_FLAGS "" +#define ETHADDR_FLAGS +#define NET_FLAGS #endif #ifndef CONFIG_ENV_OVERWRITE
@@ -64,6 +73,7 @@ enum env_flags_varaccess {#define ENV_FLAGS_LIST_STATIC \ ETHADDR_FLAGS \ + NET_FLAGS \ SERIAL_FLAGS \ CONFIG_ENV_FLAGS_LIST_STATIC
Signature · 1 line
1.7.11.5
PATCH v4 13/26 net: Remove duplicate bootfile syncing functionality
In reply to Joe HershbergerThe bootfile env var is already kept up to date by the callback in net.c so there is no need to poll it too.
---
Changes in v4: None
Changes in v3:
-New for version 3
Changes in v2: None
net/eth.c | 12 ------------ 1 file changed, 12 deletions(-)
net/eth.c +0 -12
@@ -60,16 +60,6 @@ static inline int eth_setenv_enetaddr_by_index(const char *base_name, int index,return eth_setenv_enetaddr (enetvar, enetaddr); } -static void eth_env_init (void ) -{ -const char *s; - - s =getenv ("bootfile" ); -if (s !=NULL ) -copy_filename (net_boot_file_name, s, -sizeof (net_boot_file_name)); -} -static int eth_mac_skip (int index) {char enetvar[15 ];
@@ -104,8 +94,6 @@ static void eth_common_init(void)phy_init ();#endif -eth_env_init (); -/* * If board-specific initialization exists, call it. * If not, call a CPU-specific one
Signature · 1 line
1.7.11.5
PATCH v4 14/26 net: Handle ethaddr changes as an env callback
In reply to Joe HershbergerWhen the ethaddr is changed in the env, update the device pdata at the same time (only if it is probed for the DM case; only if registered for the non-DM case). Again this gets us closer to completely non-polled env needed to simplify the net_loop.
This requires that the NET feature select the REGEX feature.
---
Changes in v4: None
Changes in v3:
-New for version 3
Changes in v2: None
include/env_callback.h | 3 +- net/Kconfig | 1 + net/eth.c | 83 ++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 63 insertions(+), 24 deletions(-)
include/env_callback.h +2 -1
@@ -52,7 +52,8 @@"serverip:serverip," \"nvlan:nvlan," \"vlan:vlan," \ - DNS_CALLBACK +DNS_CALLBACK \ + "eth\\d?addr:ethaddr,"#else #define NET_CALLBACKS #endif
net/Kconfig +1 -0
@@ -4,6 +4,7 @@ menuconfig NET bool "Networking support" + select REGEX if NET
net/eth.c +60 -23
124 lines not on this page · raw message
Signature · 1 line
1.7.11.5