Implement fastboot multiresponce
Subsystems (3)
v7 cover Implement fastboot multiresponce
Currently u-boot fastboot can only send one message back to host, so if there is a need to print more than one line messages must be kept sending until all the required data is obtained. This behavior can be adjusted using multiresponce ability (getting multiple lines of response) proposed in this patch set.
Implementation of multiresponce leads to ability to dump content of console buffer which, with use of "oem run", allows to entirely avoid need in UART.
---
Changes in v7:
- fix hush/dollar bugs introduced in u-boot/next
Changes in v6:
- remove prev console changes
- add console_record_isempty helper
- set record flag on init
Changes in v5:
- restored membuff_readline behavior changed in v4
Changes in v4:
- adjust membuff_readline behavior with overflow
Changes in v3:
- fix missing function calls if CONFIG_CONSOLE_RECORD is not enabled
Changes in v2:
- changed variables to static
- fixed multiresponce for udp
- documented use of "MORE"
- converted #if to if (...)
---
Ion Agorria (7):
fastboot: multiresponse support
fastboot: implement "getvar all"
common: console: introduce console_record_isempty helper
common: console: record console from the beginning
lib: membuff: fix readline not returning line in case of overflow
fastboot: add oem console command support
test: hush: dollar: fix bagous behavior
boot/bootmeth_extlinux.c | 2 +- common/console.c | 10 +++- doc/android/fastboot-protocol.rst | 3 ++ doc/android/fastboot.rst | 1 + drivers/fastboot/Kconfig | 7 +++ drivers/fastboot/fb_command.c | 52 +++++++++++++++++++++ drivers/fastboot/fb_getvar.c | 77 +++++++++++++++++++++++++------ drivers/usb/gadget/f_fastboot.c | 29 ++++++++++++ include/console.h | 13 ++++++ include/fastboot-internal.h | 7 +++ include/fastboot.h | 19 ++++++++ include/membuff.h | 5 +- lib/membuff.c | 4 +- net/fastboot_udp.c | 29 +++++++++--- test/hush/dollar.c | 23 ++------- 15 files changed, 236 insertions(+), 45 deletions(-)
Signature · 1 line
2.40.1
PATCH v7 1/7 fastboot: multiresponse support
From: Ion Agorria <[email protected]>
Currently u-boot fastboot can only send one message back to host, so if there is a need to print more than one line messages must be kept sending until all the required data is obtained. This behavior can be adjusted using multiresponce ability (getting multiple lines of response) proposed in this patch.
--- drivers/fastboot/fb_command.c | 10 ++++++++++ drivers/usb/gadget/f_fastboot.c | 29 +++++++++++++++++++++++++++++ include/fastboot.h | 18 ++++++++++++++++++ net/fastboot_udp.c | 29 +++++++++++++++++++++++------ 4 files changed, 80 insertions(+), 6 deletions(-)
drivers/fastboot/fb_command.c +10 -0
@@ -5,6 +5,7 @@#include <common.h> #include <command.h> +#include <console.h> #include <env.h> #include <fastboot.h> #include <fastboot-internal.h>
@@ -152,6 +153,15 @@ int fastboot_handle_command(char *cmd_string, char *response)return -1 ; } +void fastboot_multiresponse (int cmd,char *response) +{ +switch (cmd) { +default : +fastboot_fail ("Unknown multiresponse command" , response); +break ; + } +} +/** * okay() - Send bare OKAY response *
drivers/usb/gadget/f_fastboot.c +29 -0
@@ -497,6 +497,25 @@ static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)do_exit_on_complete (ep, req); } +static int multiresponse_cmd =-1 ; +static void multiresponse_on_complete (struct usb_ep *ep,struct usb_request *req) +{ +char response[FASTBOOT_RESPONSE_LEN ] = {0 }; + +if (multiresponse_cmd ==-1 ) +return ; + +/* Call handler to obtain next response */ +fastboot_multiresponse (multiresponse_cmd, response); +fastboot_tx_write_str (response); + +/* If response is final OKAY/FAIL response disconnect this handler and unset cmd */ +if (!strncmp ("OKAY" , response,4 ) || !strncmp ("FAIL" , response,4 )) { + multiresponse_cmd =-1 ; + fastboot_func->in_req->complete = fastboot_complete; + } +} +static void do_acmd_complete (struct usb_ep *ep,struct usb_request *req) {/* When usb dequeue complete will be called
@@ -524,6 +543,16 @@ static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)fastboot_fail ("buffer overflow" , response); } +if (!strncmp (FASTBOOT_MULTIRESPONSE_START , response,4 )) { + multiresponse_cmd = cmd; +fastboot_multiresponse (multiresponse_cmd, response); + +/* Only add complete callback if first is not a final OKAY/FAIL response */ +if (strncmp ("OKAY" , response,4 ) &&strncmp ("FAIL" , response,4 )) { + fastboot_func->in_req->complete = multiresponse_on_complete; + } + } +if (!strncmp ("DATA" , response,4 )) { req->complete = rx_handler_dl_image; req->length =rx_bytes_expected (ep);
include/fastboot.h +18 -0
@@ -14,6 +14,16 @@#define FASTBOOT_VERSION "0.4" +/* +* Signals u-boot fastboot code to send multiple responses by +* calling response generating function repeatedly until a OKAY/FAIL +* is generated as final response. +* +* This status code is only used internally to signal, must NOT +* be sent to host. +*/ +#define FASTBOOT_MULTIRESPONSE_START ("MORE") +/* The 64 defined bytes plus \0 */ #define FASTBOOT_COMMAND_LEN (64 + 1)#define FASTBOOT_RESPONSE_LEN (64 + 1)
@@ -172,5 +182,13 @@ void fastboot_data_download(const void *fastboot_data,*/ void fastboot_data_complete (char *response); +/** +* fastboot_handle_multiresponse() - Called for each response to send +* +* @cmd: Command id that requested multiresponse +* @response: Pointer to fastboot response buffer +*/ +void fastboot_multiresponse (int cmd,char *response); +void fastboot_acmd_complete (void );#endif /* _FASTBOOT_H_ */
net/fastboot_udp.c +23 -6
@@ -42,16 +42,15 @@ static int fastboot_remote_port;static int fastboot_our_port;/** -* fastboot_udp_send_info() - Send an INFO packet during long commands. +* fastboot_udp_send_response() - Send an response into UDP * -* @msg: String describing the reason for waiting +* @response: Response to send */ -static void fastboot_udp_send_info (const char *msg) +static void fastboot_udp_send_response (const char *response) {uchar *packet;uchar *packet_base;int len =0 ; -char response[FASTBOOT_RESPONSE_LEN ] = {0 };struct fastboot_header response_header = { .id =FASTBOOT_FASTBOOT ,
@@ -66,7 +65,6 @@ static void fastboot_udp_send_info(const char *msg)memcpy (packet, &response_header,sizeof (response_header)); packet +=sizeof (response_header);/* Write response */ -fastboot_response ("INFO" , response,"%s" , msg);memcpy (packet, response,strlen (response)); packet +=strlen (response);
@@ -91,6 +89,7 @@ static void fastboot_udp_send_info(const char *msg)static void fastboot_timed_send_info (const char *msg) {static ulong start; +char response[FASTBOOT_RESPONSE_LEN ] = {0 };/* Initialize timer */ if (start ==0 )
@@ -99,7 +98,8 @@ static void fastboot_timed_send_info(const char *msg)/* Send INFO packet to host every 30 seconds */ if (time >=30000 ) { start =get_timer (0 ); -fastboot_udp_send_info (msg); +fastboot_response ("INFO" , response,"%s" , msg); +fastboot_udp_send_response (response); } }
@@ -180,6 +180,23 @@ static void fastboot_send(struct fastboot_header header, char *fastboot_data, }else { cmd =fastboot_handle_command (command, response); pending_command = false; + +if (!strncmp (FASTBOOT_MULTIRESPONSE_START , response,4 )) { +while (1 ) { +/* Call handler to obtain next response */ +fastboot_multiresponse (cmd, response); + +/* +* Send more responses or break to send +* final OKAY/FAIL response +*/ +if (strncmp ("OKAY" , response,4 ) && +strncmp ("FAIL" , response,4 )) +fastboot_udp_send_response (response); +else +break ; + } + } }/* * Sent some INFO packets, need to update sequence number in
Signature · 1 line
2.40.1
PATCH v7 2/7 fastboot: implement "getvar all"
In reply to Svyatoslav RyhelFrom: Ion Agorria <[email protected]>
This commit implements "fastboot getvar all" listing by iterating the existing dispatchers that don't require parameters (as we pass NULL), uses fastboot multiresponse.
--- doc/android/fastboot-protocol.rst | 3 ++ drivers/fastboot/fb_command.c | 3 ++ drivers/fastboot/fb_getvar.c | 77 +++++++++++++++++++++++++------ include/fastboot-internal.h | 7 +++ 4 files changed, 77 insertions(+), 13 deletions(-)
doc/android/fastboot-protocol.rst +3 -0
@@ -173,6 +173,9 @@ The various currently defined names are:: bootloader requiring a signature before it will install or boot images. + all Provides all info from commands above as + they were called one by one + Names starting with a lowercase character are reserved by this specification. OEM-specific names should not start with lowercase characters.
drivers/fastboot/fb_command.c +3 -0
@@ -156,6 +156,9 @@ int fastboot_handle_command(char *cmd_string, char *response)void fastboot_multiresponse (int cmd,char *response) {switch (cmd) { +case FASTBOOT_COMMAND_GETVAR : +fastboot_getvar_all (response); +break ;default :fastboot_fail ("Unknown multiresponse command" , response);break ;
drivers/fastboot/fb_getvar.c +64 -13
129 lines not on this page · raw message
include/fastboot-internal.h +7 -0
@@ -18,6 +18,13 @@ extern u32 fastboot_buf_size;*/ extern void (*fastboot_progress_callback)(const char *msg); +/** +* fastboot_getvar_all() - Writes current variable being listed from "all" to response. +* +* @response: Pointer to fastboot response buffer +*/ +void fastboot_getvar_all (char *response); +/** * fastboot_getvar() - Writes variable indicated by cmd_parameter to response. *
Signature · 1 line
2.40.1
PATCH v7 3/7 common: console: introduce console_record_isempty helper
In reply to Svyatoslav RyhelFrom: Ion Agorria <[email protected]>
Add console_record_isempty to check if console record buffer contains any data.
--- common/console.c | 5 +++++ include/console.h | 13 +++++++++++++ 2 files changed, 18 insertions(+)
common/console.c +5 -0
@@ -853,6 +853,11 @@ int console_record_avail(void)return membuff_avail ((struct membuff *)&gd->console_out); } +bool console_record_isempty (void ) +{ +return membuff_isempty ((struct membuff *)&gd->console_out); +} +int console_in_puts (const char *str) {return membuff_put ((struct membuff *)&gd->console_in, str,strlen (str));
include/console.h +13 -0
@@ -84,6 +84,13 @@ int console_record_readline(char *str, int maxlen);*/ int console_record_avail (void ); +/** +* console_record_isempty() - Returns if console output is empty +* +* Return: true if empty +*/ +bool console_record_isempty (void ); +/** * console_in_puts() - Write a string to the console input buffer *
@@ -131,6 +138,12 @@ static inline int console_in_puts(const char *str) return 0; } +static inline bool console_record_isempty (void ) +{ +/* Always empty */ +return true; +} +#endif /* !CONFIG_CONSOLE_RECORD */ /**
Signature · 1 line
2.40.1
PATCH v7 4/7 common: console: record console from the beginning
In reply to Svyatoslav RyhelFrom: Ion Agorria <[email protected]>
Set flag to enable console record on console_record_init and not only on console_record_reset_enable. This fixes missing start of U-Boot log for fastboot oem console command.
--- common/console.c | 3 +++ 1 file changed, 3 insertions(+)
common/console.c +3 -0
@@ -821,6 +821,9 @@ int console_record_init(void) ret =membuff_new ((struct membuff *)&gd->console_in,CONFIG_CONSOLE_RECORD_IN_SIZE ); +/* Start recording from the beginning */ + gd->flags |=GD_FLG_RECORD ; +return ret; }
Signature · 1 line
2.40.1
PATCH v7 5/7 lib: membuff: fix readline not returning line in case of overflow
In reply to Svyatoslav RyhelFrom: Ion Agorria <[email protected]>
If line overflows readline it will not be returned, fix this behavior, make it optional and documented properly.
--- boot/bootmeth_extlinux.c | 2 +- common/console.c | 2 +- include/membuff.h | 5 +++-- lib/membuff.c | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-)
boot/bootmeth_extlinux.c +1 -1
@@ -82,7 +82,7 @@ static int extlinux_fill_info(struct bootflow *bflow)log_debug ("parsing bflow file size %x\n" , bflow->size);membuff_init (&mb, bflow->buf, bflow->size);membuff_putraw (&mb, bflow->size, true, &data); -while (len =membuff_readline (&mb, line,sizeof (line) -1 ,' ' ), len) { +while (len =membuff_readline (&mb, line,sizeof (line) -1 ,' ' , true), len) {char *tok, *p = line; tok =strsep (&p," " );
common/console.c +1 -1
@@ -848,7 +848,7 @@ int console_record_readline(char *str, int maxlen)return -ENOSPC ;return membuff_readline ((struct membuff *)&gd->console_out, str, - maxlen,'\0' ); + maxlen,'\0' , false); }int console_record_avail (void )
include/membuff.h +3 -2
@@ -192,10 +192,11 @@ int membuff_free(struct membuff *mb);* @mb: membuff to adjust * @str: Place to put the line * @maxlen: Maximum line length (excluding terminator) +* @must_fit: If true then str is empty if line doesn't fit * Return: number of bytes read (including terminator) if a line has been -* read, 0 if nothing was there +* read, 0 if nothing was there or line didn't fit when must_fit is set */ -int membuff_readline (struct membuff *mb,char *str,int maxlen,int minch); +int membuff_readline (struct membuff *mb,char *str,int maxlen,int minch,bool must_fit);/** * membuff_extend_by() - expand a membuff
lib/membuff.c +2 -2
@@ -287,7 +287,7 @@ int membuff_free(struct membuff *mb) (mb->end - mb->start) -1 -membuff_avail (mb); } -int membuff_readline (struct membuff *mb,char *str,int maxlen,int minch) +int membuff_readline (struct membuff *mb,char *str,int maxlen,int minch,bool must_fit) {int len;/* number of bytes read (!= string length) */ char *s, *end;
@@ -309,7 +309,7 @@ int membuff_readline(struct membuff *mb, char *str, int maxlen, int minch) }/* couldn't get the whole string */ -if (!ok) { +if (!ok && must_fit) {if (maxlen) *orig ='\0' ;return 0 ;
Signature · 1 line
2.40.1
PATCH v7 6/7 fastboot: add oem console command support
In reply to Svyatoslav RyhelFrom: Ion Agorria <[email protected]>
"oem console" serves to read console record buffer.
--- doc/android/fastboot.rst | 1 + drivers/fastboot/Kconfig | 7 +++++++ drivers/fastboot/fb_command.c | 39 +++++++++++++++++++++++++++++++++++ include/fastboot.h | 1 + 4 files changed, 48 insertions(+)
doc/android/fastboot.rst +1 -0
@@ -29,6 +29,7 @@ The following OEM commands are supported (if enabled): with <arg> = boot_ack boot_partition - ``oem bootbus`` - this executes ``mmc bootbus %x %s`` to configure eMMC - ``oem run`` - this executes an arbitrary U-Boot command +- ``oem console`` - this dumps U-Boot console record buffer Support for both eMMC and NAND devices is included.
drivers/fastboot/Kconfig +7 -0
@@ -242,6 +242,13 @@ config FASTBOOT_OEM_RUN this feature if you are using verified boot, as it will allow an attacker to bypass any restrictions you have in place. +config FASTBOOT_CMD_OEM_CONSOLE + bool "Enable the 'oem console' command" + depends on CONSOLE_RECORD + help + Add support for the "oem console" command to input and read console + record buffer. + endif # FASTBOOT endmenu
drivers/fastboot/fb_command.c +39 -0
@@ -41,6 +41,7 @@ static void reboot_recovery(char *, char *);static void oem_format (char *,char *);static void oem_partconf (char *,char *);static void oem_bootbus (char *,char *); +static void oem_console (char *,char *);static void run_ucmd (char *,char *);static void run_acmd (char *,char *);
@@ -108,6 +109,10 @@ static const struct { .command = "oem run", .dispatch =CONFIG_IS_ENABLED (FASTBOOT_OEM_RUN , (run_ucmd), (NULL )) }, + [FASTBOOT_COMMAND_OEM_CONSOLE] = { + .command = "oem console", + .dispatch =CONFIG_IS_ENABLED (FASTBOOT_CMD_OEM_CONSOLE , (oem_console), (NULL )) + }, [FASTBOOT_COMMAND_UCMD] = { .command ="UCmd" , .dispatch = CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT, (run_ucmd), (NULL))
@@ -159,6 +164,23 @@ void fastboot_multiresponse(int cmd, char *response)case FASTBOOT_COMMAND_GETVAR :fastboot_getvar_all (response);break ; +case FASTBOOT_COMMAND_OEM_CONSOLE : +if (CONFIG_IS_ENABLED (FASTBOOT_CMD_OEM_CONSOLE )) { +char buf[FASTBOOT_RESPONSE_LEN ] = {0 }; + +if (console_record_isempty ()) { +console_record_reset (); +fastboot_okay (NULL , response); + }else { +int ret =console_record_readline (buf,sizeof (buf) -5 ); + +if (ret <0 ) +fastboot_fail ("Error reading console" , response); +else +fastboot_response ("INFO" , response,"%s" , buf); + } +break ; + }default :fastboot_fail ("Unknown multiresponse command" , response);break ;
@@ -503,3 +525,20 @@ static void __maybe_unused oem_bootbus(char *cmd_parameter, char *response)else fastboot_okay (NULL , response); } + +/** +* oem_console() - Execute the OEM console command +* +* @cmd_parameter: Pointer to command parameter +* @response: Pointer to fastboot response buffer +*/ +static void __maybe_unused oem_console (char *cmd_parameter,char *response) +{ +if (cmd_parameter) +console_in_puts (cmd_parameter); + +if (console_record_isempty ()) +fastboot_fail ("Empty console" , response); +else +fastboot_response (FASTBOOT_MULTIRESPONSE_START , response,NULL ); +}
include/fastboot.h +1 -0
@@ -47,6 +47,7 @@ enum {FASTBOOT_COMMAND_OEM_PARTCONF ,FASTBOOT_COMMAND_OEM_BOOTBUS ,FASTBOOT_COMMAND_OEM_RUN , +FASTBOOT_COMMAND_OEM_CONSOLE ,FASTBOOT_COMMAND_ACMD ,FASTBOOT_COMMAND_UCMD ,FASTBOOT_COMMAND_COUNT
Signature · 1 line
2.40.1
PATCH v7 7/7 test: hush: dollar: fix bagous behavior
In reply to Svyatoslav RyhelFrom: Ion Agorria <[email protected]>
The dollar test was merged with bagous console behavior, and instead of fixing it, this behavior was just workarounded.
It seems like without the fix the ut_assert_skipline(); didn't clear console and running ut_assert_skipline(); many times would give always OK. With
lib: membuff: fix readline not returning line in case of overflow
the line is cleared correctly and next assert fails because now there is nothing to clean which is correct if we look the this a bit above the failing assert:
if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
/*
* For some strange reasons, the console is not empty after
* running above command.
* So, we reset it to not have side effects for other tests.
*/
console_record_reset_enable();
} else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
ut_assert_console_end();
}Which further confirms that tests workaround the old problem and now that problem is fixed we can remove the whole if blocks and simply place ut_assert_console_end() right after ut_assert_skipline() without any conditional and will pass green.
So this part of code goes from:
ut_assert_skipline();
ut_assert_skipline();
if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
/* See above comments. */
console_record_reset_enable();
} else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
ut_assert_console_end();
}to become:
ut_assert_skipline();
ut_assert_console_end();Same thing should be done with the if block mentioned above that calls console_record_reset_enable().
--- test/hush/dollar.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-)
test/hush/dollar.c +3 -20
@@ -53,29 +53,12 @@ static int hush_test_simple_dollar(struct unit_test_state *uts)ut_asserteq (1 ,run_command ("dollar_foo='bar quux" ,0 ));/* Next line contains error message */ ut_assert_skipline (); - -if (gd->flags &GD_FLG_HUSH_MODERN_PARSER ) { -/* -* For some strange reasons, the console is not empty after -* running above command. -* So, we reset it to not have side effects for other tests. -*/ -console_record_reset_enable (); - }else if (gd->flags &GD_FLG_HUSH_OLD_PARSER ) { -ut_assert_console_end (); - } +ut_assert_console_end ();ut_asserteq (1 ,run_command ("dollar_foo=bar quux\"" ,0 )); -/* Two next lines contain error message */ -ut_assert_skipline (); +/* Next line contains error message */ ut_assert_skipline (); - -if (gd->flags &GD_FLG_HUSH_MODERN_PARSER ) { -/* See above comments. */ -console_record_reset_enable (); - }else if (gd->flags &GD_FLG_HUSH_OLD_PARSER ) { -ut_assert_console_end (); - } +ut_assert_console_end ();ut_assertok (run_command ("dollar_foo='bar \"quux'" ,0 ));
Signature · 1 line
2.40.1
Re: [PATCH v7 7/7] test: hush: dollar: fix bagous behavior
Hi Svyatoslav,
Thank you for the patch.
Quoted 43 lines · Svyatoslav Ryhel
From: Ion Agorria <[email protected]>
The dollar test was merged with bagous console behavior, and instead of fixing it, this behavior was just workarounded.
It seems like without the fix the
ut_assert_skipline(); didn't clear console and runningut_assert_skipline(); many times would give always OK. Withlib: membuff: fix readline not returning line in case of overflow
the line is cleared correctly and next assert fails because now there is nothing to clean which is correct if we look the this a bit above the failing assert:
if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) { /* * For some strange reasons, the console is not empty after * running above command. * So, we reset it to not have side effects for other tests. */ console_record_reset_enable(); } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { ut_assert_console_end(); }Which further confirms that tests workaround the old problem and now that problem is fixed we can remove the whole if blocks and simply place
ut_assert_console_end()right afterut_assert_skipline()without any conditional and will pass green.So this part of code goes from:
ut_assert_skipline(); ut_assert_skipline(); if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) { /* See above comments. */ console_record_reset_enable(); } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { ut_assert_console_end(); }to become:
Quoted 8 lines
ut_assert_skipline(); ut_assert_console_end();Same thing should be done with the if block mentioned above that calls
console_record_reset_enable().Signed-off-by Ion Agorria <[email protected]>Signed-off-by Svyatoslav Ryhel <[email protected]>
I confirm this fixes the problem reported in:
https://lore.kernel.org/all/[email protected]/
The commit message is a bit long, but I don't mind it staying this way.
Quoted 43 lines
--- test/hush/dollar.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-)test/hush/dollar.c +3
-20@@ -53,29 +53,12 @@ static int hush_test_simple_dollar(struct unit_test_state *uts)ut_asserteq (1 ,run_command ("dollar_foo='bar quux" ,0 ));/* Next line contains error message */ ut_assert_skipline (); - -if (gd->flags &GD_FLG_HUSH_MODERN_PARSER ) { -/* -* For some strange reasons, the console is not empty after -* running above command. -* So, we reset it to not have side effects for other tests. -*/ -console_record_reset_enable (); - }else if (gd->flags &GD_FLG_HUSH_OLD_PARSER ) { -ut_assert_console_end (); - } +ut_assert_console_end ();ut_asserteq (1 ,run_command ("dollar_foo=bar quux\"" ,0 )); -/* Two next lines contain error message */ -ut_assert_skipline (); +/* Next line contains error message */ ut_assert_skipline (); - -if (gd->flags &GD_FLG_HUSH_MODERN_PARSER ) { -/* See above comments. */ -console_record_reset_enable (); - }else if (gd->flags &GD_FLG_HUSH_OLD_PARSER ) { -ut_assert_console_end (); - } +ut_assert_console_end ();ut_assertok (run_command ("dollar_foo='bar \"quux'" ,0 ));Signature · 1 line
2.40.1
Re: [PATCH v7 7/7] test: hush: dollar: fix bagous behavior
9 січня 2024 р. 15:54:32 GMT+02:00, Mattijs Korpershoek <[email protected]> написав(-ла):
Quoted 58 lines
Hi Svyatoslav,
Thank you for the patch.
Quoted 43 lines · Svyatoslav Ryhel
From: Ion Agorria <[email protected]>
The dollar test was merged with bagous console behavior, and instead of fixing it, this behavior was just workarounded.
It seems like without the fix the
ut_assert_skipline(); didn't clear console and runningut_assert_skipline(); many times would give always OK. Withlib: membuff: fix readline not returning line in case of overflow
the line is cleared correctly and next assert fails because now there is nothing to clean which is correct if we look the this a bit above the failing assert:
if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) { /* * For some strange reasons, the console is not empty after * running above command. * So, we reset it to not have side effects for other tests. */ console_record_reset_enable(); } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { ut_assert_console_end(); }Which further confirms that tests workaround the old problem and now that problem is fixed we can remove the whole if blocks and simply place
ut_assert_console_end()right afterut_assert_skipline()without any conditional and will pass green.So this part of code goes from:
ut_assert_skipline(); ut_assert_skipline(); if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) { /* See above comments. */ console_record_reset_enable(); } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { ut_assert_console_end(); }to become:
Quoted 8 lines
ut_assert_skipline(); ut_assert_console_end();Same thing should be done with the if block mentioned above that calls
console_record_reset_enable().Signed-off-by Ion Agorria <[email protected]>Signed-off-by Svyatoslav Ryhel <[email protected]>
Quoted 9 lines
I confirm this fixes the problem reported in:
https://lore.kernel.org/all/[email protected]/Tested-by Mattijs Korpershoek <[email protected]>The commit message is a bit long, but I don't mind it staying this way.
Reviewed-by Mattijs Korpershoek <[email protected]>
Thanks! Commit title might have a typo. Not "bagous" but "bugous" should be correct. May you adjust on pick if not too hard?
Quoted 43 lines
Quoted 43 lines
--- test/hush/dollar.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-)test/hush/dollar.c +3
-20@@ -53,29 +53,12 @@ static int hush_test_simple_dollar(struct unit_test_state *uts)ut_asserteq (1 ,run_command ("dollar_foo='bar quux" ,0 ));/* Next line contains error message */ ut_assert_skipline (); - -if (gd->flags &GD_FLG_HUSH_MODERN_PARSER ) { -/* -* For some strange reasons, the console is not empty after -* running above command. -* So, we reset it to not have side effects for other tests. -*/ -console_record_reset_enable (); - }else if (gd->flags &GD_FLG_HUSH_OLD_PARSER ) { -ut_assert_console_end (); - } +ut_assert_console_end ();ut_asserteq (1 ,run_command ("dollar_foo=bar quux\"" ,0 )); -/* Two next lines contain error message */ -ut_assert_skipline (); +/* Next line contains error message */ ut_assert_skipline (); - -if (gd->flags &GD_FLG_HUSH_MODERN_PARSER ) { -/* See above comments. */ -console_record_reset_enable (); - }else if (gd->flags &GD_FLG_HUSH_OLD_PARSER ) { -ut_assert_console_end (); - } +ut_assert_console_end ();ut_assertok (run_command ("dollar_foo='bar \"quux'" ,0 ));Signature · 1 line
2.40.1
Re: [PATCH v7 7/7] test: hush: dollar: fix bagous behavior
Hi Svyatoslav,
Quoted 62 lines · Svyatoslav
9 січня 2024 р. 15:54:32 GMT+02:00, Mattijs Korpershoek <[email protected]> написав(-ла):
Quoted 61 lines
Hi Svyatoslav,
Thank you for the patch.
Quoted 43 lines · Svyatoslav Ryhel
From: Ion Agorria <[email protected]>
The dollar test was merged with bagous console behavior, and instead of fixing it, this behavior was just workarounded.
It seems like without the fix the
ut_assert_skipline(); didn't clear console and runningut_assert_skipline(); many times would give always OK. Withlib: membuff: fix readline not returning line in case of overflow
the line is cleared correctly and next assert fails because now there is nothing to clean which is correct if we look the this a bit above the failing assert:
if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) { /* * For some strange reasons, the console is not empty after * running above command. * So, we reset it to not have side effects for other tests. */ console_record_reset_enable(); } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { ut_assert_console_end(); }Which further confirms that tests workaround the old problem and now that problem is fixed we can remove the whole if blocks and simply place
ut_assert_console_end()right afterut_assert_skipline()without any conditional and will pass green.So this part of code goes from:
ut_assert_skipline(); ut_assert_skipline(); if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) { /* See above comments. */ console_record_reset_enable(); } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { ut_assert_console_end(); }to become:
Quoted 8 lines
ut_assert_skipline(); ut_assert_console_end();Same thing should be done with the if block mentioned above that calls
console_record_reset_enable().Signed-off-by Ion Agorria <[email protected]>Signed-off-by Svyatoslav Ryhel <[email protected]>I confirm this fixes the problem reported in:
https://lore.kernel.org/all/[email protected]/
Quoted 8 lines
Quoted 6 lines
Tested-by Mattijs Korpershoek <[email protected]>The commit message is a bit long, but I don't mind it staying this way.
Reviewed-by Mattijs Korpershoek <[email protected]>Thanks! Commit title might have a typo. Not "bagous" but "bugous" should be correct. May you adjust on pick if not too hard?
Yes, will update while picking up.
Quoted 44 lines
Quoted 44 lines
Quoted 44 lines
--- test/hush/dollar.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-)test/hush/dollar.c +3
-20@@ -53,29 +53,12 @@ static int hush_test_simple_dollar(struct unit_test_state *uts)ut_asserteq (1 ,run_command ("dollar_foo='bar quux" ,0 ));/* Next line contains error message */ ut_assert_skipline (); - -if (gd->flags &GD_FLG_HUSH_MODERN_PARSER ) { -/* -* For some strange reasons, the console is not empty after -* running above command. -* So, we reset it to not have side effects for other tests. -*/ -console_record_reset_enable (); - }else if (gd->flags &GD_FLG_HUSH_OLD_PARSER ) { -ut_assert_console_end (); - } +ut_assert_console_end ();ut_asserteq (1 ,run_command ("dollar_foo=bar quux\"" ,0 )); -/* Two next lines contain error message */ -ut_assert_skipline (); +/* Next line contains error message */ ut_assert_skipline (); - -if (gd->flags &GD_FLG_HUSH_MODERN_PARSER ) { -/* See above comments. */ -console_record_reset_enable (); - }else if (gd->flags &GD_FLG_HUSH_OLD_PARSER ) { -ut_assert_console_end (); - } +ut_assert_console_end ();ut_assertok (run_command ("dollar_foo='bar \"quux'" ,0 ));Signature · 1 line
2.40.1
Hi,
Quoted 11 lines · Svyatoslav Ryhel
Currently u-boot fastboot can only send one message back to host, so if there is a need to print more than one line messages must be kept sending until all the required data is obtained. This behavior can be adjusted using multiresponce ability (getting multiple lines of response) proposed in this patch set.
Implementation of multiresponce leads to ability to dump content of console buffer which, with use of "oem run", allows to entirely avoid need in UART.
[...]
Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu (u-boot-dfu)
[1/7] fastboot: multiresponse support
https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/85fcd69dc2c03025648a1b1b511c1f10abf87c1e [2/7] fastboot: implement "getvar all" https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/475aa9aabee7ab472341d755cc339f1345d5f49e [3/7] common: console: introduce console_record_isempty helper https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/9ce75f49127858d1aa36d455a869137e4d36681b [4/7] common: console: record console from the beginning https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/90087dd076d42c196de3506b6fa4d052f0869670 [5/7] lib: membuff: fix readline not returning line in case of overflow https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/e58bafc35fe37491bb3546299593dcc054145adb [6/7] fastboot: add oem console command support https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/16f79dd4cd624de0ee336dfeeac6db954f99ae68 [7/7] test: hush: dollar: fix bagous behavior https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/6c2f753f4ad3dcee60190949d1286736a6d51d17
--
Mattijs