Skip to content

Commit 09fbebc

Browse files
committed
[fdt] Add the "fdt" command
Allow a Flattened Device Tree blob (DTB) to be provided to a booted operating system using a script such as: #!ipxe kernel /images/vmlinuz console=ttyAMA0 initrd /images/initrd.img fdt /images/rk3566-radxa-zero-3e.dtb boot Signed-off-by: Michael Brown <[email protected]>
1 parent cfd9346 commit 09fbebc

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed

src/config/config.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ REQUIRE_OBJECT ( image_crypt_cmd );
308308
#ifdef USB_CMD
309309
REQUIRE_OBJECT ( usb_cmd );
310310
#endif
311+
#ifdef FDT_CMD
312+
REQUIRE_OBJECT ( fdt_cmd );
313+
#endif
311314

312315
/*
313316
* Drag in miscellaneous objects

src/config/defaults/efi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
6464

6565
#if defined ( __arm__ ) || defined ( __aarch64__ )
6666
#define IOAPI_ARM
67+
#define FDT_CMD
6768
#endif
6869

6970
#if defined ( __aarch64__ )
7071
#define IMAGE_GZIP /* GZIP image support */
72+
#define FDT_CMD
7173
#endif
7274

7375
#if defined ( __loongarch__ )
@@ -76,6 +78,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
7678

7779
#if defined ( __riscv )
7880
#define IOAPI_RISCV
81+
#define FDT_CMD
7982
#endif
8083

8184
#endif /* CONFIG_DEFAULTS_EFI_H */

src/config/defaults/sbi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
3232

3333
#define REBOOT_CMD
3434
#define POWEROFF_CMD
35+
#define FDT_CMD
3536

3637
#endif /* CONFIG_DEFAULTS_SBI_H */

src/config/general.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
173173
#define IMAGE_ARCHIVE_CMD /* Archive image management commands */
174174
#define SHIM_CMD /* EFI shim command (or dummy command) */
175175
//#define USB_CMD /* USB commands */
176+
//#define FDT_CMD /* Flattened Device Tree commands */
176177

177178
/*
178179
* Certificate sources

src/hci/commands/fdt_cmd.c

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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

Comments
 (0)