From ae92be36253032f2c9d86bba23df7725e52bed78 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" <5425387+Ralim@users.noreply.github.com> Date: Tue, 9 Apr 2024 08:35:58 +1000 Subject: [PATCH 1/5] Fix S60P flash size --- src/config.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/config.h b/src/config.h index e2f62dc..3492a0d 100644 --- a/src/config.h +++ b/src/config.h @@ -36,7 +36,8 @@ #define FLASH_SIZE_KB 128 #define FLASH_BOOTLDR_SIZE_KB 16 #define FLASH_BOOTLDR_PAYLOAD_SIZE_KB 112 -#elif MODEL_S60 || MODEL_S60P + +#elif MODEL_S60 #define GPIO_DFU_BOOT_PORT GPIOB #define GPIO_DFU_BOOT_PIN 0 #define GPIO_DP_PULLUP_PORT GPIOA @@ -45,6 +46,15 @@ #define FLASH_BOOTLDR_SIZE_KB 17 #define FLASH_BOOTLDR_PAYLOAD_SIZE_KB 111 +#elif MODEL_S60P +#define GPIO_DFU_BOOT_PORT GPIOB +#define GPIO_DFU_BOOT_PIN 0 +#define GPIO_DP_PULLUP_PORT GPIOA +#define GPIO_DP_PULLUP_PIN 8 +#define FLASH_SIZE_KB 128 +#define FLASH_BOOTLDR_SIZE_KB 20 +#define FLASH_BOOTLDR_PAYLOAD_SIZE_KB 108 + #elif MODEL_TS80 || MODEL_TS80P #define GPIO_DFU_BOOT_PORT GPIOB #define GPIO_DFU_BOOT_PIN 1 From dabba1b128dd4ee97065b099e122a1dfe9cb5add Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Tue, 9 Apr 2024 18:53:43 +1000 Subject: [PATCH 2/5] Fix declaration order of config so protection works --- src/config.h | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/config.h b/src/config.h index 3492a0d..c862ca0 100644 --- a/src/config.h +++ b/src/config.h @@ -5,23 +5,6 @@ #define ENABLE_DFU_UPLOAD #define ENABLE_WATCHDOG 26 -#if VECTOR_TABLE_OFFSET != 0 -#define SHOW_HASH -#define HASH_REGION_START FLASH_BASE_ADDR -#define HASH_REGION_END (FLASH_BASE_ADDR + (1024 * FLASH_BOOTLDR_SIZE_KB)) -#define DFU_VALID_FLASH_START (FLASH_BASE_ADDR) -#define DFU_VALID_FLASH_END (FLASH_BASE_ADDR + (FLASH_BOOTLDR_SIZE_KB * 1024)) -#define RUNTIME_MODE -#else -#define BOOTLOADER_MODE -#define DFU_VALID_FLASH_START (FLASH_BASE_ADDR + (FLASH_BOOTLDR_SIZE_KB * 1024)) -#define DFU_VALID_FLASH_END (FLASH_BASE_ADDR + (FLASH_BOOTLDR_PAYLOAD_SIZE_KB * 1024)) -// In DFU mode, we use button to enter - -#define ENABLE_GPIO_DFU_BOOT - -#endif - /* Commands sent with wBlockNum == 0 as per ST implementation. */ #define CMD_SETADDR 0x21 #define CMD_ERASE 0x41 @@ -37,7 +20,7 @@ #define FLASH_BOOTLDR_SIZE_KB 16 #define FLASH_BOOTLDR_PAYLOAD_SIZE_KB 112 -#elif MODEL_S60 +#elif MODEL_S60 #define GPIO_DFU_BOOT_PORT GPIOB #define GPIO_DFU_BOOT_PIN 0 #define GPIO_DP_PULLUP_PORT GPIOA @@ -83,4 +66,22 @@ #define SDA_Pin 7 #define SDA_GPIO_Port GPIOB +// Setup defines for other code so we protect writing OOB + +#if VECTOR_TABLE_OFFSET != 0 +#define SHOW_HASH +#define HASH_REGION_START FLASH_BASE_ADDR +#define HASH_REGION_END (FLASH_BASE_ADDR + (1024 * FLASH_BOOTLDR_SIZE_KB)) +#define DFU_VALID_FLASH_START (FLASH_BASE_ADDR) +#define DFU_VALID_FLASH_END (FLASH_BASE_ADDR + (FLASH_BOOTLDR_SIZE_KB * 1024)) +#define RUNTIME_MODE +#else +#define BOOTLOADER_MODE +#define DFU_VALID_FLASH_START (FLASH_BASE_ADDR + (FLASH_BOOTLDR_SIZE_KB * 1024)) +#define DFU_VALID_FLASH_END (FLASH_BASE_ADDR + (FLASH_BOOTLDR_PAYLOAD_SIZE_KB * 1024)) +// In DFU mode, we use button to enter + +#define ENABLE_GPIO_DFU_BOOT + +#endif #endif From 813af6831f2970338160ca9dfd44df1ffbeded94 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Tue, 9 Apr 2024 18:54:00 +1000 Subject: [PATCH 3/5] Fix: always set vtor at start --- src/main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 592e28f..729ab8e 100644 --- a/src/main.c +++ b/src/main.c @@ -27,7 +27,10 @@ #include "watchdog.h" // Payload/app comes inmediately after Bootloader -#define APP_ADDRESS (FLASH_BASE_ADDR + (FLASH_BOOTLDR_SIZE_KB)*1024) +#define APP_ADDRESS (FLASH_BASE_ADDR + (FLASH_BOOTLDR_SIZE_KB) * 1024) +#ifndef VECTOR_TABLE_OFFSET +#error MUST set VTOR +#endif #ifdef ENABLE_PINRST_DFU_BOOT static inline int reset_due_to_pin() { return (RCC_CSR & RCC_CSR_PINRSTF) && !(RCC_CSR & (RCC_CSR_LPWRRSTF | RCC_CSR_WWDGRSTF | RCC_CSR_IWDGRSTF | RCC_CSR_SFTRSTF | RCC_CSR_PORRSTF)); } @@ -38,9 +41,9 @@ int main(void) { * asked to reboot into DFU mode. This should make the CPU to * boot into DFU if the user app has been erased. */ - // Setup vector table to use out offset whatever it is + // Setup vector table to use our offset whatever it is volatile uint32_t *_csb_vtor = (uint32_t *)0xE000ED08U; - *_csb_vtor = 0; + *_csb_vtor = VECTOR_TABLE_OFFSET; #ifdef ENABLE_WATCHDOG // Enable the watchdog From 7ab0a57c49e1913b87b49ae458e641aa48adea87 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Wed, 10 Apr 2024 20:49:28 +1000 Subject: [PATCH 4/5] Draw OLED centred on larger screens --- src/display.c | 2 +- src/oled.c | 15 +++++++-------- src/oled.h | 19 ++++++++++++------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/display.c b/src/display.c index 67c9fd4..2dd5512 100644 --- a/src/display.c +++ b/src/display.c @@ -29,6 +29,6 @@ void display_show_version(void) { void display_splash(void) { // Print the splash screen directly to the OLED oled_clearScreen(); - oled_DrawArea(0, 0, 96, 16, logo_buffer); + oled_DrawArea(OLED_AREA_X, OLED_AREA_Y, 96, 16, logo_buffer); oled_Refresh(); } diff --git a/src/oled.c b/src/oled.c index 9dfa8b3..57eb3db 100644 --- a/src/oled.c +++ b/src/oled.c @@ -151,12 +151,11 @@ void oled_DrawArea(uint8_t x, uint8_t y, uint8_t wide, uint8_t height, const uin // Y is the height value (affects the bits) // Y is either 0 or 8, we dont do smaller bit blatting uint8_t lines = height / 8; - // We draw the 1 or two stripes seperately - for (uint8_t i = 0; i < (wide * lines); i++) { - uint8_t xp = x + (i % wide); - uint8_t yoffset = i < wide ? 0 : OLED_WIDTH; - if (y == 8) - yoffset = OLED_WIDTH; + // We draw the 1 or two stripes separately + for (uint16_t i = 0; i < (wide * lines); i++) { + uint16_t xp = x + (i % wide); + + uint16_t yoffset = ((i / wide) + (y / 8)) * OLED_WIDTH; displayBuffer[xp + yoffset] = ptr[i]; } @@ -166,7 +165,7 @@ void oled_DrawArea(uint8_t x, uint8_t y, uint8_t wide, uint8_t height, const uin Function:Clear_Screen Description:Clear the entire screen to off (black) *******************************************************************************/ -void oled_clearScreen(void) { memset(displayBuffer, 0, 96 * 2); } +void oled_clearScreen(void) { memset(displayBuffer, 0, OLED_WIDTH * (OLED_HEIGHT / 8)); } /* * Draws a string onto the screen starting at the left @@ -202,5 +201,5 @@ void OLED_DrawChar(char c, uint8_t x, const uint8_t row) { offset *= (FONT_WIDTH * (FONT_HEIGHT / 8)); ptr += offset; - oled_DrawArea(x, row * 8, FONT_WIDTH, FONT_HEIGHT, (uint8_t *)ptr); + oled_DrawArea(OLED_AREA_X + x, OLED_AREA_Y + (row * 8), FONT_WIDTH, FONT_HEIGHT, (uint8_t *)ptr); } diff --git a/src/oled.h b/src/oled.h index 227b874..eee4c8a 100644 --- a/src/oled.h +++ b/src/oled.h @@ -6,29 +6,34 @@ #define DEVICEADDR_OLED (0x3c << 1) #if MODEL_S60 || MODEL_S60P -// TODO; for now just cropping in on the screen from 128x32 to 96x16 -#define OLED_WIDTH 96 -#define OLED_HEIGHT 16 -#define OLED_GRAM_START 0x10 // Should be 0x00 when we have full width -#define OLED_GRAM_END 0x6F // Should be 0x7F when we have full width +#define OLED_AREA_X 16 +#define OLED_AREA_Y 8 +#define OLED_WIDTH 128 +#define OLED_HEIGHT 32 +#define OLED_GRAM_START 0x00 +#define OLED_GRAM_END 0x7F #define OLED_VCOM_LAYOUT 0x12 #define OLED_SEGMENT_MAP 0xA1 #else + +#define OLED_AREA_X 0 +#define OLED_AREA_Y 0 #define OLED_WIDTH 96 #define OLED_HEIGHT 16 #define OLED_VCOM_LAYOUT 0x02 #ifdef OLED_FLIP -#define OLED_GRAM_START 0 // Should be 0x00 when we have full width +#define OLED_GRAM_START 0 // Aligned to top left of buffer #define OLED_GRAM_END 95 #define OLED_SEGMENT_MAP 0xA1 #else -#define OLED_GRAM_START 0x20 // Should be 0x00 when we have full width +#define OLED_GRAM_START 0x20 // Align to bottom right of buffer #define OLED_GRAM_END 0x7F #define OLED_SEGMENT_MAP 0xA0 #endif #endif + #define FRAMEBUFFER_START 17 // Run OLED init From c157229e1e8fb465a8abebd13ad7c7489885f7c9 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" <5425387+Ralim@users.noreply.github.com> Date: Sat, 1 Jun 2024 16:24:49 +1000 Subject: [PATCH 5/5] Sequre S99 Support (#29) * Add to build script * Another Sequre product, Another random offset * Fix build_all * Update BackUp.md --- .github/workflows/push.yml | 2 +- Makefile | 37 ++++++++++-------- build_all.sh | 9 ++++- docs/BackUp.md | 5 +++ src/config.h | 9 +++++ src/oled.h | 2 +- src/stm32f103_runtime_s99.ld | 73 ++++++++++++++++++++++++++++++++++++ 7 files changed, 119 insertions(+), 18 deletions(-) create mode 100644 src/stm32f103_runtime_s99.ld diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 0f7d3e9..e32ebe5 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -9,7 +9,7 @@ jobs: image: alpine:3.15 strategy: matrix: - model: ["TS100", "TS80", "TS80P", "MHP30", "S60P", "S60"] + model: ["TS100", "TS80", "TS80P", "MHP30", "S60P", "S60", "S99"] fail-fast: true steps: - name: Install dependencies (apk) diff --git a/Makefile b/Makefile index e6392fb..ecc0da0 100644 --- a/Makefile +++ b/Makefile @@ -7,21 +7,28 @@ ifeq ($(build_type), runtime) ifeq ($(model), S60P) VECTOR_TABLE_OFFSET := 0x5000 SRC_LD = src/stm32f103_runtime_s60p.ld - else - ifeq ($(model), S60) - VECTOR_TABLE_OFFSET := 0x4400 - SRC_LD = src/stm32f103_runtime_s60.ld - else - # For MHP30 override the runtime to offset to 32k - ifeq ($(model),"MHP30") - VECTOR_TABLE_OFFSET := 0x8000 - SRC_LD = stm32f103_32k_runtime.ld - else - - VECTOR_TABLE_OFFSET := 0x4000 - SRC_LD = src/stm32f103_runtime.ld - endif - endif + endif + + ifeq ($(model), S60) + VECTOR_TABLE_OFFSET := 0x4400 + SRC_LD = src/stm32f103_runtime_s60.ld + endif + + ifeq ($(model), S99) + VECTOR_TABLE_OFFSET := 0x4C00 + SRC_LD = src/stm32f103_runtime_s99.ld + endif + + + + # For MHP30 override the runtime to offset to 32k + ifeq ($(model),MHP30) + VECTOR_TABLE_OFFSET := 0x8000 + SRC_LD = src/stm32f103_32k_runtime.ld + endif + ifeq ($(model),$(filter $(model), TS100 TS80 TS80P )) + VECTOR_TABLE_OFFSET := 0x4000 + SRC_LD = src/stm32f103_runtime.ld endif BIN = runtime diff --git a/build_all.sh b/build_all.sh index 4ea3e23..2af1390 100755 --- a/build_all.sh +++ b/build_all.sh @@ -1,4 +1,6 @@ -!# bin/sh +#! bin/sh + +set -eux make clean make -j build_type=bootloader model=TS100 @@ -25,3 +27,8 @@ make -j build_type=bootloader model=S60P rm -rf build/*.o build/*.d make -j build_type=runtime model=S60P rm -rf build/*.o build/*.d + +make -j build_type=bootloader model=S99 +rm -rf build/*.o build/*.d +make -j build_type=runtime model=S99 +rm -rf build/*.o build/*.d diff --git a/docs/BackUp.md b/docs/BackUp.md index 0b44572..c731bf1 100644 --- a/docs/BackUp.md +++ b/docs/BackUp.md @@ -32,6 +32,10 @@ However, we will publish known checksums of the backups so you can check if your `sudo dfu-util -d 28e9:0189 -U backup.bin -s 0x08000000:0x5000` +### S99 + +`sudo dfu-util -d 28e9:0189 -U backup.bin -s 0x08000000:0x4C00` + ### MHP30 `sudo dfu-util -d 28e9:0189 -U backup.bin -s 0x08000000:0x8000` @@ -70,6 +74,7 @@ Known recorded MD5 checksums: | TS80P | 3.50 | 1805EC83F64C74DD89F87A1B57B7E631 | | TS80 | 3.45 | FADAE45B4249D4F156C30B7D4B0A853E | | S60P | V14.00 | 631C8823D84D3F53ED80266ACE37139E | +| S99 | V12.00 | ca373fe47f4d3f736479e671c481fd6e | In the mean time, you can validate if your backup looks valid by loading it into [hexed.it](https://hexed.it/). diff --git a/src/config.h b/src/config.h index c862ca0..175cfa1 100644 --- a/src/config.h +++ b/src/config.h @@ -38,6 +38,15 @@ #define FLASH_BOOTLDR_SIZE_KB 20 #define FLASH_BOOTLDR_PAYLOAD_SIZE_KB 108 +#elif MODEL_S99 +#define GPIO_DFU_BOOT_PORT GPIOB +#define GPIO_DFU_BOOT_PIN 0 +#define GPIO_DP_PULLUP_PORT GPIOA +#define GPIO_DP_PULLUP_PIN 8 +#define FLASH_SIZE_KB 128 +#define FLASH_BOOTLDR_SIZE_KB 19 +#define FLASH_BOOTLDR_PAYLOAD_SIZE_KB 109 + #elif MODEL_TS80 || MODEL_TS80P #define GPIO_DFU_BOOT_PORT GPIOB #define GPIO_DFU_BOOT_PIN 1 diff --git a/src/oled.h b/src/oled.h index eee4c8a..728151b 100644 --- a/src/oled.h +++ b/src/oled.h @@ -5,7 +5,7 @@ #define DEVICEADDR_OLED (0x3c << 1) -#if MODEL_S60 || MODEL_S60P +#if MODEL_S60 || MODEL_S60P || MODEL_S99 #define OLED_AREA_X 16 #define OLED_AREA_Y 8 #define OLED_WIDTH 128 diff --git a/src/stm32f103_runtime_s99.ld b/src/stm32f103_runtime_s99.ld new file mode 100644 index 0000000..98cf19e --- /dev/null +++ b/src/stm32f103_runtime_s99.ld @@ -0,0 +1,73 @@ +/* + * This file is part of the libopenstm32 project. + * + * Copyright (C) 2010 Thomas Otto + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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, see . + */ + +/* Define memory regions. */ +MEMORY +{ + rom (rx) : ORIGIN = 0x08004C00, LENGTH = 19K + ram (rwx) : ORIGIN = 0x20000000, LENGTH = 8k +} + +/* Enforce emmition of the vector table. */ +EXTERN (vector_table) + +/* Define the entry point of the output file. */ +ENTRY(reset_handler) + +/* Define sections. */ +SECTIONS +{ + .text : { + *(.vectors) /* Vector table */ + *(.text*) /* Program code */ + . = ALIGN(4); + *(.rodata*) /* Read-only data */ + . = ALIGN(4); + } >rom + + _etext = .; + + .data : { + _data = .; + *(.data*) /* Read-write initialized data */ + . = ALIGN(4); + _edata = .; + } >ram AT >rom + _data_loadaddr = LOADADDR(.data); + + .bss : { + *(.bss*) /* Read-write zero initialized data */ + *(COMMON) + . = ALIGN(4); + _ebss = .; + } >ram + + /* + * The .eh_frame section appears to be used for C++ exception handling. + * You may need to fix this if you're using C++. + */ + /DISCARD/ : { *(.eh_frame) } + + . = ALIGN(4); + end = .; +} + +PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); + +