diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | misc/crc.s | 24 | ||||
-rw-r--r-- | octedit/.gitignore | 1 | ||||
-rw-r--r-- | octedit/Makefile | 13 | ||||
-rw-r--r-- | octedit/crc.s | 6 | ||||
-rw-r--r-- | octedit/crc32.c | 22 | ||||
-rw-r--r-- | octedit/pico_persist.ld | 5 |
7 files changed, 58 insertions, 14 deletions
@@ -2,3 +2,4 @@ *.o *.uf2 *.so +*.bin diff --git a/misc/crc.s b/misc/crc.s new file mode 100644 index 0000000..03c0ce2 --- /dev/null +++ b/misc/crc.s @@ -0,0 +1,24 @@ +.syntax unified +.cpu cortex-m0plus +.thumb + +.type CRC32, %function +.global CRC32 + +// R0 = input addr +// R1 = length +CRC32: LDR R5, =0x04C11DB7 + LDR R4, =0xFFFFFFFF +10: LDR R2, [R0] + REV R2, R2; + EORS R4, R2 + MOVS R3, 32 +20: LSLS R4, 1 + BCC 30f + EORS R4, R5 +30: SUBS R3, 1 + BNE 20b + ADDS R0, 4 + SUBS R1, 1 + BNE 10b + BX LR diff --git a/octedit/.gitignore b/octedit/.gitignore new file mode 100644 index 0000000..2d5bda1 --- /dev/null +++ b/octedit/.gitignore @@ -0,0 +1 @@ +crc32 diff --git a/octedit/Makefile b/octedit/Makefile index 74ce9d4..cc3773d 100644 --- a/octedit/Makefile +++ b/octedit/Makefile @@ -15,20 +15,23 @@ octedit.uf2: octedit.bin printf %220s | tr " " "\0" >> octedit.uf2 # 0 padding echo -ne "\x30\x6F\xB1\x0A" >> octedit.uf2 # Magic end -octedit.bin: octedit.elf +octedit.bin: octedit.elf crc32 arm-none-eabi-objcopy -O binary octedit.elf octedit.bin + ./crc32 < octedit.bin >> octedit.bin -objects = setup.o octedit.o uart.o crc.o +crc32: crc32.c + gcc crc32.c -o crc32 -octedit.elf: $(objects) +objects = setup.o octedit.o uart.o + +octedit.elf: $(objects) pico_persist.ld arm-none-eabi-ld -T pico_persist.ld -o octedit.elf $(objects) - ./checksum_pico_elf.py octedit.elf $(objects): %.o: %.s arm-none-eabi-as -o $@ $< clean: - rm octedit.elf octedit.bin octedit.uf2 *.o + rm octedit.elf octedit.bin octedit.uf2 *.o crc32 flash: octedit.uf2 [ -h /dev/disk/by-label/RPI-RP2 ] || sleep 3s diff --git a/octedit/crc.s b/octedit/crc.s deleted file mode 100644 index 8019c6d..0000000 --- a/octedit/crc.s +++ /dev/null @@ -1,6 +0,0 @@ -.syntax unified -.cpu cortex-m0plus -.thumb - -.section .stage_2_crc -.word 0x00000000 diff --git a/octedit/crc32.c b/octedit/crc32.c new file mode 100644 index 0000000..175ab50 --- /dev/null +++ b/octedit/crc32.c @@ -0,0 +1,22 @@ +#include <stdio.h> +#include <unistd.h> +#include <stdint.h> + +#define DATA_LEN 252 +#define DIVISOR 0x04C11DB7 + +int main() { + uint8_t data[DATA_LEN]; + read(STDIN_FILENO, data, DATA_LEN); + uint32_t crc = 0xFFFFFFFF; + for (size_t i = 0; i < DATA_LEN; i++) { + crc ^= data[i] << 24; + for (uint8_t j = 0; j < 8; j++) { + uint8_t nskip = crc >> 31; + crc <<= 1; + if (nskip) crc ^= DIVISOR; + } + } + write(STDOUT_FILENO, (uint8_t *) &crc, 4); + return 0; +} diff --git a/octedit/pico_persist.ld b/octedit/pico_persist.ld index fd9cf67..14caad7 100644 --- a/octedit/pico_persist.ld +++ b/octedit/pico_persist.ld @@ -1,6 +1,6 @@ MEMORY { FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 2M - SRAM(rx) : ORIGIN = 0x20041f00, LENGTH = 256 + SRAM(rx) : ORIGIN = 0x20041f00, LENGTH = 252 } SECTIONS { @@ -8,7 +8,6 @@ SECTIONS { setup.o(.text); octedit.o(.text); uart.o(.text); - . = 252; - *(.stage_2_crc); + . = LENGTH(SRAM); } >SRAM AT>FLASH } |