All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Steffen Jaeckel <jaeckel-floss@eyet-services.de>,
	Michal Simek <michal.simek@xilinx.com>,
	Tom Rini <trini@konsulko.com>, Dennis Gilmore <dennis@ausil.us>,
	Daniel Schwierzeck <daniel.schwierzeck@gmail.com>,
	Lukas Auer <lukas.auer@aisec.fraunhofer.de>,
	Simon Glass <sjg@chromium.org>
Subject: [PATCH 08/28] pxe: Tidy up some comments in pxe_utils
Date: Wed, 18 Aug 2021 21:45:41 -0600	[thread overview]
Message-ID: <20210818214547.8.I63fc393bcaf374bf63eb47403a82236173781ba7@changeid> (raw)
In-Reply-To: <20210819034601.1618773-1-sjg@chromium.org>

Some of these functions are a big vague in the comments. Tidy them up a
bit.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 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.rc1.237.g0d66db33f3-goog


  parent reply	other threads:[~2021-08-19  3:47 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-19  3:45 [PATCH 00/28] Initial implementation of bootmethod/bootflow Simon Glass
2021-08-19  3:45 ` [PATCH 01/28] Create a new boot/ directory Simon Glass
2021-08-19  3:45 ` [PATCH 02/28] pxe: Move API comments to the header files Simon Glass
2021-08-19  3:45 ` [PATCH 03/28] pxe: Use a context pointer Simon Glass
2021-08-19  3:45 ` [PATCH 04/28] pxe: Move do_getfile() into the context Simon Glass
2021-08-19  3:45 ` [PATCH 05/28] pxe: Add a userdata field to " Simon Glass
2021-08-19  3:45 ` [PATCH 06/28] pxe: Tidy up the is_pxe global Simon Glass
2021-08-19  3:45 ` [PATCH 07/28] pxe: Move pxe_utils files Simon Glass
2021-08-19  3:45 ` Simon Glass [this message]
2021-08-19  3:45 ` [PATCH 09/28] pxe: Tidy up code style a little in pxe_utils Simon Glass
2021-08-19  3:45 ` [PATCH 10/28] pxe: Move common parsing coding into pxe_util Simon Glass
2021-08-19  3:45 ` [PATCH 11/28] pxe: Clean up the use of bootfile Simon Glass
2021-08-19  3:45 ` [PATCH 12/28] pxe: Drop get_bootfile_path() Simon Glass
2021-08-19  3:45 ` [PATCH 13/28] lib: Add tests for simple_itoa() Simon Glass
2021-08-19  3:45 ` [PATCH 14/28] lib: Add a function to convert a string to a hex value Simon Glass
2021-08-19  3:45 ` [PATCH 15/28] pxe: Return the file size from the getfile() function Simon Glass
2021-08-19  3:45 ` [PATCH 16/28] pxe: Refactor sysboot to have one helper Simon Glass
2021-08-19  3:45 ` [PATCH 17/28] doc: Move distro boot doc to rST Simon Glass
2021-08-19  3:45 ` [PATCH 18/28] pxe: Allow calling the pxe_get logic directly Simon Glass
2021-08-19  3:45 ` [PATCH 19/28] bootmethod: Add the uclass and core implementation Simon Glass
2021-08-19  3:45 ` [PATCH 20/28] bootmethod: Add an implementation of distro boot Simon Glass
2021-08-19  3:45 ` [PATCH 21/28] bootmethod: Add a command Simon Glass
2021-08-19  3:45 ` [PATCH 22/28] bootflow: " Simon Glass
2021-08-19  3:45 ` [PATCH 23/28] bootmethod: Add tests for bootmethod and bootflow Simon Glass
2021-08-19  3:45 ` [PATCH 24/28] bootmethod: doc: Add documentation Simon Glass
2021-08-19  3:45 ` [PATCH 25/28] mmc: Allow for children other than the block device Simon Glass
2021-08-19  3:45 ` [PATCH 26/28] mmc: Add a bootmethod Simon Glass
2021-08-19  3:46 ` [PATCH 27/28] ethernet: " Simon Glass
2021-08-19  3:46 ` [PATCH 28/28] RFC: rpi: Switch over to use bootflow Simon Glass
2021-08-19 13:59 ` [PATCH 00/28] Initial implementation of bootmethod/bootflow Tom Rini
2021-08-19 14:25   ` Simon Glass
2021-08-19 17:27     ` Tom Rini
2021-08-23 12:35       ` Ilias Apalodimas
2021-08-23 17:25         ` Simon Glass
2021-08-23 20:08           ` Tom Rini
2021-08-24  9:29             ` Ilias Apalodimas
2021-08-25 13:11               ` Simon Glass
2021-08-25 13:29                 ` Peter Robinson
2021-08-25 21:34                   ` Mark Kettenis
2021-08-25 21:58                     ` Tom Rini
2021-08-20  3:15     ` AKASHI Takahiro
2021-08-20 18:22       ` Simon Glass
2021-08-23  0:46         ` AKASHI Takahiro
2021-08-23 11:54 ` Mark Kettenis
2021-08-23 17:25   ` Simon Glass
2021-08-23 20:01     ` Tom Rini
2021-08-24 10:22       ` Mark Kettenis
2021-08-25 10:45         ` Emmanuel Vadot
2021-08-25 13:11           ` Simon Glass
2021-08-25 14:42             ` AKASHI Takahiro
2021-08-25 14:56               ` Tom Rini
2021-08-25 21:54                 ` Mark Kettenis
2021-08-25 22:06                   ` Tom Rini
2021-08-26  6:33                     ` AKASHI Takahiro
2021-08-26 13:03                       ` Tom Rini
2021-08-26 12:01                     ` Mark Kettenis
2021-08-26 13:00                       ` Tom Rini
2021-08-26 13:32                         ` Mark Kettenis
2021-08-26 13:50                           ` Ilias Apalodimas
2021-08-26 11:55                 ` Peter Robinson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210818214547.8.I63fc393bcaf374bf63eb47403a82236173781ba7@changeid \
    --to=sjg@chromium.org \
    --cc=daniel.schwierzeck@gmail.com \
    --cc=dennis@ausil.us \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jaeckel-floss@eyet-services.de \
    --cc=lukas.auer@aisec.fraunhofer.de \
    --cc=michal.simek@xilinx.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.