Skip to content

Commit 49a219e

Browse files
Merge pull request #6930 from Frauschi/zephyr_fix
Fixes for the Zephyr port
2 parents 73d3277 + a666c39 commit 49a219e

4 files changed

Lines changed: 57 additions & 15 deletions

File tree

.github/workflows/zephyr.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ jobs:
77
run_test:
88
name: Build and run
99
strategy:
10+
fail-fast: false
1011
matrix:
1112
config:
1213
- zephyr-ref: v3.4.0
1314
zephyr-sdk: 0.16.1
15+
- zephyr-ref: v3.5.0
16+
zephyr-sdk: 0.16.3
1417
runs-on: ubuntu-latest
1518
# This should be a safe limit for the tests to run.
1619
timeout-minutes: 15

wolfcrypt/src/random.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3506,23 +3506,16 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
35063506
* extern int myRngFunc(byte* output, word32 sz);
35073507
*/
35083508

3509-
#elif defined(WOLFSSL_SAFERTOS) || defined(WOLFSSL_LEANPSK) || \
3510-
defined(WOLFSSL_IAR_ARM) || defined(WOLFSSL_MDK_ARM) || \
3511-
defined(WOLFSSL_uITRON4) || defined(WOLFSSL_uTKERNEL2) || \
3512-
defined(WOLFSSL_LPC43xx) || defined(NO_STM32_RNG) || \
3513-
defined(MBED) || defined(WOLFSSL_EMBOS) || \
3514-
defined(WOLFSSL_GENSEED_FORTEST) || defined(WOLFSSL_CHIBIOS) || \
3515-
defined(WOLFSSL_CONTIKI) || defined(WOLFSSL_AZSPHERE)
3516-
3517-
/* these platforms do not have a default random seed and
3518-
you'll need to implement your own wc_GenerateSeed or define via
3519-
CUSTOM_RAND_GENERATE_BLOCK */
3520-
3521-
#define USE_TEST_GENSEED
3522-
35233509
#elif defined(WOLFSSL_ZEPHYR)
35243510

3511+
#include <version.h>
3512+
3513+
#if KERNEL_VERSION_NUMBER >= 0x30500
3514+
#include <zephyr/random/random.h>
3515+
#else
35253516
#include <zephyr/random/rand32.h>
3517+
#endif
3518+
35263519
#ifndef _POSIX_C_SOURCE
35273520
#include <zephyr/posix/time.h>
35283521
#else
@@ -3623,6 +3616,20 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
36233616
return ret;
36243617
}
36253618

3619+
#elif defined(WOLFSSL_SAFERTOS) || defined(WOLFSSL_LEANPSK) || \
3620+
defined(WOLFSSL_IAR_ARM) || defined(WOLFSSL_MDK_ARM) || \
3621+
defined(WOLFSSL_uITRON4) || defined(WOLFSSL_uTKERNEL2) || \
3622+
defined(WOLFSSL_LPC43xx) || defined(NO_STM32_RNG) || \
3623+
defined(MBED) || defined(WOLFSSL_EMBOS) || \
3624+
defined(WOLFSSL_GENSEED_FORTEST) || defined(WOLFSSL_CHIBIOS) || \
3625+
defined(WOLFSSL_CONTIKI) || defined(WOLFSSL_AZSPHERE)
3626+
3627+
/* these platforms do not have a default random seed and
3628+
you'll need to implement your own wc_GenerateSeed or define via
3629+
CUSTOM_RAND_GENERATE_BLOCK */
3630+
3631+
#define USE_TEST_GENSEED
3632+
36263633
#elif defined(NO_DEV_RANDOM)
36273634

36283635
#error "you need to write an os specific wc_GenerateSeed() here"

wolfcrypt/src/wc_port.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3164,6 +3164,30 @@ time_t z_time(time_t * timer)
31643164
{
31653165
struct timespec ts;
31663166

3167+
#if defined(CONFIG_RTC) && \
3168+
(defined(CONFIG_PICOLIBC) || defined(CONFIG_NEWLIB_LIBC))
3169+
/* Try to obtain the actual time from an RTC */
3170+
static const struct device *rtc = DEVICE_DT_GET(DT_NODELABEL(rtc));
3171+
3172+
if (device_is_ready(rtc)) {
3173+
struct rtc_time rtc_time;
3174+
struct tm *tm_time = rtc_time_to_tm(&rtc_time);
3175+
3176+
int ret = rtc_get_time(rtc, &rtc_time);
3177+
3178+
if (ret == 0) {
3179+
time_t epochTime = mktime(tm_time);
3180+
3181+
if (timer != NULL)
3182+
*timer = epochTime;
3183+
3184+
return epochTime;
3185+
}
3186+
}
3187+
#endif
3188+
3189+
/* Fallback to uptime since boot. This works for relative times, but
3190+
* not for ASN.1 date validation */
31673191
if (clock_gettime(CLOCK_REALTIME, &ts) == 0)
31683192
if (timer != NULL)
31693193
*timer = ts.tv_sec;

wolfssl/wolfcrypt/wc_port.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,15 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
982982
#ifndef _POSIX_C_SOURCE
983983
#include <zephyr/posix/time.h>
984984
#else
985-
#include <sys/time.h>
985+
#include <time.h>
986+
#endif
987+
988+
#if defined(CONFIG_RTC)
989+
#if defined(CONFIG_PICOLIBC) || defined(CONFIG_NEWLIB_LIBC)
990+
#include <zephyr/drivers/rtc.h>
991+
#else
992+
#warning "RTC support needs picolibc or newlib (nano)"
993+
#endif
986994
#endif
987995

988996
time_t z_time(time_t *timer);

0 commit comments

Comments
 (0)