From mboxrd@z Thu Jan 1 00:00:00 1970 From: Heinrich Schuchardt Date: Tue, 27 Oct 2020 09:02:28 +0100 Subject: [PATCH 4/5] sandbox: implement reset In-Reply-To: References: <20201025060441.11961-1-xypron.glpk@gmx.de> <20201025060441.11961-5-xypron.glpk@gmx.de> Message-ID: <3d7f163f-092d-059f-39be-ad817fda5808@gmx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 27.10.20 05:52, Simon Glass wrote: > Hi Heinrich, > > On Sun, 25 Oct 2020 at 00:04, Heinrich Schuchardt wrote: >> >> Up to now the sandbox would shutdown upon a cold reset request. Instead it >> should be reset. >> >> In our coding we use static variables. The only safe way to return to an >> initial state is to relaunch the U-Boot binary. > > This is unfortunate, but I suspect you may be right. Have you looked at it? > >> >> The reset implementation uses a longjmp() to return to the main() function >> and then relaunches U-Boot using execv(). >> >> Signed-off-by: Heinrich Schuchardt >> --- >> arch/sandbox/cpu/os.c | 14 ++++++++++++++ >> arch/sandbox/cpu/start.c | 22 ++++++++++++++++++++++ >> arch/sandbox/cpu/state.c | 1 + >> arch/sandbox/include/asm/u-boot-sandbox.h | 3 +++ >> drivers/sysreset/sysreset_sandbox.c | 3 +++ >> include/os.h | 5 +++++ >> 6 files changed, 48 insertions(+) >> >> diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c >> index c461fb0db0..ed044e87fb 100644 >> --- a/arch/sandbox/cpu/os.c >> +++ b/arch/sandbox/cpu/os.c >> @@ -817,3 +817,17 @@ void *os_find_text_base(void) >> >> return base; >> } >> + >> +void os_relaunch(int argc, char *argv[]) >> +{ >> + char **args; >> + >> + args = calloc(argc + 1, sizeof(char *)); >> + if (!args) >> + goto out; >> + memcpy(args, argv, sizeof(char *) * argc); >> + args[argc] = NULL; >> + execv(args[0], args); >> +out: >> + os_exit(1); >> +} >> diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c >> index c6a2bbe468..ee1d4b9581 100644 >> --- a/arch/sandbox/cpu/start.c >> +++ b/arch/sandbox/cpu/start.c >> @@ -5,6 +5,7 @@ >> >> #include >> #include >> +#include > > Put before linux/ below https://www.denx.de/wiki/U-Boot/CodingStyle does not allow this. It requires: "Within that order, sort your includes.". Alphabetically dm/* goes before errno.h. Should the driver model require anything else, please, update the coding style guideline accordingly. Looking at dm/root.h I cannot see any such requirement. I think we should move the code style guideline to the HTML documentation and get rid of the Wiki page. Best regards Heinrich > >> #include >> #include >> #include >> @@ -14,11 +15,15 @@ >> #include >> #include >> #include >> +#include >> #include >> #include >> >> DECLARE_GLOBAL_DATA_PTR;