From patchwork Fri Dec 13 07:14:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 1208977 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.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 RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Z24w1hK2z9sPK for ; Fri, 13 Dec 2019 18:15:44 +1100 (AEDT) Received: from phobos.denx.de (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1C14381795; Fri, 13 Dec 2019 08:15:13 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org 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 0A8A38177F; Fri, 13 Dec 2019 08:15:09 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=SPF_HELO_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 0597381785 for ; Fri, 13 Dec 2019 08:15:03 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E774ADA7; Thu, 12 Dec 2019 23:15:02 -0800 (PST) Received: from usa.arm.com (a074948-lin.blr.arm.com [10.162.4.147]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 241EB3F52E; Thu, 12 Dec 2019 23:18:14 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Subject: [PATCH v3 5/8] sandbox: rng: Add a random number generator(rng) driver Date: Fri, 13 Dec 2019 12:44:24 +0530 Message-Id: <1576221267-5948-6-git-send-email-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1576221267-5948-1-git-send-email-sughosh.ganu@linaro.org> References: <1576221267-5948-1-git-send-email-sughosh.ganu@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 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.101.4 at phobos.denx.de X-Virus-Status: Clean Add a sandbox driver for random number generation. Mostly aimed at providing a unit test for rng uclass. Signed-off-by: Sughosh Ganu Reviewed-by: Patrice Chotard --- arch/sandbox/dts/test.dts | 4 ++++ drivers/rng/Kconfig | 7 +++++++ drivers/rng/Makefile | 1 + drivers/rng/sandbox_rng.c | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 drivers/rng/sandbox_rng.c diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index fdb08f2..2c85540 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -599,6 +599,10 @@ reset-names = "other", "test"; }; + rng@0 { + compatible = "sandbox,sandbox-rng"; + }; + rproc_1: rproc@1 { compatible = "sandbox,test-processor"; remoteproc-name = "remoteproc-test-dev1"; diff --git a/drivers/rng/Kconfig b/drivers/rng/Kconfig index 5fc11db..3a1d3f0 100644 --- a/drivers/rng/Kconfig +++ b/drivers/rng/Kconfig @@ -6,6 +6,13 @@ config DM_RNG This interface is used to initialise the rng device and to read the random seed from the device. +config RNG_SANDBOX + bool "Sandbox random number generator" + depends on SANDBOX && DM_RNG + help + Enable random number generator for sandbox. This is an + emulation of a rng device. + config RNG_STM32MP1 bool "Enable random number generator for STM32MP1" depends on ARCH_STM32MP && DM_RNG diff --git a/drivers/rng/Makefile b/drivers/rng/Makefile index 699beb3..3517005 100644 --- a/drivers/rng/Makefile +++ b/drivers/rng/Makefile @@ -4,4 +4,5 @@ # obj-$(CONFIG_DM_RNG) += rng-uclass.o +obj-$(CONFIG_RNG_SANDBOX) += sandbox_rng.o obj-$(CONFIG_RNG_STM32MP1) += stm32mp1_rng.o diff --git a/drivers/rng/sandbox_rng.c b/drivers/rng/sandbox_rng.c new file mode 100644 index 0000000..c5be552 --- /dev/null +++ b/drivers/rng/sandbox_rng.c @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019, Linaro Limited + */ + +#include +#include +#include + +static unsigned long random = 0xdeadbeef; + +static int sandbox_rng_read(struct udevice *dev, void *data, size_t len) +{ + random ^= ~0UL; + *(unsigned long *)data = random; + + return sizeof(random); +} + +static const struct dm_rng_ops sandbox_rng_ops = { + .read = sandbox_rng_read, +}; + +static const struct udevice_id sandbox_rng_match[] = { + { + .compatible = "sandbox,sandbox-rng", + }, + {}, +}; + +U_BOOT_DRIVER(sandbox_rng) = { + .name = "sandbox-rng", + .id = UCLASS_RNG, + .of_match = sandbox_rng_match, + .ops = &sandbox_rng_ops, +};