2 * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
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.
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.
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
24 #include <ipxe/command.h>
25 #include <ipxe/parseopt.h>
27 #include <ipxe/sanboot.h>
28 #include <usr/autoboot.h>
30 FILE_LICENCE ( GPL2_OR_LATER );
38 /** "sanboot" options */
39 struct sanboot_options {
42 /** Do not describe SAN device */
44 /** Keep SAN device */
48 /** "sanboot" option list */
50 /* "sanboot" takes all three options */
51 struct option_descriptor sanboot[3];
52 /* "sanhook" takes only --drive and --no-describe */
53 struct option_descriptor sanhook[2];
54 /* "sanunhook" takes only --drive */
55 struct option_descriptor sanunhook[1];
58 OPTION_DESC ( "drive", 'd', required_argument,
59 struct sanboot_options, drive, parse_integer ),
60 OPTION_DESC ( "no-describe", 'n', no_argument,
61 struct sanboot_options, no_describe, parse_flag ),
62 OPTION_DESC ( "keep", 'k', no_argument,
63 struct sanboot_options, keep, parse_flag ),
68 /** "sanhook" command descriptor */
69 static struct command_descriptor sanhook_cmd =
70 COMMAND_DESC ( struct sanboot_options, opts.sanhook, 1, 1,
73 /** "sanboot" command descriptor */
74 static struct command_descriptor sanboot_cmd =
75 COMMAND_DESC ( struct sanboot_options, opts.sanboot, 0, 1,
78 /** "sanunhook" command descriptor */
79 static struct command_descriptor sanunhook_cmd =
80 COMMAND_DESC ( struct sanboot_options, opts.sanunhook, 0, 0, NULL );
83 * The "sanboot", "sanhook" and "sanunhook" commands
85 * @v argc Argument count
86 * @v argv Argument list
87 * @v default_flags Default set of flags for uriboot()
88 * @v no_root_path_flags Additional flags to apply if no root path is present
89 * @ret rc Return status code
91 static int sanboot_core_exec ( int argc, char **argv,
92 struct command_descriptor *cmd,
93 int default_flags, int no_root_path_flags ) {
94 struct sanboot_options opts;
95 const char *root_path;
100 /* Initialise options */
101 memset ( &opts, 0, sizeof ( opts ) );
102 opts.drive = san_default_drive();
105 if ( ( rc = reparse_options ( argc, argv, cmd, &opts ) ) != 0 )
106 goto err_parse_options;
108 /* Parse root path, if present */
109 if ( argc > optind ) {
110 root_path = argv[optind];
111 uri = parse_uri ( root_path );
121 /* Construct flags */
122 flags = default_flags;
123 if ( opts.no_describe )
124 flags |= URIBOOT_NO_SAN_DESCRIBE;
126 flags |= URIBOOT_NO_SAN_UNHOOK;
128 flags |= no_root_path_flags;
130 /* Boot from root path */
131 if ( ( rc = uriboot ( NULL, uri, opts.drive, flags ) ) != 0 )
142 * The "sanhook" command
144 * @v argc Argument count
145 * @v argv Argument list
146 * @ret rc Return status code
148 static int sanhook_exec ( int argc, char **argv ) {
149 return sanboot_core_exec ( argc, argv, &sanhook_cmd,
150 ( URIBOOT_NO_SAN_BOOT |
151 URIBOOT_NO_SAN_UNHOOK ), 0 );
155 * The "sanboot" command
157 * @v argc Argument count
158 * @v argv Argument list
159 * @ret rc Return status code
161 static int sanboot_exec ( int argc, char **argv ) {
162 return sanboot_core_exec ( argc, argv, &sanboot_cmd,
163 0, URIBOOT_NO_SAN_UNHOOK );
167 * The "sanunhook" command
169 * @v argc Argument count
170 * @v argv Argument list
171 * @ret rc Return status code
173 static int sanunhook_exec ( int argc, char **argv ) {
174 return sanboot_core_exec ( argc, argv, &sanunhook_cmd,
175 ( URIBOOT_NO_SAN_DESCRIBE |
176 URIBOOT_NO_SAN_BOOT ), 0 );
180 struct command sanboot_commands[] __command = {
183 .exec = sanhook_exec,
187 .exec = sanboot_exec,
191 .exec = sanunhook_exec,