iPXE
image_mem_cmd.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 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 
31 /** @file
32  *
33  * Read memory command
34  *
35  */
36 
37 /** "imgmem" options */
39  /** Image name */
40  char *name;
41 };
42 
43 /** "imgmem" option list */
44 static struct option_descriptor imgmem_opts[] = {
45  OPTION_DESC ( "name", 'n', required_argument,
46  struct imgmem_options, name, parse_string ),
47 };
48 
49 /** "imgmem" command descriptor */
51  COMMAND_DESC ( struct imgmem_options, imgmem_opts, 2, 2,
52  "<address> <length>" );
53 
54 /**
55  * The "imgmem" command
56  *
57  * @v argc Argument count
58  * @v argv Argument list
59  * @ret rc Return status code
60  */
61 static int imgmem_exec ( int argc, char **argv ) {
62  struct imgmem_options opts;
63  unsigned int data;
64  unsigned int len;
65  int rc;
66 
67  /* Parse options */
68  if ( ( rc = parse_options ( argc, argv, &imgmem_cmd, &opts ) ) != 0 )
69  return rc;
70 
71  /* Use start address as name if none specified */
72  if ( ! opts.name )
73  opts.name = argv[optind];
74 
75  /* Parse address */
76  if ( ( rc = parse_integer ( argv[optind++], &data ) ) != 0 )
77  return rc;
78 
79  /* Parse length */
80  if ( ( rc = parse_integer ( argv[optind++], &len ) ) != 0 )
81  return rc;
82 
83  /* Create image */
84  if ( ( rc = imgmem ( opts.name, phys_to_user ( data ), len ) ) != 0 )
85  return rc;
86 
87  return 0;
88 }
89 
90 /** Read memory command */
91 struct command imgmem_commands[] __command = {
92  {
93  .name = "imgmem",
94  .exec = imgmem_exec,
95  },
96 };
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:91
int imgmem(const char *name, userptr_t data, size_t len)
Create image from block of memory.
Definition: imgmgmt.c:187
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
static int imgmem_exec(int argc, char **argv)
The "imgmem" command.
Definition: image_mem_cmd.c:61
int optind
Current option index.
Definition: getopt.c:51
A command-line command.
Definition: command.h:9
static struct command_descriptor imgmem_cmd
"imgmem" command descriptor
Definition: image_mem_cmd.c:50
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
userptr_t phys_to_user(unsigned long phys_addr)
Convert physical address to user pointer.
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:484
A command descriptor.
Definition: parseopt.h:77
"imgmem" options
Definition: image_mem_cmd.c:38
Parse command-line options.
int parse_string(char *text, char **value)
Parse string value.
Definition: parseopt.c:73
Command line option parsing.
char * name
Image name.
Definition: image_mem_cmd.c:40
static struct option_descriptor imgmem_opts[]
"imgmem" option list
Definition: image_mem_cmd.c:44
static union @437 opts
"cert<xxx>" option list
const char * name
Name of the command.
Definition: command.h:11
uint32_t len
Length.
Definition: ena.h:14
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
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:108
struct command imgmem_commands [] __command
Read memory command.
Definition: image_mem_cmd.c:91