Seperate compilation of scratch rom
This commit is contained in:
parent
b6d2c587f6
commit
3e8cc817b7
@ -8,3 +8,37 @@ CFLAGS+=-DLEVEL=2
|
|||||||
|
|
||||||
# Enable I2C debug on 0x76
|
# Enable I2C debug on 0x76
|
||||||
# CFLAGS+=-DI2C_DEBUGGER=0x76
|
# CFLAGS+=-DI2C_DEBUGGER=0x76
|
||||||
|
|
||||||
|
# Add scratch ROM source
|
||||||
|
SCRATCH_SRC=$(wildcard $(BOARD_DIR)/scratch/*.c)
|
||||||
|
SCRATCH_OBJ=$(patsubst src/%.c,$(BUILD)/%.rel,$(SCRATCH_SRC))
|
||||||
|
SCRATCH_CC=\
|
||||||
|
sdcc \
|
||||||
|
-mmcs51 \
|
||||||
|
--model-small \
|
||||||
|
--code-size 1024 \
|
||||||
|
--Werror
|
||||||
|
|
||||||
|
# Convert from binary file to C header
|
||||||
|
$(BUILD)/include/scratch.h: $(BUILD)/scratch.rom
|
||||||
|
@mkdir -p $(@D)
|
||||||
|
xxd --include < $< > $@
|
||||||
|
|
||||||
|
# Convert from Intel Hex file to binary file
|
||||||
|
$(BUILD)/scratch.rom: $(BUILD)/scratch.ihx
|
||||||
|
@mkdir -p $(@D)
|
||||||
|
makebin -p < $< > $@
|
||||||
|
|
||||||
|
# Link object files into Intel Hex file
|
||||||
|
$(BUILD)/scratch.ihx: $(SCRATCH_OBJ)
|
||||||
|
@mkdir -p $(@D)
|
||||||
|
$(SCRATCH_CC) -o $@ $^
|
||||||
|
|
||||||
|
# Compile C files into object files
|
||||||
|
$(SCRATCH_OBJ): $(BUILD)/%.rel: src/%.c
|
||||||
|
@mkdir -p $(@D)
|
||||||
|
$(SCRATCH_CC) -o $@ -c $<
|
||||||
|
|
||||||
|
# Require scratch.rom to be compiled before main firmware
|
||||||
|
CFLAGS+=-I$(BUILD)/include
|
||||||
|
INCLUDE+=$(BUILD)/include/scratch.h
|
||||||
|
@ -1,21 +1,22 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
volatile uint8_t __xdata __at(0x103B) ECINDAR0;
|
#include <common/macro.h>
|
||||||
volatile uint8_t __xdata __at(0x103C) ECINDAR1;
|
|
||||||
volatile uint8_t __xdata __at(0x103D) ECINDAR2;
|
// Include scratch ROM, must be less than 1024 bytes, controlled by makefile
|
||||||
volatile uint8_t __xdata __at(0x103E) ECINDAR3;
|
uint8_t __code scratch_rom[] = {
|
||||||
volatile uint8_t __xdata __at(0x103F) ECINDDR;
|
#include <scratch.h>
|
||||||
volatile uint8_t __xdata __at(0x1040) SCAR0L;
|
};
|
||||||
volatile uint8_t __xdata __at(0x1041) SCAR0M;
|
|
||||||
volatile uint8_t __xdata __at(0x1042) SCAR0H;
|
// Scratch RAM 1 is 1024 bytes, located at 2048 bytes
|
||||||
|
volatile uint8_t __xdata __at(0x0800) scratch_ram_1[1024];
|
||||||
|
|
||||||
volatile uint8_t __xdata __at(0x1043) SCAR1L;
|
volatile uint8_t __xdata __at(0x1043) SCAR1L;
|
||||||
volatile uint8_t __xdata __at(0x1044) SCAR1M;
|
volatile uint8_t __xdata __at(0x1044) SCAR1M;
|
||||||
volatile uint8_t __xdata __at(0x1045) SCAR1H;
|
volatile uint8_t __xdata __at(0x1045) SCAR1H;
|
||||||
|
|
||||||
// Create new segment located at 0x1000
|
// Create new segment located at 0x1000, after scratch ROM mapping
|
||||||
static void scratch_start(void) __naked
|
static void scratch_start(void) __naked {
|
||||||
{
|
|
||||||
__asm
|
__asm
|
||||||
.area SCRATCH (ABS,CODE)
|
.area SCRATCH (ABS,CODE)
|
||||||
__endasm;
|
__endasm;
|
||||||
@ -24,52 +25,37 @@ static void scratch_start(void) __naked
|
|||||||
__endasm;
|
__endasm;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define FLASH_SPI 0x00000000
|
// Enter scratch ROM
|
||||||
#define FLASH_EMBEDDED 0x40000000
|
int scratch_trampoline(void) {
|
||||||
|
// Uses SCAR1 which is mapped at 0x0800 in data space and is 1024 bytes in
|
||||||
|
// size. SCAR0 cannot be used due to __pdata overwriting it.
|
||||||
|
|
||||||
static int flash_transaction(uint32_t offset, uint8_t * data, int length, bool read) {
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < length; i++, offset++) {
|
// Copy scratch ROM
|
||||||
ECINDAR3 = (uint8_t)(offset >> 24);
|
for (i = 0; i < ARRAY_SIZE(scratch_rom) && i < ARRAY_SIZE(scratch_ram_1); i++) {
|
||||||
ECINDAR2 = (uint8_t)(offset >> 16);
|
scratch_ram_1[i] = scratch_rom[i];
|
||||||
ECINDAR1 = (uint8_t)(offset >> 8);
|
|
||||||
ECINDAR0 = (uint8_t)(offset);
|
|
||||||
if (read) {
|
|
||||||
data[i] = ECINDDR;
|
|
||||||
} else {
|
|
||||||
ECINDDR = data[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main program while running in scratch ROM
|
// Fill the rest with nop
|
||||||
static void scratch_main(void) {
|
for (; i < ARRAY_SIZE(scratch_ram_1); i++) {
|
||||||
// TODO: implement flashing protocol and prevent access to flash
|
scratch_ram_1[i] = 0x00;
|
||||||
// data (i.e. calling functions in CSEG) during this process
|
}
|
||||||
for (;;) {}
|
|
||||||
|
// Set mapping at 0x0000 and enable
|
||||||
|
SCAR1L = 0x00;
|
||||||
|
SCAR1M = 0x00;
|
||||||
|
SCAR1H = 0x00;
|
||||||
|
|
||||||
|
// Jump to scratch reset function
|
||||||
|
__asm__("ljmp 0");
|
||||||
|
|
||||||
|
// Should never happen
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finish segment located at 0x1000
|
// Finish segment located at 0x1000
|
||||||
static void scratch_end(void) __naked
|
static void scratch_end(void) __naked {
|
||||||
{
|
|
||||||
__asm
|
__asm
|
||||||
.area CSEG (REL,CODE)
|
.area CSEG (REL,CODE)
|
||||||
__endasm;
|
__endasm;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enter scratch ROM
|
|
||||||
void scratch_trampoline(void) {
|
|
||||||
// Uses SCAR1 which is mapped at 0x0800 in data space and is 1024 bytes in
|
|
||||||
// size. SCAR0 cannot be used due to __pdata overwriting it.
|
|
||||||
|
|
||||||
// Set flag to use DMA on next write
|
|
||||||
SCAR1H = 0x80;
|
|
||||||
// Set mapping at 0x1000
|
|
||||||
SCAR1L = 0x00;
|
|
||||||
SCAR1M = 0x10;
|
|
||||||
// Set DMA and enable code space mapping
|
|
||||||
SCAR1H = 0x00;
|
|
||||||
|
|
||||||
scratch_main();
|
|
||||||
}
|
|
||||||
|
34
src/board/system76/galp3-c/scratch/main.c
Normal file
34
src/board/system76/galp3-c/scratch/main.c
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
volatile uint8_t __xdata __at(0x103B) ECINDAR0;
|
||||||
|
volatile uint8_t __xdata __at(0x103C) ECINDAR1;
|
||||||
|
volatile uint8_t __xdata __at(0x103D) ECINDAR2;
|
||||||
|
volatile uint8_t __xdata __at(0x103E) ECINDAR3;
|
||||||
|
volatile uint8_t __xdata __at(0x103F) ECINDDR;
|
||||||
|
|
||||||
|
#define FLASH_SPI 0x00000000
|
||||||
|
#define FLASH_EMBEDDED 0x40000000
|
||||||
|
|
||||||
|
static int flash_transaction(uint32_t offset, uint8_t * data, int length, bool read) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < length; i++, offset++) {
|
||||||
|
ECINDAR3 = (uint8_t)(offset >> 24);
|
||||||
|
ECINDAR2 = (uint8_t)(offset >> 16);
|
||||||
|
ECINDAR1 = (uint8_t)(offset >> 8);
|
||||||
|
ECINDAR0 = (uint8_t)(offset);
|
||||||
|
if (read) {
|
||||||
|
data[i] = ECINDDR;
|
||||||
|
} else {
|
||||||
|
ECINDDR = data[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main program while running in scratch ROM
|
||||||
|
void main(void) {
|
||||||
|
// TODO: implement flashing protocol and prevent access to flash
|
||||||
|
// data (i.e. calling functions in CSEG) during this process
|
||||||
|
for (;;) {}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user