fdt: refactor initrd related code

Created a new fdt_initrd() to deal with setting the initrd properties
in the device tree and fixing up the mem reserve.  We can use this
both in the choosen node handling and lets us remove some duplicated
code when we fixup the initrd info in bootm on PPC.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
This commit is contained in:
Kumar Gala 2008-08-15 08:24:43 -05:00 committed by Wolfgang Denk
parent 3082d2348c
commit 2a1a2cb6e2
3 changed files with 71 additions and 69 deletions

View File

@ -99,24 +99,28 @@ static int fdt_fixup_stdout(void *fdt, int chosenoff)
} }
#endif #endif
int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force)
{ {
int nodeoffset; int nodeoffset;
int err; int err, j, total;
u32 tmp; /* used to set 32 bit integer properties */ u32 tmp;
char *str; /* used to set string properties */
const char *path; const char *path;
uint64_t addr, size;
err = fdt_check_header(fdt); /* Find the "chosen" node. */
if (err < 0) { nodeoffset = fdt_path_offset (fdt, "/chosen");
printf("fdt_chosen: %s\n", fdt_strerror(err));
return err; /* If there is no "chosen" node in the blob return */
if (nodeoffset < 0) {
printf("fdt_initrd: %s\n", fdt_strerror(nodeoffset));
return nodeoffset;
} }
if (initrd_start && initrd_end) { /* just return if initrd_start/end aren't valid */
uint64_t addr, size; if ((initrd_start == 0) || (initrd_end == 0))
int total = fdt_num_mem_rsv(fdt); return 0;
int j;
total = fdt_num_mem_rsv(fdt);
/* /*
* Look for an existing entry and update it. If we don't find * Look for an existing entry and update it. If we don't find
@ -132,9 +136,46 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force)
err = fdt_add_mem_rsv(fdt, initrd_start, initrd_end - initrd_start + 1); err = fdt_add_mem_rsv(fdt, initrd_start, initrd_end - initrd_start + 1);
if (err < 0) { if (err < 0) {
printf("fdt_chosen: %s\n", fdt_strerror(err)); printf("fdt_initrd: %s\n", fdt_strerror(err));
return err; return err;
} }
path = fdt_getprop(fdt, nodeoffset, "linux,initrd-start", NULL);
if ((path == NULL) || force) {
tmp = __cpu_to_be32(initrd_start);
err = fdt_setprop(fdt, nodeoffset,
"linux,initrd-start", &tmp, sizeof(tmp));
if (err < 0) {
printf("WARNING: "
"could not set linux,initrd-start %s.\n",
fdt_strerror(err));
return err;
}
tmp = __cpu_to_be32(initrd_end);
err = fdt_setprop(fdt, nodeoffset,
"linux,initrd-end", &tmp, sizeof(tmp));
if (err < 0) {
printf("WARNING: could not set linux,initrd-end %s.\n",
fdt_strerror(err));
return err;
}
}
return 0;
}
int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force)
{
int nodeoffset;
int err;
char *str; /* used to set string properties */
const char *path;
err = fdt_check_header(fdt);
if (err < 0) {
printf("fdt_chosen: %s\n", fdt_strerror(err));
return err;
} }
/* /*
@ -173,24 +214,8 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force)
fdt_strerror(err)); fdt_strerror(err));
} }
} }
if (initrd_start && initrd_end) {
path = fdt_getprop(fdt, nodeoffset, "linux,initrd-start", NULL); fdt_initrd(fdt, initrd_start, initrd_end, force);
if ((path == NULL) || force) {
tmp = __cpu_to_be32(initrd_start);
err = fdt_setprop(fdt, nodeoffset,
"linux,initrd-start", &tmp, sizeof(tmp));
if (err < 0)
printf("WARNING: "
"could not set linux,initrd-start %s.\n",
fdt_strerror(err));
tmp = __cpu_to_be32(initrd_end);
err = fdt_setprop(fdt, nodeoffset,
"linux,initrd-end", &tmp, sizeof(tmp));
if (err < 0)
printf("WARNING: could not set linux,initrd-end %s.\n",
fdt_strerror(err));
}
}
#ifdef CONFIG_OF_STDOUT_VIA_ALIAS #ifdef CONFIG_OF_STDOUT_VIA_ALIAS
path = fdt_getprop(fdt, nodeoffset, "linux,stdout-path", NULL); path = fdt_getprop(fdt, nodeoffset, "linux,stdout-path", NULL);

View File

@ -29,6 +29,7 @@
#include <fdt.h> #include <fdt.h>
int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force); int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force);
int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force);
void do_fixup_by_path(void *fdt, const char *path, const char *prop, void do_fixup_by_path(void *fdt, const char *path, const char *prop,
const void *val, int len, int create); const void *val, int len, int create);
void do_fixup_by_path_u32(void *fdt, const char *path, const char *prop, void do_fixup_by_path_u32(void *fdt, const char *path, const char *prop,

View File

@ -182,32 +182,8 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
#if defined(CONFIG_OF_LIBFDT) #if defined(CONFIG_OF_LIBFDT)
/* fixup the initrd now that we know where it should be */ /* fixup the initrd now that we know where it should be */
if ((of_flat_tree) && (initrd_start && initrd_end)) { if ((of_flat_tree) && (initrd_start && initrd_end))
uint64_t addr, size; fdt_initrd(of_flat_tree, initrd_start, initrd_end, 1);
int total = fdt_num_mem_rsv(of_flat_tree);
int j;
/* Look for the dummy entry and delete it */
for (j = 0; j < total; j++) {
fdt_get_mem_rsv(of_flat_tree, j, &addr, &size);
if (addr == images->rd_start) {
fdt_del_mem_rsv(of_flat_tree, j);
break;
}
}
ret = fdt_add_mem_rsv(of_flat_tree, initrd_start,
initrd_end - initrd_start + 1);
if (ret < 0) {
printf("fdt_chosen: %s\n", fdt_strerror(ret));
goto error;
}
do_fixup_by_path_u32(of_flat_tree, "/chosen",
"linux,initrd-start", initrd_start, 0);
do_fixup_by_path_u32(of_flat_tree, "/chosen",
"linux,initrd-end", initrd_end, 0);
}
#endif #endif
debug ("## Transferring control to Linux (at address %08lx) ...\n", debug ("## Transferring control to Linux (at address %08lx) ...\n",
(ulong)kernel); (ulong)kernel);