diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2022-10-25 02:43:18 +0200 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2022-10-27 11:34:31 +0100 |
commit | e1e618b9a0f9c23e9caa5933fa30ee3d33e00bfe (patch) | |
tree | c0120a03d9d9ae3dfd1cddccf5fcca624e7b8026 /softmmu | |
parent | 7966d70f6f6b188475e67c2c363f19eec3d28c96 (diff) | |
download | qemu-e1e618b9a0f9c23e9caa5933fa30ee3d33e00bfe.zip qemu-e1e618b9a0f9c23e9caa5933fa30ee3d33e00bfe.tar.gz qemu-e1e618b9a0f9c23e9caa5933fa30ee3d33e00bfe.tar.bz2 |
device-tree: add re-randomization helper function
When the system reboots, the rng-seed that the FDT has should be
re-randomized, so that the new boot gets a new seed. Several
architectures require this functionality, so export a function for
injecting a new seed into the given FDT.
Cc: Alistair Francis <alistair.francis@wdc.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-id: 20221025004327.568476-3-Jason@zx2c4.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'softmmu')
-rw-r--r-- | softmmu/device_tree.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c index ce74f3d..30aa3ae 100644 --- a/softmmu/device_tree.c +++ b/softmmu/device_tree.c @@ -22,6 +22,7 @@ #include "qemu/option.h" #include "qemu/bswap.h" #include "qemu/cutils.h" +#include "qemu/guest-random.h" #include "sysemu/device_tree.h" #include "hw/loader.h" #include "hw/boards.h" @@ -680,3 +681,23 @@ void hmp_dumpdtb(Monitor *mon, const QDict *qdict) info_report("dtb dumped to %s", filename); } + +void qemu_fdt_randomize_seeds(void *fdt) +{ + int noffset, poffset, len; + const char *name; + uint8_t *data; + + for (noffset = fdt_next_node(fdt, 0, NULL); + noffset >= 0; + noffset = fdt_next_node(fdt, noffset, NULL)) { + for (poffset = fdt_first_property_offset(fdt, noffset); + poffset >= 0; + poffset = fdt_next_property_offset(fdt, poffset)) { + data = (uint8_t *)fdt_getprop_by_offset(fdt, poffset, &name, &len); + if (!data || strcmp(name, "rng-seed")) + continue; + qemu_guest_getrandom_nofail(data, len); + } + } +} |