[FEATURE/FDT] Add bootargs select in early

Maybe use for memory/DMA buffer init before
ofw_node unflatten.

Signed-off-by: GuEe-GUI <2991707448@qq.com>
This commit is contained in:
GuEe-GUI 2024-09-10 13:34:54 +08:00 committed by Meco Man
parent cb665f932e
commit 117e6ed347
2 changed files with 50 additions and 0 deletions

View File

@ -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);

View File

@ -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)