1 // SPDX-License-Identifier: GPL-2.0+
3 * The 'kaslrseed' command takes bytes from the hardware random number
4 * generator and uses them to set the kaslr-seed value in the chosen node.
6 * Copyright (c) 2021, Chris Morgan <macromorgan@hotmail.com>
15 #include <fdt_support.h>
17 static int do_kaslr_seed(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
23 int ret = CMD_RET_SUCCESS;
25 if (uclass_get_device(UCLASS_RNG, 0, &dev) || !dev) {
26 printf("No RNG device\n");
27 return CMD_RET_FAILURE;
32 printf("Out of memory\n");
33 return CMD_RET_FAILURE;
36 if (dm_rng_read(dev, buf, n)) {
37 printf("Reading RNG failed\n");
38 return CMD_RET_FAILURE;
42 printf("No FDT memory address configured. Please configure\n"
43 "the FDT address via \"fdt addr <address>\" command.\n"
45 return CMD_RET_FAILURE;
48 ret = fdt_check_header(working_fdt);
50 printf("fdt_chosen: %s\n", fdt_strerror(ret));
51 return CMD_RET_FAILURE;
54 nodeoffset = fdt_find_or_add_subnode(working_fdt, 0, "chosen");
56 printf("Reading chosen node failed\n");
57 return CMD_RET_FAILURE;
60 ret = fdt_setprop(working_fdt, nodeoffset, "kaslr-seed", buf, sizeof(buf));
62 printf("Unable to set kaslr-seed on chosen node: %s\n", fdt_strerror(ret));
63 return CMD_RET_FAILURE;
71 #ifdef CONFIG_SYS_LONGHELP
72 static char kaslrseed_help_text[] =
74 " - append random bytes to chosen kaslr-seed node\n";
78 kaslrseed, 1, 0, do_kaslr_seed,
79 "feed bytes from the hardware random number generator to the kaslr-seed",