Skip to content

Commit

Permalink
Fixed undefined reference error when "make recover" in EON
Browse files Browse the repository at this point in the history
In commaai/panda@fd23383
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: commaai#522
  • Loading branch information
kernyan authored and rbiasini committed Feb 13, 2019
1 parent c91f038 commit e0dd558
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion board/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
34 changes: 30 additions & 4 deletions crypto/sha.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit e0dd558

Please sign in to comment.