[PATCH] Added Getentropy() support to beagle BSP

Udit agarwal dev.madaari at gmail.com
Thu Mar 15 11:00:17 UTC 2018


On Thu, Mar 15, 2018 at 2:38 PM, Sebastian Huber <
sebastian.huber at embedded-brains.de> wrote:

> On 15/03/18 09:20, Udit agarwal wrote:
>
>> Also, will it be ok to keep atsam_trng_mutex even after user has finished
>> using getentropy() i.e when we don't use destroy(&atsam_trng_mutex) at all?
>>
>
> Why do you want to destroy the mutex?

Just trying to reduce redundancy, but then i don't think that's a good
idea. BTW, here's atsam patch, please have a look:

>From 35313002ea19715c5914c5983a24471b0763aa68 Mon Sep 17 00:00:00 2001
From: Udit agarwal <dev.madaari at gmail.com>
Date: Thu, 15 Mar 2018 16:21:51 +0530
Subject: [PATCH] Added mutex across TRNG_GetRandData

---
 c/src/lib/libbsp/arm/atsam/startup/getentropy-trng.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/c/src/lib/libbsp/arm/atsam/startup/getentropy-trng.c
b/c/src/lib/libbsp/arm/atsam/startup/getentropy-trng.c
index 11e24dc..2789970 100644
--- a/c/src/lib/libbsp/arm/atsam/startup/getentropy-trng.c
+++ b/c/src/lib/libbsp/arm/atsam/startup/getentropy-trng.c
@@ -16,6 +16,9 @@
 #include <unistd.h>
 #include <string.h>
 #include <rtems/sysinit.h>
+#include <rtems/thread.h>
+
+static rtems_mutex atsam_trng_mutex =
RTEMS_MUTEX_INITIALIZER("atsam_trng");

 static void atsam_trng_enable(void)
 {
@@ -25,6 +28,9 @@ static void atsam_trng_enable(void)

 int getentropy(void *ptr, size_t n)
 {
+
+    rtems_mutex_lock(&atsam_trng_mutex);
+
     while (n > 0) {
         uint32_t random;
         size_t copy;
@@ -51,6 +57,7 @@ int getentropy(void *ptr, size_t n)
         ptr += copy;
     }

+    rtems_mutex_unlock(&atsam_trng_mutex);
     return 0;
 }

-- 
1.9.1



>
>
> --
> Sebastian Huber, embedded brains GmbH
>
> Address : Dornierstr. 4, D-82178 Puchheim, G
> <https://maps.google.com/?q=ess+:+Dornierstr.+4,+D-82178+Puchheim,+G&entry=gmail&source=g>
> ermany
> Phone   : +49 89 189 47 41-16
> Fax     : +49 89 189 47 41-09
> E-Mail  : sebastian.huber at embedded-brains.de
> PGP     : Public key available on request.
>
> Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20180315/7bf6a8fc/attachment-0002.html>


More information about the devel mailing list