From e0dd55841a20fafdcba4efa85e940f11417ba4cd Mon Sep 17 00:00:00 2001 From: kernyan Date: Fri, 8 Feb 2019 15:15:46 -0500 Subject: [PATCH] Fixed undefined reference error when "make recover" in EON In https://github.com/commaai/panda/commit/fd233832ef64a04456fc26e2f2763d946f853128 the linker flag -lgcc might not work on EON as it does not have the correct library. The fix was a workaround in sha.c such that we no longer need to import function __aeabi_llsr from library, by replacing right shift operation with const argument. E.g., uint64_t a = b >> i // requires __aeabi_llsr from libgcc uint64_t a = b >> 2 // does not require external library Resolves: #522 --- board/build.mk | 2 +- crypto/sha.c | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/board/build.mk b/board/build.mk index b1f6313a7f0a7c..9f2c4250c2c772 100644 --- a/board/build.mk +++ b/board/build.mk @@ -55,7 +55,7 @@ obj/$(PROJ_NAME).bin: obj/$(STARTUP_FILE).o obj/main.$(PROJ_NAME).o obj/bootstub.$(PROJ_NAME).bin: obj/$(STARTUP_FILE).o obj/bootstub.$(PROJ_NAME).o obj/sha.$(PROJ_NAME).o obj/rsa.$(PROJ_NAME).o - $(CC) $(CFLAGS) -o obj/bootstub.$(PROJ_NAME).elf $^ -lgcc + $(CC) $(CFLAGS) -o obj/bootstub.$(PROJ_NAME).elf $^ $(OBJCOPY) -v -O binary obj/bootstub.$(PROJ_NAME).elf $@ clean: diff --git a/crypto/sha.c b/crypto/sha.c index 47676df4b6d8a6..8e1715525c68a2 100644 --- a/crypto/sha.c +++ b/crypto/sha.c @@ -127,10 +127,36 @@ const uint8_t* SHA_final(SHA_CTX* ctx) { while ((ctx->count & 63) != 56) { SHA_update(ctx, (uint8_t*)"\0", 1); } - for (i = 0; i < 8; ++i) { - uint8_t tmp = (uint8_t) (cnt >> ((7 - i) * 8)); - SHA_update(ctx, &tmp, 1); - } + + /* Hack - right shift operator with non const argument requires + * libgcc.a which is missing in EON + * thus expanding for loop from + + for (i = 0; i < 8; ++i) { + uint8_t tmp = (uint8_t) (cnt >> ((7 - i) * 8)); + SHA_update(ctx, &tmp, 1); + } + + to + */ + + uint8_t tmp = 0; + tmp = (uint8_t) (cnt >> ((7 - 0) * 8)); + SHA_update(ctx, &tmp, 1); + tmp = (uint8_t) (cnt >> ((7 - 1) * 8)); + SHA_update(ctx, &tmp, 1); + tmp = (uint8_t) (cnt >> ((7 - 2) * 8)); + SHA_update(ctx, &tmp, 1); + tmp = (uint8_t) (cnt >> ((7 - 3) * 8)); + SHA_update(ctx, &tmp, 1); + tmp = (uint8_t) (cnt >> ((7 - 4) * 8)); + SHA_update(ctx, &tmp, 1); + tmp = (uint8_t) (cnt >> ((7 - 5) * 8)); + SHA_update(ctx, &tmp, 1); + tmp = (uint8_t) (cnt >> ((7 - 6) * 8)); + SHA_update(ctx, &tmp, 1); + tmp = (uint8_t) (cnt >> ((7 - 7) * 8)); + SHA_update(ctx, &tmp, 1); for (i = 0; i < 5; i++) { uint32_t tmp = ctx->state[i];