boot: extension: Move overlay apply custom logic to command level
The extension_overlay_cmd environment variable approach is specific to the U-Boot extension_board command, while other boot flows (pxe_utils, bootstd) handle overlay loading differently. Move the extension_overlay_cmd execution out of the core extension framework to the command level. This decouples the framework from command-specific behavior and prepares for future extension support in other boot flows. Signed-off-by: Kory Maincent (TI.com) <kory.maincent@bootlin.com> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
committed by
Tom Rini
parent
2d12958ee7
commit
f9b139342c
@@ -59,92 +59,34 @@ int extension_scan(void)
|
||||
return ops->scan(dev, extension_list);
|
||||
}
|
||||
|
||||
static int _extension_apply(const struct extension *extension)
|
||||
int extension_apply(struct fdt_header *working_fdt, ulong size)
|
||||
{
|
||||
ulong extrasize, overlay_addr;
|
||||
struct fdt_header *blob;
|
||||
char *overlay_cmd;
|
||||
ulong overlay_addr;
|
||||
int ret;
|
||||
|
||||
if (!working_fdt) {
|
||||
printf("No FDT memory address configured. Please configure\n"
|
||||
"the FDT address via \"fdt addr <address>\" command.\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
overlay_cmd = env_get("extension_overlay_cmd");
|
||||
if (!overlay_cmd) {
|
||||
printf("Environment extension_overlay_cmd is missing\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
overlay_addr = env_get_hex("extension_overlay_addr", 0);
|
||||
if (!overlay_addr) {
|
||||
printf("Environment extension_overlay_addr is missing\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
env_set("extension_overlay_name", extension->overlay);
|
||||
ret = run_command(overlay_cmd, 0);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
extrasize = env_get_hex("filesize", 0);
|
||||
if (!extrasize)
|
||||
return -EINVAL;
|
||||
|
||||
fdt_shrink_to_minimum(working_fdt, extrasize);
|
||||
fdt_shrink_to_minimum(working_fdt, size);
|
||||
|
||||
blob = map_sysmem(overlay_addr, 0);
|
||||
if (!fdt_valid(&blob)) {
|
||||
printf("Invalid overlay devicetree %s\n", extension->overlay);
|
||||
printf("Invalid overlay devicetree\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Apply method prints messages on error */
|
||||
ret = fdt_overlay_apply_verbose(working_fdt, blob);
|
||||
if (ret)
|
||||
printf("Failed to apply overlay %s\n", extension->overlay);
|
||||
printf("Failed to apply overlay\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int extension_apply(int extension_num)
|
||||
{
|
||||
struct alist *extension_list = extension_get_list();
|
||||
const struct extension *extension;
|
||||
|
||||
if (!extension_list)
|
||||
return -ENOENT;
|
||||
|
||||
extension = alist_get(extension_list, extension_num,
|
||||
struct extension);
|
||||
if (!extension) {
|
||||
printf("Wrong extension number\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return _extension_apply(extension);
|
||||
}
|
||||
|
||||
int extension_apply_all(void)
|
||||
{
|
||||
struct alist *extension_list = extension_get_list();
|
||||
const struct extension *extension;
|
||||
int ret;
|
||||
|
||||
if (!extension_list)
|
||||
return -ENOENT;
|
||||
|
||||
alist_for_each(extension, extension_list) {
|
||||
ret = _extension_apply(extension);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
UCLASS_DRIVER(extension) = {
|
||||
.name = "extension",
|
||||
.id = UCLASS_EXTENSION,
|
||||
|
||||
@@ -7,8 +7,90 @@
|
||||
#include <alist.h>
|
||||
#include <exports.h>
|
||||
#include <command.h>
|
||||
#include <env.h>
|
||||
#include <extension_board.h>
|
||||
|
||||
static int
|
||||
cmd_extension_load_overlay_from_env(const struct extension *extension,
|
||||
ulong *filesize)
|
||||
{
|
||||
ulong size, overlay_addr;
|
||||
char *overlay_cmd;
|
||||
int ret;
|
||||
|
||||
overlay_cmd = env_get("extension_overlay_cmd");
|
||||
if (!overlay_cmd) {
|
||||
printf("Environment extension_overlay_cmd is missing\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
overlay_addr = env_get_hex("extension_overlay_addr", 0);
|
||||
if (!overlay_addr) {
|
||||
printf("Environment extension_overlay_addr is missing\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
env_set("extension_overlay_name", extension->overlay);
|
||||
ret = run_command(overlay_cmd, 0);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
size = env_get_hex("filesize", 0);
|
||||
if (!size)
|
||||
return -EINVAL;
|
||||
|
||||
*filesize = size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_extension_apply(int extension_num)
|
||||
{
|
||||
struct alist *extension_list = extension_get_list();
|
||||
const struct extension *extension;
|
||||
ulong size;
|
||||
int ret;
|
||||
|
||||
if (!extension_list)
|
||||
return -ENODEV;
|
||||
|
||||
extension = alist_get(extension_list, extension_num,
|
||||
struct extension);
|
||||
if (!extension) {
|
||||
printf("Wrong extension number\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = cmd_extension_load_overlay_from_env(extension, &size);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return extension_apply(working_fdt, size);
|
||||
}
|
||||
|
||||
static int cmd_extension_apply_all(void)
|
||||
{
|
||||
struct alist *extension_list = extension_get_list();
|
||||
const struct extension *extension;
|
||||
int ret;
|
||||
|
||||
if (!extension_list)
|
||||
return -ENODEV;
|
||||
|
||||
alist_for_each(extension, extension_list) {
|
||||
ulong size;
|
||||
|
||||
ret = cmd_extension_load_overlay_from_env(extension, &size);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = extension_apply(working_fdt, size);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_extension_list(struct cmd_tbl *cmdtp, int flag,
|
||||
int argc, char *const argv[])
|
||||
{
|
||||
@@ -55,12 +137,18 @@ static int do_extension_apply(struct cmd_tbl *cmdtp, int flag,
|
||||
if (argc < 2)
|
||||
return CMD_RET_USAGE;
|
||||
|
||||
if (!working_fdt) {
|
||||
printf("No FDT memory address configured. Please configure\n"
|
||||
"the FDT address via \"fdt addr <address>\" command.\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "all") == 0) {
|
||||
if (extension_apply_all())
|
||||
if (cmd_extension_apply_all())
|
||||
return CMD_RET_FAILURE;
|
||||
} else {
|
||||
extension_id = simple_strtol(argv[1], NULL, 10);
|
||||
if (extension_apply(extension_id))
|
||||
if (cmd_extension_apply(extension_id))
|
||||
return CMD_RET_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,17 +44,11 @@ int extension_scan(void);
|
||||
|
||||
/**
|
||||
* extension_apply - Apply extension board overlay to the devicetree
|
||||
* @extension_num: Extension number to be applied
|
||||
* @working_fdt: Pointer to working flattened device tree
|
||||
* @size: Size of the devicetree overlay
|
||||
* Return: Zero on success, negative on failure.
|
||||
*/
|
||||
int extension_apply(int extension_num);
|
||||
|
||||
/**
|
||||
* extension_apply_all - Apply all extension board overlays to the
|
||||
* devicetree
|
||||
* Return: Zero on success, negative on failure.
|
||||
*/
|
||||
int extension_apply_all(void);
|
||||
int extension_apply(struct fdt_header *working_fdt, ulong size);
|
||||
|
||||
/**
|
||||
* extension - Description fields of an extension board
|
||||
|
||||
Reference in New Issue
Block a user