From patchwork Wed May 15 00:22:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Harvey X-Patchwork-Id: 1935231 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VfDTN4DVCz1ymw for ; Wed, 15 May 2024 10:23:04 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 00D0D8814E; Wed, 15 May 2024 02:22:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gateworks.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 8F50388168; Wed, 15 May 2024 02:22:57 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from finn.localdomain (finn.gateworks.com [108.161.129.64]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8A6D6880F1 for ; Wed, 15 May 2024 02:22:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gateworks.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=tharvey@gateworks.com Received: from syn-068-189-091-139.biz.spectrum.com ([68.189.91.139] helo=tharvey.pdc.gateworks.com) by finn.localdomain with esmtp (Exim 4.95) (envelope-from ) id 1s72Pz-0088Md-QT; Wed, 15 May 2024 00:22:51 +0000 From: Tim Harvey To: u-boot@lists.denx.de, Tom Rini Cc: Simon Glass , Patrick Delaunay , Patrice Chotard , Devarsh Thakkar , Heinrich Schuchardt , Hugo Villeneuve , Marek Vasut , Tim Harvey Subject: [PATCH] fdt: add kaslr-seed if DM_RNG is enabled Date: Tue, 14 May 2024 17:22:48 -0700 Message-Id: <20240515002248.2920155-1-tharvey@gateworks.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean If RANDOMIZE_BASE is enabled in the Linux kernel instructing it to randomize the virtual address at which the kernel image is loaded, it expects entropy to be provided by the bootloader by populating /chosen/kaslr-seed with a 64-bit value from source of entropy at boot. If we have DM_RNG enabled poulate this value automatically when fdt_chosen is called. Signed-off-by: Tim Harvey --- boot/fdt_support.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/boot/fdt_support.c b/boot/fdt_support.c index 874ca4d6f5af..cd3069baf450 100644 --- a/boot/fdt_support.c +++ b/boot/fdt_support.c @@ -7,10 +7,12 @@ */ #include +#include #include #include #include #include +#include #include #include #include @@ -300,6 +302,27 @@ int fdt_chosen(void *fdt) if (nodeoffset < 0) return nodeoffset; + if (IS_ENABLED(CONFIG_DM_RNG)) { + struct udevice *dev; + size_t len = 0x8; + u64 *data; + + data = malloc(len); + if (!data) + return -ENOMEM; + + err = uclass_get_device(UCLASS_RNG, 0, &dev); + if (!err) + err = dm_rng_read(dev, data, len); + if (!err) + err = fdt_setprop(fdt, nodeoffset, "kaslr-seed", data, len); + if (err < 0) { + printf("WARNING: could not set kaslr-seed %s.\n", + fdt_strerror(err)); + return err; + } + } + if (IS_ENABLED(CONFIG_BOARD_RNG_SEED) && !board_rng_seed(&buf)) { err = fdt_setprop(fdt, nodeoffset, "rng-seed", abuf_data(&buf), abuf_size(&buf));