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
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26#include <getopt.h>
27#include <ipxe/uaccess.h>
28#include <ipxe/command.h>
29#include <ipxe/parseopt.h>
30#include <usr/imgmgmt.h>
31
32/** @file
33 *
34 * Read memory command
35 *
36 */
37
38/** "imgmem" options */
40 /** Image name */
41 char *name;
42};
43
44/** "imgmem" option list */
45static struct option_descriptor imgmem_opts[] = {
46 OPTION_DESC ( "name", 'n', required_argument,
48};
49
50/** "imgmem" command descriptor */
53 "<address> <length>" );
54
55/**
56 * The "imgmem" command
57 *
58 * @v argc Argument count
59 * @v argv Argument list
60 * @ret rc Return status code
61 */
62static int imgmem_exec ( int argc, char **argv ) {
63 struct imgmem_options opts;
64 unsigned int data;
65 unsigned int len;
66 int rc;
67
68 /* Parse options */
69 if ( ( rc = parse_options ( argc, argv, &imgmem_cmd, &opts ) ) != 0 )
70 return rc;
71
72 /* Use start address as name if none specified */
73 if ( ! opts.name )
74 opts.name = argv[optind];
75
76 /* Parse address */
77 if ( ( rc = parse_integer ( argv[optind++], &data ) ) != 0 )
78 return rc;
79
80 /* Parse length */
81 if ( ( rc = parse_integer ( argv[optind++], &len ) ) != 0 )
82 return rc;
83
84 /* Create image */
85 if ( ( rc = imgmem ( opts.name, phys_to_virt ( data ), len ) ) != 0 )
86 return rc;
87
88 return 0;
89}
90
91/** Read memory command */
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
const char * name
Definition ath9k_hw.c:1986
static union @024010030001061367220137227263210031030210157031 opts
"cert<xxx>" option list
#define COMMAND(name, exec)
Definition command.h:27
ring len
Length.
Definition dwmac.h:226
uint8_t data[48]
Additional event data.
Definition ena.h:11
int optind
Current option index.
Definition getopt.c:52
Parse command-line options.
@ required_argument
Option requires an argument.
Definition getopt.h:19
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
static struct command_descriptor imgmem_cmd
"imgmem" command descriptor
static int imgmem_exec(int argc, char **argv)
The "imgmem" command.
static struct option_descriptor imgmem_opts[]
"imgmem" option list
int imgmem(const char *name, const void *data, size_t len)
Create image from block of memory.
Definition imgmgmt.c:189
Image management.
Access to external ("user") memory.
int parse_string(char *text, char **value)
Parse string value.
Definition parseopt.c:74
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition parseopt.c:92
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition parseopt.c:485
Command line option parsing.
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition parseopt.h:109
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition parseopt.h:68
A command descriptor.
Definition parseopt.h:78
"imgmem" options
char * name
Image name.
A command-line option descriptor.
Definition parseopt.h:24