stand/fdt: Make fdt_overlay_apply signature-compatible with libfdt

libfdt will assume a writable fdt overlay blob has been passed in, so make
ours compatible to allow easier review when we try to drop libfdt into
place. overlay from the calling context is writable, making it safe to
simply rip out everything related to copying the overlay blob in
fdt_overlay_apply.

I note here that we still have problems: fdt_overlay_apply, both our version
and libfdt's, may fail and have already clobbered the base fdt to some
extent. Future work will make sure we don't apply a potentially bogus fdt,
instead discarding the base fdt if we had an error.

Reviewed by:	gonzo
Differential Revision:	https://reviews.freebsd.org/D13695
This commit is contained in:
kevans 2017-12-31 05:22:26 +00:00
parent a29455420d
commit 7a95cfd16f
3 changed files with 11 additions and 28 deletions

View File

@ -386,7 +386,8 @@ fdt_apply_overlays()
for (fp = file_findfile(NULL, "dtbo"); fp != NULL; fp = fp->f_next) {
printf("applying DTB overlay '%s'\n", fp->f_name);
COPYOUT(fp->f_addr, overlay, fp->f_size);
fdt_overlay_apply(new_fdtp, overlay, fp->f_size);
/* Both overlay and new_fdtp may be modified in place */
fdt_overlay_apply(new_fdtp, overlay);
}
free(fdtp);

View File

@ -409,41 +409,23 @@ fdt_overlay_apply_fragments(void *main_fdtp, void *overlay_fdtp)
}
int
fdt_overlay_apply(void *main_fdtp, void *overlay_fdtp, size_t overlay_length)
fdt_overlay_apply(void *main_fdtp, void *overlay_fdtp)
{
void *overlay_copy;
int rv;
rv = 0;
/* We modify overlay in-place, so we need writable copy */
overlay_copy = malloc(overlay_length);
if (overlay_copy == NULL) {
printf("failed to allocate memory for overlay copy\n");
if (fdt_overlay_do_fixups(main_fdtp, overlay_fdtp) < 0) {
printf("failed to perform fixups in overlay\n");
return (-1);
}
memcpy(overlay_copy, overlay_fdtp, overlay_length);
if (fdt_overlay_do_fixups(main_fdtp, overlay_copy) < 0) {
printf("failed to perform fixups in overlay\n");
rv = -1;
goto out;
}
if (fdt_overlay_do_local_fixups(main_fdtp, overlay_copy) < 0) {
if (fdt_overlay_do_local_fixups(main_fdtp, overlay_fdtp) < 0) {
printf("failed to perform local fixups in overlay\n");
rv = -1;
goto out;
return (-1);
}
if (fdt_overlay_apply_fragments(main_fdtp, overlay_copy) < 0) {
if (fdt_overlay_apply_fragments(main_fdtp, overlay_fdtp) < 0) {
printf("failed to apply fragments\n");
rv = -1;
return (-1);
}
out:
free(overlay_copy);
return (rv);
return (0);
}

View File

@ -29,6 +29,6 @@
#ifndef FDT_OVERLAY_H
#define FDT_OVERLAY_H
int fdt_overlay_apply(void *main_fdtp, void *overlay_fdtp, size_t overlay_length);
int fdt_overlay_apply(void *main_fdtp, void *overlay_fdtp);
#endif /* FDT_OVERLAY_H */