iPXE
fdt_cmd.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2025 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #include <getopt.h>
27 #include <ipxe/command.h>
28 #include <ipxe/parseopt.h>
29 #include <usr/imgmgmt.h>
30 #include <usr/fdtmgmt.h>
31 
32 /** @file
33  *
34  * Flattened Device Tree commands
35  *
36  */
37 
38 /** "fdt" options */
39 struct fdt_options {
40  /** Download timeout */
41  unsigned long timeout;
42 };
43 
44 /** "fdt" option list */
45 static struct option_descriptor fdt_opts[] = {
46  OPTION_DESC ( "timeout", 't', required_argument,
48 };
49 
50 /** "fdt" command descriptor */
51 static struct command_descriptor fdt_cmd =
52  COMMAND_DESC ( struct fdt_options, fdt_opts, 0, 1, "[<uri>]" );
53 
54 /**
55  * The "fdt" command
56  *
57  * @v argc Argument count
58  * @v argv Argument list
59  * @ret rc Return status code
60  */
61 static int fdt_exec ( int argc, char **argv ) {
62  struct fdt_options opts;
63  struct image *image = NULL;
64  char *name_uri;
65  int rc;
66 
67  /* Parse options */
68  if ( ( rc = parse_options ( argc, argv, &fdt_cmd, &opts ) ) != 0 )
69  goto err_parse;
70 
71  /* Parse name/URI string */
72  name_uri = argv[optind];
73 
74  /* Acquire image, if applicable */
75  if ( name_uri && ( ( rc = imgacquire ( name_uri, opts.timeout,
76  &image ) ) != 0 ) ) {
77  goto err_image;
78  }
79 
80  /* (Un)register as FDT */
81  if ( ( rc = imgfdt ( image ) ) != 0 )
82  goto err_fdt;
83 
84  err_fdt:
85  err_image:
86  err_parse:
87  return rc;
88 }
89 
90 /** Flattened Device Tree commands */
91 COMMAND ( fdt, fdt_exec );
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static struct option_descriptor fdt_opts[]
"fdt" option list
Definition: fdt_cmd.c:45
int optind
Current option index.
Definition: getopt.c:51
static int fdt_exec(int argc, char **argv)
The "fdt" command.
Definition: fdt_cmd.c:61
int parse_timeout(char *text, unsigned long *value)
Parse timeout value (in ms)
Definition: parseopt.c:114
int imgfdt(struct image *image)
Apply flattened device tree image.
Definition: fdtmgmt.c:41
Flattened Device Tree management.
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:484
An executable image.
Definition: image.h:23
"fdt" options
Definition: fdt_cmd.c:39
A command descriptor.
Definition: parseopt.h:77
Parse command-line options.
static struct command_descriptor fdt_cmd
"fdt" command descriptor
Definition: fdt_cmd.c:51
Command line option parsing.
unsigned long timeout
Download timeout.
Definition: fdt_cmd.c:41
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
A device tree.
Definition: fdt.h:88
Image management.
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:67
Option requires an argument.
Definition: getopt.h:18
A command-line option descriptor.
Definition: parseopt.h:23
static union @447 opts
"cert<xxx>" option list
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:108
void timeout(int)
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
int imgacquire(const char *name_uri, unsigned long timeout, struct image **image)
Acquire an image.
Definition: imgmgmt.c:142
COMMAND(fdt, fdt_exec)
Flattened Device Tree commands.