]> rtime.felk.cvut.cz Git - sysless.git/commitdiff
Included H8300 boot block and bootstrap loader code
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 21 Jul 2010 13:54:30 +0000 (15:54 +0200)
committerPavel Pisa <pisa@cmp.felk.cvut.cz>
Tue, 16 Nov 2010 15:54:52 +0000 (16:54 +0100)
The app/ directory was mess. This is an attempt to make the situation
better.

arch/h8300/generic/Makefile.omk
arch/h8300/generic/bloader/Makefile [new file with mode: 0644]
arch/h8300/generic/bloader/Makefile.omk [new file with mode: 0644]
arch/h8300/generic/bloader/Makefile.std [new file with mode: 0644]
arch/h8300/generic/bloader/bloader.c [new file with mode: 0644]
arch/h8300/generic/bloader/bootstrap [new file with mode: 0755]
arch/h8300/generic/bloader/make_bloader.log [new file with mode: 0644]
arch/h8300/generic/bloader/scratchpad.txt [new file with mode: 0644]

index 6a31eafe10bef75e8a9f9a6f3fa175529e4a4565..88885963c4178a56acb75ad7ae7327647452bc1d 100644 (file)
@@ -1,3 +1,3 @@
 # -*- makefile -*-
 
-SUBDIRS = defines libs drivers tools
+SUBDIRS = defines libs drivers bloader tools
diff --git a/arch/h8300/generic/bloader/Makefile b/arch/h8300/generic/bloader/Makefile
new file mode 100644 (file)
index 0000000..76b56fd
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
+else
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/arch/h8300/generic/bloader/Makefile.omk b/arch/h8300/generic/bloader/Makefile.omk
new file mode 100644 (file)
index 0000000..b8ef378
--- /dev/null
@@ -0,0 +1,25 @@
+# -*- makefile -*-
+
+bin_PROGRAMS = bloader
+
+bloader_SOURCES = bloader.c 
+bloader_LIBS = boot_fn bspbase
+#bloader_MOREOBJS = boot_fn.o
+
+link_VARIANTS = boot bload
+
+bootstrap: TOHIT=$(USER_COMPILED_DIR_NAME)/bin-utils/tohit -d $(HIT_DEV)
+bootstrap: HIT_BAUD=19200
+.PHONY: bootstrap
+
+bootstrap:
+       @$(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
+       @$(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
+       @$(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
diff --git a/arch/h8300/generic/bloader/Makefile.std b/arch/h8300/generic/bloader/Makefile.std
new file mode 100644 (file)
index 0000000..8607219
--- /dev/null
@@ -0,0 +1,177 @@
+# -*- makefile -*-
+TOPDIR=..
+
+TARGET_ARCH = -ms
+#TARGET_ARCH = -bh8300-coff -ms
+#TARGET_ARCH = -bh8300-coff -ms -mrelax
+#TARGET_ARCH = -bm68k-coff -m68332
+#TARGET_ARCH = -bm68k-elf -m68332
+#TARGET_ARCH = -bi586-mingw32
+
+TOHIT=../tohit/tohit -d /dev/ttyS0
+
+BOARD_LAYOUT=id_cpu1
+#BOARD_LAYOUT=edk2638
+
+#CC = gcc
+CC = h8300-coff-gcc
+
+LINK = h8300-coff-ld
+
+OBJCOPY = h8300-coff-objcopy
+
+CFLAGS  += $(TARGET_ARCH)
+CFLAGS += -g 
+CFLAGS += -O2 -Wall
+
+CFLAGS += -I. -I../../_compiled/include
+
+
+LDFLAGS += $(TARGET_ARCH)
+#LDFLAGS += -Xlinker -Ttext -Xlinker 0x0FFE400
+LDFLAGS += -nostartfiles
+#LDFLAGS += -nodefaultlibs
+#LDFLAGS +=  -Xlinker -T -Xlinker h8300s.x
+LDFLAGS +=  -Xlinker -Map -Xlinker bloader.map
+LDFLAGS += --relax
+LDFLAGS += -L. -L../../_compiled/lib
+LDFLAGS += -lboot_fn
+
+CRT0_O = crt0.o
+
+LCSCRIPTB = 
+
+HIT_BAUD = 19200
+#HIT_BAUD = 38400
+#CFLAGS        += -DHIT_LOAD_BAUD=$(HIT_BAUD)
+
+#CFLAGS        += -v
+#LDFLAGS += -v
+
+######################################################################
+# New rules
+
+.S.o:
+       $(CC) -D__ASSEMBLY__ $(AFLAGS) $(TARGET_ARCH) -c $< -o $@
+
+.c.s:
+       $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -S $< -o $@
+
+######################################################################
+
+all   : bloader.bin
+
+dep:
+       $(CC) $(CFLAGS) $(CPPFLAGS) -w -E -M *.c $(MORE_C_FILES) > depend
+
+depend:
+       @touch depend
+
+cleanapps : clean
+
+clean   :
+       rm -f *.o
+       rm -f *.bin *.srec
+       rm -f bloader bloader-boot bloader-ram bloader-flash
+
+boot_fn.o : ../../_build/arch/h8300/generic/libs/boot/boot_fn.o
+       ln -s $< $@ 
+
+crt0.o : ../../_compiled/lib/crt0.o
+       ln -s $< $@ 
+
+#LDFORBOOT += -Xlinker -Ttext -Xlinker 0xffc000 
+#LDFORBOOT += -Xlinker -Tdata -Xlinker 0xffc000 
+#LDFORBOOT += -Xlinker -Tbss  -Xlinker 0xffc000
+
+bloader :bloader.o $(BOOT_FN_O)
+       $(CC) $(LDFLAGS) -T $(BOARD_LAYOUT).ld-bload $(LDFORBOOT) $^ -o $@
+
+bloader-flash :bloader.o $(BOOT_FN_O)
+       $(CC) $(LDFLAGS) -T $(BOARD_LAYOUT).ld-flash $^ -o $@
+
+bloader-ram :bloader.o $(BOOT_FN_O)
+       $(CC) $(LDFLAGS) -T $(BOARD_LAYOUT).ld-ram $^ -o $@
+
+bloader-boot :bloader.o $(BOOT_FN_O)
+       $(CC) $(LDFLAGS) -T $(BOARD_LAYOUT).ld-boot $^ -o $@
+
+bloader.bin : bloader
+       $(OBJCOPY)  --output-target=binary -S bloader bloader.bin
+
+# Load bloader to internal ram (in boot mode, all flash is erased)
+load : bloader.bin
+       $(TOHIT) --baud 4800 --command B --blockmode 128 bloader.bin /* boot program mode */
+#      $(TOHIT) --command B  bloader.bin  
+       $(TOHIT) --baud $(HIT_BAUD) --upload --start 0 --length 0x400 bloader.rd
+#      $(TOHIT) B 0 bloader.bin
+
+bloader1 :
+       ((cd ../boot ; rm *.o ; make ; ) ; rm *.o ; make bloader-ram; objdump --source bloader-ram ) 2>&1  | less
+
+
+# Use previously loaded bloader to load bloader to external ram
+load1 : bloader-ram
+       $(OBJCOPY) --output-target=binary -S bloader-ram bloader1.bin
+       $(OBJCOPY) --output-target=srec   -S bloader-ram bloader1.srec
+       $(TOHIT) --baud $(HIT_BAUD) --blockmode 32 --start 0x200000 bloader1.bin
+       $(TOHIT) --baud $(HIT_BAUD) --upload --start 0x200000 --length 0x1A00 bloader1.rd
+       $(TOHIT) --baud $(HIT_BAUD) --go 0x200000
+
+# Use previously loaded bloader to store bloader in flash
+load2 : bloader-boot
+       $(OBJCOPY) --output-target=binary -S bloader-boot bloader2.bin
+       $(TOHIT) --baud $(HIT_BAUD) --erase --start 0x000000 --length 0x1600
+       $(TOHIT) --baud $(HIT_BAUD) --command 1 --blockmode 32 --start 0x000000 bloader2.bin
+       $(TOHIT) --baud $(HIT_BAUD) --upload --start 0x000000 --length 0x1600 --blockmode 32 bloader2.rd
+
+# Use previously loaded bloader to load bloader to internal ram as in boot-mode
+load3 : bloader.bin
+       $(TOHIT) --baud $(HIT_BAUD) --start 0xffc000 --blockmode 32 --go 0xffc000 bloader.bin
+
+read_bb : 
+       $(TOHIT) --baud $(HIT_BAUD) --upload --start 0xffc000 --length 0x400 bloader.rd
+
+read_st : 
+       $(TOHIT) --baud $(HIT_BAUD) --upload --start 0x280000 --length 0x1000 --blockmode 32 bloader.rd
+
+read_flash : 
+       $(TOHIT) --baud $(HIT_BAUD) --upload --start 0x000000 --length 0x2000 bloader2.rd
+       cmp -l bloader2.bin bloader2.rd
+
+flash_prg : 
+       $(TOHIT) --baud $(HIT_BAUD) --erase --start 0x010000 --length 0x80
+       $(TOHIT) --baud $(HIT_BAUD) --command 1 --blockmode 32 --start 0x010000 pat.bin
+       $(TOHIT) --baud $(HIT_BAUD) --upload --start 0x010000 --length 0x80 pat.rd
+       cmp -l pat.bin pat.rd
+
+flash_prg1 : 
+       $(TOHIT) --baud $(HIT_BAUD) --erase --start 0x007000 --length 0x200
+       $(TOHIT) --baud $(HIT_BAUD) --command 1 --blockmode 32 --start 0x007000 pat1.bin
+       $(TOHIT) --baud $(HIT_BAUD) --upload --start 0x007000 --length 0x200 pat1.rd
+       cmp -l pat1.bin pat1.rd
+
+ram_test : 
+       $(TOHIT) --baud $(HIT_BAUD) --wait-reply 1000 --blockmode 32 --start 0x200000 pat.bin
+#      $(TOHIT) --baud $(HIT_BAUD) --break
+       sleep 1
+       $(TOHIT) --baud $(HIT_BAUD) --wait-reply 1000 --upload --start 0x200000 --length 0x0400 pat.rd
+       cmp -l pat.bin pat.rd
+
+reset : 
+       $(TOHIT) --baud $(HIT_BAUD) --reset
+
+break : 
+       $(TOHIT) --baud $(HIT_BAUD) --break
+
+goto0 : 
+       $(TOHIT) --baud $(HIT_BAUD) --go 0xffc000
+
+goto1 : 
+       $(TOHIT) --baud $(HIT_BAUD) --go 0x200000
+
+goto2 : 
+       $(TOHIT) --baud $(HIT_BAUD) --go 0x000500
+
+
+-include depend
diff --git a/arch/h8300/generic/bloader/bloader.c b/arch/h8300/generic/bloader/bloader.c
new file mode 100644 (file)
index 0000000..0d2aa45
--- /dev/null
@@ -0,0 +1,210 @@
+/* procesor H8S/2638 ver 1.1  */
+#include <types.h>
+#include <cpu_def.h>
+#include <mcu_regs.h>
+//#include <periph/chmod_lcd.h>
+//#include <periph/sgm_lcd.h>
+#include <system_def.h>
+#include <string.h>
+
+
+#ifndef DEB_LED_INIT
+#define DEB_LED_INIT()
+#define DEB_LED_OFF(num)
+#define DEB_LED_ON(num)
+#endif
+
+#define BOOT_TEST
+#define APPLICATION_START
+
+/*#define USE_FONT_6x8*/
+
+#ifndef HIT_LOAD_BAUD
+  #define HIT_LOAD_BAUD 0
+#endif
+
+/* hack for start of main, should use crt0.o instead */
+/* Used in boot mode to start main(). */
+__asm__ /*__volatile__*/(
+       ".global _start_hack\n\t"
+       "_start_hack : \n\t"
+       "mov.l  #0xffdffe,sp\n\t"
+       "jsr    _main\n"
+       "0: bra 0b\n"
+       );
+
+void exit(int status)
+{
+  while(1);
+}
+
+void deb_wr_hex(long hex, short digs);
+
+char data_test[]={'D','A','T','A',0};
+
+ /*
+ *----------------------------------------------------------
+ */
+void deb_wr_hex(long hex, short digs)
+{
+  char c;
+  while(digs--){
+    c=((hex>>(4*digs))&0xf)+'0';
+    if(c>'9') c+='A'-'9'-1;  
+  }
+}
+
+static void deb_led_out(char val)
+{
+  if (val&1)
+    DEB_LED_ON(0);
+  else
+    DEB_LED_OFF(0);
+  if (val&2)
+    DEB_LED_ON(1);
+  else
+    DEB_LED_OFF(1);
+  if (val&4)
+    DEB_LED_ON(2);
+  else
+    DEB_LED_OFF(2);
+  if (val&8)
+    DEB_LED_ON(3);
+  else
+    DEB_LED_OFF(3);
+}
+
+
+#ifdef BOOT_TEST
+
+#include <boot_fn.h>
+
+/* Provided by linker script */
+extern char __boot_fn_start;
+extern char __boot_fn_end;
+
+void RelocatedProgMode(unsigned long where, 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);
+  /*deb_wr_hex((long)ProgMode_ptr,8);*/
+  (*ProgMode_ptr)(baud);
+}
+
+
+void boot_test()
+{
+  /*set power on for SCI0 and SCI1 module*/
+  *SYS_MSTPCRB&=~MSTPCRB_SCI0m;
+  *SYS_MSTPCRB&=~MSTPCRB_SCI1m;
+
+ #if 0
+  SCIInit(HIT_LOAD_BAUD);
+
+  SCISend('B');
+  SCISend('B');
+  SCISend(':');
+
+ #endif
+
+  /* switch off SCI2 module*/
+  *SYS_MSTPCRB|=MSTPCRB_SCI2m;
+  
+  *DIO_PADR |= 0x0f;
+  *DIO_PADDR = 0x0f;
+
+  if(!HIT_LOAD_BAUD) {
+    long bauddet;   
+    bauddet=SCIAutoBaud();
+    deb_wr_hex(bauddet,4);
+  }
+
+  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);
+  }
+   else
+    ProgMode(HIT_LOAD_BAUD);
+}
+
+#endif /* BOOT_TEST */
+
+inline int call_address(unsigned long addr)
+{
+  typedef int (*my_call_t)(void);
+  my_call_t my_call=(my_call_t)addr;
+  return my_call();  
+}
+
+/*
+ *-----------------------------------------------------------
+ */
+
+
+/* Only for debuging */
+void deb_led_blink() {
+  while(1) {
+    deb_led_out(1);
+    FlWait(1*1000000);
+    deb_led_out(2);
+    FlWait(1*1000000);
+  };
+};
+
+int main()
+{
+  __u8 *p;
+
+  _setup_board(); /* Provided in bspbase library of each board */
+
+  p=(__u8*)&deb_wr_hex;
+  if(p>=IRAM_START) p=" IRAM";
+#ifdef SRAM_START
+  else if(p>=SRAM_START) p=" SRAM";
+#endif
+#ifdef XRAM_START
+  else if(p>=XRAM_START) p=" XRAM";
+#endif
+  else if(p>(__u8*)0x4000l) p=" FLSHU";
+  else p=" FLSHB";
+
+
+#if 0          /* FLASH timing test */
+  do{
+    deb_led_out(~0);
+    FlWait(1l);
+    deb_led_out(~1);
+    FlWait(2l);
+    deb_led_out(~2);
+    FlWait(10l);
+    deb_led_out(~3);
+    FlWait(20l);
+  }while(1);
+#endif
+
+#ifdef APPLICATION_START
+  if(((*FLM_FLMCR1) & FLMCR1_FWEm)==0) {
+    if (*((unsigned long *)0x4000)!=0xffffffff){
+      call_address(0x4000);
+    }
+  }
+#endif /* APPLICATION_START */
+  deb_led_out(15);
+  FlWait(1*100000);
+  deb_led_out(3);
+#ifdef BOOT_TEST
+  boot_test();
+#endif /* BOOT_TEST */ 
+  return 0;
+};
+
+
diff --git a/arch/h8300/generic/bloader/bootstrap b/arch/h8300/generic/bloader/bootstrap
new file mode 100755 (executable)
index 0000000..3dac464
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+make bootstrap "$@"
diff --git a/arch/h8300/generic/bloader/make_bloader.log b/arch/h8300/generic/bloader/make_bloader.log
new file mode 100644 (file)
index 0000000..a6d2309
--- /dev/null
@@ -0,0 +1,4 @@
+h8300-coff-gcc -ms -g  -O2 -Wall -I. -I../include -I../include/h8s -I..  -ms -c -o test.o test.c
+ln -s ../lib/boot_fn.o boot_fn.o 
+h8300-coff-gcc -ms -nostartfiles -Xlinker -Map -Xlinker test.map --relax -L. -L../lib -T id_cpu1.ld-bload  test.o boot_fn.o -o test
+h8300-coff-objcopy  --output-target=binary -S test test.bin
diff --git a/arch/h8300/generic/bloader/scratchpad.txt b/arch/h8300/generic/bloader/scratchpad.txt
new file mode 100644 (file)
index 0000000..df1da83
--- /dev/null
@@ -0,0 +1,7 @@
+Notices for H8300 flashing
+seyon -modems /dev/ttyS1
+../tohit/tohit -d /dev/ttyS1 -w 10000 -B19200 -s 0x0000 -l 0x0100 -u rd.bin
+make flash_prg -n
+minicom
+make flash_prg
+nedit Makefile