Skip to content

Commit

Permalink
[FEATURE/FDT] Add bootargs select in early
Browse files Browse the repository at this point in the history
Maybe use for memory/DMA buffer init before
ofw_node unflatten.

Signed-off-by: GuEe-GUI <[email protected]>
  • Loading branch information
GuEe-GUI authored and mysterywolf committed Sep 13, 2024
1 parent cb665f9 commit 117e6ed
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions components/drivers/include/drivers/ofw_fdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ rt_err_t rt_fdt_boot_dump(void);
void rt_fdt_earlycon_output(const char *str);
void rt_fdt_earlycon_kick(int why);
rt_err_t rt_fdt_scan_chosen_stdout(void);
rt_err_t rt_fdt_bootargs_select(const char *key, int index, const char **out_result);
rt_err_t rt_fdt_unflatten(void);

struct rt_ofw_node *rt_fdt_unflatten_single(void *fdt);
Expand Down
49 changes: 49 additions & 0 deletions components/drivers/ofw/fdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,55 @@ rt_err_t rt_fdt_scan_chosen_stdout(void)
return err;
}

rt_err_t rt_fdt_bootargs_select(const char *key, int index, const char **out_result)
{
rt_err_t err;

if (key && index >= 0 && out_result)
{
int offset = fdt_path_offset(_fdt, "/chosen");

if (offset >= 0)
{
int len, key_len = rt_strlen(key);
const char *bootargs = fdt_getprop(_fdt, offset, "bootargs", &len), *end;

end = bootargs + len;
err = -RT_EEMPTY;

for (int i = 0; bootargs < end; ++i)
{
bootargs = rt_strstr(bootargs, key);

if (!bootargs)
{
break;
}

bootargs += key_len;

if (i == index)
{
*out_result = bootargs;

err = -RT_EOK;
break;
}
}
}
else
{
err = -RT_ERROR;
}
}
else
{
err = -RT_EINVAL;
}

return err;
}

static void system_node_init_flag(struct rt_ofw_node *np)
{
if (np)
Expand Down

0 comments on commit 117e6ed

Please sign in to comment.