diff options
Diffstat (limited to 'flash')
-rw-r--r-- | flash/bootloader/Makefile | 9 | ||||
-rw-r--r-- | flash/bootloader/bootloader.c | 69 | ||||
-rw-r--r-- | flash/bootloader/bootloader.h | 1 | ||||
-rw-r--r-- | flash/bootloader/bootloader.lds | 2 | ||||
-rw-r--r-- | flash/bootloader/no_rom.lds | 2 |
5 files changed, 10 insertions, 73 deletions
diff --git a/flash/bootloader/Makefile b/flash/bootloader/Makefile index e7bd17aae9..edc32113c6 100644 --- a/flash/bootloader/Makefile +++ b/flash/bootloader/Makefile | |||
@@ -46,7 +46,7 @@ endif | |||
46 | 46 | ||
47 | SRC := $(wildcard *.c) | 47 | SRC := $(wildcard *.c) |
48 | 48 | ||
49 | OBJS := $(SRC:%.c=$(OBJDIR)/%.o) | 49 | OBJS := $(SRC:%.c=$(OBJDIR)/%.o) $(OBJDIR)/sh_nrv2e_d8.o |
50 | 50 | ||
51 | ifdef NO_ROM | 51 | ifdef NO_ROM |
52 | LINKFILE = $(OBJDIR)/no_rom.lds | 52 | LINKFILE = $(OBJDIR)/no_rom.lds |
@@ -64,9 +64,12 @@ ifndef NO_ROM | |||
64 | $(TOOLSDIR)/scramble $(OBJDIR)/$(TARGET).bin $(OBJDIR)/$(TARGET).ajz | 64 | $(TOOLSDIR)/scramble $(OBJDIR)/$(TARGET).bin $(OBJDIR)/$(TARGET).ajz |
65 | endif | 65 | endif |
66 | 66 | ||
67 | $(OBJDIR)/$(TARGET).elf : $(OBJS) | 67 | $(OBJDIR)/$(TARGET).elf : $(OBJS) |
68 | $(CC) -Os -nostdlib -o $(OBJDIR)/$(TARGET).elf -L$(OBJDIR) -T$(LINKFILE) -Wl,-Map,$(OBJDIR)/$(TARGET).map | 68 | $(CC) -Os -nostdlib -o $@ $(OBJS) -T$(LINKFILE) -Wl,-Map,$(OBJDIR)/$(TARGET).map |
69 | 69 | ||
70 | # cross-reference, saves code duplication | ||
71 | $(OBJDIR)/sh_nrv2e_d8.o : ../../firmware/decompressor/sh_nrv2e_d8.S | ||
72 | $(CC) $(CFLAGS) -c $< -o $@ | ||
70 | 73 | ||
71 | clean: | 74 | clean: |
72 | -rm -f \ | 75 | -rm -f \ |
diff --git a/flash/bootloader/bootloader.c b/flash/bootloader/bootloader.c index d1955c2ccd..40c0dc5c54 100644 --- a/flash/bootloader/bootloader.c +++ b/flash/bootloader/bootloader.c | |||
@@ -29,7 +29,6 @@ | |||
29 | 29 | ||
30 | // prototypes | 30 | // prototypes |
31 | static void PlatformInit(void); | 31 | static void PlatformInit(void); |
32 | static int ucl_nrv2e_decompress_8(const UINT8 *src, UINT8 *dst, UINT32* dst_len); | ||
33 | static void DecompressStart(tImage* pImage); | 32 | static void DecompressStart(tImage* pImage); |
34 | #ifdef USE_ADC | 33 | #ifdef USE_ADC |
35 | static int ReadADC(int channel); | 34 | static int ReadADC(int channel); |
@@ -41,7 +40,7 @@ static void SetLed(BOOL bOn); | |||
41 | static void UartInit(void); | 40 | static void UartInit(void); |
42 | static UINT8 UartRead(void); | 41 | static UINT8 UartRead(void); |
43 | static void UartWrite(UINT8 byte); | 42 | static void UartWrite(UINT8 byte); |
44 | static void MiniMon(void); | 43 | static void MiniMon(void); |
45 | 44 | ||
46 | 45 | ||
47 | #ifdef NO_ROM | 46 | #ifdef NO_ROM |
@@ -188,72 +187,6 @@ static void PlatformInit(void) | |||
188 | } | 187 | } |
189 | 188 | ||
190 | 189 | ||
191 | /* Thinned out version of the UCL 2e decompression sourcecode | ||
192 | * Original (C) Markus F.X.J Oberhumer under GNU GPL license */ | ||
193 | #define GETBIT(bb, src, ilen) \ | ||
194 | (((bb = bb & 0x7f ? bb*2 : ((unsigned)src[ilen++]*2+1)) >> 8) & 1) | ||
195 | |||
196 | static int ucl_nrv2e_decompress_8( | ||
197 | const UINT8 *src, UINT8 *dst, UINT32* dst_len) | ||
198 | { | ||
199 | UINT32 bb = 0; | ||
200 | unsigned ilen = 0, olen = 0, last_m_off = 1; | ||
201 | |||
202 | for (;;) | ||
203 | { | ||
204 | unsigned m_off, m_len; | ||
205 | |||
206 | while (GETBIT(bb,src,ilen)) | ||
207 | { | ||
208 | dst[olen++] = src[ilen++]; | ||
209 | } | ||
210 | m_off = 1; | ||
211 | for (;;) | ||
212 | { | ||
213 | m_off = m_off*2 + GETBIT(bb,src,ilen); | ||
214 | if (GETBIT(bb,src,ilen)) break; | ||
215 | m_off = (m_off-1)*2 + GETBIT(bb,src,ilen); | ||
216 | } | ||
217 | if (m_off == 2) | ||
218 | { | ||
219 | m_off = last_m_off; | ||
220 | m_len = GETBIT(bb,src,ilen); | ||
221 | } | ||
222 | else | ||
223 | { | ||
224 | m_off = (m_off-3)*256 + src[ilen++]; | ||
225 | if (m_off == 0xffffffff) | ||
226 | break; | ||
227 | m_len = (m_off ^ 0xffffffff) & 1; | ||
228 | m_off >>= 1; | ||
229 | last_m_off = ++m_off; | ||
230 | } | ||
231 | if (m_len) | ||
232 | m_len = 1 + GETBIT(bb,src,ilen); | ||
233 | else if (GETBIT(bb,src,ilen)) | ||
234 | m_len = 3 + GETBIT(bb,src,ilen); | ||
235 | else | ||
236 | { | ||
237 | m_len++; | ||
238 | do { | ||
239 | m_len = m_len*2 + GETBIT(bb,src,ilen); | ||
240 | } while (!GETBIT(bb,src,ilen)); | ||
241 | m_len += 3; | ||
242 | } | ||
243 | m_len += (m_off > 0x500); | ||
244 | { | ||
245 | const UINT8 *m_pos; | ||
246 | m_pos = dst + olen - m_off; | ||
247 | dst[olen++] = *m_pos++; | ||
248 | do dst[olen++] = *m_pos++; while (--m_len > 0); | ||
249 | } | ||
250 | } | ||
251 | *dst_len = olen; | ||
252 | |||
253 | return ilen; | ||
254 | } | ||
255 | |||
256 | |||
257 | /* move the image into place and start it */ | 190 | /* move the image into place and start it */ |
258 | static void DecompressStart(tImage* pImage) | 191 | static void DecompressStart(tImage* pImage) |
259 | { | 192 | { |
diff --git a/flash/bootloader/bootloader.h b/flash/bootloader/bootloader.h index 948311f55d..5811fd0aa4 100644 --- a/flash/bootloader/bootloader.h +++ b/flash/bootloader/bootloader.h | |||
@@ -77,6 +77,7 @@ typedef struct | |||
77 | #define FW_VERSION *(unsigned short*)(FLASH_BASE + 0xFE) // firmware version | 77 | #define FW_VERSION *(unsigned short*)(FLASH_BASE + 0xFE) // firmware version |
78 | 78 | ||
79 | // prototypes | 79 | // prototypes |
80 | int ucl_nrv2e_decompress_8(const UINT8 *src, UINT8 *dst, UINT32* dst_len); | ||
80 | void _main(void) __attribute__ ((section (".startup"))); | 81 | void _main(void) __attribute__ ((section (".startup"))); |
81 | int main(void); | 82 | int main(void); |
82 | 83 | ||
diff --git a/flash/bootloader/bootloader.lds b/flash/bootloader/bootloader.lds index 143d83bdc7..ecc1268988 100644 --- a/flash/bootloader/bootloader.lds +++ b/flash/bootloader/bootloader.lds | |||
@@ -1,5 +1,4 @@ | |||
1 | OUTPUT_FORMAT(elf32-sh) | 1 | OUTPUT_FORMAT(elf32-sh) |
2 | INPUT(bootloader.o) | ||
3 | 2 | ||
4 | MEMORY | 3 | MEMORY |
5 | { | 4 | { |
@@ -19,6 +18,7 @@ SECTIONS | |||
19 | .text : | 18 | .text : |
20 | { | 19 | { |
21 | *(.text) | 20 | *(.text) |
21 | *(.icode) | ||
22 | . = ALIGN(0x4); | 22 | . = ALIGN(0x4); |
23 | } > IRAM | 23 | } > IRAM |
24 | 24 | ||
diff --git a/flash/bootloader/no_rom.lds b/flash/bootloader/no_rom.lds index e65e7fdd3c..796fbda4fb 100644 --- a/flash/bootloader/no_rom.lds +++ b/flash/bootloader/no_rom.lds | |||
@@ -2,7 +2,6 @@ | |||
2 | where the flash ROM is mirrored to address zero */ | 2 | where the flash ROM is mirrored to address zero */ |
3 | 3 | ||
4 | OUTPUT_FORMAT(elf32-sh) | 4 | OUTPUT_FORMAT(elf32-sh) |
5 | INPUT(bootloader.o) | ||
6 | 5 | ||
7 | MEMORY | 6 | MEMORY |
8 | { | 7 | { |
@@ -29,6 +28,7 @@ SECTIONS | |||
29 | { | 28 | { |
30 | _begin_text = .; | 29 | _begin_text = .; |
31 | *(.text) | 30 | *(.text) |
31 | *(.icode) | ||
32 | . = ALIGN(0x4); | 32 | . = ALIGN(0x4); |
33 | _end_text = .; | 33 | _end_text = .; |
34 | } > IRAM | 34 | } > IRAM |