From patchwork Thu Apr 14 13:59:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Scull X-Patchwork-Id: 1617263 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=ZA4PW5dT; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfLhG1F1dz9sG3 for ; Fri, 15 Apr 2022 00:00:30 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8D1F183ED4; Thu, 14 Apr 2022 16:00:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="ZA4PW5dT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 15E6B83EB7; Thu, 14 Apr 2022 15:59:55 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,T_FILL_THIS_FORM_SHORT,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) (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 8EE7883EA1 for ; Thu, 14 Apr 2022 15:59:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=31yhYYgYKBqICUEWNNIQQING.EQOW-DQQVNKUVU.FGPZ.FG@flex--ascull.bounces.google.com Received: by mail-wr1-x449.google.com with SMTP id p18-20020adf9592000000b00207bc12decbso568710wrp.21 for ; Thu, 14 Apr 2022 06:59:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=r3TH9LBgLVh4j5q9NWoGtaBoWIB7LnLcRkXh02iJnQ0=; b=ZA4PW5dTtvLoSxKjqwJxJaAVuPbvn4XAi0SQWMgwjKDbpK/oEw4/W+lMpcnxxd8e9W R2b0nD5TbbyfY8KaJjbSMGUUbca5XzlePPmgwnRzAtbERch+VET+lmZ/TJjMwGuMbGQJ Ypq2PVlSThgDYTFLwu8kDBQolGjytqiOon9/oqggHK559lvFh1daElYYTfaa/YsdbUmS my+KkaKnbzsdSMPS3BHlybBH0orPGPBxw4pp8z/8eVsUfFSXEuggTFy5+/TKr7NocCLx 13yy1f+UCE14YcguSWS54dwFTXkmBpPHjUag6nZI1rcJwRnMxIMOGfZ7nvPiSGYwilnu 2wLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=r3TH9LBgLVh4j5q9NWoGtaBoWIB7LnLcRkXh02iJnQ0=; b=klQaCQKdX9JCMQQVkKFUcrlvkBpmX25PKTQaEJVUo8RFYF1SafHrxXIm6YDb+sEW+x V4w9RiFV+yn6aJudnKUSWQsF7RJ/Vd16iQiKzcPnOwYYakcsXFzk/VtlBH595y3cqY3l 4gi0urNWga11cxt6XT4GjzlAo0J+kKiR00gV7a5d8yuB6PXfjIW7uXWlHHkUK7XQ9GQC +/sJclNW9q5bSQ3sD+j6pGIOwBNG/fquIA7V4dlCf8pHNkqwIYEsY5j5SlatrsfvgSL7 1ZXoAZ/NanjKo4LrWAnSCxAEwLts3WbqiBi2VtYpgZXiEvxjTQmFxU2SmZWvAgS0+zRR f1Iw== X-Gm-Message-State: AOAM531pahHUPqlCmOqYtcZ29Qu7wC8FkYyk/W2BxO4Y+eOuEu4IO2LQ 7yAP9J7IQsR8XFuJH3LejOjwYUum6+gUVQ3RES7uKVcR0rBPcdO5tlDO6gSECv1GpeokNQ6wVKH JwN6pDHFREceFrfZvsD0/lj/V9E96jY8PnAGZ2ac7WqSErfiaj3t9M+svHuc= X-Google-Smtp-Source: ABdhPJzcxhj8JylhO5NBKPfZk/3G9wiA/zywTC51Y4vx2+KQC5uR7HGOyY7B6UtNeUNsvnSB4A9qDKFVFOg= X-Received: from ascull.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1510]) (user=ascull job=sendgmr) by 2002:a05:600c:1456:b0:38e:bd55:700 with SMTP id h22-20020a05600c145600b0038ebd550700mr3315506wmi.204.1649944791048; Thu, 14 Apr 2022 06:59:51 -0700 (PDT) Date: Thu, 14 Apr 2022 13:59:32 +0000 In-Reply-To: <20220414135941.1732585-1-ascull@google.com> Message-Id: <20220414135941.1732585-4-ascull@google.com> Mime-Version: 1.0 References: <20220414135941.1732585-1-ascull@google.com> X-Mailer: git-send-email 2.35.1.1178.g4f1659d476-goog Subject: [PATCH v2 03/12] sandbox: Migrate getopt section to linker list From: Andrew Scull To: u-boot@lists.denx.de Cc: sjg@chromium.org, xypron.glpk@gmx.de, Andrew Scull 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.5 at phobos.denx.de X-Virus-Status: Clean Use the common infrastructure to create a linker list of the sandbox command line flags rather than using a custom method. The list is changed from containing pointers to containing structs and the uses are updated accordingly. Signed-off-by: Andrew Scull Reviewed-by: Simon Glass --- arch/sandbox/cpu/os.c | 21 ++++++++++----------- arch/sandbox/cpu/start.c | 10 +++++----- arch/sandbox/cpu/u-boot-spl.lds | 6 ------ arch/sandbox/cpu/u-boot.lds | 6 ------ arch/sandbox/include/asm/getopt.h | 19 ++++++++++++------- arch/sandbox/include/asm/sections.h | 25 ------------------------- 6 files changed, 27 insertions(+), 60 deletions(-) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index d83c862182..72a72029f2 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -424,9 +424,8 @@ static struct option *long_opts; int os_parse_args(struct sandbox_state *state, int argc, char *argv[]) { - struct sandbox_cmdline_option **sb_opt = - __u_boot_sandbox_option_start(); - size_t num_options = __u_boot_sandbox_option_count(); + struct sandbox_cmdline_option *sb_opt = SANDBOX_CMDLINE_OPT_START(); + size_t num_options = SANDBOX_CMDLINE_OPT_COUNT(); size_t i; int hidden_short_opt; @@ -455,17 +454,17 @@ int os_parse_args(struct sandbox_state *state, int argc, char *argv[]) hidden_short_opt = 0x100; si = 0; for (i = 0; i < num_options; ++i) { - long_opts[i].name = sb_opt[i]->flag; - long_opts[i].has_arg = sb_opt[i]->has_arg ? + long_opts[i].name = sb_opt[i].flag; + long_opts[i].has_arg = sb_opt[i].has_arg ? required_argument : no_argument; long_opts[i].flag = NULL; - if (sb_opt[i]->flag_short) { - short_opts[si++] = long_opts[i].val = sb_opt[i]->flag_short; + if (sb_opt[i].flag_short) { + short_opts[si++] = long_opts[i].val = sb_opt[i].flag_short; if (long_opts[i].has_arg == required_argument) short_opts[si++] = ':'; } else - long_opts[i].val = sb_opt[i]->flag_short = hidden_short_opt++; + long_opts[i].val = sb_opt[i].flag_short = hidden_short_opt++; } short_opts[si] = '\0'; @@ -480,9 +479,9 @@ int os_parse_args(struct sandbox_state *state, int argc, char *argv[]) */ while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) { for (i = 0; i < num_options; ++i) { - if (sb_opt[i]->flag_short == c) { - if (sb_opt[i]->callback(state, optarg)) { - state->parse_err = sb_opt[i]->flag; + if (sb_opt[i].flag_short == c) { + if (sb_opt[i].callback(state, optarg)) { + state->parse_err = sb_opt[i].flag; return 0; } break; diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index 0f5a87309d..6bcb8ffa28 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -59,9 +59,8 @@ static int h_compare_opt(const void *p1, const void *p2) int sandbox_early_getopt_check(void) { struct sandbox_state *state = state_get_current(); - struct sandbox_cmdline_option **sb_opt = - __u_boot_sandbox_option_start(); - size_t num_options = __u_boot_sandbox_option_count(); + struct sandbox_cmdline_option *sb_opt = SANDBOX_CMDLINE_OPT_START(); + size_t num_options = SANDBOX_CMDLINE_OPT_COUNT(); size_t i; int max_arg_len, max_noarg_len; struct sandbox_cmdline_option **sorted_opt; @@ -85,7 +84,7 @@ int sandbox_early_getopt_check(void) max_arg_len = 0; for (i = 0; i < num_options; ++i) - max_arg_len = max((int)strlen(sb_opt[i]->flag), max_arg_len); + max_arg_len = max((int)strlen(sb_opt[i].flag), max_arg_len); max_noarg_len = max_arg_len + 7; /* Sort the options */ @@ -95,7 +94,8 @@ int sandbox_early_getopt_check(void) printf("No memory to sort options\n"); os_exit(1); } - memcpy(sorted_opt, sb_opt, size); + for (i = 0; i < num_options; ++i) + sorted_opt[i] = &sb_opt[i]; qsort(sorted_opt, num_options, sizeof(*sorted_opt), h_compare_opt); for (i = 0; i < num_options; ++i) { diff --git a/arch/sandbox/cpu/u-boot-spl.lds b/arch/sandbox/cpu/u-boot-spl.lds index 6754f4ef6c..5c19d090cb 100644 --- a/arch/sandbox/cpu/u-boot-spl.lds +++ b/arch/sandbox/cpu/u-boot-spl.lds @@ -20,12 +20,6 @@ SECTIONS *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.priv_data*))) __priv_data_end = .; } - - _u_boot_sandbox_getopt : { - *(.u_boot_sandbox_getopt_start) - KEEP(*(.u_boot_sandbox_getopt)) - *(.u_boot_sandbox_getopt_end) - } } INSERT AFTER .data; diff --git a/arch/sandbox/cpu/u-boot.lds b/arch/sandbox/cpu/u-boot.lds index 7abe232ad9..6fa244fae9 100644 --- a/arch/sandbox/cpu/u-boot.lds +++ b/arch/sandbox/cpu/u-boot.lds @@ -13,12 +13,6 @@ SECTIONS KEEP(*(SORT(.u_boot_list*))); } - _u_boot_sandbox_getopt : { - *(.u_boot_sandbox_getopt_start) - *(.u_boot_sandbox_getopt) - *(.u_boot_sandbox_getopt_end) - } - efi_runtime_start : { *(___efi_runtime_start) } diff --git a/arch/sandbox/include/asm/getopt.h b/arch/sandbox/include/asm/getopt.h index d2145ad6e2..a4b510bd20 100644 --- a/arch/sandbox/include/asm/getopt.h +++ b/arch/sandbox/include/asm/getopt.h @@ -9,6 +9,8 @@ #ifndef __SANDBOX_GETOPT_H #define __SANDBOX_GETOPT_H +#include + struct sandbox_state; /* @@ -36,18 +38,13 @@ struct sandbox_cmdline_option { * magic junk that makes this all work. */ #define _SANDBOX_CMDLINE_OPT(f, s, ha, h) \ - static struct sandbox_cmdline_option sandbox_cmdline_option_##f = { \ + ll_entry_declare(struct sandbox_cmdline_option, f, sandbox_getopt) = { \ .flag = #f, \ .flag_short = s, \ .help = h, \ .has_arg = ha, \ .callback = sandbox_cmdline_cb_##f, \ - }; \ - /* Ppointer to the struct in a special section for the linker script */ \ - static __used __section(".u_boot_sandbox_getopt") \ - struct sandbox_cmdline_option \ - *sandbox_cmdline_option_##f##_ptr = \ - &sandbox_cmdline_option_##f + } /** * Macros for end code to declare new command line flags. @@ -69,4 +66,12 @@ struct sandbox_cmdline_option { */ #define SANDBOX_CMDLINE_OPT_SHORT(f, s, ha, h) _SANDBOX_CMDLINE_OPT(f, s, ha, h) +/** Get the start of the list of command line flags. */ +#define SANDBOX_CMDLINE_OPT_START() \ + ll_entry_start(struct sandbox_cmdline_option, sandbox_getopt) + +/** Get the number of entries in the command line flags list. */ +#define SANDBOX_CMDLINE_OPT_COUNT() \ + ll_entry_count(struct sandbox_cmdline_option, sandbox_getopt) + #endif diff --git a/arch/sandbox/include/asm/sections.h b/arch/sandbox/include/asm/sections.h index f4351ae7db..c335cb2061 100644 --- a/arch/sandbox/include/asm/sections.h +++ b/arch/sandbox/include/asm/sections.h @@ -11,29 +11,4 @@ #include -struct sandbox_cmdline_option; - -static inline struct sandbox_cmdline_option ** -__u_boot_sandbox_option_start(void) -{ - static char start[0] __aligned(4) __attribute__((unused)) - __section(".u_boot_sandbox_getopt_start"); - - return (struct sandbox_cmdline_option **)&start; -} - -static inline struct sandbox_cmdline_option ** -__u_boot_sandbox_option_end(void) -{ - static char end[0] __aligned(4) __attribute__((unused)) - __section(".u_boot_sandbox_getopt_end"); - - return (struct sandbox_cmdline_option **)&end; -} - -static inline size_t __u_boot_sandbox_option_count(void) -{ - return __u_boot_sandbox_option_end() - __u_boot_sandbox_option_start(); -} - #endif