Browse Source

add the code to initalize the RNG w/ SRAM..

mbed-sx1276
John-Mark Gurney 3 years ago
parent
commit
eda0e27068
5 changed files with 67 additions and 9 deletions
  1. +32
    -9
      Makefile
  2. +8
    -0
      main.c
  3. +9
    -0
      stm32/l151ccux/STM32L151CCUX_FLASH.ld
  4. +16
    -0
      strobe_rng_init.c
  5. +2
    -0
      strobe_rng_init.h

+ 32
- 9
Makefile View File

@@ -1,25 +1,48 @@
ARMCC?= arm-none-eabi-gcc
ARMOBJDUMP?= arm-none-eabi-objdump
ARMTARGET?= -mcpu=cortex-m3 -mthumb -DSTROBE_SINGLE_THREAD=1

CFLAGS = -Istrobe
PROG = lora.irr
PROGEXT = .elf

SRCS = main.c
SRCS+= strobe_rng_init.c

CFLAGS+= -DNDEBUG

SRCS = \
strobe/strobe.c strobe/x25519.c
# Strobe
.PATH: $(.CURDIR)/strobe
CFLAGS = -I$(.CURDIR)/strobe
SRCS+= strobe.c \
x25519.c

# Microcontroller
STM32=$(.CURDIR)/stm32
.PATH: $(STM32)/l151ccux
LINKER_SCRIPT=$(STM32)/l151ccux/STM32L151CCUX_FLASH.ld
SRCS+= startup_stm32l151ccux.s \
system_stm32l1xx.c

CFLAGS+= -I$(STM32)
CFLAGS+= -I$(STM32)/l151ccux
CFLAGS+= -DSTM32L151xC

.OBJDIR = build
OBJS = $(SRCS:C/.c$/.o/)

.PHONY: all
all: $(BUILDDIR)/strobe.o $(BUILDDIR)/x25519.o
all: $(PROG)$(PROGEXT) $(PROG).list

$(PROG)$(PROGEXT): $(OBJS)
$(ARMCC) $(ARMTARGET) -o $@ $(.ALLSRC) -T$(LINKER_SCRIPT) --specs=nosys.specs -Wl,--gc-sections -static --specs=nano.specs -Wl,--start-group -lc -lm -Wl,--end-group

$(PROG).list: $(PROG)$(PROGEXT)
$(ARMOBJDUMP) -h -S $(.ALLSRC) > $@

.PHONY: runtests
runtests:
ls *.py | entr sh -c 'python -m coverage run -m unittest lora && coverage report --omit=p/\* -m -i'

$(BUILDDIR):
mkdir -p $@

$(BUILDDIR)/%.o : %.c
.c.o:
$(ARMCC) $(ARMTARGET) $(CFLAGS) -c $< -o $@

STROBE_REPO = https://git.code.sf.net/p/strobe/code


+ 8
- 0
main.c View File

@@ -0,0 +1,8 @@
#include <strobe_rng_init.h>

int
main(void)
{

strobe_rng_init();
}

+ 9
- 0
stm32/l151ccux/STM32L151CCUX_FLASH.ld View File

@@ -57,6 +57,7 @@ _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */

_Min_Heap_Size = 0x200 ; /* required amount of heap */
_Min_Stack_Size = 0x400 ; /* required amount of stack */
rng_save_len = 32 ; /* length of RNG state save space */

/* Memories definition */
MEMORY
@@ -177,6 +178,14 @@ SECTIONS
__bss_end__ = _ebss;
} >RAM

._rng_state :
{
. = ALIGN(4);
PROVIDE ( rng_save = .);
. = . + rng_save_len;
. = ALIGN(4);
} >RAM

/* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
._user_heap_stack :
{


+ 16
- 0
strobe_rng_init.c View File

@@ -0,0 +1,16 @@
#include <strobe.h>

#include <strobe_rng_init.h>

extern char rng_save;
extern int rng_save_len;

void
strobe_rng_init(void)
{
int r;

strobe_seed_prng(&rng_save, 2*1024);

r = strobe_randomize(&rng_save, rng_save_len);
}

+ 2
- 0
strobe_rng_init.h View File

@@ -0,0 +1,2 @@

void strobe_rng_init(void);

Loading…
Cancel
Save