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 C81FEC433EF for ; Thu, 7 Apr 2022 09:42:19 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B15D083C8F; Thu, 7 Apr 2022 11:42:00 +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="fHmNUf20"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 266B583C27; Thu, 7 Apr 2022 11:41:42 +0200 (CEST) Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) (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 6F96B83BBE for ; Thu, 7 Apr 2022 11:41:36 +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=3z7FOYgYKBoYk2m4vvqyyqvo.myw4-lyy3vs232.nox7.no@flex--ascull.bounces.google.com Received: by mail-wm1-x34a.google.com with SMTP id n19-20020a05600c305300b0038e72cfc391so2710827wmh.9 for ; Thu, 07 Apr 2022 02:41:36 -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=1+bH6o9JDbBISOLs2nR2XAsmjKxOLeWQWXLez5DL45M=; b=fHmNUf209YJ+vRHJTzpDYV6JoYVo9MPLHtPx/nXPpH94jEwQxui96jC3OwVhv/ZSfs t5rUX4IMUzQTTdu99FpNghMmHsauMXlOy9LZRM6Y3KQRhI/dAQRuGldl0WADnlE24HnZ ZNA4N+V1VR4QE5EyxBmQ/JE9xIduVWb0ggygX4Yi2UcM0jEkEbbnd5EC3xK6b55ALNEd ZTw0FIx2Pm5TIeWl1BJzEdfIk/M9OALkAbWpZCgQa47ofrYy/LRQz3fIZ3j0iTWqbO9H TRwS+1bAy+nWlkEJWv8GKtyzdzNLqfmD1C8CdFXmpshFnRlibYFd0QQtAK1Me/uW0cYf 1zvA== 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=1+bH6o9JDbBISOLs2nR2XAsmjKxOLeWQWXLez5DL45M=; b=Kgcf5nhF7s6UT8RFTwtDau6EMli39qzIZ/NKv2cWx9o4TfKqFS3Vdl9PmzcFxVnzM/ +xGH8FFrQ5RnyK7RPPxC/VvJ8pyHMzbyyQLWS6om6D7XNLGMkGzRlOi6k6yG5M1zvrU4 vXm/CZ9fpsOCA2rb2DsdEtxyIEMyho58iBsmkyIwOq37Lhv9mbi/sZw+4j4vs26C2ltH DhAWjZsy5dkuUeSbjDXJIatEgim4OfXExIBqQDhZBVnp8UH/Ah4Ukt0NSxR05HMcMquz TTTCniTlpk9nkwqDi/E0rrgCs204Ya9ifnlZLc3QvysVrzNKSl7kc9GEjkT894a0GCT9 qxlw== X-Gm-Message-State: AOAM532Ivg6qDWKuohkaE7NiTkAiU+6cFtNao0X5IasTiBU6y46+QOdW wMghx0X1dmfA73zLwTol1Urc2XrwM9UNkiRGPdsZc1zrBkaLnm40RYyxQu1jIHoZGCDF+9FGnQg 5hXOi+OCitFlyB9n4od2sMQWRJzU7oU5e8+xwWLgq9n9/CPzWmUpVhYFn+rg= X-Google-Smtp-Source: ABdhPJzd5LXwCvczh7bNaTfKCIBsgRlud/q0Kll5n2aXvFJy794qubispqH8ArB4vQZ8+hiJ5k60A+QlsPg= X-Received: from ascull.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1510]) (user=ascull job=sendgmr) by 2002:a05:600c:a47:b0:37c:965:2b6f with SMTP id c7-20020a05600c0a4700b0037c09652b6fmr11422831wmq.31.1649324495780; Thu, 07 Apr 2022 02:41:35 -0700 (PDT) Date: Thu, 7 Apr 2022 09:41:14 +0000 In-Reply-To: <20220407094123.1752236-1-ascull@google.com> Message-Id: <20220407094123.1752236-3-ascull@google.com> Mime-Version: 1.0 References: <20220407094123.1752236-1-ascull@google.com> X-Mailer: git-send-email 2.35.1.1094.g7c7d902a7c-goog Subject: [PATCH 02/11] sandbox: Migrate getopt section to linker list From: Andrew Scull To: u-boot@lists.denx.de Cc: sjg@chromium.org, seanga2@gmail.com, Andrew Scull Content-Type: text/plain; charset="UTF-8" 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 --- 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 13b0731ec3..5cb47e1156 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -58,9 +58,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; @@ -84,7 +83,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 */ @@ -94,7 +93,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 dd675cc3d2..c3fc67a15b 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) - } - /* Sandbox has empty EFI runtime lists. */ __efi_runtime_start = .; __efi_runtime_stop = __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 -- 2.35.1.1094.g7c7d902a7c-goog