|
| 1 | +/* |
| 2 | + * Copyright (C) 2025 Michael Brown <[email protected]>. |
| 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, |
| 47 | + struct fdt_options, timeout, parse_timeout ), |
| 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 | +struct command fdt_commands[] __command = { |
| 92 | + { |
| 93 | + .name = "fdt", |
| 94 | + .exec = fdt_exec, |
| 95 | + }, |
| 96 | +}; |
0 commit comments