Chris Morgan | 61a9618 | 2021-08-25 11:22:57 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 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. |
| 5 | * |
| 6 | * Copyright (c) 2021, Chris Morgan <macromorgan@hotmail.com> |
| 7 | */ |
| 8 | |
Chris Morgan | 61a9618 | 2021-08-25 11:22:57 -0500 | [diff] [blame] | 9 | #include <command.h> |
| 10 | #include <dm.h> |
| 11 | #include <hexdump.h> |
| 12 | #include <malloc.h> |
| 13 | #include <rng.h> |
| 14 | #include <fdt_support.h> |
| 15 | |
| 16 | static int do_kaslr_seed(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
| 17 | { |
Tim Harvey | c75fab4 | 2024-06-18 14:06:08 -0700 | [diff] [blame] | 18 | int err = CMD_RET_SUCCESS; |
Chris Morgan | 61a9618 | 2021-08-25 11:22:57 -0500 | [diff] [blame] | 19 | |
Tim Harvey | c75fab4 | 2024-06-18 14:06:08 -0700 | [diff] [blame] | 20 | printf("Notice: a /chosen/kaslr-seed is automatically added to the device-tree when booted via booti/bootm/bootz therefore using this command is likely no longer needed\n"); |
Chris Morgan | 61a9618 | 2021-08-25 11:22:57 -0500 | [diff] [blame] | 21 | |
| 22 | if (!working_fdt) { |
| 23 | printf("No FDT memory address configured. Please configure\n" |
| 24 | "the FDT address via \"fdt addr <address>\" command.\n" |
| 25 | "Aborting!\n"); |
Tim Harvey | c75fab4 | 2024-06-18 14:06:08 -0700 | [diff] [blame] | 26 | err = CMD_RET_FAILURE; |
| 27 | } else { |
| 28 | if (fdt_kaslrseed(working_fdt, true) < 0) |
| 29 | err = CMD_RET_FAILURE; |
Chris Morgan | 61a9618 | 2021-08-25 11:22:57 -0500 | [diff] [blame] | 30 | } |
| 31 | |
Tim Harvey | c75fab4 | 2024-06-18 14:06:08 -0700 | [diff] [blame] | 32 | return cmd_process_error(cmdtp, err); |
Chris Morgan | 61a9618 | 2021-08-25 11:22:57 -0500 | [diff] [blame] | 33 | } |
| 34 | |
Tom Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 35 | U_BOOT_LONGHELP(kaslrseed, |
Heinrich Schuchardt | a585918 | 2024-06-18 14:29:13 +0200 | [diff] [blame] | 36 | "\n" |
Tom Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 37 | " - append random bytes to chosen kaslr-seed node\n"); |
Chris Morgan | 61a9618 | 2021-08-25 11:22:57 -0500 | [diff] [blame] | 38 | |
| 39 | U_BOOT_CMD( |
| 40 | kaslrseed, 1, 0, do_kaslr_seed, |
| 41 | "feed bytes from the hardware random number generator to the kaslr-seed", |
| 42 | kaslrseed_help_text |
| 43 | ); |