Now it should be bullet-proof and is tested with h8canusb.
VERBOSE=-vv
-bootstrap: TOHIT=$(USER_COMPILED_DIR_NAME)/bin-utils/tohit -d $(HIT_DEV)
-bootstrap: HIT_BAUD=19200
-.PHONY: bootstrap
+TOHIT=$(USER_COMPILED_DIR_NAME)/bin-utils/tohit -d $(HIT_DEV)
+HIT_BAUD=19200
-bootstrap:
+.PHONY: bootstrap bootstrap_ram bootstrap_erase bootstrap_flash
+bootstrap: bootstrap_ram bootstrap_erase bootstrap_flash
+
+bootstrap_ram:
@$(QUIET_CMD_ECHO) "Bootstrap to internal ram"
$(Q)$(TOHIT) $(VERBOSE) --baud 4800 --command B --blockmode 128 $(USER_COMPILED_DIR_NAME)/bin/bloader-bload.bin || exit 1
@$(QUIET_CMD_ECHO) "Done"
- $(Q)sleep 3
+
+bootstrap_erase:
@$(QUIET_CMD_ECHO) "Erasing flash"
$(Q)$(TOHIT) $(VERBOSE) --baud $(HIT_BAUD) --erase --start 0x000000 --length 0x1600 || exit 1
@$(QUIET_CMD_ECHO) "Done"
- $(Q)sleep 1
+
+bootstrap_flash:
@$(QUIET_CMD_ECHO) "Programming flash"
$(Q)$(TOHIT) $(VERBOSE) --baud $(HIT_BAUD) --command 1 --blockmode 32 --start 0x000000 $(USER_COMPILED_DIR_NAME)/bin/bloader-boot.bin || exit
#include <boot_fn.h>
-/* Provided by linker script */
-extern char __boot_fn_start;
-extern char __boot_fn_end;
-extern char etext;
-
-void RelocatedProgMode(unsigned baud)
-{
- size_t reloc_size=&__boot_fn_end-&__boot_fn_start;
- memcpy(&__boot_fn_start,&etext,reloc_size);
- /*deb_wr_hex((long)ProgMode_ptr,8);*/
- ProgMode(baud);
-}
-
-
void boot_test()
{
/*set power on for SCI0 and SCI1 module*/
}
- if((__u8*)&etext<(__u8*)0xffb000) {
- /* If we are not in the internal RAM, copy and run us from
- * there */
- RelocatedProgMode(HIT_LOAD_BAUD);
- }
- else
- ProgMode(HIT_LOAD_BAUD);
+ ProgMode(HIT_LOAD_BAUD);
}
#endif /* BOOT_TEST */
DEB_LED_OFF(3);
}
+/* Provided by linker script */
+extern char __boot_fn_load;
+extern char __boot_fn_start;
+extern char __boot_fn_end;
+
+static void relocate_boot_fn()
+{
+ size_t reloc_size=&__boot_fn_end-&__boot_fn_start;
+
+ if(&__boot_fn_load != &__boot_fn_start) {
+ memcpy(&__boot_fn_start,&__boot_fn_load,reloc_size);
+ }
+}
+
void _setup_board()
{
//int i, j;// POE-100
DEB_LED_INIT();
+ relocate_boot_fn();
+
/* show something on debug leds */
deb_led_out(0);
FlWait(1*100000);
*(.strings)
. = ALIGN( 4 ) ;
___boot_fn_start = ALIGN( 0x4 ) ;
+ ___boot_fn_load = ALIGN( 0x4 ) ;
KEEP (*boot_fn.o(.text))
KEEP (*boot_fn.o(.rodata))
. = ALIGN( 4 ) ;
. = ALIGN( 0x4 ) ;
} > iram0
- .text :
+ .text.boot_fn ALIGN(4) :
{
- text_start = . ;
- KEEP (crt0.o(.text))
- *(EXCLUDE_FILE(*boot_fn.o) .text)
- *(EXCLUDE_FILE(*boot_fn.o) .rodata)
- *(EXCLUDE_FILE(*boot_fn.o) .text .stub .text.* .gnu.linkonce.t.*)
- *(EXCLUDE_FILE(*boot_fn.o) .rodata .rodata.* .gnu.linkonce.r.*)
- *(EXCLUDE_FILE(*boot_fn.o) .strings)
. = ALIGN( 0x4 ) ;
- _etext = ALIGN( 0x4 ) ;
- } > flashbb
- .text.boot_fn :
- {
- . = ALIGN( 4 ) ;
- ___boot_fn_start = ALIGN( 0x4 ) ;
KEEP (boot_fn.o(.text))
KEEP (boot_fn.o(.rodata))
KEEP (boot_fn.o(.strings))
. = ALIGN( 4 ) ;
- ___boot_fn_end = ALIGN( 0x4 ) ;
- } > bloader AT>flashbb
+ } > iram0 AT>flashbb
+ ___boot_fn_start = ADDR(.text.boot_fn);
+ ___boot_fn_end = ADDR(.text.boot_fn) + SIZEOF(.text.boot_fn);
+ ___boot_fn_load = LOADADDR(.text.boot_fn);
+ .text :
+ {
+ text_start = . ;
+ KEEP (crt0.o(.text))
+ *(.text)
+ *(.rodata)
+ *(.text .stub .text.* .gnu.linkonce.t.*)
+ *(.rodata .rodata.* .gnu.linkonce.r.*)
+ *(.strings)
+ . = ALIGN( 0x4 ) ;
+ _etext = ALIGN( 0x4 ) ;
+ } > flashbb
.tors :
{
___ctors = . ;
LONG( ABSOLUTE( _start ) + 0x5a000000 ) /* JMP _start */
/* KEEP (crt0.o(.text)) */
. = ALIGN( 4 ) ;
+ ___boot_fn_load = ALIGN( 0x4 ) ;
___boot_fn_start = ALIGN( 0x4 ) ;
KEEP (*boot_fn.o(.text))
KEEP (*boot_fn.o(.rodata))
KEEP (boot_fn.o(.strings))
. = ALIGN( 4 ) ;
___boot_fn_end = ALIGN( 0x4 ) ;
- } > bloader AT>flashbb
+ } > iram0 AT>flashbb
.tors :
{