]> rtime.felk.cvut.cz Git - sysless.git/commitdiff
h8300: Make bloader work with ELF toolchain
authorMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 15 Mar 2011 17:50:27 +0000 (18:50 +0100)
committerPavel Pisa <pisa@cmp.felk.cvut.cz>
Wed, 16 Mar 2011 16:00:13 +0000 (17:00 +0100)
Do not use PIC (position independent code) hacks in boot loader. Compile
it for fixed address and use different LMA and VMA in the linker scripts.
So far, only linker script for h8eurobot board was updated!

Bootstraping was tested with both 32 and 64 bit hosts and it works, despite
that 64 bit compiler produces a lot of warnings such as:
/tmp/cco5hbea.s:1218: Warning: operand #0xffffffffffffffef out of range.

arch/h8300/generic/bloader/Makefile.omk
arch/h8300/generic/bloader/bloader.c
arch/h8300/generic/libs/boot/Makefile.omk
arch/h8300/generic/libs/boot/boot_fn.c
arch/h8300/generic/tools/tohit/tohit_fn.c
board/h8300/h8eurobot/libs/h8canusb.ld-boot

index b8ef37878dd7fd846ba0d9b113d8cd071608f176..be8fba6ceaa416ae27b5fe5235bde74e4945a43c 100644 (file)
@@ -8,6 +8,8 @@ bloader_LIBS = boot_fn bspbase
 
 link_VARIANTS = boot bload
 
+VERBOSE=-vv
+
 bootstrap: TOHIT=$(USER_COMPILED_DIR_NAME)/bin-utils/tohit -d $(HIT_DEV)
 bootstrap: HIT_BAUD=19200
 .PHONY: bootstrap
index 0d2aa45a423eb1a84ea5e54edd001a13f0811034..60dbeb07816b2c124058abd143af36aa992242f5 100644 (file)
@@ -82,17 +82,14 @@ static void deb_led_out(char val)
 /* Provided by linker script */
 extern char __boot_fn_start;
 extern char __boot_fn_end;
+extern char etext;
 
-void RelocatedProgMode(unsigned long where, unsigned baud)
+void RelocatedProgMode(unsigned baud)
 { 
-  void (*ProgMode_ptr)(unsigned baud);
-  unsigned long reloc_offs=where-(unsigned long)&__boot_fn_start;
   size_t reloc_size=&__boot_fn_end-&__boot_fn_start;
-  ProgMode_ptr=&ProgMode;
-  ProgMode_ptr=(__u8*)ProgMode_ptr+reloc_offs;
-  memcpy((char*)where,&__boot_fn_start,reloc_size);
+  memcpy(&__boot_fn_start,&etext,reloc_size);
   /*deb_wr_hex((long)ProgMode_ptr,8);*/
-  (*ProgMode_ptr)(baud);
+  ProgMode(baud);
 }
 
 
@@ -127,7 +124,7 @@ void boot_test()
   if((__u8*)&__boot_fn_start<(__u8*)0xffb000) {
          /* If we are not in the internal RAM, copy and run us from
           * there */
-         RelocatedProgMode(0xffb000,HIT_LOAD_BAUD);
+         RelocatedProgMode(HIT_LOAD_BAUD);
   }
    else
     ProgMode(HIT_LOAD_BAUD);
index 08f552f10460a2717bb3dec6ed030e1d05cd3ee4..7e4be7bf212334d9f43c9a420959a951a8720ad9 100644 (file)
@@ -1,11 +1,11 @@
 # -*- makefile -*-
 
 lib_LIBRARIES=boot_fn
-boot_fn_SOURCES = boot_fn.o
+boot_fn_SOURCES = boot_fn.c
 
 
 #bin_PROGRAMS = boot
-boot_SOURCES = boot.c boot_fn.o
+boot_SOURCES = boot.c boot_fn.c
 
 #link_VARIANTS = ram flash
 
