summaryrefslogtreecommitdiff
path: root/flash/minimon
diff options
context:
space:
mode:
Diffstat (limited to 'flash/minimon')
-rw-r--r--flash/minimon/Makefile53
-rw-r--r--flash/minimon/README6
-rw-r--r--flash/minimon/minimon.c156
-rw-r--r--flash/minimon/minimon.h24
-rw-r--r--flash/minimon/minimon.lds60
5 files changed, 299 insertions, 0 deletions
diff --git a/flash/minimon/Makefile b/flash/minimon/Makefile
new file mode 100644
index 0000000000..57ae13e940
--- /dev/null
+++ b/flash/minimon/Makefile
@@ -0,0 +1,53 @@
1# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
7# $Id$
8#
9
10CC = sh-elf-gcc
11LD = sh-elf-ld
12AR = sh-elf-ar
13AS = sh-elf-as
14OC = sh-elf-objcopy
15
16FIRMWARE := ../../firmware
17TOOLSDIR=../../tools
18
19TARGET = minimon
20LDS := $(TARGET).lds
21
22INCLUDES= -I$(FIRMWARE)/export -I. -I$(OBJDIR)
23OBJDIR := .
24
25CFLAGS = -fpic -O -W -Wall -m1 -nostdlib -ffreestanding -Wstrict-prototypes -fomit-frame-pointer -fschedule-insns $(INCLUDES) $(DEFINES)
26AFLAGS += -small -relax
27
28
29ifdef DEBUG
30 DEFINES := -DDEBUG
31 CFLAGS += -g
32endif
33
34SRC := $(wildcard *.c)
35
36OBJS := $(SRC:%.c=$(OBJDIR)/%.o)
37
38LINKFILE = $(OBJDIR)/$(TARGET).lds
39
40
41$(OBJDIR)/$(TARGET).bin : $(OBJDIR)/$(TARGET).elf
42 $(OC) -O binary $(OBJDIR)/$(TARGET).elf $(OBJDIR)/$(TARGET).bin
43 $(TOOLSDIR)/sh2d $(OBJDIR)/$(TARGET).bin -o 0900000 > $(OBJDIR)/$(TARGET).asm
44
45$(OBJDIR)/$(TARGET).elf : $(OBJS)
46 $(CC) -Os -nostdlib -o $(OBJDIR)/$(TARGET).elf -L$(OBJDIR) -T$(LINKFILE) -Wl,-Map,$(OBJDIR)/$(TARGET).map
47
48
49clean:
50 -rm -f $(OBJS) $(OBJDIR)/$(TARGET).asm \
51 $(OBJDIR)/$(TARGET).bin \
52 $(OBJDIR)/$(TARGET).elf \
53 $(OBJDIR)/$(TARGET).map
diff --git a/flash/minimon/README b/flash/minimon/README
new file mode 100644
index 0000000000..b80edd9689
--- /dev/null
+++ b/flash/minimon/README
@@ -0,0 +1,6 @@
1(c) 2003 by Jörg Hohensohn
2
3MiniMon is the tiny but powerful-enough piece of code that can be loaded
4with the UART boot mod.
5It allows to read and write memory, flash program, execute code.
6This is suitable to reflash the box, load Rockbox or the gdb stub, etc.
diff --git a/flash/minimon/minimon.c b/flash/minimon/minimon.c
new file mode 100644
index 0000000000..e7981f2d09
--- /dev/null
+++ b/flash/minimon/minimon.c
@@ -0,0 +1,156 @@
1// minimalistic monitor
2// to be loaded with the UART boot feature
3// capable of reading and writing bytes, commanded by UART
4
5#include "sh7034.h"
6#include "minimon.h"
7
8// scalar types
9typedef unsigned char UINT8;
10typedef unsigned short UINT16;
11typedef unsigned long UINT32;
12
13typedef void(*tpFunc)(void); // type for exec
14typedef int(*tpMain)(void); // type for start vector to main()
15
16
17// prototypes
18int main(void);
19
20// our binary has to start with a vector to the entry point
21tpMain start_vector[] __attribute__ ((section (".startvector"))) = {main};
22
23
24UINT8 uart_read(void)
25{
26 UINT8 byte;
27 while (!(SSR1 & SCI_RDRF)); // wait for char to be available
28 byte = RDR1;
29 SSR1 &= ~SCI_RDRF;
30 return byte;
31}
32
33
34void uart_write(UINT8 byte)
35{
36 while (!(SSR1 & SCI_TDRE)); // wait for transmit buffer empty
37 TDR1 = byte;
38 SSR1 &= ~SCI_TDRE;
39}
40
41
42int main(void)
43{
44 UINT8 cmd;
45 UINT32 addr;
46 UINT32 size;
47 UINT32 content;
48 volatile UINT8* paddr = 0;
49 volatile UINT8* pflash; // flash base address
50
51 while (1)
52 {
53 cmd = uart_read();
54 switch (cmd)
55 {
56 case BAUDRATE:
57 content = uart_read();
58 uart_write(cmd); // acknowledge by returning the command value
59 while (!(SSR1 & SCI_TEND)); // wait for empty shift register, before changing baudrate
60 BRR1 = content;
61 break;
62
63 case ADDRESS:
64 addr = (uart_read() << 24) | (uart_read() << 16) | (uart_read() << 8) | uart_read();
65 paddr = (UINT8*)addr;
66 pflash = (UINT8*)(addr & 0xFFF80000); // round down to 512k align
67 uart_write(cmd); // acknowledge by returning the command value
68 break;
69
70 case BYTE_READ:
71 content = *paddr++;
72 uart_write(content); // the content is the ack
73 break;
74
75 case BYTE_WRITE:
76 content = uart_read();
77 *paddr++ = content;
78 uart_write(cmd); // acknowledge by returning the command value
79 break;
80
81 case BYTE_READ16:
82 size = 16;
83 while (size--)
84 {
85 content = *paddr++;
86 uart_write(content); // the content is the ack
87 }
88 break;
89
90 case BYTE_WRITE16:
91 size = 16;
92 while (size--)
93 {
94 content = uart_read();
95 *paddr++ = content;
96 }
97 uart_write(cmd); // acknowledge by returning the command value
98 break;
99
100 case BYTE_FLASH:
101 content = uart_read();
102 pflash[0x5555] = 0xAA; // set flash to command mode
103 pflash[0x2AAA] = 0x55;
104 pflash[0x5555] = 0xA0; // byte program command
105 *paddr++ = content;
106 uart_write(cmd); // acknowledge by returning the command value
107 break;
108
109 case BYTE_FLASH16:
110 size = 16;
111 while (size--)
112 {
113 content = uart_read();
114 pflash[0x5555] = 0xAA; // set flash to command mode
115 pflash[0x2AAA] = 0x55;
116 pflash[0x5555] = 0xA0; // byte program command
117 *paddr++ = content;
118 }
119 uart_write(cmd); // acknowledge by returning the command value
120 break;
121
122 case HALFWORD_READ:
123 content = *(UINT16*)paddr;
124 paddr += 2;
125 uart_write(content >> 8); // highbyte
126 uart_write(content & 0xFF); // lowbyte
127 break;
128
129 case HALFWORD_WRITE:
130 content = uart_read() << 8 | uart_read();
131 *(UINT16*)paddr = content;
132 paddr += 2;
133 uart_write(cmd); // acknowledge by returning the command value
134 break;
135
136 case EXECUTE:
137 {
138 tpFunc pFunc = (tpFunc)paddr;
139 pFunc();
140 uart_write(cmd); // acknowledge by returning the command value
141 }
142 break;
143
144
145 default:
146 {
147 volatile UINT16* pPortB = (UINT16*)0x05FFFFC2;
148 *pPortB |= 1 << 6; // bit 6 is red LED on
149 uart_write(~cmd); // error acknowledge
150 }
151
152 } // case
153 }
154
155 return 0;
156}
diff --git a/flash/minimon/minimon.h b/flash/minimon/minimon.h
new file mode 100644
index 0000000000..b6e9805ecf
--- /dev/null
+++ b/flash/minimon/minimon.h
@@ -0,0 +1,24 @@
1#ifndef _MINIMON_H
2#define _MINIMON_H
3
4
5// Commands
6// all multibyte values (address, halfwords) are passed as big endian
7// (most significant of the bytes first)
8
9// set the address (all read/write commands will auto-increment it)
10#define BAUDRATE 0x00 // followed by BRR value; response: command byte
11#define ADDRESS 0x01 // followed by 4 bytes address; response: command byte
12#define BYTE_READ 0x02 // response: 1 byte content
13#define BYTE_WRITE 0x03 // followed by 1 byte content; response: command byte
14#define BYTE_READ16 0x04 // response: 16 bytes content
15#define BYTE_WRITE16 0x05 // followed by 16 bytes; response: command byte
16#define BYTE_FLASH 0x06 // followed by 1 byte content; response: command byte
17#define BYTE_FLASH16 0x07 // followed by 16 bytes; response: command byte
18#define HALFWORD_READ 0x08 // response: 2 byte content
19#define HALFWORD_WRITE 0x09 // followed by 2 byte content; response: command byte
20#define EXECUTE 0x0A // response: command byte if call returns
21#define VERSION 0x0B // response: version
22
23
24#endif // _MINIMON_H
diff --git a/flash/minimon/minimon.lds b/flash/minimon/minimon.lds
new file mode 100644
index 0000000000..dbdbdc3faa
--- /dev/null
+++ b/flash/minimon/minimon.lds
@@ -0,0 +1,60 @@
1OUTPUT_FORMAT(elf32-sh)
2INPUT(minimon.o)
3
4MEMORY
5{
6 DRAM : ORIGIN = 0x09000000, LENGTH = 0x200000
7}
8
9SECTIONS
10{
11 .startvector :
12 {
13 *(.startvector)
14 . = ALIGN(0x4);
15 } > DRAM
16
17 .got :
18 {
19 *(.got)
20 } > DRAM
21
22 .got.plt :
23 {
24 *(.got.plt)
25 } > DRAM
26
27 .rela.got :
28 {
29 *(.rela.got)
30 } > DRAM
31
32 .text :
33 {
34 . = ALIGN(0x200);
35 *(.entry)
36 *(.text)
37 . = ALIGN(0x4);
38 } > DRAM
39
40 .data :
41 {
42 *(.data)
43 } > DRAM
44
45 .rodata :
46 {
47 *(.rodata)
48 . = ALIGN(0x4);
49 } > DRAM
50
51 .bss :
52 {
53 *(.bss)
54 } > DRAM
55
56 .stack :
57 {
58 *(.stack)
59 } > DRAM
60}