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
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.
28 #include <ipxe/command.h>
29 #include <ipxe/parseopt.h>
31 #include <ipxe/sanboot.h>
32 #include <usr/autoboot.h>
34 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
42 /** "sanboot" options */
43 struct sanboot_options {
46 /** Do not describe SAN device */
48 /** Keep SAN device */
52 /** "sanboot" option list */
54 /* "sanboot" takes all three options */
55 struct option_descriptor sanboot[3];
56 /* "sanhook" takes only --drive and --no-describe */
57 struct option_descriptor sanhook[2];
58 /* "sanunhook" takes only --drive */
59 struct option_descriptor sanunhook[1];
62 OPTION_DESC ( "drive", 'd', required_argument,
63 struct sanboot_options, drive, parse_integer ),
64 OPTION_DESC ( "no-describe", 'n', no_argument,
65 struct sanboot_options, no_describe, parse_flag ),
66 OPTION_DESC ( "keep", 'k', no_argument,
67 struct sanboot_options, keep, parse_flag ),
72 /** "sanhook" command descriptor */
73 static struct command_descriptor sanhook_cmd =
74 COMMAND_DESC ( struct sanboot_options, opts.sanhook, 1, 1,
77 /** "sanboot" command descriptor */
78 static struct command_descriptor sanboot_cmd =
79 COMMAND_DESC ( struct sanboot_options, opts.sanboot, 0, 1,
82 /** "sanunhook" command descriptor */
83 static struct command_descriptor sanunhook_cmd =
84 COMMAND_DESC ( struct sanboot_options, opts.sanunhook, 0, 0, NULL );
87 * The "sanboot", "sanhook" and "sanunhook" commands
89 * @v argc Argument count
90 * @v argv Argument list
91 * @v default_flags Default set of flags for uriboot()
92 * @v no_root_path_flags Additional flags to apply if no root path is present
93 * @ret rc Return status code
95 static int sanboot_core_exec ( int argc, char **argv,
96 struct command_descriptor *cmd,
97 int default_flags, int no_root_path_flags ) {
98 struct sanboot_options opts;
99 const char *root_path;
104 /* Initialise options */
105 memset ( &opts, 0, sizeof ( opts ) );
106 opts.drive = san_default_drive();
109 if ( ( rc = reparse_options ( argc, argv, cmd, &opts ) ) != 0 )
110 goto err_parse_options;
112 /* Parse root path, if present */
113 if ( argc > optind ) {
114 root_path = argv[optind];
115 uri = parse_uri ( root_path );
125 /* Construct flags */
126 flags = default_flags;
127 if ( opts.no_describe )
128 flags |= URIBOOT_NO_SAN_DESCRIBE;
130 flags |= URIBOOT_NO_SAN_UNHOOK;
132 flags |= no_root_path_flags;
134 /* Boot from root path */
135 if ( ( rc = uriboot ( NULL, uri, opts.drive, flags ) ) != 0 )
146 * The "sanhook" command
148 * @v argc Argument count
149 * @v argv Argument list
150 * @ret rc Return status code
152 static int sanhook_exec ( int argc, char **argv ) {
153 return sanboot_core_exec ( argc, argv, &sanhook_cmd,
154 ( URIBOOT_NO_SAN_BOOT |
155 URIBOOT_NO_SAN_UNHOOK ), 0 );
159 * The "sanboot" command
161 * @v argc Argument count
162 * @v argv Argument list
163 * @ret rc Return status code
165 static int sanboot_exec ( int argc, char **argv ) {
166 return sanboot_core_exec ( argc, argv, &sanboot_cmd,
167 0, URIBOOT_NO_SAN_UNHOOK );
171 * The "sanunhook" command
173 * @v argc Argument count
174 * @v argv Argument list
175 * @ret rc Return status code
177 static int sanunhook_exec ( int argc, char **argv ) {
178 return sanboot_core_exec ( argc, argv, &sanunhook_cmd,
179 ( URIBOOT_NO_SAN_DESCRIBE |
180 URIBOOT_NO_SAN_BOOT ), 0 );
184 struct command sanboot_commands[] __command = {
187 .exec = sanhook_exec,
191 .exec = sanboot_exec,
195 .exec = sanunhook_exec,