From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 97C91C4332F for ; Tue, 1 Nov 2022 19:30:10 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D2CEE84F49; Tue, 1 Nov 2022 20:29:51 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="QslHsuWn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0B25B84FBE; Tue, 1 Nov 2022 20:21:47 +0100 (CET) Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D56598504B for ; Tue, 1 Nov 2022 20:21:21 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=francis.laniel@amarulasolutions.com Received: by mail-wr1-x431.google.com with SMTP id k8so21527514wrh.1 for ; Tue, 01 Nov 2022 12:21:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=C8s1Y1MK9Zely4Rwre6qKGO9tLS76LW4Wyl088qxwEA=; b=QslHsuWnh5DWpinzhg2uTOYg6wcQeZc63wYjaDpX1UigHvnCWyNM298SS83J3ZIkZ7 JuvVxdZVXWtJXT5AtxVcuQQhl6IkOJiR0rTVX1A0HxefrgcCLkwmpa7PZj02OqMRkDpt kR+QhkEBrIgacZjld3FwPBYZ0b23s4jErL6us= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C8s1Y1MK9Zely4Rwre6qKGO9tLS76LW4Wyl088qxwEA=; b=1xePeTt3dnTuNzjrZE/eEvWTJqA04L0Nr5zGaB9bryYKVJni5lGYF3/CxCD5M9RmxH LxKKbekL+iBArl1HyIY/dzKK2oF1m5gMWjboS2N/bzev+9nX6c3bDVLvz/t8MZ/g4JGy kXz2pW3pnC3rZHCA+CliD2XwIrdo0vvu3kPr6Sk/R9X60yXoN8jQzLn7skbS1Oe3sZX7 FveBUmg/1PxF7ZsNB2ayXU96k5hLKpsbp1q/FPoMbzyD3rodvGjzNUYTJun2fdvukf9U yD6UrwkXH+fj8hVLPSjlrP6Iry5VDreuYCQQWfu15bGnhMJ/1Kv8yXs8eSmuO3JWQ7MF upKQ== X-Gm-Message-State: ACrzQf1SkLY/cV28NPun0n/PmkSmEdz9nCvtf3nj9MAL7PncHylzXGLt 8uXdRlbNrdPfvYYooVmnJO4PoYLPIq8kvg== X-Google-Smtp-Source: AMsMyM5dMao344zpEdjhcD5aO1MLG1DK1hbE9bhoV7qX0/+ZP1Yv7DD6svYTrKdupmu33YFchnetPQ== X-Received: by 2002:a05:6000:684:b0:236:839f:9276 with SMTP id bo4-20020a056000068400b00236839f9276mr12247301wrb.586.1667330481669; Tue, 01 Nov 2022 12:21:21 -0700 (PDT) Received: from pwmachine.numericable.fr (85-170-25-210.rev.numericable.fr. [85.170.25.210]) by smtp.gmail.com with ESMTPSA id h17-20020a5d6e11000000b002356c051b9csm10755732wrz.66.2022.11.01.12.21.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Nov 2022 12:21:21 -0700 (PDT) From: Francis Laniel To: u-boot@lists.denx.de Cc: Michael Nazzareno Trimarchi , Tom Rini , Aleksandar Gerasimovski , Holger Brunck , Francis Laniel , Heinrich Schuchardt , Simon Glass , Jason Liu , AKASHI Takahiro Subject: [RFC PATCH v5 12/24] cli: Enables using hush 2021 parser as command line parser Date: Tue, 1 Nov 2022 20:20:17 +0100 Message-Id: <20221101192029.10231-13-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221101192029.10231-1-francis.laniel@amarulasolutions.com> References: <20221101192029.10231-1-francis.laniel@amarulasolutions.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean If one defines HUSH_2021_PARSER, it is then possible to use 2021 parser with: => parser get old => parser set 2021 2021> parser get 2021 Signed-off-by: Francis Laniel --- cmd/parser.c | 7 ++++- common/cli.c | 38 +++++++++++++++++++---- include/asm-generic/global_data.h | 4 +++ include/cli_hush.h | 51 +++++++++++++++++++++++++++++-- 4 files changed, 91 insertions(+), 9 deletions(-) diff --git a/cmd/parser.c b/cmd/parser.c index 0a433b7dc6..f7b0f0dc9d 100644 --- a/cmd/parser.c +++ b/cmd/parser.c @@ -12,6 +12,8 @@ static const char *gd_flags_to_parser(void) { if (gd->flags & GD_FLG_HUSH_OLD_PARSER) return "old"; + if (gd->flags & GD_FLG_HUSH_2021_PARSER) + return "2021"; return NULL; } @@ -34,12 +36,15 @@ static int parser_string_to_gd_flags(const char *parser) { if (!strcmp(parser, "old")) return GD_FLG_HUSH_OLD_PARSER; + if (!strcmp(parser, "2021")) + return GD_FLG_HUSH_2021_PARSER; return -1; } static void reset_parser_gd_flags(void) { gd->flags &= ~GD_FLG_HUSH_OLD_PARSER; + gd->flags &= ~GD_FLG_HUSH_2021_PARSER; } static int do_parser_set(struct cmd_tbl *cmdtp, int flag, int argc, @@ -108,7 +113,7 @@ static int do_parser(struct cmd_tbl *cmdtp, int flag, int argc, #if CONFIG_IS_ENABLED(SYS_LONGHELP) static char parser_help_text[] = "get - print current parser\n" - "set - set the current parser, possible value is: old" + "set - set the current parser, possible values are: old, 2021" ; #endif diff --git a/common/cli.c b/common/cli.c index 65ec00dc9f..c2287443d4 100644 --- a/common/cli.c +++ b/common/cli.c @@ -40,12 +40,15 @@ int run_command(const char *cmd, int flag) return 1; return 0; -#else +#elif CONFIG_IS_ENABLED(HUSH_OLD_PARSER) int hush_flags = FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP; if (flag & CMD_FLAG_ENV) hush_flags |= FLAG_CONT_ON_NEWLINE; return parse_string_outer(cmd, hush_flags); +#else /* HUSH_2021_PARSER */ + /* Not yet implemented. */ + return 1; #endif } @@ -105,7 +108,12 @@ int run_command_list(const char *cmd, int len, int flag) buff[len] = '\0'; } #ifdef CONFIG_HUSH_PARSER +#if CONFIG_IS_ENABLED(HUSH_OLD_PARSER) rcode = parse_string_outer(buff, FLAG_PARSE_SEMICOLON); +#else /* HUSH_2021_PARSER */ + /* Not yet implemented. */ + rcode = 1; +#endif #else /* * This function will overwrite any \n it sees with a \0, which @@ -240,8 +248,13 @@ err: void cli_loop(void) { bootstage_mark(BOOTSTAGE_ID_ENTER_CLI_LOOP); -#ifdef CONFIG_HUSH_PARSER - parse_file_outer(); +#if CONFIG_IS_ENABLED(HUSH_PARSER) + if (gd->flags & GD_FLG_HUSH_2021_PARSER) + parse_and_run_file(); + else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) + parse_file_outer(); + + printf("Problem\n"); /* This point is never reached */ for (;;); #elif defined(CONFIG_CMDLINE) @@ -254,10 +267,23 @@ void cli_loop(void) void cli_init(void) { #ifdef CONFIG_HUSH_PARSER + /* This if block is used to initialize hush parser gd flag. */ if (!(gd->flags & GD_FLG_HUSH_OLD_PARSER) - && CONFIG_IS_ENABLED(HUSH_OLD_PARSER)) - gd->flags |= GD_FLG_HUSH_OLD_PARSER; - u_boot_hush_start(); + && !(gd->flags & GD_FLG_HUSH_2021_PARSER)) { + if (CONFIG_IS_ENABLED(HUSH_OLD_PARSER)) + gd->flags |= GD_FLG_HUSH_OLD_PARSER; + else if (CONFIG_IS_ENABLED(HUSH_2021_PARSER)) + gd->flags |= GD_FLG_HUSH_2021_PARSER; + } + + if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { + u_boot_hush_start(); + } else if (gd->flags & GD_FLG_HUSH_2021_PARSER) { + u_boot_hush_start_2021(); + } else { + printf("No valid hush parser to use, cli will not initialized!\n"); + return; + } #endif #if defined(CONFIG_HUSH_INIT_VAR) diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index 9179442564..7d70a1be0c 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -654,6 +654,10 @@ enum gd_flags { * @GD_FLG_HUSH_OLD_PARSER: Use hush old parser. */ GD_FLG_HUSH_OLD_PARSER = 0x200000, + /** + * @GD_FLG_HUSH_2021_PARSER: Use hush 2021 parser. + */ + GD_FLG_HUSH_2021_PARSER = 0x400000, }; #endif /* __ASSEMBLY__ */ diff --git a/include/cli_hush.h b/include/cli_hush.h index 2bd35670c7..4ef79de53c 100644 --- a/include/cli_hush.h +++ b/include/cli_hush.h @@ -12,11 +12,58 @@ #define FLAG_REPARSING (1 << 2) /* >=2nd pass */ #define FLAG_CONT_ON_NEWLINE (1 << 3) /* continue when we see \n */ +#if CONFIG_IS_ENABLED(HUSH_OLD_PARSER) extern int u_boot_hush_start(void); -extern int parse_string_outer(const char *, int); +extern int parse_string_outer(const char *str, int flag); extern int parse_file_outer(void); - int set_local_var(const char *s, int flg_export); +#else +static inline int u_boot_hush_start(void) +{ + return 0; +} + +static inline int parse_string_outer(const char *str, int flag) +{ + return 1; +} + +static inline int parse_file_outer(void) +{ + return 0; +} + +static inline int set_local_var(const char *s, int flg_export) +{ + return 0; +} +#endif +#if CONFIG_IS_ENABLED(HUSH_2021_PARSER) +extern int u_boot_hush_start_2021(void); +extern int parse_string_outer_2021(const char *str, int flag); +extern void parse_and_run_file(void); +int set_local_var_2021(char *s, int flg_export); +#else +static inline int u_boot_hush_start_2021(void) +{ + return 0; +} + +static inline int parse_string_outer_2021(const char *str, int flag) +{ + return 1; +} + +static inline void parse_and_run_file(void) +{ +} + +static inline int set_local_var_2021(char *s, int flg_export) +{ + return 0; +} +#endif + void unset_local_var(const char *name); char *get_local_var(const char *s); -- 2.25.1