@@ -14,24 +14,3 @@ INCLUDES = -g
 lib_obj_SOURCES = crt0.S boot_fn.o
 
 include_HEADERS = boot_fn.h
-
-default_CONFIG = CONFIG_PIC_BOOT_FN=y
-
-ifeq ($(CONFIG_PIC_BOOT_FN),y)
-# The following is for non-standard compilation of boot_fn
-define local_EVALUATE
-$(call COMPILE_c_o_template,$(SOURCES_DIR)/boot_fn.c,boot_fn.s1,-fpic -S)
-$(call COMPILE_S_o_template,boot_fn.s,boot_fn.o,-fpic -c)
-endef
-
-# This rule replaces jsr instructions by bsr ones which are relative
-# calls.
-boot_fn.s : boot_fn.s1
-       @$(QUIET_CMD_ECHO) "  SED     $@"
-       $(Q) sed 's/jsr[^0-9_A-Za-z]*@_\([0-9_A-Za-z]*\)\([^0-9_A-Za-z]*\)/bsr _\1:16\2/g' <$< >$@
-
-clean-custom:
-       @rm boot_fn.s1 boot_fn.s
-else
-USER_SOURCES += boot_fn.c
-endif # CONFIG_PIC_BOOT_FN
index 3127f98072811541cef7602086ec2410353edc88..f46f3af4352b5aa2deef1d5daad1dbfa987d00a9 100644 (file)
@@ -55,16 +55,6 @@ void wdg_clear()
 
 #define TO_TEXT __attribute__ ((section (".text")))
 
-#define PIC_ADR(_ptr,_var) \
-       { \
-         __asm__ ( \
-           "bsr 1f\n" \
-           "1:\tmov.l @sp+,%0\n" \
-           "\tadd.l %1-1b,%0\n" \
-           : "=r" (_ptr) : "i" (&(_var)) : "cc" \
-         ); \
-       }
-
 static const unsigned long
   flash_blocks[] TO_TEXT =
        {0x00000,0x01000,0x02000,0x03000,0x04000,0x05000,0x06000,0x07000,
@@ -110,7 +100,7 @@ int FlAdr2Blk(unsigned long adr)
 {
   int bl=0;
   unsigned long *blocks;
-  PIC_ADR(blocks,flash_blocks[0]);
+  blocks = &flash_blocks[0];
 
   if(adr<blocks[0]) return -1;
   while(blocks[bl+1]){
@@ -125,7 +115,7 @@ int FlTest(int bl)
 {
   __u16 *p, *pe;
   unsigned long *blocks;
-  PIC_ADR(blocks,flash_blocks[0]);
+  blocks = &flash_blocks[0];
   
   if(bl>=flash_block_count) return -2;
   if(bl<0) return -2;
index 1083497d5827522d9d121521489253ab23928088..87f272b1228a7769a6691f264282ad83318ec0ff 100644 (file)
@@ -400,7 +400,7 @@ int tohit_cmdrepchk(int fd)
 {
   int res;
   verbose(2, "Waiting for end reply\n");
-  rs232_test(fd,2000000);
+  rs232_test(fd,3000000);
   res=rs232_recch(fd);
   if(res<0){
     printf("Error no end reply\n");
index c56266904737a4bfe2e88957b0b913139b2f7252..ba4080645bae5f40864ab1d4886395a4c62f4eb6 100644 (file)
@@ -28,18 +28,24 @@ SECTIONS
        {
          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(.text))
+         KEEP (boot_fn.o(.rodata))
+         KEEP (boot_fn.o(.strings))
          . = ALIGN( 4 ) ;
          ___boot_fn_end = ALIGN( 0x4 ) ;
-         *(.text .stub .text.* .gnu.linkonce.t.*)
-         *(.rodata .rodata.* .gnu.linkonce.r.*)
-         *(.strings)
-         . = ALIGN( 0x4 ) ;
-         _etext = ALIGN( 0x4 ) ;
-        } > flashbb
+       } > bloader AT>flashbb
 
        .tors : 
        {