From b9f5803fa8cb80e145dd67e3913c835a60521288 Mon Sep 17 00:00:00 2001 From: Christophe de Dinechin Date: Wed, 21 Jun 2023 08:29:59 +0200 Subject: [PATCH] Add build steps to adjust CRC for QSPI file This is lifted from the WP43 project. The idea is to be able to move "heavy" and rarely moving data, like fonts, into the QSPI, so that we have more room for the main program in Flash. Signed-off-by: Christophe de Dinechin --- Makefile | 13 +++++++---- src/qspi_crc.h | 44 +---------------------------------- tools/adjust_crc | 8 +++++++ tools/forcecrc32/forcecrc32.c | 2 +- 4 files changed, 19 insertions(+), 48 deletions(-) create mode 100755 tools/adjust_crc diff --git a/Makefile b/Makefile index f7fc4a14..f65b9e44 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,10 @@ TOOLS = tools # CRC adjustment CRCFIX = $(TOOLS)/forcecrc32/forcecrc32 +FLASH=$(BUILD)/$(TARGET)_flash.bin +QSPI =$(BUILD)/$(TARGET)_qspi.bin + + #============================================================================== # @@ -240,10 +244,11 @@ $(BUILD)/%.o: %.s Makefile | $(BUILD) $(BUILD)/$(TARGET).elf: $(OBJECTS) Makefile $(CC) $(OBJECTS) $(LDFLAGS) -o $@ $(TARGET).pgm: $(BUILD)/$(TARGET).elf Makefile $(CRCFIX) - $(OBJCOPY) --remove-section .qspi -O ihex $< $(BUILD)/$(TARGET)_flash.hex - $(OBJCOPY) --remove-section .qspi -O binary $< $(BUILD)/$(TARGET)_flash.bin - $(OBJCOPY) --only-section .qspi -O ihex $< $(BUILD)/$(TARGET)_qspi.hex - $(OBJCOPY) --only-section .qspi -O binary $< $(BUILD)/$(TARGET)_qspi.bin + $(OBJCOPY) --remove-section .qspi -O binary $< $(FLASH) + $(OBJCOPY) --remove-section .qspi -O ihex $< $(FLASH:.bin=.hex) + $(OBJCOPY) --only-section .qspi -O binary $< $(QSPI) + $(OBJCOPY) --only-section .qspi -O ihex $< $(QSPI:.bin=.hex) + $(TOOLS)/adjust_crc $(CRCFIX) $(QSPI) $(TOOLS)/check_qspi_crc $(TARGET) $(BUILD)/$(TARGET)_qspi.bin src/qspi_crc.h || ( $(MAKE) clean && false ) $(TOOLS)/add_pgm_chsum $(BUILD)/$(TARGET)_flash.bin $@ $(SIZE) $< diff --git a/src/qspi_crc.h b/src/qspi_crc.h index 2a53af94..0c235518 100644 --- a/src/qspi_crc.h +++ b/src/qspi_crc.h @@ -1,46 +1,4 @@ -/* -BSD 3-Clause License - -Copyright (c) 2015-2022, SwissMicros -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - - The software and related material is released as “NOMAS” (NOt MAnufacturer Supported). - - 1. Info is released to assist customers using, exploring and extending the product - 2. Do NOT contact the manufacturer with questions, seeking support, etc. regarding - NOMAS material as no support is implied or committed-to by the Manufacturer - 3. The Manufacturer may reply and/or update materials if and when needed solely - at their discretion - -*/ - -#define QSPI_DATA_SIZE 1370864 +#define QSPI_DATA_SIZE 1370868 #define QSPI_DATA_CRC 0x000cfed6 diff --git a/tools/adjust_crc b/tools/adjust_crc new file mode 100755 index 00000000..87438725 --- /dev/null +++ b/tools/adjust_crc @@ -0,0 +1,8 @@ +#!/bin/bash + +crcfix="$1" +qspi="$2" + +sz=$(cat $qspi | wc -c) +echo -n -e '\x00\x00\x00\x00' >> $qspi +$crcfix $qspi $sz 000CFED6 diff --git a/tools/forcecrc32/forcecrc32.c b/tools/forcecrc32/forcecrc32.c index ff7c17dd..62f3df42 100644 --- a/tools/forcecrc32/forcecrc32.c +++ b/tools/forcecrc32/forcecrc32.c @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } char temp[21] = {0}; - sprintf(temp, "%" PRIu64, offset); + snprintf(temp, sizeof(temp), "%" PRIu64, offset); if (strcmp(temp, argv[2]) != 0) { fprintf(stderr, "Error: Invalid byte offset\n"); return EXIT_FAILURE;