diff --git a/emk_project.py b/emk_project.py index cad35a4..43c9d6d 100644 --- a/emk_project.py +++ b/emk_project.py @@ -1,6 +1,6 @@ import os -c, link = emk.module("c", "link") +c, link, asm, utils = emk.module("c", "link", "asm", "utils") default_compile_flags = ["-fvisibility=hidden", "-Wall", "-Wextra", "-Wshadow", "-Werror", "-Wno-missing-field-initializers", "-Wno-unused-parameter", \ "-Wno-comment", "-Wno-unused", "-Wno-unknown-pragmas"] @@ -63,13 +63,33 @@ def setup_avr(): def setup_arm_thumb(): global c global link + global asm + global utils + asm.assembler = asm.GccAssembler("/cross/arm_cortex/bin/arm-none-eabi-") c.compiler = c.GccCompiler("/cross/arm_cortex/bin/arm-none-eabi-") link.linker = link.GccLinker("/cross/arm_cortex/bin/arm-none-eabi-") - c.flags += ["-march=armv6-m", "-mthumb", "-ffunction-sections", "-fdata-sections"] - link.local_flags += ["-march=armv6-m", "-mthumb", "-Wl,--gc-sections"] + c.flags.extend(["-mcpu=cortex-m0", "-mthumb", "-ffunction-sections", "-fdata-sections", "-fno-builtin-fprintf", "-fno-builtin-printf"]) + c.defines["LPC11XX"] = 1 + + link.local_flags.extend(["-mcpu=cortex-m0", "-mthumb", "-nostartfiles", "-nostdlib", "-Wl,--gc-sections"]) + link.local_flags.extend(["-Tflash.lds", "-L/Projects/lpc11xx/core", "/Projects/lpc11xx/core/" + emk.build_dir + "/board_cstartup.o"]) + link.local_syslibs += ["gcc"] + link.depdirs += ["/Projects/lpc11xx/stdlib"] + + def do_objcopy(produces, requires): + utils.call("/cross/arm_cortex/bin/arm-none-eabi-objcopy", "-O", "binary", requires[0], produces[0]) + + def handle_exe(path): + emk.depend(path, "/Projects/lpc11xx/core/" + emk.build_dir + "/board_cstartup.o") + emk.rule(do_objcopy, path + ".bin", path, cwd_safe=True, ex_safe=True) + emk.autobuild(path + ".bin") + + link.exe_funcs.append(handle_exe) link.strip = True + + emk.recurse("/Projects/lpc11xx/core") setup_build_dir() diff --git a/test/test_ecdh.c b/test/test_ecdh.c index 713eeb2..4b4176b 100644 --- a/test/test_ecdh.c +++ b/test/test_ecdh.c @@ -5,6 +5,29 @@ #include #include +#if LPC11XX + +#include "/Projects/lpc11xx/peripherals/uart.h" +#include "/Projects/lpc11xx/peripherals/time.h" + +static uint64_t g_rand = 88172645463325252ull; +int fake_rng(uint8_t *p_dest, unsigned p_size) +{ + while(p_size) + { + g_rand ^= (g_rand << 13); + g_rand ^= (g_rand >> 7); + g_rand ^= (g_rand << 17); + + unsigned l_amount = (p_size > 8 ? 8 : p_size); + memcpy(p_dest, &g_rand, l_amount); + p_size -= l_amount; + } + return 1; +} + +#endif + void vli_print(uint8_t *p_vli, unsigned int p_size) { while(p_size) @@ -16,6 +39,13 @@ void vli_print(uint8_t *p_vli, unsigned int p_size) int main() { +#if LPC11XX + uartInit(BAUD_115200); + initTime(); + + uECC_set_rng(&fake_rng); +#endif + int i; uint8_t l_private1[uECC_BYTES]; @@ -32,7 +62,9 @@ int main() for(i=0; i<256; ++i) { printf("."); + #if !LPC11XX fflush(stdout); + #endif if(!uECC_make_key(l_public1, l_private1) || !uECC_make_key(l_public2, l_private2)) { diff --git a/test/test_ecdsa.c b/test/test_ecdsa.c index d3a84f9..9be3b93 100644 --- a/test/test_ecdsa.c +++ b/test/test_ecdsa.c @@ -5,8 +5,38 @@ #include #include +#if LPC11XX + +#include "/Projects/lpc11xx/peripherals/uart.h" +#include "/Projects/lpc11xx/peripherals/time.h" + +static uint64_t g_rand = 88172645463325252ull; +int fake_rng(uint8_t *p_dest, unsigned p_size) +{ + while(p_size) + { + g_rand ^= (g_rand << 13); + g_rand ^= (g_rand >> 7); + g_rand ^= (g_rand << 17); + + unsigned l_amount = (p_size > 8 ? 8 : p_size); + memcpy(p_dest, &g_rand, l_amount); + p_size -= l_amount; + } + return 1; +} + +#endif + int main() { +#if LPC11XX + uartInit(BAUD_115200); + initTime(); + + uECC_set_rng(&fake_rng); +#endif + uint8_t l_public[uECC_BYTES*2]; uint8_t l_private[uECC_BYTES]; @@ -21,7 +51,9 @@ int main() for(i=0; i<256; ++i) { printf("."); + #if !LPC11XX fflush(stdout); + #endif if(!uECC_make_key(l_public, l_private)) {