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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A58C4C433EF for ; Thu, 14 Oct 2021 18:50:29 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 1CAED60E78 for ; Thu, 14 Oct 2021 18:50:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1CAED60E78 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 286E2837B7; Thu, 14 Oct 2021 20:50:07 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org 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=chromium.org header.i=@chromium.org header.b="is+CqMni"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D0FB38379B; Thu, 14 Oct 2021 20:48:59 +0200 (CEST) Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) (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 6A9C683688 for ; Thu, 14 Oct 2021 20:48:32 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd30.google.com with SMTP id b188so56532iof.8 for ; Thu, 14 Oct 2021 11:48:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GrFQkH1esz/VuUqio0lIluXqXmQooNsaH+UjOWWE77Q=; b=is+CqMni+IKqya+Cdvaj/KukfSlw5mr1HJb5Hm9jeADRY6r2Zprcwt8ITI/tHYsjna KwWmmwgY5gbhfwoBWdxuKd5cwy2kO+6945wkzRMbDsdnztvZIupM+pA15cgQdIVVlyKF okYzmNzahkrJ0sLb4kF6bDoIP9AQJZ3N1lUgI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GrFQkH1esz/VuUqio0lIluXqXmQooNsaH+UjOWWE77Q=; b=e8xvIRrYWRovq+eWTks/Ph3trpshyIXjrjwG1BDO6dxbV0YigFJ0v/v0Cc+NYq7LZ2 6nkQxqAUz5GoFnDxBPGWcsckM2f4Phar4A2ycrLK8exxJ3orvt+PI2g0zMk8P1+/70Tq qir2zLyzkgO9DjINfuGo7oElZYEIFCBQz/v2Gq6OBz7DwaMyq3GBMMGIEeLa2oiqEIOr gV/5W+hXGXG21OmCpvNPkBq1cGpxRerjIDE8ZnqtFQWY3XdiDqtKwBNwdxR7sydNVV8q E8/1hHer5ryx+uCPNsm/zH4md4YZ7Q8CtxIYgXs555eS+L69SEakE8VL2WXHueCSnpxL z1IQ== X-Gm-Message-State: AOAM530IdG7amMSwMgcb1n6eN2V/79yoV13ZFYoueBjeJf1zbm5j7Bmz UwYM3+w4Ncap794ah5YfJ+avtIoVeV16DA== X-Google-Smtp-Source: ABdhPJzwDAPZRLkizAy3vOkBNilHV7QSQfRl4qcpAkTTtQQyBJWdO2/rcGiWE+LGOu7g4vuP0ExQnQ== X-Received: by 2002:a05:6602:2ac8:: with SMTP id m8mr545215iov.112.1634237310697; Thu, 14 Oct 2021 11:48:30 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id w15sm1697625ill.23.2021.10.14.11.48.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Oct 2021 11:48:30 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Patrice Chotard , Artem Lapkin , Tom Rini , Joe Hershberger , Heinrich Schuchardt , Peter Hoyes , Simon Glass Subject: [PATCH v3 08/18] pxe: Tidy up some comments in pxe_utils Date: Thu, 14 Oct 2021 12:48:01 -0600 Message-Id: <20211014124803.v3.8.I63fc393bcaf374bf63eb47403a82236173781ba7@changeid> X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog In-Reply-To: <20211014184811.482560-1-sjg@chromium.org> References: <20211014184811.482560-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean Some of these functions are a big vague in the comments. Tidy them up a bit. Signed-off-by: Simon Glass --- (no changes since v1) boot/pxe_utils.c | 189 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 138 insertions(+), 51 deletions(-) diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c index 7d15c75dd87..7a2213a5925 100644 --- a/boot/pxe_utils.c +++ b/boot/pxe_utils.c @@ -30,6 +30,21 @@ #define MAX_TFTP_PATH_LEN 512 +/** + * format_mac_pxe() - obtain a MAC address in the PXE format + * + * This produces a MAC-address string in the format for the current ethernet + * device: + * + * 01-aa-bb-cc-dd-ee-ff + * + * where aa-ff is the MAC address in hex + * + * @outbuf: Buffer to write string to + * @outbuf_len: length of buffer + * @return 1 if OK, -ENOSPC if buffer is too small, -ENOENT is there is no + * current ethernet device + */ int format_mac_pxe(char *outbuf, size_t outbuf_len) { uchar ethaddr[6]; @@ -37,7 +52,7 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len) if (outbuf_len < 21) { printf("outbuf is too small (%zd < 21)\n", outbuf_len); - return -EINVAL; + return -ENOSPC; } if (!eth_env_get_enetaddr_by_index("eth", eth_get_dev_index(), ethaddr)) @@ -50,10 +65,20 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len) return 1; } -/* - * Returns the directory the file specified in the bootfile env variable is +/** + * get_bootfile_path() - Figure out the path of a file to read + * + * Returns the directory the file specified in the 'bootfile' env variable is * in. If bootfile isn't defined in the environment, return NULL, which should * be interpreted as "don't prepend anything to paths". + * + * @file_path: File path to read (relative to the PXE file) + * @bootfile_path: Place to put the bootfile path + * @bootfile_path_size: Size of @bootfile_path in bytes + * @allow_abs_path: true to allow an absolute path (where @file_path starts with + * '/', false to return an empty path (and success) in that case + * Returns 1 for success, -ENOSPC if bootfile_path_size is to small to hold the + * resulting path */ static int get_bootfile_path(const char *file_path, char *bootfile_path, size_t bootfile_path_size, bool allow_abs_path) @@ -81,7 +106,7 @@ static int get_bootfile_path(const char *file_path, char *bootfile_path, printf("bootfile_path too small. (%zd < %zd)\n", bootfile_path_size, path_len); - return -1; + return -ENOSPC; } strncpy(bootfile_path, bootfile, path_len); @@ -92,13 +117,18 @@ static int get_bootfile_path(const char *file_path, char *bootfile_path, return 1; } -/* +/** + * get_relfile() - read a file relative to the PXE file + * * As in pxelinux, paths to files referenced from files we retrieve are * relative to the location of bootfile. get_relfile takes such a path and * joins it with the bootfile path to get the full path to the target file. If * the bootfile path is NULL, we use file_path as is. * - * Returns 1 for success, or < 0 on error. + * @ctx: PXE context + * @file_path: File path to read (relative to the PXE file) + * @file_addr: Address to load file to + * Returns 1 for success, or < 0 on error */ static int get_relfile(struct pxe_context *ctx, const char *file_path, unsigned long file_addr) @@ -132,6 +162,16 @@ static int get_relfile(struct pxe_context *ctx, const char *file_path, return ctx->getfile(ctx, relfile, addr_buf); } +/** + * get_pxe_file() - read a file + * + * The file is read and nul-terminated + * + * @ctx: PXE context + * @file_path: File path to read (relative to the PXE file) + * @file_addr: Address to load file to + * Returns 1 for success, or < 0 on error + */ int get_pxe_file(struct pxe_context *ctx, const char *file_path, unsigned long file_addr) { @@ -166,6 +206,14 @@ int get_pxe_file(struct pxe_context *ctx, const char *file_path, #define PXELINUX_DIR "pxelinux.cfg/" +/** + * get_pxelinux_path() - Get a file in the pxelinux.cfg/ directory + * + * @ctx: PXE context + * @file: Filename to process (relative to pxelinux.cfg/) + * Returns 1 for success, -ENAMETOOLONG if the resulting path is too long. + * or other value < 0 on other error + */ int get_pxelinux_path(struct pxe_context *ctx, const char *file, unsigned long pxefile_addr_r) { @@ -183,12 +231,20 @@ int get_pxelinux_path(struct pxe_context *ctx, const char *file, return get_pxe_file(ctx, path, pxefile_addr_r); } -/* +/** + * get_relfile_envaddr() - read a file to an address in an env var + * * Wrapper to make it easier to store the file at file_path in the location * specified by envaddr_name. file_path will be joined to the bootfile path, * if any is specified. * - * Returns 1 on success or < 0 on error. + * @ctx: PXE context + * @file_path: File path to read (relative to the PXE file) + * @envaddr_name: Name of environment variable which contains the address to + * load to + * Returns 1 on success, -ENOENT if @envaddr_name does not exist as an + * environment variable, -EINVAL if its format is not valid hex, or other + * value < 0 on other error */ static int get_relfile_envaddr(struct pxe_context *ctx, const char *file_path, const char *envaddr_name) @@ -207,11 +263,13 @@ static int get_relfile_envaddr(struct pxe_context *ctx, const char *file_path, return get_relfile(ctx, file_path, file_addr); } -/* +/** + * label_create() - crate a new PXE label + * * Allocates memory for and initializes a pxe_label. This uses malloc, so the * result must be free()'d to reclaim the memory. * - * Returns NULL if malloc fails. + * Returns a pointer to the label, or NULL if out of memory */ static struct pxe_label *label_create(void) { @@ -227,13 +285,18 @@ static struct pxe_label *label_create(void) return label; } -/* - * Free the memory used by a pxe_label, including that used by its name, - * kernel, append and initrd members, if they're non NULL. +/** + * label_destroy() - free the memory used by a pxe_label + * + * This frees @label itself as well as memory used by its name, + * kernel, config, append, initrd, fdt, fdtdir and fdtoverlay members, if + * they're non-NULL. * * So - be sure to only use dynamically allocated memory for the members of * the pxe_label struct, unless you want to clean it up first. These are * currently only created by the pxe file parsing code. + * + * @label: Label to free */ static void label_destroy(struct pxe_label *label) { @@ -264,11 +327,13 @@ static void label_destroy(struct pxe_label *label) free(label); } -/* - * Print a label and its string members if they're defined. +/** + * label_print() - Print a label and its string members if they're defined * * This is passed as a callback to the menu code for displaying each * menu entry. + * + * @data: Label to print (is cast to struct pxe_label *) */ static void label_print(void *data) { @@ -278,14 +343,16 @@ static void label_print(void *data) printf("%s:\t%s\n", label->num, c); } -/* - * Boot a label that specified 'localboot'. This requires that the 'localcmd' - * environment variable is defined. Its contents will be executed as U-Boot - * command. If the label specified an 'append' line, its contents will be - * used to overwrite the contents of the 'bootargs' environment variable prior - * to running 'localcmd'. +/** + * label_localboot() - Boot a label that specified 'localboot' + * + * This requires that the 'localcmd' environment variable is defined. Its + * contents will be executed as U-Boot commands. If the label specified an + * 'append' line, its contents will be used to overwrite the contents of the + * 'bootargs' environment variable prior to running 'localcmd'. * - * Returns 1 on success or < 0 on error. + * @label: Label to process + * Returns 1 on success or < 0 on error */ static int label_localboot(struct pxe_label *label) { @@ -309,8 +376,11 @@ static int label_localboot(struct pxe_label *label) return run_command_list(localcmd, strlen(localcmd), 0); } -/* - * Loads fdt overlays specified in 'fdtoverlays'. +/** + * label_boot_fdtoverlay() - Loads fdt overlays specified in 'fdtoverlays' + * + * @ctx: PXE context + * @label: Label to process */ #ifdef CONFIG_OF_LIBFDT_OVERLAY static void label_boot_fdtoverlay(struct pxe_context *ctx, @@ -396,8 +466,8 @@ skip_overlay: } #endif -/* - * Boot according to the contents of a pxe_label. +/** + * label_boot() - Boot according to the contents of a pxe_label * * If we can't boot for any reason, we return. A successful boot never * returns. @@ -410,6 +480,11 @@ skip_overlay: * * If the label specifies an 'append' line, its contents will overwrite that * of the 'bootargs' environment variable. + * + * @ctx: PXE context + * @label: Label to process + * Returns does not return on success, otherwise returns 0 if a localboot + * label was processed, or 1 on error */ static int label_boot(struct pxe_context *ctx, struct pxe_label *label) { @@ -648,9 +723,7 @@ cleanup: return 1; } -/* - * Tokens for the pxe file parser. - */ +/** enum token_type - Tokens for the pxe file parser */ enum token_type { T_EOL, T_STRING, @@ -676,17 +749,13 @@ enum token_type { T_INVALID }; -/* - * A token - given by a value and a type. - */ +/** struct token - token - given by a value and a type */ struct token { char *val; enum token_type type; }; -/* - * Keywords recognized. - */ +/* Keywords recognized */ static const struct token keywords[] = { {"menu", T_MENU}, {"title", T_TITLE}, @@ -711,7 +780,9 @@ static const struct token keywords[] = { {NULL, T_INVALID} }; -/* +/** + * enum lex_state - lexer state + * * Since pxe(linux) files don't have a token to identify the start of a * literal, we have to keep track of when we're in a state where a literal is * expected vs when we're in a state a keyword is expected. @@ -722,11 +793,10 @@ enum lex_state { L_SLITERAL }; -/* - * get_string retrieves a string from *p and stores it as a token in - * *t. +/** + * get_string() - retrieves a string from *p and stores it as a token in *t. * - * get_string used for scanning both string literals and keywords. + * This is used for scanning both string literals and keywords. * * Characters from *p are copied into t-val until a character equal to * delim is found, or a NUL byte is reached. If delim has the special value of @@ -739,9 +809,15 @@ enum lex_state { * The location of *p is updated to point to the first character after the end * of the token - the ending delimiter. * - * On success, the new value of t->val is returned. Memory for t->val is - * allocated using malloc and must be free()'d to reclaim it. If insufficient - * memory is available, NULL is returned. + * Memory for t->val is allocated using malloc and must be free()'d to reclaim + * it. + * + * @p: Points to a pointer to the current position in the input being processed. + * Updated to point at the first character after the current token + * @t: Pointers to a token to fill in + * @delim: Delimiter character to look for, either newline or space + * @lower: true to convert the string to lower case when storing + * Returns the new value of t->val, on success, NULL if out of memory */ static char *get_string(char **p, struct token *t, char delim, int lower) { @@ -792,8 +868,11 @@ static char *get_string(char **p, struct token *t, char delim, int lower) return t->val; } -/* - * Populate a keyword token with a type and value. +/** + * get_keyword() - Populate a keyword token with a type and value + * + * Updates the ->type field based on the keyword string in @val + * @t: Token to populate */ static void get_keyword(struct token *t) { @@ -807,11 +886,14 @@ static void get_keyword(struct token *t) } } -/* - * Get the next token. We have to keep track of which state we're in to know - * if we're looking to get a string literal or a keyword. +/** + * get_token() - Get the next token + * + * We have to keep track of which state we're in to know if we're looking to get + * a string literal or a keyword. * - * *p is updated to point at the first character after the current token. + * @p: Points to a pointer to the current position in the input being processed. + * Updated to point at the first character after the current token */ static void get_token(char **p, struct token *t, enum lex_state state) { @@ -855,8 +937,13 @@ static void get_token(char **p, struct token *t, enum lex_state state) *p = c; } -/* - * Increment *c until we get to the end of the current line, or EOF. +/** + * eol_or_eof() - Find end of line + * + * Increment *c until we get to the end of the current line, or EOF + * + * @c: Points to a pointer to the current position in the input being processed. + * Updated to point at the first character after the current token */ static void eol_or_eof(char **c) { -- 2.33.0.1079.g6e70778dc9-goog