diff --git a/Makefile b/Makefile index 6000ee8f..b9deaced 100644 --- a/Makefile +++ b/Makefile @@ -94,14 +94,10 @@ test-app/image_v1_signed.bin: test-app/image.bin @echo "\t[SIGN] $(BOOT_IMG)" $(Q)$(SIGN_TOOL) $(SIGN_OPTIONS) $(BOOT_IMG) $(PRIVATE_KEY) 1 -factory.bin: $(BOOT_IMG) wolfboot-align.bin $(PRIVATE_KEY) test-app/image_v1_signed.bin +factory.bin: $(BOOT_IMG) wolfboot-align.bin $(PRIVATE_KEY) test-app/image_v1_signed.bin $(BINASSEMBLE) @echo "\t[MERGE] $@" - $(Q)$(OBJCOPY) --set-start=$(ARCH_OFFSET) \ - --add-section .signed_image=test-app/image_v1_signed.bin \ - --change-section-vma .signed_image=$(WOLFBOOT_PARTITION_BOOT_ADDRESS) \ - --set-section-flags .signed_image=alloc,readonly \ - wolfboot.elf factory.elf - $(Q)$(OBJCOPY) --gap-fill=255 -O binary factory.elf $@ + $(Q)$(BINASSEMBLE) $@ $(ARCH_FLASH_OFFSET) wolfboot-align.bin \ + $(WOLFBOOT_PARTITION_BOOT_ADDRESS) test-app/image_v1_signed.bin wolfboot.elf: include/target.h $(OBJS) $(LSCRIPT) FORCE @echo "\t[LD] $@" diff --git a/tools/bin-assemble/Makefile b/tools/bin-assemble/Makefile new file mode 100644 index 00000000..8c2288d8 --- /dev/null +++ b/tools/bin-assemble/Makefile @@ -0,0 +1,11 @@ +CC=gcc +CFLAGS=-Wall -g -ggdb +EXE=bin-assemble + +LIBS= + +$(EXE): $(EXE).o + $(CC) -o $@ $^ $(CFLAGS) $(LIBS) + +clean: + rm -f *.o $(EXE) diff --git a/tools/bin-assemble/bin-assemble.c b/tools/bin-assemble/bin-assemble.c new file mode 100644 index 00000000..610b11f6 --- /dev/null +++ b/tools/bin-assemble/bin-assemble.c @@ -0,0 +1,205 @@ +/* bin-assemble.c + * + * Copyright (C) 2006-2020 wolfSSL Inc. + * + * This file is part of wolfBoot. + * + * wolfBoot is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * wolfBoot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * + *============================================================================= + * + * assemble binary parts based on address + * + */ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#define BLOCK_SZ 1024 + +void usage(const char* execname) +{ + fprintf(stderr, + "%s output [
]\n" + "assemble binary parts with addresses", + execname); + exit(1); +} + +typedef struct { + const char* fname; + size_t address; + size_t nbytes; +} binentry_t; + +int binentry_address_compare(const void* a, const void* b) +{ + const binentry_t* ba = (const binentry_t*)a; + const binentry_t* bb = (const binentry_t*)b; + + if (ba->address < bb->address) { + return -1; + } else if (ba->address > bb->address) { + return 1; + } else { + return 0; + } +} + + +int main(int argc, const char* argv[]) { + const char* outname = NULL; + size_t i = 0; + size_t num_entries = 0; + binentry_t* entries = NULL; + size_t cur_add = 0; + char fill = '\xff'; + size_t nr = 0; + size_t nw = 0; + char data[BLOCK_SZ]; + int err = 0; + + /* require at least 1 input file */ + if (argc < 4 || (argc % 2) != 0) { + usage(argv[0]); + } + + outname = argv[1]; + num_entries = (argc - 2) / 2; + + entries = malloc( sizeof(binentry_t) * num_entries); + if (entries == NULL) { + fprintf(stderr, "unable to allocate %zu entries\n;", num_entries); + return EXIT_FAILURE; + } + + for (i=0; i entries[i].address) { + fprintf(stderr, + "overlap with %s(end address 0x%zx) and %s (start address 0x%zx \n", + entries[i-1].fname, endaddr, + entries[i].fname, entries[i].address); + err = 1; + } + if (err) { + return err; + } + + } + + // TODO: consider handling stdout "-" + + FILE* fo = fopen(outname, "wb"); + if (fo == NULL){ + fprintf(stderr, "opening %s failed %s\n", + outname, strerror(errno)); + return EXIT_FAILURE; + } + + cur_add = entries[0].address; + for (i=0; i