summaryrefslogtreecommitdiff
path: root/flash
diff options
context:
space:
mode:
Diffstat (limited to 'flash')
-rw-r--r--flash/README7
-rw-r--r--flash/bootbox/Makefile75
-rw-r--r--flash/bootbox/SOURCES1
-rw-r--r--flash/bootbox/bootbox.make15
-rw-r--r--flash/bootbox/main.c224
-rw-r--r--flash/bootloader/Makefile81
-rw-r--r--flash/bootloader/README4
-rw-r--r--flash/bootloader/bootloader.c467
-rw-r--r--flash/bootloader/bootloader.h109
-rw-r--r--flash/bootloader/bootloader.lds34
-rw-r--r--flash/bootloader/no_rom.lds62
-rw-r--r--flash/extract/README5
-rw-r--r--flash/extract/extract.c147
-rw-r--r--flash/extract/extract.dsp100
-rw-r--r--flash/make_firmware/README20
-rw-r--r--flash/make_firmware/make_firmware.c359
-rw-r--r--flash/make_firmware/make_firmware.dsp96
-rw-r--r--flash/minimon/Makefile53
-rw-r--r--flash/minimon/README9
-rw-r--r--flash/minimon/minimon.c156
-rw-r--r--flash/minimon/minimon.h24
-rw-r--r--flash/minimon/minimon.lds60
-rw-r--r--flash/uart_boot/Makefile19
-rw-r--r--flash/uart_boot/README8
-rw-r--r--flash/uart_boot/client.c737
-rw-r--r--flash/uart_boot/client.h22
-rw-r--r--flash/uart_boot/flash.c78
-rw-r--r--flash/uart_boot/flash.h10
-rw-r--r--flash/uart_boot/minimon.h24
-rw-r--r--flash/uart_boot/scalar_types.h45
-rw-r--r--flash/uart_boot/uart.h57
-rw-r--r--flash/uart_boot/uart_boot.c370
-rw-r--r--flash/uart_boot/uart_boot.dsp130
-rw-r--r--flash/uart_boot/uart_win.c139
34 files changed, 0 insertions, 3747 deletions
diff --git a/flash/README b/flash/README
deleted file mode 100644
index 47ae4ce780..0000000000
--- a/flash/README
+++ /dev/null
@@ -1,7 +0,0 @@
1(c) 2003 by Jörg Hohensohn
2
3Sourcecode for the flash "infrastructure"
4Please bear in mind that these are powerful tools, don't fool with them!
5
6For most up-to-date info about flashing see:
7http://rockbox.haxx.se/docs/flash.html
diff --git a/flash/bootbox/Makefile b/flash/bootbox/Makefile
deleted file mode 100644
index 754f95dd49..0000000000
--- a/flash/bootbox/Makefile
+++ /dev/null
@@ -1,75 +0,0 @@
1# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
7# $Id$
8#
9
10INCLUDES= $(TARGET_INC) -I$(FIRMDIR)/include -I$(FIRMDIR)/export -I. -I$(OBJDIR) \
11 -I$(BUILDDIR)
12
13DEPFILE = $(OBJDIR)/dep-bootbox
14LDS := $(FIRMDIR)/target/$(CPU)/$(MANUFACTURER)/app.lds
15
16ifdef DEBUG
17 DEFINES := -DDEBUG
18 CFLAGS += -g
19endif
20
21SRC := $(shell cat SOURCES | $(CC) -DMEMORYSIZE=$(MEMORYSIZE) $(INCLUDES) $(TARGET) $(DEFINES) -E -P -include "config.h" - )
22DIRS = .
23
24ifdef APPEXTRA
25 DIRS += $(subst :, ,$(APPEXTRA))
26 INCLUDES += $(patsubst %,-I%,$(subst :, ,$(APPEXTRA)))
27endif
28
29CFLAGS = $(GCCOPTS) $(INCLUDES) $(TARGET) $(DEFINES) \
30 $(EXTRA_DEFINES) -DMEM=${MEMORYSIZE}
31
32OBJS := $(SRC:%.c=$(OBJDIR)/%.o)
33SOURCES = $(SRC)
34LINKFILE = $(OBJDIR)/linkage.lds
35MAXINFILE = $(OBJDIR)/romstart.temp
36MAXOUTFILE = $(OBJDIR)/romstart
37
38LIBROCKBOX = $(BUILDDIR)/librockbox.a
39
40all: $(BUILDDIR)/$(BINARY) $(FLASHFILE)
41
42dep: $(DEPFILE)
43
44$(LINKFILE): $(LDS)
45 $(call PRINTS,Build $(@F))cat $< | $(CC) -DMEMORYSIZE=$(MEMORYSIZE) $(INCLUDES) $(TARGET) $(DEFINES) -E -P $(ROMBUILD) - >$@
46
47$(MAXOUTFILE):
48 $(SILENT)echo '#include "config.h"' > $(MAXINFILE)
49 $(SILENT)echo "ROM_START" >> $(MAXINFILE)
50 $(SILENT)cat $(MAXINFILE) | $(CC) -DMEMORYSIZE=$(MEMORYSIZE) $(INCLUDES) $(TARGET) $(DEFINES) -E -P $(ROMBUILD) - > $(MAXOUTFILE)
51 $(SILENT)rm $(MAXINFILE)
52
53$(OBJDIR)/bootbox.elf : $(OBJS) $(LINKFILE) $(DEPFILE) $(LIBROCKBOX)
54 $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -Wl,--gc-sections -Os -nostdlib -o $@ $(OBJS) -L$(BUILDDIR) -L$(BUILDDIR)/firmware -lrockbox -lgcc -T$(LINKFILE) -Wl,-Map,$(OBJDIR)/bootbox.map
55
56$(OBJDIR)/bootbox.bin : $(OBJDIR)/bootbox.elf
57 $(call PRINTS,OBJCOPY $(@F))$(OC) -O binary $< $@
58
59$(OBJDIR)/bootbox.asm: $(OBJDIR)/bootbox.bin
60 $(TOOLSDIR)/sh2d -sh1 $< > $@
61
62$(BUILDDIR)/$(BINARY) : $(OBJDIR)/bootbox.bin
63 $(call PRINTS,Build bootbox file)$(MKFIRMWARE) $< $@
64
65$(FLASHFILE): $(OBJDIR)/bootbox.bin
66 $(call PRINTS,UCLPACK bootbox)$(TOOLSDIR)/uclpack --best --2e $< $@ >/dev/null 2>&1;
67
68include $(TOOLSDIR)/make.inc
69
70clean:
71 $(call PRINTS,cleaning bootbox)-rm -f $(OBJS) $(BUILDDIR)/$(BINARY) $(OBJDIR)/bootbox.asm $(OBJDIR)/rockbox.ucl \
72 $(OBJDIR)/bootbox.bin $(OBJDIR)/bootbox.elf $(OBJDIR)/*.map \
73 $(LINKFILE) $(MAXOUTFILE) $(DEPFILE) $(FLASHFILE)
74
75-include $(DEPFILE)
diff --git a/flash/bootbox/SOURCES b/flash/bootbox/SOURCES
deleted file mode 100644
index e241137f99..0000000000
--- a/flash/bootbox/SOURCES
+++ /dev/null
@@ -1 +0,0 @@
1main.c
diff --git a/flash/bootbox/bootbox.make b/flash/bootbox/bootbox.make
deleted file mode 100644
index 38a664d57d..0000000000
--- a/flash/bootbox/bootbox.make
+++ /dev/null
@@ -1,15 +0,0 @@
1# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
7# $Id$
8#
9
10SRC += $(call preprocess,$(APPSDIR)/SOURCES)
11
12CORE_GCSECTIONS = yes
13
14# don't build rombox.ucl
15ARCHOSROM=
diff --git a/flash/bootbox/main.c b/flash/bootbox/main.c
deleted file mode 100644
index ac90d60336..0000000000
--- a/flash/bootbox/main.c
+++ /dev/null
@@ -1,224 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Jörg Hohensohn aka [IDC]Dragon
11 *
12 * This is "Bootbox", a minimalistic loader, rescue firmware for just
13 * booting into a full features one. Aside from that it does charging
14 * and USB mode, to enable copying the desired firmware.
15 *
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
20 *
21 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
22 * KIND, either express or implied.
23 *
24 ****************************************************************************/
25#include "config.h"
26
27#include <stdlib.h>
28#include <stdio.h>
29#include "cpu.h"
30#include "system.h"
31#include "lcd.h"
32#include "../kernel-internal.h"
33#include "storage.h"
34#include "disk.h"
35#include "font.h"
36#include "adc.h"
37#include "button.h"
38#include "panic.h"
39#include "power.h"
40#include "file.h"
41#include "rolo.h"
42#include "usb.h"
43#include "powermgmt.h"
44
45static void usb_screen(void)
46{
47 lcd_clear_display();
48 lcd_puts(0, 0, "USB mode");
49 lcd_update();
50
51 usb_acknowledge(SYS_USB_CONNECTED_ACK);
52 while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) {
53 }
54}
55
56static void show_logo(void)
57{
58 lcd_clear_display();
59 lcd_puts(0, 0, "Rockbox");
60 lcd_puts(0, 1, "Rescue boot");
61 lcd_update();
62}
63
64#if CONFIG_CHARGING
65static void charging_screen(void)
66{
67 unsigned int button;
68 const char* msg;
69
70 ide_power_enable(false); /* power down the disk, else would be spinning */
71
72 lcd_clear_display();
73
74 do
75 {
76#ifdef ARCHOS_RECORDER
77 if (charge_state == CHARGING)
78 msg = "charging";
79 else if (charge_state == TOPOFF)
80 msg = "topoff charge";
81 else if (charge_state == TRICKLE)
82 msg = "trickle charge";
83 else
84 msg = "not charging";
85#else
86 msg = "charging";
87#endif
88 lcd_puts(0, 0, msg);
89 {
90 char buf[32];
91 int battv = battery_voltage();
92 snprintf(buf, sizeof(buf), "%d.%02dV %d%%",
93 battv / 1000, (battv % 1000) / 10, battery_level());
94 lcd_puts(0, 1, buf);
95 }
96 lcd_update();
97
98 button = button_get_w_tmo(HZ/2);
99#ifdef BUTTON_ON
100 if (button == (BUTTON_ON | BUTTON_REL))
101#else
102 if (button == (BUTTON_RIGHT | BUTTON_REL))
103#endif
104 break; /* start */
105 else
106 {
107 if (usb_detect() == USB_INSERTED)
108 break;
109 else if (!charger_inserted())
110 power_off(); /* charger removed: power down */
111 }
112 } while (1);
113}
114#endif /* CONFIG_CHARGING */
115
116/* prompt user to plug USB and fix a problem */
117static void prompt_usb(const char* msg1, const char* msg2)
118{
119 int button;
120 lcd_clear_display();
121 lcd_puts(0, 0, msg1);
122 lcd_puts(0, 1, msg2);
123#ifdef HAVE_LCD_BITMAP
124 lcd_puts(0, 2, "Insert USB cable");
125 lcd_puts(0, 3, "and fix it.");
126#endif
127 lcd_update();
128 do
129 {
130 button = button_get(true);
131 if (button == SYS_POWEROFF)
132 {
133 power_off();
134 }
135 } while (button != SYS_USB_CONNECTED);
136 usb_screen();
137 system_reboot();
138}
139
140void main(void)
141{
142 int rc;
143
144 power_init();
145 system_init();
146 kernel_init();
147 lcd_init();
148 show_logo();
149 enable_irq();
150 adc_init();
151 usb_init();
152 button_init();
153 powermgmt_init();
154
155#if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
156 if (charger_inserted()
157#ifdef ATA_POWER_PLAYERSTYLE
158 && !ide_powered() /* relies on probing result from bootloader */
159#endif
160 )
161 {
162 charging_screen(); /* display a "charging" screen */
163 show_logo(); /* again, to provide better visual feedback */
164 }
165#endif
166
167 rc = storage_init();
168 if(rc)
169 {
170#ifdef HAVE_LCD_BITMAP
171 char str[32];
172 lcd_clear_display();
173 snprintf(str, 31, "ATA error: %d", rc);
174 lcd_puts(0, 1, str);
175 lcd_update();
176 while(!(button_get(true) & BUTTON_REL));
177#endif
178 panicf("storage: %d", rc);
179 }
180
181 usb_start_monitoring();
182 while (usb_detect() == USB_INSERTED)
183 { /* enter USB mode early, before trying to mount */
184 if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED)
185 {
186 usb_screen();
187 }
188 }
189
190 rc = disk_mount_all();
191 if (rc<=0)
192 {
193 prompt_usb("No partition", "found.");
194 }
195
196 { // rolo the firmware
197 static const char filename[] = "/" BOOTFILE;
198 rolo_load((char*)filename); /* won't return if started */
199
200 prompt_usb("No firmware", filename);
201 }
202
203
204}
205
206/* These functions are present in the firmware library, but we reimplement
207 them here because the originals do a lot more than we want */
208
209void audio_stop(void)
210{
211}
212
213int audio_status(void)
214{
215 return 0;
216}
217
218void audio_stop_recording(void)
219{
220}
221
222void mp3_shutdown(void)
223{
224}
diff --git a/flash/bootloader/Makefile b/flash/bootloader/Makefile
deleted file mode 100644
index edc32113c6..0000000000
--- a/flash/bootloader/Makefile
+++ /dev/null
@@ -1,81 +0,0 @@
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 = bootloader
20LDS := $(TARGET).lds
21
22
23ifndef PLATFORM
24not_configured:
25 @echo "No platform given."
26 @echo "Use make PLATFORM=PLAYER|RECORDER|FM|ONDIO {NO_ROM=1}"
27##else
28##configured:
29## @echo "Building bootloader for platform "$(PLATFORM)
30endif
31
32
33INCLUDES= -I$(FIRMWARE)/export -I. -I$(OBJDIR)
34DEFINES= -DPLATFORM_$(PLATFORM)
35
36OBJDIR := .
37
38CFLAGS = -Os -W -Wall -m1 -nostdlib -ffreestanding -Wstrict-prototypes -fomit-frame-pointer -fschedule-insns $(INCLUDES) $(DEFINES)
39AFLAGS += -small -relax
40
41
42ifdef DEBUG
43 DEFINES := -DDEBUG
44 CFLAGS += -g
45endif
46
47SRC := $(wildcard *.c)
48
49OBJS := $(SRC:%.c=$(OBJDIR)/%.o) $(OBJDIR)/sh_nrv2e_d8.o
50
51ifdef NO_ROM
52LINKFILE = $(OBJDIR)/no_rom.lds
53ORIGIN = 0
54DEFINES += -DNO_ROM
55else
56LINKFILE = $(OBJDIR)/$(TARGET).lds
57ORIGIN = FFFF500
58endif
59
60$(OBJDIR)/$(TARGET).bin : $(OBJDIR)/$(TARGET).elf
61 $(OC) -O binary $(OBJDIR)/$(TARGET).elf $(OBJDIR)/$(TARGET).bin
62 $(TOOLSDIR)/sh2d $(OBJDIR)/$(TARGET).bin -o $(ORIGIN) > $(OBJDIR)/$(TARGET).asm
63ifndef NO_ROM
64 $(TOOLSDIR)/scramble $(OBJDIR)/$(TARGET).bin $(OBJDIR)/$(TARGET).ajz
65endif
66
67$(OBJDIR)/$(TARGET).elf : $(OBJS)
68 $(CC) -Os -nostdlib -o $@ $(OBJS) -T$(LINKFILE) -Wl,-Map,$(OBJDIR)/$(TARGET).map
69
70# cross-reference, saves code duplication
71$(OBJDIR)/sh_nrv2e_d8.o : ../../firmware/decompressor/sh_nrv2e_d8.S
72 $(CC) $(CFLAGS) -c $< -o $@
73
74clean:
75 -rm -f \
76 $(OBJS) \
77 $(OBJDIR)/$(TARGET).asm \
78 $(OBJDIR)/$(TARGET).bin \
79 $(OBJDIR)/$(TARGET).ajz \
80 $(OBJDIR)/$(TARGET).elf \
81 $(OBJDIR)/$(TARGET).map
diff --git a/flash/bootloader/README b/flash/bootloader/README
deleted file mode 100644
index 47583da445..0000000000
--- a/flash/bootloader/README
+++ /dev/null
@@ -1,4 +0,0 @@
1(c) 2003 by Jörg Hohensohn
2
3This is the source code for the flash bootloader.
4It give the dual boot feature, decompresses one of two software images.
diff --git a/flash/bootloader/bootloader.c b/flash/bootloader/bootloader.c
deleted file mode 100644
index 40c0dc5c54..0000000000
--- a/flash/bootloader/bootloader.c
+++ /dev/null
@@ -1,467 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2003 by Jörg Hohensohn
11 *
12 * Second-level bootloader, with dual-boot feature by holding F1/Menu
13 * This is the image being descrambled and executed by the boot ROM.
14 * It's task is to copy Rockbox from Flash to DRAM.
15 * The image(s) in flash may optionally be compressed with UCL 2e
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version 2
20 * of the License, or (at your option) any later version.
21 *
22 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
23 * KIND, either express or implied.
24 *
25 ****************************************************************************/
26
27#include "sh7034.h"
28#include "bootloader.h"
29
30// prototypes
31static void PlatformInit(void);
32static void DecompressStart(tImage* pImage);
33#ifdef USE_ADC
34static int ReadADC(int channel);
35#endif
36static int ButtonPressed(void);
37static tImage* GetStartImage(int nPreferred);
38// test functions
39static void SetLed(BOOL bOn);
40static void UartInit(void);
41static UINT8 UartRead(void);
42static void UartWrite(UINT8 byte);
43static void MiniMon(void);
44
45
46#ifdef NO_ROM
47/* start with the vector table */
48UINT32 vectors[] __attribute__ ((section (".vectors"))) =
49{
50 (UINT32)_main, /* entry point, the copy routine */
51 (UINT32)(end_stack - 1), /* initial stack pointer */
52 FLASH_BASE + 0x200, /* source of image in flash */
53 (UINT32)total_size, /* size of image */
54 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
55 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
56 0x03020080 /* mask and version (just as a suggestion) */
57};
58#else
59/* our binary has to start with a vector to the entry point */
60tpMain start_vector[] __attribute__ ((section (".startvector"))) = {main};
61#endif
62
63#ifdef NO_ROM /* some code which is only needed for the romless variant */
64void _main(void)
65{
66 UINT32* pSrc;
67 UINT32* pDest;
68 UINT32* pEnd;
69/*
70 asm volatile ("ldc %0,sr" : : "r"(0xF0)); // disable interrupts
71 asm volatile ("mov.l @%0,r15" : : "r"(4)); // load stack
72 asm volatile ("ldc %0,vbr" : : "r"(0)); // load vector base
73*/
74 /* copy everything to IRAM and continue there */
75 pSrc = begin_iramcopy;
76 pDest = begin_text;
77 pEnd = pDest + (begin_stack - begin_text);
78
79 do
80 {
81 *pDest++ = *pSrc++;
82 }
83 while (pDest < pEnd);
84
85 main(); /* jump to the real main() */
86}
87
88
89static void BootInit(void)
90{
91 /* inits from the boot ROM, whether they make sense or not */
92 PBDR &= 0xFFBF; /* LED off (0x131E) */
93 PBCR2 = 0; /* all GPIO */
94 PBIOR |= 0x0040; /* LED output */
95 PBIOR &= 0xFFF1; /* LCD lines input */
96
97 /* init DRAM like the boot ROM does */
98 PACR2 &= 0xFFFB;
99 PACR2 |= 0x0008;
100 CASCR = 0xAF;
101 BCR |= 0x8000;
102 WCR1 &= 0xFDFD;
103 DCR = 0x0E00;
104 RCR = 0x5AB0;
105 RTCOR = 0x9605;
106 RTCSR = 0xA518;
107}
108#endif /* #ifdef NO_ROM */
109
110
111int main(void)
112{
113 int nButton;
114
115 PlatformInit(); /* model-specific inits */
116
117 nButton = ButtonPressed();
118
119 if (nButton == 3)
120 { /* F3 means start monitor */
121 MiniMon();
122 }
123 else
124 {
125 tImage* pImage;
126 pImage = GetStartImage(nButton); /* which image */
127 DecompressStart(pImage); /* move into place and start it */
128 }
129
130 return 0; /* I guess we won't return ;-) */
131}
132
133
134/* init code that is specific to certain platform */
135static void PlatformInit(void)
136{
137#ifdef NO_ROM
138 BootInit(); /* if not started by boot ROM, we need to init what it did */
139#endif
140
141#if defined PLATFORM_PLAYER
142 BRR1 = 0x19; /* 14400 Baud for monitor */
143 PBDRL |= 0x10; /* set PB4 to 1 to power the hd early (and prepare for
144 * probing in case the charger is connected) */
145 PBIORL |= 0x10; /* make PB4 an output */
146 PACR2 &= 0xFFFC; /* GPIO for PA0 (charger detection, input by default) */
147 if (!(PADRL & 0x01)) /* charger plugged? */
148 { /* we need to probe whether the box is able to control hd power */
149 int i;
150
151 PBIORL &= ~0x10; /* set PB4 to input */
152 /* wait whether it goes low, max. ~1 ms */
153 for (i = 0; (PBDRL & 0x10) && i < 1000; i++);
154
155 if (~(PBDRL & 0x10)) /* pulled low -> power controllable */
156 PBDRL &= 0x10; /* set PB4 low */
157 else /* still floating high -> not controllable */
158 PBDRL |= 0x10; /* set PB4 high */
159 PBIORL |= 0x10; /* ..and output again */
160 }
161#elif defined PLATFORM_RECORDER
162 BRR1 = 0x02; /* 115200 Baud for monitor */
163 if (ReadADC(7) > 0x100) /* charger plugged? */
164 { /* switch off the HD, else a flat battery may not start */
165 PACR2 &= 0xFBFF; /* GPIO for PA5 */
166 PAIOR |= 0x0020; /* make PA5 an output (low by default) */
167 }
168#elif defined PLATFORM_FM
169 BRR1 = 0x02; /* 115200 Baud for monitor */
170 PBDR |= 0x0020; /* set PB5 to keep power (fixes the ON-holding problem) */
171 PBIOR |= 0x0020; /* make PB5 an output */
172 if (ReadADC(0) < 0x1FF) /* charger plugged? */
173 { /* switch off the HD, else a flat battery may not start */
174 PACR2 &= 0xFBFF; /* GPIO for PA5 */
175 PAIOR |= 0x0020; /* make PA5 an output (low by default) */
176 }
177#elif defined PLATFORM_ONDIO
178 BRR1 = 0x19; /* 14400 Baud for monitor */
179 PBDR |= 0x0020; /* set PB5 to keep power (fixes the ON-holding problem) */
180 PBIOR |= 0x0020; /* make PB5 an output */
181#endif
182
183 /* platform-independent inits */
184 DCR |= 0x1000; /* enable burst mode on DRAM */
185 BCR |= 0x2000; /* activate Warp mode (simultaneous internal and external
186 * mem access) */
187}
188
189
190/* move the image into place and start it */
191static void DecompressStart(tImage* pImage)
192{
193 UINT32* pSrc;
194 UINT32* pDest;
195
196 pSrc = pImage->image;
197 pDest = pImage->pDestination;
198
199 if (pSrc != pDest) /* if not linked to that flash address */
200 {
201 if (pImage->flags & IF_UCL_2E)
202 { /* UCL compressed, algorithm 2e */
203 UINT32 dst_len; /* dummy */
204 ucl_nrv2e_decompress_8((UINT8*)pSrc, (UINT8*)pDest, &dst_len);
205 }
206 else
207 { /* uncompressed, copy it */
208 UINT32 size = pImage->size;
209 UINT32* pEnd;
210 size = (size + 3) / 4; /* round up to 32bit-words */
211 pEnd = pDest + size;
212
213 do
214 {
215 *pDest++ = *pSrc++;
216 }
217 while (pDest < pEnd);
218 }
219 }
220
221 pImage->pExecute();
222}
223
224#ifdef USE_ADC
225static int ReadADC(int channel)
226{
227 /* after channel 3, the ports wrap and get re-used */
228 volatile UINT16* pResult = (UINT16*)(ADDRAH_ADDR + 2 * (channel & 0x03));
229 int timeout = 266; /* conversion takes 266 clock cycles */
230
231 ADCSR = 0x20 | channel; /* start single conversion */
232 while (((ADCSR & 0x80) == 0) && (--timeout)); /* 6 instructions per round*/
233
234 return (timeout == 0) ? -1 : *pResult>>6;
235}
236#endif
237
238
239/* This function is platform-dependent,
240 * until I figure out how to distinguish at runtime. */
241static int ButtonPressed(void) /* return 1,2,3 for F1,F2,F3, 0 if none pressed */
242{
243#ifdef USE_ADC
244 int value = ReadADC(CHANNEL);
245
246 if (value >= F1_LOWER && value <= F1_UPPER) /* in range */
247 return 1;
248 else if (value >= F2_LOWER && value <= F2_UPPER) /* in range */
249 return 2;
250 else if (value >= F3_LOWER && value <= F3_UPPER) /* in range */
251 return 3;
252#else
253 int value = PCDR;
254
255 if (!(value & F1_MASK))
256 return 1;
257 else if (!(value & F2_MASK))
258 return 2;
259 else if (!(value & F3_MASK))
260 return 3;
261#endif
262
263 return 0;
264}
265
266
267/* Determine the image to be started */
268static tImage* GetStartImage(int nPreferred)
269{
270 tImage* pImage1;
271 tImage* pImage2 = NULL; /* default to not present */
272 UINT32 pos;
273 UINT32* pFlash = (UINT32*)FLASH_BASE;
274
275 /* determine the first image position */
276 pos = pFlash[2] + pFlash[3]; /* position + size of the bootloader
277 * = after it */
278 pos = (pos + 3) & ~3; /* be sure it's 32 bit aligned */
279
280 pImage1 = (tImage*)pos;
281
282 if (pImage1->size != 0)
283 { /* check for second image */
284 pos = (UINT32)(&pImage1->image) + pImage1->size;
285 pImage2 = (tImage*)pos;
286
287 /* does it make sense? (not in FF or 00 erazed space) */
288 if (pImage2->pDestination == (void*)0xFFFFFFFF
289 || pImage2->size == 0xFFFFFFFF
290 || pImage2->pExecute == (void*)0xFFFFFFFF
291 || pImage2->flags == 0xFFFFFFFF
292 || pImage2->pDestination == NULL)
293 /* size, execute and flags can legally be 0 */
294 {
295 pImage2 = NULL; /* invalidate */
296 }
297 }
298
299 if (pImage2 == NULL || nPreferred == 1)
300 { /* no second image or overridden: return the first */
301 return pImage1;
302 }
303
304 return pImage2; /* return second image */
305}
306
307/* diagnostic functions */
308
309static void SetLed(BOOL bOn)
310{
311 if (bOn)
312 PBDR |= 0x0040;
313 else
314 PBDR &= ~0x0040;
315}
316
317
318static void UartInit(void)
319{
320 PBIOR &= 0xFBFF; /* input: RXD1 remote pin */
321 PBCR1 |= 0x00A0; /* set PB11+PB10 to UART */
322 PBCR1 &= 0xFFAF; /* clear bits 6, 4 -> UART */
323 SMR1 = 0x00; /* async format 8N1, baud generator input is CPU clock */
324 SCR1 = 0x30; /* transmit+receive enable */
325 PBCR1 &= 0x00FF; /* set bit 12...15 as GPIO */
326 SSR1 &= 0xBF; /* clear bit 6 (RDRF, receive data register full) */
327}
328
329
330static UINT8 UartRead(void)
331{
332 UINT8 byte;
333 while (!(SSR1 & SCI_RDRF)); /* wait for char to be available */
334 byte = RDR1;
335 SSR1 &= ~SCI_RDRF;
336 return byte;
337}
338
339
340static void UartWrite(UINT8 byte)
341{
342 while (!(SSR1 & SCI_TDRE)); /* wait for transmit buffer empty */
343 TDR1 = byte;
344 SSR1 &= ~SCI_TDRE;
345}
346
347
348/* include the mini monitor as a rescue feature, started with F3 */
349static void MiniMon(void)
350{
351 UINT8 cmd;
352 UINT32 addr;
353 UINT32 size;
354 UINT32 content;
355 volatile UINT8* paddr = NULL;
356 volatile UINT8* pflash = NULL; /* flash base address */
357
358 UartInit();
359
360 while (1)
361 {
362 cmd = UartRead();
363 switch (cmd)
364 {
365 case BAUDRATE:
366 content = UartRead();
367 UartWrite(cmd); /* acknowledge by returning the command value */
368 while (!(SSR1 & SCI_TEND)); /* wait for empty shift register,
369 * before changing baudrate */
370 BRR1 = content;
371 break;
372
373 case ADDRESS:
374 addr = (UartRead() << 24) | (UartRead() << 16)
375 | (UartRead() << 8) | UartRead();
376 paddr = (UINT8*)addr;
377 pflash = (UINT8*)(addr & 0xFFF80000); /* round down to 512k align*/
378 UartWrite(cmd); /* acknowledge by returning the command value */
379 break;
380
381 case BYTE_READ:
382 content = *paddr++;
383 UartWrite(content); /* the content is the ack */
384 break;
385
386 case BYTE_WRITE:
387 content = UartRead();
388 *paddr++ = content;
389 UartWrite(cmd); /* acknowledge by returning the command value */
390 break;
391
392 case BYTE_READ16:
393 size = 16;
394 while (size--)
395 {
396 content = *paddr++;
397 UartWrite(content); /* the content is the ack */
398 }
399 break;
400
401 case BYTE_WRITE16:
402 size = 16;
403 while (size--)
404 {
405 content = UartRead();
406 *paddr++ = content;
407 }
408 UartWrite(cmd); /* acknowledge by returning the command value */
409 break;
410
411 case BYTE_FLASH:
412 content = UartRead();
413 pflash[0x5555] = 0xAA; /* set flash to command mode */
414 pflash[0x2AAA] = 0x55;
415 pflash[0x5555] = 0xA0; /* byte program command */
416 *paddr++ = content;
417 UartWrite(cmd); /* acknowledge by returning the command value */
418 break;
419
420 case BYTE_FLASH16:
421 size = 16;
422 while (size--)
423 {
424 content = UartRead();
425 pflash[0x5555] = 0xAA; /* set flash to command mode */
426 pflash[0x2AAA] = 0x55;
427 pflash[0x5555] = 0xA0; /* byte program command */
428 *paddr++ = content;
429 }
430 UartWrite(cmd); /* acknowledge by returning the command value */
431 break;
432
433 case HALFWORD_READ:
434 content = *(UINT16*)paddr;
435 paddr += 2;
436 UartWrite(content >> 8); /* highbyte */
437 UartWrite(content & 0xFF); /* lowbyte */
438 break;
439
440 case HALFWORD_WRITE:
441 content = UartRead() << 8 | UartRead();
442 *(UINT16*)paddr = content;
443 paddr += 2;
444 UartWrite(cmd); /* acknowledge by returning the command value */
445 break;
446
447 case EXECUTE:
448 {
449 tpFunc pFunc = (tpFunc)paddr;
450 pFunc();
451 UartWrite(cmd); /* acknowledge by returning the command value*/
452 }
453 break;
454
455 case VERSION:
456 UartWrite(1); /* return our version number */
457 break;
458
459 default:
460 {
461 SetLed(TRUE);
462 UartWrite(~cmd); /* error acknowledge */
463 }
464
465 } /* case */
466 } /* while (1) */
467}
diff --git a/flash/bootloader/bootloader.h b/flash/bootloader/bootloader.h
deleted file mode 100644
index 5811fd0aa4..0000000000
--- a/flash/bootloader/bootloader.h
+++ /dev/null
@@ -1,109 +0,0 @@
1#ifndef NULL
2#define NULL ((void*)0)
3#endif
4
5#define TRUE 1
6#define FALSE 0
7
8// scalar types
9typedef unsigned char UINT8;
10typedef unsigned short UINT16;
11typedef unsigned long UINT32;
12typedef int BOOL;
13
14typedef void(*tpFunc)(void); // type for execute
15typedef int(*tpMain)(void); // type for start vector to main()
16
17
18// structure of an image in the flash
19typedef struct
20{
21 UINT32* pDestination; // address to copy it to
22 UINT32 size; // how many bytes of payload (to the next header)
23 tpFunc pExecute; // entry point
24 UINT32 flags; // uncompressed or compressed
25 // end of header, now comes the payload
26 UINT32 image[]; // the binary image starts here
27 // after the payload, the next header may follow, all 0xFF if none
28} tImage;
29
30// flags valid for image header
31#define IF_NONE 0x00000000
32#define IF_UCL_2E 0x00000001 // image is compressed with UCL, algorithm 2e
33
34
35// resolve platform dependency of F1 button check
36#if defined PLATFORM_PLAYER
37#define F1_MASK 0x0001 // Player has no F1 button, so we use "-"
38#define F2_MASK 0x0008 // Player has no F2 button, so we use "Play"
39#define F3_MASK 0x0004 // Player has no F3 button, so we use "+"
40
41#elif defined PLATFORM_RECORDER
42#define USE_ADC
43#define CHANNEL 4
44#define F1_LOWER 250
45#define F1_UPPER 499
46#define F2_LOWER 500
47#define F2_UPPER 699
48#define F3_LOWER 900
49#define F3_UPPER 1023
50
51#elif defined PLATFORM_FM
52#define USE_ADC
53#define CHANNEL 4
54#define F1_LOWER 150
55#define F1_UPPER 384
56#define F2_LOWER 385
57#define F2_UPPER 544
58#define F3_LOWER 700
59#define F3_UPPER 1023
60
61#elif defined PLATFORM_ONDIO
62#define USE_ADC
63#define CHANNEL 4
64#define F1_LOWER 0x2EF // Ondio has no F1 button,
65#define F1_UPPER 0x3FF // so we use "Left".
66#define F2_LOWER 0x19D // Ondio has no F2 button,
67#define F2_UPPER 0x245 // so we use "Up".
68#define F3_LOWER 0x246 // Ondio has no F3 button,
69#define F3_UPPER 0x2EE // so we use "Right".
70
71#else
72#error ("No platform given!")
73#endif
74
75
76#define FLASH_BASE 0x02000000 // start of the flash memory
77#define FW_VERSION *(unsigned short*)(FLASH_BASE + 0xFE) // firmware version
78
79// prototypes
80int ucl_nrv2e_decompress_8(const UINT8 *src, UINT8 *dst, UINT32* dst_len);
81void _main(void) __attribute__ ((section (".startup")));
82int main(void);
83
84// minimon commands
85#define BAUDRATE 0x00 // followed by BRR value; response: command byte
86#define ADDRESS 0x01 // followed by 4 bytes address; response: command byte
87#define BYTE_READ 0x02 // response: 1 byte content
88#define BYTE_WRITE 0x03 // followed by 1 byte content; response: command byte
89#define BYTE_READ16 0x04 // response: 16 bytes content
90#define BYTE_WRITE16 0x05 // followed by 16 bytes; response: command byte
91#define BYTE_FLASH 0x06 // followed by 1 byte content; response: command byte
92#define BYTE_FLASH16 0x07 // followed by 16 bytes; response: command byte
93#define HALFWORD_READ 0x08 // response: 2 byte content
94#define HALFWORD_WRITE 0x09 // followed by 2 byte content; response: command byte
95#define EXECUTE 0x0A // response: command byte if call returns
96#define VERSION 0x0B // response: version
97
98
99// linker symbols
100extern UINT32 begin_text[];
101extern UINT32 end_text[];
102extern UINT32 begin_data[];
103extern UINT32 end_data[];
104extern UINT32 begin_bss[];
105extern UINT32 end_bss[];
106extern UINT32 begin_stack[];
107extern UINT32 end_stack[];
108extern UINT32 begin_iramcopy[];
109extern UINT32 total_size[];
diff --git a/flash/bootloader/bootloader.lds b/flash/bootloader/bootloader.lds
deleted file mode 100644
index ecc1268988..0000000000
--- a/flash/bootloader/bootloader.lds
+++ /dev/null
@@ -1,34 +0,0 @@
1OUTPUT_FORMAT(elf32-sh)
2
3MEMORY
4{
5 /* the boot ROM uses IRAM at 400-430, stay away and start at 500 */
6 IRAM : ORIGIN = 0x0FFFF500, LENGTH = 0xA00
7 /* and leave some room for stack at the end */
8}
9
10SECTIONS
11{
12 .startvector :
13 {
14 *(.startvector)
15 . = ALIGN(0x4);
16 } > IRAM
17
18 .text :
19 {
20 *(.text)
21 *(.icode)
22 . = ALIGN(0x4);
23 } > IRAM
24
25 .data :
26 {
27 *(.data)
28 } > IRAM
29
30 .bss :
31 {
32 *(.bss)
33 } > IRAM
34}
diff --git a/flash/bootloader/no_rom.lds b/flash/bootloader/no_rom.lds
deleted file mode 100644
index 9f6af52aef..0000000000
--- a/flash/bootloader/no_rom.lds
+++ /dev/null
@@ -1,62 +0,0 @@
1/* This is for the variant without boot ROM,
2 where the flash ROM is mirrored to address zero */
3
4OUTPUT_FORMAT(elf32-sh)
5
6MEMORY
7{
8 IRAM : ORIGIN = 0x0FFFF000, LENGTH = 0x1000
9 FLASH : ORIGIN = 0x00000000, LENGTH = 0x40000
10}
11
12SECTIONS
13{
14 .vectors :
15 {
16 KEEP(*(.vectors))
17 . = ALIGN(0x200);
18 } > FLASH
19
20 .startup :
21 {
22 *(.startup)
23 . = ALIGN(0x4);
24 _begin_iramcopy = .;
25 } > FLASH
26
27 .text : AT ( _begin_iramcopy )
28 {
29 _begin_text = .;
30 *(.text)
31 *(.icode)
32 . = ALIGN(0x4);
33 _end_text = .;
34 } > IRAM
35
36 .data : AT ( _end_text )
37 {
38 _begin_data = .;
39 *(.data)
40 . = ALIGN(0x4);
41 _end_data = .;
42 } > IRAM
43
44 .bss : AT ( _end_data )
45 {
46 _begin_bss = .;
47 *(.bss)
48 . = ALIGN(0x4);
49 _end_bss = .;
50 } > IRAM
51
52 .stack :
53 {
54 _begin_stack = .;
55 *(.stack)
56 . = ALIGN(0x1000);
57 _end_stack = .;
58 } > IRAM
59
60 /* size of the program (without vectors) */
61 _total_size = SIZEOF(.startup) + SIZEOF(.text) + SIZEOF(.data);
62}
diff --git a/flash/extract/README b/flash/extract/README
deleted file mode 100644
index 6f1934906e..0000000000
--- a/flash/extract/README
+++ /dev/null
@@ -1,5 +0,0 @@
1(c) 2003 by Jörg Hohensohn
2
3This tool extracts the firmware image out of an original Archos ROM dump,
4like created with the Rockbox debug->dump feature.
5The extracted image can then be used to compose a dual-boot firmware.
diff --git a/flash/extract/extract.c b/flash/extract/extract.c
deleted file mode 100644
index 2389f9290e..0000000000
--- a/flash/extract/extract.c
+++ /dev/null
@@ -1,147 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2003 by Jörg Hohensohn
11 *
12 * Tool to extract the scrambled image out of an Archos flash ROM dump
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <inttypes.h>
27
28#define UINT8 unsigned char
29#define UINT16 unsigned short
30#define UINT32 unsigned long
31
32#define IMAGE_HEADER 0x6000 // a 32 byte header in front of the software image
33#define IMAGE_START 0x6020 // software image position in Flash
34
35
36// place a 32 bit value into memory, big endian
37void Write32(UINT8* pByte, UINT32 value)
38{
39 pByte[0] = (UINT8)(value >> 24);
40 pByte[1] = (UINT8)(value >> 16);
41 pByte[2] = (UINT8)(value >> 8);
42 pByte[3] = (UINT8)(value);
43}
44
45
46// read a 32 bit value from memory, big endian
47UINT32 Read32(UINT8* pByte)
48{
49 UINT32 value = 0;
50
51 value |= (UINT32)pByte[0] << 24;
52 value |= (UINT32)pByte[1] << 16;
53 value |= (UINT32)pByte[2] << 8;
54 value |= (UINT32)pByte[3];
55
56 return value;
57}
58
59
60// entry point
61int main(int argc, char* argv[])
62{
63 FILE* pInFile;
64 FILE* pOutFile;
65 UINT8 aHeader[6];
66 UINT8 aImage[256*1024];
67 UINT32 i;
68 UINT32 uiSize, uiStart;
69 UINT16 usChecksum = 0;
70
71 if (argc < 2)
72 {
73 printf("Extract the software image out of an original Archos Flash ROM dump.\n");
74 printf("Result is a scrambled file, use the descramble tool to get the binary,\n");
75 printf(" always without the -fm option, even if processing an FM software.\n\n");
76 printf("Usage: extract <flash dump file> <output file>\n");
77 printf("Example: extract internal_rom_2000000-203FFFF.bin archos.ajz\n");
78 exit(0);
79 }
80
81 pInFile = fopen(argv[1], "rb");
82 if (pInFile == NULL)
83 {
84 printf("Error opening input file %s\n", argv[1]);
85 exit(1);
86 }
87
88 if (fread(aImage, 1, sizeof(aImage), pInFile) != sizeof(aImage))
89 {
90 printf("Error reading input file %s, must be 256kB in size.\n", argv[1]);
91 fclose(pInFile);
92 exit(2);
93 }
94 fclose(pInFile);
95
96 // find out about the type
97 uiStart = Read32(aImage + 8);
98 uiSize = Read32(aImage + 12); // booted ROM image
99 if (uiStart == 0x02000100 && uiSize > 20000)
100 { // Player has no loader, starts directly with the image
101 uiStart = 0x0100;
102 }
103 else
104 { // Recorder / FM / V2 Recorder
105 uiStart = IMAGE_START;
106 uiSize = Read32(aImage + IMAGE_HEADER + 4); // size record of header
107 }
108
109 // sanity check
110 if (uiSize > sizeof(aImage) - uiStart || uiSize < 40000)
111 {
112 printf("Error: Impossible image size %d bytes.\n", uiSize);
113 exit(3);
114 }
115
116 // generate checksum
117 for (i=0; i<uiSize; i++)
118 {
119 UINT8 byte;
120 byte = aImage[uiStart + i];
121 byte = ~((byte >> 1) | ((byte << 7) & 0x80)); /* poor man's ROR */
122 usChecksum += byte;
123 }
124
125 // make header
126 Write32(aHeader + 2, usChecksum); // checksum in 5th and 6th byte
127 Write32(aHeader, uiSize); // size in first 4 bytes
128
129 pOutFile = fopen(argv[2], "wb");
130 if (pOutFile == NULL)
131 {
132 printf("Error opening output file %s\n", argv[2]);
133 exit(4);
134 }
135
136 if (fwrite(aHeader, 1, sizeof(aHeader), pOutFile) != sizeof(aHeader)
137 || fwrite(aImage + uiStart, 1, uiSize, pOutFile) != uiSize)
138 {
139 printf("Write error\n");
140 fclose(pOutFile);
141 exit(5);
142 }
143
144 fclose(pOutFile);
145
146 return 0;
147}
diff --git a/flash/extract/extract.dsp b/flash/extract/extract.dsp
deleted file mode 100644
index e10281a829..0000000000
--- a/flash/extract/extract.dsp
+++ /dev/null
@@ -1,100 +0,0 @@
1# Microsoft Developer Studio Project File - Name="extract" - Package Owner=<4>
2# Microsoft Developer Studio Generated Build File, Format Version 6.00
3# ** DO NOT EDIT **
4
5# TARGTYPE "Win32 (x86) Console Application" 0x0103
6
7CFG=extract - Win32 Debug
8!MESSAGE This is not a valid makefile. To build this project using NMAKE,
9!MESSAGE use the Export Makefile command and run
10!MESSAGE
11!MESSAGE NMAKE /f "extract.mak".
12!MESSAGE
13!MESSAGE You can specify a configuration when running NMAKE
14!MESSAGE by defining the macro CFG on the command line. For example:
15!MESSAGE
16!MESSAGE NMAKE /f "extract.mak" CFG="extract - Win32 Debug"
17!MESSAGE
18!MESSAGE Possible choices for configuration are:
19!MESSAGE
20!MESSAGE "extract - Win32 Release" (based on "Win32 (x86) Console Application")
21!MESSAGE "extract - Win32 Debug" (based on "Win32 (x86) Console Application")
22!MESSAGE
23
24# Begin Project
25# PROP AllowPerConfigDependencies 0
26# PROP Scc_ProjName ""
27# PROP Scc_LocalPath ""
28CPP=cl.exe
29RSC=rc.exe
30
31!IF "$(CFG)" == "extract - Win32 Release"
32
33# PROP BASE Use_MFC 0
34# PROP BASE Use_Debug_Libraries 0
35# PROP BASE Output_Dir "Release"
36# PROP BASE Intermediate_Dir "Release"
37# PROP BASE Target_Dir ""
38# PROP Use_MFC 0
39# PROP Use_Debug_Libraries 0
40# PROP Output_Dir "Release"
41# PROP Intermediate_Dir "Release"
42# PROP Target_Dir ""
43# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
44# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
45# ADD BASE RSC /l 0x407 /d "NDEBUG"
46# ADD RSC /l 0x407 /d "NDEBUG"
47BSC32=bscmake.exe
48# ADD BASE BSC32 /nologo
49# ADD BSC32 /nologo
50LINK32=link.exe
51# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
52# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
53
54!ELSEIF "$(CFG)" == "extract - Win32 Debug"
55
56# PROP BASE Use_MFC 0
57# PROP BASE Use_Debug_Libraries 1
58# PROP BASE Output_Dir "Debug"
59# PROP BASE Intermediate_Dir "Debug"
60# PROP BASE Target_Dir ""
61# PROP Use_MFC 0
62# PROP Use_Debug_Libraries 1
63# PROP Output_Dir "Debug"
64# PROP Intermediate_Dir "Debug"
65# PROP Target_Dir ""
66# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
67# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
68# ADD BASE RSC /l 0x407 /d "_DEBUG"
69# ADD RSC /l 0x407 /d "_DEBUG"
70BSC32=bscmake.exe
71# ADD BASE BSC32 /nologo
72# ADD BSC32 /nologo
73LINK32=link.exe
74# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
75# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
76
77!ENDIF
78
79# Begin Target
80
81# Name "extract - Win32 Release"
82# Name "extract - Win32 Debug"
83# Begin Group "Source Files"
84
85# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
86# Begin Source File
87
88SOURCE=.\extract.c
89# End Source File
90# End Group
91# Begin Group "Header Files"
92
93# PROP Default_Filter "h;hpp;hxx;hm;inl"
94# End Group
95# Begin Group "Resource Files"
96
97# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
98# End Group
99# End Target
100# End Project
diff --git a/flash/make_firmware/README b/flash/make_firmware/README
deleted file mode 100644
index 534b1fc1cd..0000000000
--- a/flash/make_firmware/README
+++ /dev/null
@@ -1,20 +0,0 @@
1(c) 2003 by Jörg Hohensohn
2
3This tool composes a firmware file, out of:
41. Template for the first Flash page
52. Flash bootloader
63. First (alternate) image - usually bootbox
74. Second (main) image - rockbox or rombox. Can be left blank
8
9Use with extreme caution, the components have to match!
10The aspects are:
11- Model (Player, Recorder, FM, V2, Ondio FM, Ondio SP)
12- boot type (standard boot ROM or ROMless)
13
14If you need to adjust the size of the flash bootloader or the first
15image in order to match a desired rombox link address, do not try to
16pad the files manually! It will most probably lead to a non-working
17firmware file. You can pad the bootloader by including a dummy
18initialized array instead (at least one element needs to be non-zero).
19
20Such a firmware file can then be programmed with "firmware_flash.rock".
diff --git a/flash/make_firmware/make_firmware.c b/flash/make_firmware/make_firmware.c
deleted file mode 100644
index bd838bf3bf..0000000000
--- a/flash/make_firmware/make_firmware.c
+++ /dev/null
@@ -1,359 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2003 by Jörg Hohensohn
11 *
12 * Autoring tool for the firmware image to be programmed into Flash ROM
13 * It composes the flash content with header, bootloader and image(s)
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 ****************************************************************************/
24
25
26#include <stdio.h>
27#include <stdlib.h>
28#include <inttypes.h>
29#include <string.h>
30
31#define UINT8 unsigned char
32#define UINT16 unsigned short
33#define UINT32 unsigned long
34#define BOOL int
35#define TRUE 1
36#define FALSE 0
37
38// size of one flash sector, the granularity with which it can be erased
39#define SECTORSIZE 4096
40
41#define BOOTLOAD_DEST 0x0FFFF500 // for the "normal" one
42#define FLASH_START 0x02000000
43#define BOOTLOAD_SCR 0x02000100
44#define ROCKBOX_DEST 0x09000000
45#define ROCKBOX_EXEC 0x09000200
46
47
48// place a 32 bit value into memory, big endian
49void Write32(UINT8* pByte, UINT32 value)
50{
51 pByte[0] = (UINT8)(value >> 24);
52 pByte[1] = (UINT8)(value >> 16);
53 pByte[2] = (UINT8)(value >> 8);
54 pByte[3] = (UINT8)(value);
55}
56
57
58// read a 32 bit value from memory, big endian
59UINT32 Read32(UINT8* pByte)
60{
61 UINT32 value = 0;
62
63 value |= (UINT32)pByte[0] << 24;
64 value |= (UINT32)pByte[1] << 16;
65 value |= (UINT32)pByte[2] << 8;
66 value |= (UINT32)pByte[3];
67
68 return value;
69}
70
71
72static UINT32 CalcCRC32 (const UINT8* buf, UINT32 len)
73{
74 static const UINT32 crc_table[256] =
75 { // CRC32 lookup table for polynomial 0x04C11DB7
76 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, 0x130476DC, 0x17C56B6B,
77 0x1A864DB2, 0x1E475005, 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61,
78 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD, 0x4C11DB70, 0x48D0C6C7,
79 0x4593E01E, 0x4152FDA9, 0x5F15ADAC, 0x5BD4B01B, 0x569796C2, 0x52568B75,
80 0x6A1936C8, 0x6ED82B7F, 0x639B0DA6, 0x675A1011, 0x791D4014, 0x7DDC5DA3,
81 0x709F7B7A, 0x745E66CD, 0x9823B6E0, 0x9CE2AB57, 0x91A18D8E, 0x95609039,
82 0x8B27C03C, 0x8FE6DD8B, 0x82A5FB52, 0x8664E6E5, 0xBE2B5B58, 0xBAEA46EF,
83 0xB7A96036, 0xB3687D81, 0xAD2F2D84, 0xA9EE3033, 0xA4AD16EA, 0xA06C0B5D,
84 0xD4326D90, 0xD0F37027, 0xDDB056FE, 0xD9714B49, 0xC7361B4C, 0xC3F706FB,
85 0xCEB42022, 0xCA753D95, 0xF23A8028, 0xF6FB9D9F, 0xFBB8BB46, 0xFF79A6F1,
86 0xE13EF6F4, 0xE5FFEB43, 0xE8BCCD9A, 0xEC7DD02D, 0x34867077, 0x30476DC0,
87 0x3D044B19, 0x39C556AE, 0x278206AB, 0x23431B1C, 0x2E003DC5, 0x2AC12072,
88 0x128E9DCF, 0x164F8078, 0x1B0CA6A1, 0x1FCDBB16, 0x018AEB13, 0x054BF6A4,
89 0x0808D07D, 0x0CC9CDCA, 0x7897AB07, 0x7C56B6B0, 0x71159069, 0x75D48DDE,
90 0x6B93DDDB, 0x6F52C06C, 0x6211E6B5, 0x66D0FB02, 0x5E9F46BF, 0x5A5E5B08,
91 0x571D7DD1, 0x53DC6066, 0x4D9B3063, 0x495A2DD4, 0x44190B0D, 0x40D816BA,
92 0xACA5C697, 0xA864DB20, 0xA527FDF9, 0xA1E6E04E, 0xBFA1B04B, 0xBB60ADFC,
93 0xB6238B25, 0xB2E29692, 0x8AAD2B2F, 0x8E6C3698, 0x832F1041, 0x87EE0DF6,
94 0x99A95DF3, 0x9D684044, 0x902B669D, 0x94EA7B2A, 0xE0B41DE7, 0xE4750050,
95 0xE9362689, 0xEDF73B3E, 0xF3B06B3B, 0xF771768C, 0xFA325055, 0xFEF34DE2,
96 0xC6BCF05F, 0xC27DEDE8, 0xCF3ECB31, 0xCBFFD686, 0xD5B88683, 0xD1799B34,
97 0xDC3ABDED, 0xD8FBA05A, 0x690CE0EE, 0x6DCDFD59, 0x608EDB80, 0x644FC637,
98 0x7A089632, 0x7EC98B85, 0x738AAD5C, 0x774BB0EB, 0x4F040D56, 0x4BC510E1,
99 0x46863638, 0x42472B8F, 0x5C007B8A, 0x58C1663D, 0x558240E4, 0x51435D53,
100 0x251D3B9E, 0x21DC2629, 0x2C9F00F0, 0x285E1D47, 0x36194D42, 0x32D850F5,
101 0x3F9B762C, 0x3B5A6B9B, 0x0315D626, 0x07D4CB91, 0x0A97ED48, 0x0E56F0FF,
102 0x1011A0FA, 0x14D0BD4D, 0x19939B94, 0x1D528623, 0xF12F560E, 0xF5EE4BB9,
103 0xF8AD6D60, 0xFC6C70D7, 0xE22B20D2, 0xE6EA3D65, 0xEBA91BBC, 0xEF68060B,
104 0xD727BBB6, 0xD3E6A601, 0xDEA580D8, 0xDA649D6F, 0xC423CD6A, 0xC0E2D0DD,
105 0xCDA1F604, 0xC960EBB3, 0xBD3E8D7E, 0xB9FF90C9, 0xB4BCB610, 0xB07DABA7,
106 0xAE3AFBA2, 0xAAFBE615, 0xA7B8C0CC, 0xA379DD7B, 0x9B3660C6, 0x9FF77D71,
107 0x92B45BA8, 0x9675461F, 0x8832161A, 0x8CF30BAD, 0x81B02D74, 0x857130C3,
108 0x5D8A9099, 0x594B8D2E, 0x5408ABF7, 0x50C9B640, 0x4E8EE645, 0x4A4FFBF2,
109 0x470CDD2B, 0x43CDC09C, 0x7B827D21, 0x7F436096, 0x7200464F, 0x76C15BF8,
110 0x68860BFD, 0x6C47164A, 0x61043093, 0x65C52D24, 0x119B4BE9, 0x155A565E,
111 0x18197087, 0x1CD86D30, 0x029F3D35, 0x065E2082, 0x0B1D065B, 0x0FDC1BEC,
112 0x3793A651, 0x3352BBE6, 0x3E119D3F, 0x3AD08088, 0x2497D08D, 0x2056CD3A,
113 0x2D15EBE3, 0x29D4F654, 0xC5A92679, 0xC1683BCE, 0xCC2B1D17, 0xC8EA00A0,
114 0xD6AD50A5, 0xD26C4D12, 0xDF2F6BCB, 0xDBEE767C, 0xE3A1CBC1, 0xE760D676,
115 0xEA23F0AF, 0xEEE2ED18, 0xF0A5BD1D, 0xF464A0AA, 0xF9278673, 0xFDE69BC4,
116 0x89B8FD09, 0x8D79E0BE, 0x803AC667, 0x84FBDBD0, 0x9ABC8BD5, 0x9E7D9662,
117 0x933EB0BB, 0x97FFAD0C, 0xAFB010B1, 0xAB710D06, 0xA6322BDF, 0xA2F33668,
118 0xBCB4666D, 0xB8757BDA, 0xB5365D03, 0xB1F740B4
119 };
120 UINT32 i;
121 UINT32 crc = 0xffffffff;
122
123 for (i = 0; i < len; i++)
124 crc = (crc << 8) ^ crc_table[((crc >> 24) ^ *buf++) & 0xFF];
125
126 return crc;
127}
128
129
130static UINT32 PlaceImage(char* filename, UINT32 pos, UINT8* pFirmware, UINT32 limit)
131{
132 UINT32 size, read;
133 FILE* pFile;
134 UINT32 align;
135 UINT32 flags;
136 UINT32 load_addr = ROCKBOX_DEST, exec_addr = ROCKBOX_EXEC; // defaults
137
138 // magic file header for compressed files
139 static const UINT8 magic[8] = { 0x00,0xe9,0x55,0x43,0x4c,0xff,0x01,0x1a };
140 UINT8 ucl_header[26];
141
142 pFile = fopen(filename, "rb"); // open the current image
143 if (pFile == NULL)
144 {
145 printf("Image file %s not found!\n", filename);
146 exit(5);
147 }
148
149 fseek(pFile, 0, SEEK_END);
150 size = ftell(pFile);
151 fseek(pFile, 0, SEEK_SET);
152
153 // determine if compressed
154 flags = 0x00000000; // default: flags for uncompressed
155 fread(ucl_header, 1, sizeof(ucl_header), pFile);
156 if (memcmp(magic, ucl_header, sizeof(magic)) == 0)
157 {
158 if (ucl_header[12] != 0x2E // check algorithm
159 && ucl_header[12] != 0x2B) // or uncompressed
160 {
161 printf("UCL compressed files must use algorithm 2e, not %d\n", ucl_header[12]);
162 printf("Generate with: uclpack --best --2e rockbox.bin %s\n", filename);
163 exit(6);
164 }
165
166 size = Read32(ucl_header + 22); // compressed size
167 if (Read32(ucl_header + 18) > size) // compare with uncompressed size
168 { // normal case
169 flags = 0x00000001; // flags for UCL compressed
170 }
171
172 if (ucl_header[12] == 0x2B) // uncompressed means "ROMbox", for direct flash execution
173 {
174 UINT8 start_addr[4];
175 UINT8 reset_vec[4];
176 fread(start_addr, 1, sizeof(start_addr), pFile); // read the link address from image
177 fread(reset_vec, 1, sizeof(reset_vec), pFile); // read the reset vector from image
178 fseek(pFile, 0-sizeof(start_addr)-sizeof(reset_vec), SEEK_CUR); // wind back
179 load_addr = Read32(start_addr);
180 if (load_addr != FLASH_START + pos + 16) // behind 16 byte header
181 {
182 printf("Error: Rombox .ucl file is linked to 0x%08X instead of 0x%08X\n", load_addr, FLASH_START + pos + 16);
183 exit(11);
184 }
185 exec_addr = Read32(reset_vec);
186 }
187 }
188 else
189 {
190 fseek(pFile, 0, SEEK_SET); // go back
191 }
192
193 if (pos + 16 + size > limit) // enough space for all that?
194 {
195 printf("Exceeding maximum image size %d\n", limit);
196 exit(7);
197 }
198
199 // write header
200 align = (pos + 16 + size + SECTORSIZE-1) & ~(SECTORSIZE-1); // round up to next flash sector
201 Write32(pFirmware + pos, load_addr); // load address
202 Write32(pFirmware + pos + 4, align - (pos + 16)); // image size
203 Write32(pFirmware + pos + 8, exec_addr); // execution address
204 Write32(pFirmware + pos + 12, flags); // compressed or not
205 pos += 16;
206
207 // load image
208 read = fread(pFirmware + pos, 1, size, pFile);
209 if (read != size)
210 {
211 printf("Read error, expecting %d bytes, got only %d\n", size, read);
212 exit(8);
213 }
214 fclose (pFile);
215
216 pos += size;
217
218 return pos;
219}
220
221
222int main(int argc, char* argv[])
223{
224 static UINT8 aFirmware[512*1024]; // maximum with exchanged chip
225 FILE* pFile;
226 UINT32 size; // size of loaded item
227 UINT32 pos; // current position in firmware
228 UINT32 crc32; // checksum of "payload"
229 BOOL hasBootRom; // flag if regular boot ROM or directly starts from flash
230 UINT32 template_F8, template_FC; // my platform ID, mask and version
231
232 int i;
233
234 if (argc <= 4)
235 {
236 printf("Usage:\n");
237 printf("make_firmware <output> <template.bin> <bootloader.ajz> <image1.ucl> {image2.ucl}\n");
238 printf("<template.bin> is the original firmware from your box\n");
239 printf("<bootloader.ajz> is the scrambled bootloader\n");
240 printf("<image1.ucl> is the first image, compressed (recommended) or uncompressed\n");
241 printf("<image1.ucl> is the second image, compressed (recommended) or uncompressed\n");
242 printf("More images may follow, but keep the flash size in mind!\n");
243 printf("Compression must be UCL, algorithm 2e.\n");
244 printf("Generated with: uclpack --best --2e rockbox.bin imageN.ucl\n");
245 exit(0);
246 }
247
248 memset(aFirmware, 0xFF, sizeof(aFirmware));
249
250 /******* process template *******/
251
252 pFile = fopen(argv[2], "rb"); // open the template
253 if (pFile == NULL)
254 {
255 printf("Template file %s not found!\n", argv[2]);
256 exit(1);
257 }
258 size = fread(aFirmware, 1, 256, pFile); // need only the header
259 fclose(pFile);
260 if (size < 256) // need at least the firmware header
261 {
262 printf("Template file %s too small, need at least the header!\n", argv[2]);
263 exit(2);
264 }
265
266 if (strncmp(aFirmware, "ARCH", 4) == 0)
267 {
268 hasBootRom = TRUE;
269 pos = 256; // place bootloader after this "boot block"
270 }
271 else if (Read32(aFirmware) == 0x0200)
272 {
273 hasBootRom = FALSE;
274 pos = 0; // directly start with the bootloader
275 template_F8 = Read32(aFirmware + 0xF8); // my platform ID and future info
276 template_FC = Read32(aFirmware + 0xFC); // use mask+version from template
277 }
278 else
279 {
280 printf("Template file %s invalid!\n", argv[2]);
281 exit(3);
282 }
283
284 /******* process bootloader *******/
285
286 pFile = fopen(argv[3], "rb"); // open the bootloader
287 if (pFile == NULL)
288 {
289 printf("Bootloader file %s not found!\n", argv[3]);
290 exit(4);
291 }
292 if (hasBootRom && fseek(pFile, 6, SEEK_SET)) // skip the ajz header
293 {
294 printf("Bootloader file %s too short!\n", argv[3]);
295 exit(5);
296 }
297
298 // place bootloader after header
299 size = fread(aFirmware + pos, 1, sizeof(aFirmware) - pos, pFile);
300 fclose(pFile);
301
302 if (hasBootRom)
303 {
304 Write32(aFirmware + 4, BOOTLOAD_DEST); // boot code destination address
305
306 for (i=0x08; i<=0x28; i+=8)
307 {
308 Write32(aFirmware + i, BOOTLOAD_SCR); // boot code source address
309 Write32(aFirmware + i + 4, size); // boot code size
310 }
311 }
312 else
313 {
314 Write32(aFirmware + 0xF8, template_F8); // values from template
315 Write32(aFirmware + 0xFC, template_FC); // mask and version
316 }
317
318 size = (size + 3) & ~3; // make shure it's 32 bit aligned
319 pos += size; // prepare position for first image
320
321 /******* process images *******/
322 for (i = 4; i < argc; i++)
323 {
324 pos = PlaceImage(argv[i], pos, aFirmware, sizeof(aFirmware));
325
326 if (i < argc-1)
327 { // not the last: round up to next flash sector
328 pos = (pos + SECTORSIZE-1) & ~(SECTORSIZE-1);
329 }
330 }
331
332
333 /******* append CRC32 checksum *******/
334 crc32 = CalcCRC32(aFirmware, pos);
335 Write32(aFirmware + pos, crc32);
336 pos += sizeof(crc32); // 4 bytes
337
338
339 /******* save result to output file *******/
340
341 pFile = fopen(argv[1], "wb"); // open the output file
342 if (pFile == NULL)
343 {
344 printf("Output file %s cannot be created!\n", argv[1]);
345 exit(9);
346 }
347 size = fwrite(aFirmware, 1, pos, pFile);
348 fclose(pFile);
349
350 if (size != pos)
351 {
352 printf("Error writing %d bytes to output file %s!\n", pos, argv[1]);
353 exit(10);
354 }
355
356 printf("Firmware file generated with %d bytes.\n", pos);
357
358 return 0;
359}
diff --git a/flash/make_firmware/make_firmware.dsp b/flash/make_firmware/make_firmware.dsp
deleted file mode 100644
index 54a6f53671..0000000000
--- a/flash/make_firmware/make_firmware.dsp
+++ /dev/null
@@ -1,96 +0,0 @@
1# Microsoft Developer Studio Project File - Name="make_firmware" - Package Owner=<4>
2# Microsoft Developer Studio Generated Build File, Format Version 6.00
3# ** DO NOT EDIT **
4
5# TARGTYPE "Win32 (x86) Console Application" 0x0103
6
7CFG=make_firmware - Win32 Debug
8!MESSAGE This is not a valid makefile. To build this project using NMAKE,
9!MESSAGE use the Export Makefile command and run
10!MESSAGE
11!MESSAGE NMAKE /f "make_firmware.mak".
12!MESSAGE
13!MESSAGE You can specify a configuration when running NMAKE
14!MESSAGE by defining the macro CFG on the command line. For example:
15!MESSAGE
16!MESSAGE NMAKE /f "make_firmware.mak" CFG="make_firmware - Win32 Debug"
17!MESSAGE
18!MESSAGE Possible choices for configuration are:
19!MESSAGE
20!MESSAGE "make_firmware - Win32 Release" (based on "Win32 (x86) Console Application")
21!MESSAGE "make_firmware - Win32 Debug" (based on "Win32 (x86) Console Application")
22!MESSAGE
23
24# Begin Project
25# PROP AllowPerConfigDependencies 0
26# PROP Scc_ProjName ""
27# PROP Scc_LocalPath ""
28CPP=cl.exe
29RSC=rc.exe
30
31!IF "$(CFG)" == "make_firmware - Win32 Release"
32
33# PROP BASE Use_MFC 0
34# PROP BASE Use_Debug_Libraries 0
35# PROP BASE Output_Dir "Release"
36# PROP BASE Intermediate_Dir "Release"
37# PROP BASE Target_Dir ""
38# PROP Use_MFC 0
39# PROP Use_Debug_Libraries 0
40# PROP Output_Dir "Release"
41# PROP Intermediate_Dir "Release"
42# PROP Target_Dir ""
43# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c
44# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX"stdafx.h" /FD /c
45# ADD BASE RSC /l 0x407 /d "NDEBUG"
46# ADD RSC /l 0x407 /d "NDEBUG"
47BSC32=bscmake.exe
48# ADD BASE BSC32 /nologo
49# ADD BSC32 /nologo
50LINK32=link.exe
51# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
52# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
53
54!ELSEIF "$(CFG)" == "make_firmware - Win32 Debug"
55
56# PROP BASE Use_MFC 0
57# PROP BASE Use_Debug_Libraries 1
58# PROP BASE Output_Dir "Debug"
59# PROP BASE Intermediate_Dir "Debug"
60# PROP BASE Target_Dir ""
61# PROP Use_MFC 0
62# PROP Use_Debug_Libraries 1
63# PROP Output_Dir "Debug"
64# PROP Intermediate_Dir "Debug"
65# PROP Target_Dir ""
66# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c
67# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX"stdafx.h" /FD /GZ /c
68# ADD BASE RSC /l 0x407 /d "_DEBUG"
69# ADD RSC /l 0x407 /d "_DEBUG"
70BSC32=bscmake.exe
71# ADD BASE BSC32 /nologo
72# ADD BSC32 /nologo
73LINK32=link.exe
74# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
75# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
76
77!ENDIF
78
79# Begin Target
80
81# Name "make_firmware - Win32 Release"
82# Name "make_firmware - Win32 Debug"
83# Begin Group "Source Files"
84
85# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
86# Begin Source File
87
88SOURCE=.\make_firmware.c
89# End Source File
90# End Group
91# Begin Group "Header Files"
92
93# PROP Default_Filter "h;hpp;hxx;hm;inl"
94# End Group
95# End Target
96# End Project
diff --git a/flash/minimon/Makefile b/flash/minimon/Makefile
deleted file mode 100644
index 16b6c2724e..0000000000
--- a/flash/minimon/Makefile
+++ /dev/null
@@ -1,53 +0,0 @@
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 0x0ffff000 > $(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
deleted file mode 100644
index d2dc1707a6..0000000000
--- a/flash/minimon/README
+++ /dev/null
@@ -1,9 +0,0 @@
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.
7
8The SVN version is linked to 0x0ffff000, i.e. start of IRAM.
9This address has to match the address uart_boot downloads it to. \ No newline at end of file
diff --git a/flash/minimon/minimon.c b/flash/minimon/minimon.c
deleted file mode 100644
index aca9cb5523..0000000000
--- a/flash/minimon/minimon.c
+++ /dev/null
@@ -1,156 +0,0 @@
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
24static UINT8 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
34static void 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 = 0; // 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
deleted file mode 100644
index b6e9805ecf..0000000000
--- a/flash/minimon/minimon.h
+++ /dev/null
@@ -1,24 +0,0 @@
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
deleted file mode 100644
index 14150b2123..0000000000
--- a/flash/minimon/minimon.lds
+++ /dev/null
@@ -1,60 +0,0 @@
1OUTPUT_FORMAT(elf32-sh)
2INPUT(minimon.o)
3
4MEMORY
5{
6 IRAM : ORIGIN = 0x0FFFF000, LENGTH = 0x500
7}
8
9SECTIONS
10{
11 .startvector :
12 {
13 *(.startvector)
14 . = ALIGN(0x4);
15 } > IRAM
16
17 .got :
18 {
19 *(.got)
20 } > IRAM
21
22 .got.plt :
23 {
24 *(.got.plt)
25 } > IRAM
26
27 .rela.got :
28 {
29 *(.rela.got)
30 } > IRAM
31
32 .text :
33 {
34 . = ALIGN(0x200);
35 *(.entry)
36 *(.text)
37 . = ALIGN(0x4);
38 } > IRAM
39
40 .data :
41 {
42 *(.data)
43 } > IRAM
44
45 .rodata :
46 {
47 *(.rodata)
48 . = ALIGN(0x4);
49 } > IRAM
50
51 .bss :
52 {
53 *(.bss)
54 } > IRAM
55
56 .stack :
57 {
58 *(.stack)
59 } > IRAM
60}
diff --git a/flash/uart_boot/Makefile b/flash/uart_boot/Makefile
deleted file mode 100644
index 04db068c07..0000000000
--- a/flash/uart_boot/Makefile
+++ /dev/null
@@ -1,19 +0,0 @@
1# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
7# $Id$
8#
9# This Makefile currently works for cygwin only!
10
11
12CFLAGS := -O -W -Wall -mno-cygwin
13
14uart_boot: uart_boot.c client.c flash.c uart_win.c
15 $(CC) $(CFLAGS) $+ -o $@
16
17clean:
18 -rm -f uart_boot.exe
19
diff --git a/flash/uart_boot/README b/flash/uart_boot/README
deleted file mode 100644
index af2b5ae87d..0000000000
--- a/flash/uart_boot/README
+++ /dev/null
@@ -1,8 +0,0 @@
1(c) 2003 by Jörg Hohensohn
2
3This is the client side for MiniMon, a command line program that communicates with it.
4It can be used to reflash a box from ground up, load a program like gdb stub or Rockbox,
5and other diagnostics.
6
7Current implementation is for Windows, but with a different UART implementation
8it should work for other platforms (Linux) as well.
diff --git a/flash/uart_boot/client.c b/flash/uart_boot/client.c
deleted file mode 100644
index 71749a2c55..0000000000
--- a/flash/uart_boot/client.c
+++ /dev/null
@@ -1,737 +0,0 @@
1// client.cpp : functions for monitor download and communication.
2//
3
4#include <stdio.h>
5#include <stdlib.h>
6#include "scalar_types.h" // (U)INT8/16/32
7#include "Uart.h" // platform abstraction for UART
8#include "minimon.h" // protocol of my little monitor
9
10// do the baudrate configuration for the Player
11int ConfigFirstlevelPlayer (tUartHandle serial_handle)
12{
13 UINT32 result_nbr;
14
15 if(!UartConfig(serial_handle, 4800, eMARKPARITY, eTWOSTOPBITS, 8))
16 {
17 UINT32 dwErr = GET_LAST_ERR();
18 printf("Error %lu setting up COM params for baudrate byte\n", dwErr);
19 exit(1);
20 }
21
22 // this will read as 0x19 when viewed with 2300 baud like the player does
23 result_nbr = UartWrite(serial_handle, (UINT8*)"\x86\xC0", 2);
24 if (result_nbr != 2)
25 {
26 UINT32 dwErr = GET_LAST_ERR();
27 printf("Error %lu setting up COM params for baudrate byte\n", dwErr);
28 }
29
30 SLEEP(100); // wait for the chars to be sent, is there a better way?
31
32 // the read 0x19 means 14423 baud with 12 MHz
33 if(!UartConfig(serial_handle, 14400, eNOPARITY, eONESTOPBIT, 8))
34 {
35 printf("Error setting up COM params for 1st level loader\n");
36 exit(1);
37 }
38
39 return 0;
40}
41
42
43// do the baudrate configuration for the Recoder/FM
44int ConfigFirstlevelRecorder (tUartHandle serial_handle)
45{
46 UINT32 result_nbr;
47
48 if(!UartConfig(serial_handle, 4800, eNOPARITY, eTWOSTOPBITS, 8))
49 {
50 UINT32 dwErr = GET_LAST_ERR();
51 printf("Error %lu setting up COM params for baudrate byte\n", dwErr);
52 exit(1);
53 }
54
55 // this will read as 0x08 when viewed with 2120 baud like the recorder does
56 result_nbr = UartWrite(serial_handle, (UINT8*)"\x00\x00", 2);
57 if(result_nbr != 2)
58 {
59 printf("Error transmitting baudrate byte\n");
60 exit(1);
61 }
62
63 SLEEP(100); // wait for the chars to be sent, is there a better way?
64
65 // the read 0x08 means 38400 baud with 11.0592 MHz
66 if(!UartConfig(serial_handle, 38400, eNOPARITY, eONESTOPBIT, 8))
67 {
68 UINT32 dwErr = GET_LAST_ERR();
69 printf("Error %lu setting up COM params for 1st level loader\n", dwErr);
70 exit(1);
71 }
72
73 return 0;
74}
75
76
77// transfer a byte for the monitor download, with or without acknowledge
78int DownloadByte(tUartHandle serial_handle, unsigned char byte, bool bAck)
79{
80 unsigned char received;
81
82 while (1)
83 {
84 UartWrite(serial_handle, &byte, 1);
85 if (bAck)
86 {
87 UartRead(serial_handle, &received, 1);
88 if (received == byte)
89 {
90 UartWrite(serial_handle, (UINT8*)"\x01", 1); // ack success
91 break; // exit the loop
92 }
93 else
94 {
95 printf("Error transmitting monitor byte 0x%02X, got 0x%0X\n", byte, received);
96 UartWrite(serial_handle, (UINT8*)"\x00", 1); // ack fail, try again
97 }
98 }
99 else
100 break; // no loop
101 }
102 return 1;
103}
104
105
106// download our little monitor, the box must have been just freshly switched on for this to work
107int DownloadMonitor(tUartHandle serial_handle, bool bRecorder, char* szFilename)
108{
109 FILE* pFile;
110 size_t filesize;
111 UINT8 byte;
112 unsigned i;
113
114 // hard-coded parameters
115 bool bAck = true; // configure if acknowledged download (without useful for remote pin boot)
116 UINT32 TargetLoad = 0x0FFFF000; // target load address
117
118 pFile = fopen(szFilename, "rb");
119 if (pFile == NULL)
120 {
121 printf("\nMonitor file %s not found, exiting\n", szFilename);
122 exit(1);
123 }
124
125 // determine file size
126 fseek(pFile, 0, SEEK_END);
127 filesize = ftell(pFile);
128 fseek(pFile, 0, SEEK_SET);
129
130 // This is _really_ tricky! The box expects a BRR value in a nonstandard baudrate,
131 // which a PC can't generate. I'm using a higher one with some wild settings
132 // to generate a pulse series that:
133 // 1) looks like a stable byte when sampled with the nonstandard baudrate
134 // 2) gives a BRR value to the box which results in a baudrate the PC can also use
135 if (bRecorder)
136 {
137 ConfigFirstlevelRecorder(serial_handle);
138 }
139 else
140 {
141 ConfigFirstlevelPlayer(serial_handle);
142 }
143
144 UartWrite(serial_handle, bAck ? (UINT8*)"\x01" : (UINT8*)"\x00", 1); // ACK mode
145
146 // transmit the size, little endian
147 DownloadByte(serial_handle, (UINT8)( filesize & 0xFF), bAck);
148 DownloadByte(serial_handle, (UINT8)((filesize>>8) & 0xFF), bAck);
149 DownloadByte(serial_handle, (UINT8)((filesize>>16) & 0xFF), bAck);
150 DownloadByte(serial_handle, (UINT8)((filesize>>24) & 0xFF), bAck);
151
152 // transmit the load address, little endian
153 DownloadByte(serial_handle, (UINT8)( TargetLoad & 0xFF), bAck);
154 DownloadByte(serial_handle, (UINT8)((TargetLoad>>8) & 0xFF), bAck);
155 DownloadByte(serial_handle, (UINT8)((TargetLoad>>16) & 0xFF), bAck);
156 DownloadByte(serial_handle, (UINT8)((TargetLoad>>24) & 0xFF), bAck);
157
158 // transmit the command byte
159 DownloadByte(serial_handle, 0xFF, bAck); // 0xFF means execute the transferred image
160
161 // transmit the image
162 for (i=0; i<filesize; i++)
163 {
164 fread(&byte, 1, 1, pFile);
165 DownloadByte(serial_handle, byte, bAck);
166 }
167
168 fclose (pFile);
169
170 // now the image should have been started, red LED off
171
172 return 0;
173}
174
175
176// wait for a fixed string to be received (no foolproof algorithm,
177// may overlook if the searched string contains repeatitions)
178int WaitForString(tUartHandle serial_handle, char* pszWait)
179{
180 int i = 0;
181 unsigned char received;
182
183 while(pszWait[i] != '\0')
184 {
185 UartRead(serial_handle, &received, 1);
186
187 printf("%c", received); // debug
188
189 if (received == pszWait[i])
190 i++; // continue
191 else
192 i=0; // mismatch, start over
193 }
194 return 0;
195}
196
197
198// send a sting and check the echo
199int SendWithEcho(tUartHandle serial_handle, char* pszSend)
200{
201 int i = 0;
202 unsigned char received;
203
204 while(pszSend[i] != '\0')
205 {
206 UartWrite(serial_handle, (unsigned char*)(pszSend + i), 1); // send char
207 do
208 {
209 UartRead(serial_handle, &received, 1); // receive echo
210 printf("%c", received); // debug
211 }
212 while (received != pszSend[i]); // should normally be equal
213 i++; // next char
214 }
215 return 0;
216}
217
218
219// rarely used variant: download our monitor using the built-in Archos monitor
220int DownloadArchosMonitor(tUartHandle serial_handle, char* szFilename)
221{
222 FILE* pFile;
223 size_t filesize;
224 UINT8 byte;
225 UINT16 checksum = 0;
226 unsigned i;
227
228 // the onboard monitor uses 115200 baud
229 if(!UartConfig(serial_handle, 115200, eNOPARITY, eONESTOPBIT, 8))
230 {
231 UINT32 dwErr = GET_LAST_ERR();
232 printf("Error %lu setting up COM params for baudrate %d\n", dwErr, 115200);
233 exit(1);
234 }
235
236 // wait for receiving "#SERIAL#"
237 WaitForString(serial_handle, "#SERIAL#");
238
239 // send magic "SRL" command to get interactive mode
240 SendWithEcho(serial_handle, "SRL\r");
241
242 // wait for menu completion: "ROOT>" at the end
243 WaitForString(serial_handle, "ROOT>");
244
245 // send upload command "UP"
246 SendWithEcho(serial_handle, "UP\r");
247
248 pFile = fopen(szFilename, "rb");
249 if (pFile == NULL)
250 {
251 printf("\nMonitor file %s not found, exiting\n", szFilename);
252 exit(1);
253 }
254
255 // determine file size
256 fseek(pFile, 0, SEEK_END);
257 filesize = ftell(pFile);
258 fseek(pFile, 0, SEEK_SET);
259
260 // calculate checksum
261 for (i=0; i<filesize; i++)
262 {
263 fread(&byte, 1, 1, pFile);
264 checksum += byte;
265 }
266 fseek(pFile, 0, SEEK_SET);
267
268 // send header
269
270 // size as 32 bit little endian
271 byte = (UINT8)( filesize & 0xFF);
272 UartWrite(serial_handle, &byte, 1);
273 byte = (UINT8)((filesize>>8) & 0xFF);
274 UartWrite(serial_handle, &byte, 1);
275 byte = (UINT8)((filesize>>16) & 0xFF);
276 UartWrite(serial_handle, &byte, 1);
277 byte = (UINT8)((filesize>>24) & 0xFF);
278 UartWrite(serial_handle, &byte, 1);
279
280 // checksum as 16 bit little endian
281 byte = (UINT8)( checksum & 0xFF);
282 UartWrite(serial_handle, &byte, 1);
283 byte = (UINT8)((checksum>>8) & 0xFF);
284 UartWrite(serial_handle, &byte, 1);
285
286 UartWrite(serial_handle, (unsigned char*)"\x00", 1); // kind (3 means flash)
287 UartWrite(serial_handle, (unsigned char*)"\x00", 1); // ignored byte
288
289 // wait for monitor to accept data
290 WaitForString(serial_handle, "#OKCTRL#");
291
292 // transmit the image
293 for (i=0; i<filesize; i++)
294 {
295 fread(&byte, 1, 1, pFile);
296 UartWrite(serial_handle, &byte, 1); // payload
297 }
298 fclose (pFile);
299
300 UartWrite(serial_handle, (unsigned char*)"\x00", 1); // ignored byte
301
302 // wait for menu completion: "ROOT>" at the end
303 WaitForString(serial_handle, "ROOT>");
304
305 // send start program command "SPRO"
306 SendWithEcho(serial_handle, "SPRO\r");
307
308 SLEEP(100); // wait a little while for startup
309
310 return 0;
311}
312
313
314/********** Target functions using the Monitor Protocol **********/
315
316// read a byte using the target monitor
317UINT8 ReadByte(tUartHandle serial_handle, UINT32 addr)
318{
319 UINT8 send;
320 UINT8 received;
321
322 // send the address command
323 send = ADDRESS;
324 UartWrite(serial_handle, &send, 1);
325
326 // transmit the address, big endian
327 send = (UINT8)((addr>>24) & 0xFF);
328 UartWrite(serial_handle, &send, 1);
329 send = (UINT8)((addr>>16) & 0xFF);
330 UartWrite(serial_handle, &send, 1);
331 send = (UINT8)((addr>>8) & 0xFF);
332 UartWrite(serial_handle, &send, 1);
333 send = (UINT8)(addr & 0xFF);
334 UartWrite(serial_handle, &send, 1);
335
336 UartRead(serial_handle, &received, 1); // response
337 if (received != ADDRESS)
338 {
339 printf("Protocol error!\n");
340 return 1;
341 }
342
343 // send the read command
344 send = BYTE_READ;
345 UartWrite(serial_handle, &send, 1);
346
347 UartRead(serial_handle, &received, 1); // response
348
349 return received;
350}
351
352
353// write a byte using the target monitor
354int WriteByte(tUartHandle serial_handle, UINT32 addr, UINT8 byte)
355{
356 UINT8 send;
357 UINT8 received;
358
359 // send the address command
360 send = ADDRESS;
361 UartWrite(serial_handle, &send, 1);
362
363 // transmit the address, big endian
364 send = (UINT8)((addr>>24) & 0xFF);
365 UartWrite(serial_handle, &send, 1);
366 send = (UINT8)((addr>>16) & 0xFF);
367 UartWrite(serial_handle, &send, 1);
368 send = (UINT8)((addr>>8) & 0xFF);
369 UartWrite(serial_handle, &send, 1);
370 send = (UINT8)(addr & 0xFF);
371 UartWrite(serial_handle, &send, 1);
372
373 UartRead(serial_handle, &received, 1); // response
374 if (received != ADDRESS)
375 {
376 printf("Protocol error, receiced 0x%02X!\n", received);
377 return 1;
378 }
379
380 // send the write command
381 send = BYTE_WRITE;
382 UartWrite(serial_handle, &send, 1);
383
384 // transmit the data
385 UartWrite(serial_handle, &byte, 1);
386
387 UartRead(serial_handle, &received, 1); // response
388
389 if (received != BYTE_WRITE)
390 {
391 printf("Protocol error!\n");
392 return 1;
393 }
394
395 return 0;
396}
397
398
399// read many bytes using the target monitor
400int ReadByteMultiple(tUartHandle serial_handle, UINT32 addr, UINT32 size, UINT8* pBuffer)
401{
402 UINT8 send, received;
403
404 // send the address command
405 send = ADDRESS;
406 UartWrite(serial_handle, &send, 1);
407
408 // transmit the address, big endian
409 send = (UINT8)((addr>>24) & 0xFF);
410 UartWrite(serial_handle, &send, 1);
411 send = (UINT8)((addr>>16) & 0xFF);
412 UartWrite(serial_handle, &send, 1);
413 send = (UINT8)((addr>>8) & 0xFF);
414 UartWrite(serial_handle, &send, 1);
415 send = (UINT8)(addr & 0xFF);
416 UartWrite(serial_handle, &send, 1);
417
418 UartRead(serial_handle, &received, 1); // response
419 if (received != ADDRESS)
420 {
421 printf("Protocol error!\n");
422 return 1;
423 }
424
425 while (size)
426 {
427 if (size >= 16)
428 { // we can use a "burst" command
429 send = BYTE_READ16;
430 UartWrite(serial_handle, &send, 1); // send the read command
431 UartRead(serial_handle, pBuffer, 16); // data response
432 pBuffer += 16;
433 size -= 16;
434 }
435 else
436 { // use single byte command
437 send = BYTE_READ;
438 UartWrite(serial_handle, &send, 1); // send the read command
439 UartRead(serial_handle, pBuffer++, 1); // data response
440 size--;
441 }
442 }
443
444 return 0;
445}
446
447
448// write many bytes using the target monitor
449int WriteByteMultiple(tUartHandle serial_handle, UINT32 addr, UINT32 size, UINT8* pBuffer)
450{
451 UINT8 send, received;
452
453 // send the address command
454 send = ADDRESS;
455 UartWrite(serial_handle, &send, 1);
456
457 // transmit the address, big endian
458 send = (UINT8)((addr>>24) & 0xFF);
459 UartWrite(serial_handle, &send, 1);
460 send = (UINT8)((addr>>16) & 0xFF);
461 UartWrite(serial_handle, &send, 1);
462 send = (UINT8)((addr>>8) & 0xFF);
463 UartWrite(serial_handle, &send, 1);
464 send = (UINT8)(addr & 0xFF);
465 UartWrite(serial_handle, &send, 1);
466
467 UartRead(serial_handle, &received, 1); // response
468 if (received != ADDRESS)
469 {
470 printf("Protocol error!\n");
471 return 1;
472 }
473
474 while (size)
475 {
476 if (size >= 16)
477 { // we can use a "burst" command
478 send = BYTE_WRITE16;
479 UartWrite(serial_handle, &send, 1); // send the write command
480 UartWrite(serial_handle, pBuffer, 16); // transmit the data
481 UartRead(serial_handle, &received, 1); // response
482 if (received != BYTE_WRITE16)
483 {
484 printf("Protocol error!\n");
485 return 1;
486 }
487 pBuffer += 16;
488 size -= 16;
489 }
490 else
491 { // use single byte command
492 send = BYTE_WRITE;
493 UartWrite(serial_handle, &send, 1); // send the write command
494 UartWrite(serial_handle, pBuffer++, 1); // transmit the data
495 UartRead(serial_handle, &received, 1); // response
496 if (received != BYTE_WRITE)
497 {
498 printf("Protocol error!\n");
499 return 1;
500 }
501 size--;
502 }
503 }
504
505 return 0;
506}
507
508
509// write many bytes using the target monitor
510int FlashByteMultiple(tUartHandle serial_handle, UINT32 addr, UINT32 size, UINT8* pBuffer)
511{
512 UINT8 send, received;
513
514 // send the address command
515 send = ADDRESS;
516 UartWrite(serial_handle, &send, 1);
517
518 // transmit the address, big endian
519 send = (UINT8)((addr>>24) & 0xFF);
520 UartWrite(serial_handle, &send, 1);
521 send = (UINT8)((addr>>16) & 0xFF);
522 UartWrite(serial_handle, &send, 1);
523 send = (UINT8)((addr>>8) & 0xFF);
524 UartWrite(serial_handle, &send, 1);
525 send = (UINT8)(addr & 0xFF);
526 UartWrite(serial_handle, &send, 1);
527
528 UartRead(serial_handle, &received, 1); // response
529 if (received != ADDRESS)
530 {
531 printf("Protocol error!\n");
532 return 1;
533 }
534
535 while (size)
536 {
537 if (size >= 16)
538 { // we can use a "burst" command
539 send = BYTE_FLASH16;
540 UartWrite(serial_handle, &send, 1); // send the write command
541 UartWrite(serial_handle, pBuffer, 16); // transmit the data
542 UartRead(serial_handle, &received, 1); // response
543 if (received != BYTE_FLASH16)
544 {
545 printf("Protocol error!\n");
546 return 1;
547 }
548 pBuffer += 16;
549 size -= 16;
550 }
551 else
552 { // use single byte command
553 send = BYTE_FLASH;
554 UartWrite(serial_handle, &send, 1); // send the write command
555 UartWrite(serial_handle, pBuffer++, 1); // transmit the data
556 UartRead(serial_handle, &received, 1); // response
557 if (received != BYTE_FLASH)
558 {
559 printf("Protocol error!\n");
560 return 1;
561 }
562 size--;
563 }
564 }
565
566 return 0;
567}
568
569
570// read a 16bit halfword using the target monitor
571UINT16 ReadHalfword(tUartHandle serial_handle, UINT32 addr)
572{
573 UINT8 send;
574 UINT8 received;
575 UINT16 halfword;
576
577 // send the address command
578 send = ADDRESS;
579 UartWrite(serial_handle, &send, 1);
580
581 // transmit the address, big endian
582 send = (UINT8)((addr>>24) & 0xFF);
583 UartWrite(serial_handle, &send, 1);
584 send = (UINT8)((addr>>16) & 0xFF);
585 UartWrite(serial_handle, &send, 1);
586 send = (UINT8)((addr>>8) & 0xFF);
587 UartWrite(serial_handle, &send, 1);
588 send = (UINT8)(addr & 0xFF);
589 UartWrite(serial_handle, &send, 1);
590
591 UartRead(serial_handle, &received, 1); // response
592 if (received != ADDRESS)
593 {
594 printf("Protocol error!\n");
595 return 1;
596 }
597
598 // send the read command
599 send = HALFWORD_READ;
600 UartWrite(serial_handle, &send, 1);
601
602 UartRead(serial_handle, &received, 1); // response
603 halfword = received << 8; // highbyte
604 UartRead(serial_handle, &received, 1);
605 halfword |= received; // lowbyte
606
607 return halfword;
608}
609
610
611// write a 16bit halfword using the target monitor
612int WriteHalfword(tUartHandle serial_handle, UINT32 addr, UINT16 halfword)
613{
614 UINT8 send;
615 UINT8 received;
616
617 // send the address command
618 send = ADDRESS;
619 UartWrite(serial_handle, &send, 1);
620
621 // transmit the address, big endian
622 send = (UINT8)((addr>>24) & 0xFF);
623 UartWrite(serial_handle, &send, 1);
624 send = (UINT8)((addr>>16) & 0xFF);
625 UartWrite(serial_handle, &send, 1);
626 send = (UINT8)((addr>>8) & 0xFF);
627 UartWrite(serial_handle, &send, 1);
628 send = (UINT8)(addr & 0xFF);
629 UartWrite(serial_handle, &send, 1);
630
631 UartRead(serial_handle, &received, 1); // response
632 if (received != ADDRESS)
633 {
634 printf("Protocol error!\n");
635 return 1;
636 }
637
638 // send the write command
639 send = HALFWORD_WRITE;
640 UartWrite(serial_handle, &send, 1);
641
642 // transmit the data
643 send = halfword >> 8; // highbyte
644 UartWrite(serial_handle, &send, 1);
645 send = halfword & 0xFF; // lowbyte
646 UartWrite(serial_handle, &send, 1);
647
648 UartRead(serial_handle, &received, 1); // response
649
650 if (received != HALFWORD_WRITE)
651 {
652 printf("Protocol error!\n");
653 return 1;
654 }
655
656 return 0;
657}
658
659
660// change baudrate using target monitor
661int SetTargetBaudrate(tUartHandle serial_handle, long lClock, long lBaudrate)
662{
663 UINT8 send;
664 UINT8 received;
665 UINT8 brr;
666 long lBRR;
667
668 lBRR = lClock / lBaudrate;
669 lBRR = ((lBRR + 16) / 32) - 1; // with rounding
670 brr = (UINT8)lBRR;
671
672 // send the command
673 send = BAUDRATE;
674 UartWrite(serial_handle, &send, 1);
675 UartWrite(serial_handle, &brr, 1); // send the BRR value
676 UartRead(serial_handle, &received, 1); // response ack
677
678 if (received != BAUDRATE)
679 { // bad situation, now we're unclear about the baudrate of the target
680 printf("Protocol error!\n");
681 return 1;
682 }
683
684 SLEEP(100); // give it some time to settle
685
686 // change our baudrate, too
687 UartConfig(serial_handle, lBaudrate, eNOPARITY, eONESTOPBIT, 8);
688
689 return 0;
690}
691
692
693// call a subroutine using the target monitor
694int Execute(tUartHandle serial_handle, UINT32 addr, bool bReturns)
695{
696 UINT8 send;
697 UINT8 received;
698
699 // send the address command
700 send = ADDRESS;
701 UartWrite(serial_handle, &send, 1);
702
703 // transmit the address, big endian
704 send = (UINT8)((addr>>24) & 0xFF);
705 UartWrite(serial_handle, &send, 1);
706 send = (UINT8)((addr>>16) & 0xFF);
707 UartWrite(serial_handle, &send, 1);
708 send = (UINT8)((addr>>8) & 0xFF);
709 UartWrite(serial_handle, &send, 1);
710 send = (UINT8)(addr & 0xFF);
711 UartWrite(serial_handle, &send, 1);
712
713 UartRead(serial_handle, &received, 1); // response
714 if (received != ADDRESS)
715 {
716 printf("Protocol error!\n");
717 return 1;
718 }
719
720 // send the execute command
721 send = EXECUTE;
722 UartWrite(serial_handle, &send, 1);
723 if (bReturns)
724 { // we expect the call to return control to minimon
725 UartRead(serial_handle, &received, 1); // response
726
727 if (received != EXECUTE)
728 {
729 printf("Protocol error!\n");
730 return 1;
731 }
732 }
733
734 return 0;
735}
736
737
diff --git a/flash/uart_boot/client.h b/flash/uart_boot/client.h
deleted file mode 100644
index a5df8c35d6..0000000000
--- a/flash/uart_boot/client.h
+++ /dev/null
@@ -1,22 +0,0 @@
1#ifndef _CLIENT_H
2#define _CLIENT_H
3
4
5// setup function for monitor download
6int DownloadMonitor(tUartHandle serial_handle, bool bRecorder, char* szFilename);
7int DownloadArchosMonitor(tUartHandle serial_handle, char* szFilename);
8
9// target functions using the Monitor Protocol
10UINT8 ReadByte(tUartHandle serial_handle, UINT32 addr);
11int WriteByte(tUartHandle serial_handle, UINT32 addr, UINT8 byte);
12int ReadByteMultiple(tUartHandle serial_handle, UINT32 addr, UINT32 size, UINT8* pBuffer);
13int WriteByteMultiple(tUartHandle serial_handle, UINT32 addr, UINT32 size, UINT8* pBuffer);
14int FlashByteMultiple(tUartHandle serial_handle, UINT32 addr, UINT32 size, UINT8* pBuffer);
15UINT16 ReadHalfword(tUartHandle serial_handle, UINT32 addr);
16int WriteHalfword(tUartHandle serial_handle, UINT32 addr, UINT16 halfword);
17int SetTargetBaudrate(tUartHandle serial_handle, long lClock, long lBaudrate);
18int Execute(tUartHandle serial_handle, UINT32 addr, bool bReturns);
19
20
21#endif
22
diff --git a/flash/uart_boot/flash.c b/flash/uart_boot/flash.c
deleted file mode 100644
index 854de20454..0000000000
--- a/flash/uart_boot/flash.c
+++ /dev/null
@@ -1,78 +0,0 @@
1// flash.cpp : higher-level functions for flashing the chip
2//
3
4#include "scalar_types.h" // (U)INT8/16/32
5#include "Uart.h" // platform abstraction for UART
6#include "client.h" // client functions
7
8
9// read the manufacturer and device ID
10int ReadID(tUartHandle serial_handle, UINT32 base, UINT8* pManufacturerID, UINT8* pDeviceID)
11{
12 base &= 0xFFF80000; // round down to 512k align, to make shure
13
14 WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
15 WriteByte(serial_handle, base + 0x2AAA, 0x55);
16 WriteByte(serial_handle, base + 0x5555, 0x90); // ID command
17 SLEEP(20); // Atmel wants 20ms pause here
18
19 *pManufacturerID = ReadByte(serial_handle, base + 0);
20 *pDeviceID = ReadByte(serial_handle, base + 1);
21
22 WriteByte(serial_handle, base + 0, 0xF0); // reset flash (back to normal read mode)
23 SLEEP(20); // Atmel wants 20ms pause here
24
25 return 0;
26}
27
28
29// erase the sector which contains the given address
30int EraseSector(tUartHandle serial_handle, UINT32 address)
31{
32 UINT32 base = address & 0xFFF80000; // round down to 512k align
33
34 WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
35 WriteByte(serial_handle, base + 0x2AAA, 0x55);
36 WriteByte(serial_handle, base + 0x5555, 0x80); // eraze command
37 WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
38 WriteByte(serial_handle, base + 0x2AAA, 0x55);
39 WriteByte(serial_handle, address, 0x30); // eraze the sector
40 SLEEP(25); // sector eraze time: 25ms
41
42 return 0;
43}
44
45
46// erase the whole flash
47int EraseChip(tUartHandle serial_handle, UINT32 base)
48{
49 base &= 0xFFF80000; // round down to 512k align, to make shure
50
51 WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
52 WriteByte(serial_handle, base + 0x2AAA, 0x55);
53 WriteByte(serial_handle, base + 0x5555, 0x80); // eraze command
54 WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
55 WriteByte(serial_handle, base + 0x2AAA, 0x55);
56 WriteByte(serial_handle, base + 0x5555, 0x10); // chip eraze command
57 SLEEP(100); // chip eraze time: 100ms
58
59 return 0;
60}
61
62
63// program a bunch of bytes "by hand"
64int ProgramBytes(tUartHandle serial_handle, UINT32 address, UINT8* pData, UINT32 size)
65{
66 UINT32 base = address & 0xFFF80000; // round down to 512k align
67
68 while (size--)
69 {
70 WriteByte(serial_handle, base + 0x5555, 0xAA); // enter command mode
71 WriteByte(serial_handle, base + 0x2AAA, 0x55);
72 WriteByte(serial_handle, base + 0x5555, 0xA0); // byte program command
73 WriteByte(serial_handle, address++, *pData++);
74 // UART protocol is slow enough such that I don't have to wait 20us here
75 }
76 return 0;
77}
78
diff --git a/flash/uart_boot/flash.h b/flash/uart_boot/flash.h
deleted file mode 100644
index 9c69ad46a5..0000000000
--- a/flash/uart_boot/flash.h
+++ /dev/null
@@ -1,10 +0,0 @@
1#ifndef _FLASH_H
2#define _FLASH_H
3
4int ReadID(tUartHandle serial_handle, UINT32 base, UINT8* pManufacturerID, UINT8* pDeviceID);
5int EraseSector(tUartHandle serial_handle, UINT32 address);
6int EraseChip(tUartHandle serial_handle, UINT32 base);
7int ProgramBytes(tUartHandle serial_handle, UINT32 address, UINT8* pData, UINT32 size);
8
9#endif
10
diff --git a/flash/uart_boot/minimon.h b/flash/uart_boot/minimon.h
deleted file mode 100644
index 69a03b1f4d..0000000000
--- a/flash/uart_boot/minimon.h
+++ /dev/null
@@ -1,24 +0,0 @@
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
22
23#endif // _MINIMON_H
24
diff --git a/flash/uart_boot/scalar_types.h b/flash/uart_boot/scalar_types.h
deleted file mode 100644
index f3ac1d86eb..0000000000
--- a/flash/uart_boot/scalar_types.h
+++ /dev/null
@@ -1,45 +0,0 @@
1// this is meant to resolve platform dependency
2
3#ifndef _SCALAR_TYPES_H
4#define _SCALAR_TYPES_H
5
6
7#ifdef WIN32
8#include <windows.h>
9#define SLEEP Sleep
10#define GET_LAST_ERR GetLastError
11#endif
12// ToDo: add stuff for Linux
13
14
15
16#ifndef UINT8
17#define UINT8 unsigned char
18#endif
19
20#ifndef UINT16
21#define UINT16 unsigned short
22#endif
23
24#ifndef UINT32
25#define UINT32 unsigned long
26#endif
27
28#ifndef bool
29#define bool int
30#endif
31
32#ifndef true
33#define true 1
34#endif
35
36#ifndef false
37#define false 0
38#endif
39
40
41
42
43
44#endif
45
diff --git a/flash/uart_boot/uart.h b/flash/uart_boot/uart.h
deleted file mode 100644
index a0c10d1a0f..0000000000
--- a/flash/uart_boot/uart.h
+++ /dev/null
@@ -1,57 +0,0 @@
1// A general definition for the required UART functionality.
2// This will be used to gain platform abstraction.
3
4#ifndef _UART_H
5#define _UART_H
6
7// data types
8
9typedef void* tUartHandle;
10#define INVALID_UART_HANDLE (tUartHandle)-1
11
12typedef enum
13{
14 eNOPARITY,
15 eODDPARITY,
16 eEVENPARITY,
17 eMARKPARITY,
18 eSPACEPARITY,
19} tParity;
20
21typedef enum
22{
23 eONESTOPBIT,
24 eONE5STOPBITS,
25 eTWOSTOPBITS,
26} tStopBits;
27
28
29// prototypes
30
31tUartHandle UartOpen( // returns NULL on error
32 char* szPortName); // COMx for windows
33
34bool UartConfig( // returns true on success, false on error
35 tUartHandle handle, // the handle returned from UartOpen()
36 long lBaudRate, // must be one of the "standard" baudrates
37 tParity nParity, // what kind of parity
38 tStopBits nStopBits, // how many stop bits
39 int nByteSize); // size of the "payload", can be 5 to 8
40
41long UartWrite( // returns how much data was actually transmitted
42 tUartHandle handle, // the handle returned from UartOpen()
43 unsigned char* pData, // pointer to the data to be transmitted
44 long lSize); // how many bytes
45
46long UartRead( // returns how much data was actually received
47 tUartHandle handle, // the handle returned from UartOpen()
48 unsigned char* pBuffer, // pointer to the destination
49 long lSize); // how many bytes to read (pBuffer must have enough room)
50
51
52void UartClose(tUartHandle handle);
53
54
55
56#endif // _UART_H
57
diff --git a/flash/uart_boot/uart_boot.c b/flash/uart_boot/uart_boot.c
deleted file mode 100644
index 06750fdbe2..0000000000
--- a/flash/uart_boot/uart_boot.c
+++ /dev/null
@@ -1,370 +0,0 @@
1// uart_boot.cpp : Defines the entry point for the console application.
2//
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7#include "scalar_types.h" // (U)INT8/16/32
8#include "Uart.h" // platform abstraction for UART
9#include "client.h" // client functions
10#include "flash.h" // flash high level functions
11
12// command line configuration: what shall we do?
13static struct
14{
15 char* szPort; // COM port to use
16 bool bRecorder; // it's a recorder
17 bool bArchos; // use the Archos monitor to load, instead of UART boot
18 bool bSpindown; // spindown the harddisk
19 bool bReadID; // read manufacturer+device ID
20 char* szFlashfile; // file to be programmed
21 char* szDumpfile; // file to dump into
22 char* szExecfile; // file with the executable
23 bool bTest; // debug action
24 bool bHold; // hold power (for FMs & V2s)
25 bool bBlink; // blink red LED
26 bool bNoDownload;
27} gCmd;
28
29
30
31int ProcessCmdLine(int argc, char* argv[])
32{
33 argc--; // exclude our name
34 argv++;
35
36 memset(&gCmd, 0, sizeof(gCmd));
37
38 if (argc == 0)
39 {
40 printf("Usage: uart_boot [-option {filename}]\n");
41 printf(" uses activated UART boot mod, box has to be fresh started\n");
42 printf("The order of the options does not matter, one letter is sufficient.\n");
43 printf("Possible options are (in the order of later processing):\n");
44 printf("-port <name of COM port to use>\n");
45 printf("-recorder (this is a recorder/FM, default is player if not specified)\n");
46 printf("-archos (use Archos bootloader, this one needs powerup while program waits)\n");
47 printf("-nodownload (no MiniMon download, it's already active)\n");
48 printf("-hold (hold the power, useful for FMs and V2s, so you can release ON)\n");
49 printf("-spindown (spindown the harddisk, else it stays on by default)\n");
50 printf("-id (read manufacturer and device ID of flash, no checks)\n");
51 printf("-flash <filename of binary to program into flash>\n");
52 printf("-dump <filename to write flash content to>\n");
53 printf("-exec <filename of executable for 0x09000000:0x09000200>\n");
54 printf("-test (some test action currently under development, don't use!)\n");
55 printf("-blink (blink red LED forever, meant as diagnostics)\n");
56 printf("\n");
57 printf("Examples:\n");
58 printf("uart_boot -r -p COM1 -s -f flashfile.bin -d dumpfile.bin\n");
59 printf(" recorder on COM1, spindown HD, program and dump (for e.g. offline verify)\n");
60 printf("uart_boot -r -p COM2 -e rockbox.bin\n");
61 printf(" recorder on COM2, load Rockbox from file and start it\n");
62 exit (0);
63 }
64
65
66 while (argc)
67 {
68 if (!strncmp("-port", *argv, 2))
69 {
70 gCmd.szPort = *++argv;
71 if (--argc <= 0 || **argv == '-')
72 {
73 printf("No argument given for option %s, aborting.\n", argv[-1]);
74 exit (-2);
75 }
76 }
77 else if (!strncmp("-recorder", *argv, 2))
78 {
79 gCmd.bRecorder = true;
80 }
81 else if (!strncmp("-archos", *argv, 2))
82 {
83 gCmd.bArchos = true;
84 }
85 else if (!strncmp("-nodownload", *argv, 2))
86 {
87 gCmd.bNoDownload = true;
88 }
89 else if (!strncmp("-spindown", *argv, 2))
90 {
91 gCmd.bSpindown = true;
92 }
93 else if (!strncmp("-id", *argv, 2))
94 {
95 gCmd.bReadID = true;
96 }
97 else if (!strncmp("-flash", *argv, 2))
98 {
99 gCmd.szFlashfile = *++argv;
100 if (--argc <= 0 || **argv == '-')
101 {
102 printf("No argument given for option %s, aborting.\n", argv[-1]);
103 exit (-2);
104 }
105 }
106 else if (!strncmp("-dump", *argv, 2))
107 {
108 gCmd.szDumpfile = *++argv;
109 if (--argc <= 0 || **argv == '-')
110 {
111 printf("No argument given for option %s, aborting.\n", argv[-1]);
112 exit (-3);
113 }
114 }
115 else if (!strncmp("-exec", *argv, 2))
116 {
117 gCmd.szExecfile = *++argv;
118 if (--argc <= 0 || **argv == '-')
119 {
120 printf("No argument given for option %s, aborting.\n", argv[-1]);
121 exit (-4);
122 }
123 }
124 else if (!strncmp("-test", *argv, 2))
125 {
126 gCmd.bTest = true;
127 }
128 else if (!strncmp("-hold", *argv, 2))
129 {
130 gCmd.bHold = true;
131 }
132 else if (!strncmp("-blink", *argv, 2))
133 {
134 gCmd.bBlink = true;
135 }
136 else
137 {
138 printf("Unknown option %s, aborting. Use 'uart_boot' without options for help.\n", *argv);
139 exit(-1);
140 }
141
142 argv++;
143 argc--;
144 }
145
146 return 0;
147}
148
149
150int main(int argc, char* argv[])
151{
152 tUartHandle serial_handle;
153 UINT16 reg;
154 FILE* pFile;
155 size_t size;
156 static UINT8 abFirmware[256*1024]; // blocksize
157 memset(abFirmware, 0xFF, sizeof(abFirmware));
158
159 ProcessCmdLine(argc, argv); // what to do
160
161 if (!gCmd.szPort)
162 {
163 printf("No serial port given, use 'uart_boot' without parameters for options.\n");
164 exit(-1);
165 }
166
167 serial_handle = UartOpen(gCmd.szPort); // opening serial port
168 if (serial_handle == NULL)
169 {
170 printf("Cannot open port %s\n", gCmd.szPort);
171 return -1;
172 }
173
174 if (gCmd.bNoDownload)
175 { // just set our speed
176 int baudrate = gCmd.bRecorder ? 115200 : 14400;
177 if (!gCmd.bRecorder && gCmd.bTest)
178 { // experimental Player speedup to 38400 baud
179 baudrate = 38400;
180 }
181
182 if (!UartConfig(serial_handle, baudrate, eNOPARITY, eONESTOPBIT, 8))
183 {
184 printf("Error setting up COM params\n");
185 exit(1);
186 }
187 }
188 else
189 { // download the monitor program
190 if (gCmd.bArchos)
191 {
192 printf("Waiting for box startup to download monitor...");
193 DownloadArchosMonitor(serial_handle, "minimon_archos.bin"); // load the monitor image
194 printf("\b\b\b done.\n");
195 }
196 else
197 {
198 printf("Downloading monitor...");
199 DownloadMonitor(serial_handle, gCmd.bRecorder, "minimon.bin"); // load the monitor image
200 // From now on, we can talk to the box.
201 printf("\b\b\b done.\n");
202
203 if (gCmd.bRecorder)
204 { // we can be faster
205 SetTargetBaudrate(serial_handle, 11059200, 115200); // set to 115200
206 }
207 else if (gCmd.bTest) // experimental Player speedup to 38400 baud
208 {
209 SetTargetBaudrate(serial_handle, 12000000, 38400); // set to 38400
210 }
211 }
212 }
213
214
215 // do the action
216 if (gCmd.bHold)
217 {
218 // hold power for FM
219 reg = ReadHalfword(serial_handle, 0x05FFFFC2); // PBDR
220 reg |= 0x0020; // set PB5 to keep power
221 WriteHalfword(serial_handle, 0x05FFFFC2, reg);
222
223 reg = ReadHalfword(serial_handle, 0x05FFFFC6); // PBIOR
224 reg |= 0x0020; // make PB5 an output
225 WriteHalfword(serial_handle, 0x05FFFFC6, reg);
226 printf("Power hold, you can release ON button now.\n");
227 }
228
229
230 if (gCmd.bSpindown)
231 {
232 // power down the disk
233 if (gCmd.bRecorder)
234 { // Recorder (V1+V2) and FM have disk power control on PA5
235 reg = ReadHalfword(serial_handle, 0x05FFFFCA); // PACR2
236 reg &= ~0x0400; // clear bit 10: GPIO
237 WriteHalfword(serial_handle, 0x05FFFFCA, reg);
238
239 reg = ReadHalfword(serial_handle, 0x05FFFFC4); // PAIOR
240 reg |= 0x0020; // set bit 5: output
241 WriteHalfword(serial_handle, 0x05FFFFC4, reg);
242
243 reg = ReadHalfword(serial_handle, 0x05FFFFC0); // PADR
244 reg &= ~0x0020; // clear PA5 to power down
245 WriteHalfword(serial_handle, 0x05FFFFC0, reg);
246 }
247 else
248 { // new Players have disk power control on PB4
249 reg = ReadHalfword(serial_handle, 0x05FFFFC6); // PBIOR
250 reg |= 0x0010; // set bit 4: output
251 WriteHalfword(serial_handle, 0x05FFFFC6, reg);
252
253 reg = ReadHalfword(serial_handle, 0x05FFFFC2); // PBDR
254 reg &= ~0x0010; // clear PB4 to power down
255 WriteHalfword(serial_handle, 0x05FFFFC2, reg);
256 }
257 printf("Harddisk powered down.\n");
258 }
259
260
261 if (gCmd.bReadID)
262 {
263 UINT8 bMan, bID;
264 ReadID(serial_handle, 0x02000000, &bMan, &bID);
265 printf("Manufacturer ID = 0x%02X, Device ID = 0x%02X\n", bMan, bID);
266 }
267
268
269 if (gCmd.szFlashfile)
270 {
271 // flash a firmware file
272 printf("Flashing file %s...", gCmd.szFlashfile);
273 pFile = fopen(gCmd.szFlashfile, "rb");
274 if (pFile == NULL)
275 {
276 printf("\nFlash file %s not found, exiting.\n", gCmd.szFlashfile);
277 return -2;
278 }
279 size = fread(abFirmware, 1, sizeof(abFirmware), pFile);
280 fclose (pFile);
281
282 EraseChip(serial_handle, 0x02000000);
283 FlashByteMultiple(serial_handle, 0x02000000, size, abFirmware);
284 printf("\b\b\b done.\n");
285 }
286
287
288 if (gCmd.szDumpfile)
289 {
290 // dump the flash content
291 printf("Writing flash dump into file %s...", gCmd.szDumpfile);
292 ReadByteMultiple(serial_handle, 0x02000000, sizeof(abFirmware), abFirmware);
293 pFile = fopen(gCmd.szDumpfile, "wb");
294 if (pFile == NULL)
295 {
296 printf("\nDump file %s cannot be opened, exiting.\n", gCmd.szDumpfile);
297 return -3;
298 }
299 fwrite(abFirmware, 1, sizeof(abFirmware), pFile);
300 fclose (pFile);
301 printf("\b\b\b done.\n");
302 }
303
304
305 if (gCmd.szExecfile)
306 {
307 UINT32 size;
308
309 printf("Downloading program...");
310
311 // init the DRAM controller like the flash boot does
312 reg = ReadHalfword(serial_handle, 0x05FFFFCA); // PACR2
313 reg &= 0xFFFB; // PA1 config: /RAS
314 reg |= 0x0008;
315 WriteHalfword(serial_handle, 0x05FFFFCA, reg); // PACR2
316 reg = 0xAFFF; // CS1, CS3 config: /CASH. /CASL
317 WriteHalfword(serial_handle, 0x05FFFFEE, reg); // CASCR
318 reg = ReadHalfword(serial_handle, 0x05FFFFA0); // BCR
319 reg |= 0x8000; // DRAM enable, default bus
320 WriteHalfword(serial_handle, 0x05FFFFA0, reg); // BCR
321 reg = ReadHalfword(serial_handle, 0x05FFFFA2); // WCR1
322 reg &= 0xFDFD; // 1-cycle CAS
323 WriteHalfword(serial_handle, 0x05FFFFA2, reg); // WCR1
324 reg = 0x0E00; // CAS 35%, multiplexed, 10 bit row addr.
325 WriteHalfword(serial_handle, 0x05FFFFA8, reg); // DCR
326 reg = 0x5AB0; // refresh, 4 cycle waitstate
327 WriteHalfword(serial_handle, 0x05FFFFAC, reg); // RCR
328 reg = 0x9605; // refresh constant
329 WriteHalfword(serial_handle, 0x05FFFFB2, reg); // RTCOR
330 reg = 0xA518; // phi/32
331 WriteHalfword(serial_handle, 0x05FFFFAE, reg); // RTCSR
332
333
334 // download Rockbox/gdb
335 pFile = fopen(gCmd.szExecfile, "rb");
336 if (pFile == NULL)
337 {
338 printf("\nExecutable file %s cannot be opened, exiting.\n", gCmd.szExecfile);
339 return -3;
340 }
341
342 size = fread(abFirmware, 1, sizeof(abFirmware), pFile);
343 WriteByteMultiple(serial_handle, 0x09000000, size, abFirmware);
344 fclose (pFile);
345 printf("\b\b\b done.\n");
346
347 // start rockbox/gdb
348 printf("Starting program...");
349 Execute(serial_handle, 0x09000200, false);
350 printf("\b\b\b done.\n");
351 }
352
353
354 if (gCmd.bBlink)
355 {
356 // blinking LED
357 UINT8 byte;
358 printf("Flashing red LED forever... (stop with Ctrl-C)\n");
359 byte = ReadByte(serial_handle, 0x05FFFFC3);
360 while (1)
361 {
362 byte ^= 0x40;
363 WriteByte(serial_handle, 0x05FFFFC3, byte);
364 Sleep(200);
365 }
366 }
367
368 return 0;
369}
370
diff --git a/flash/uart_boot/uart_boot.dsp b/flash/uart_boot/uart_boot.dsp
deleted file mode 100644
index 4d94c72530..0000000000
--- a/flash/uart_boot/uart_boot.dsp
+++ /dev/null
@@ -1,130 +0,0 @@
1# Microsoft Developer Studio Project File - Name="uart_boot" - Package Owner=<4>
2# Microsoft Developer Studio Generated Build File, Format Version 6.00
3# ** DO NOT EDIT **
4
5# TARGTYPE "Win32 (x86) Console Application" 0x0103
6
7CFG=uart_boot - Win32 Debug
8!MESSAGE This is not a valid makefile. To build this project using NMAKE,
9!MESSAGE use the Export Makefile command and run
10!MESSAGE
11!MESSAGE NMAKE /f "uart_boot.mak".
12!MESSAGE
13!MESSAGE You can specify a configuration when running NMAKE
14!MESSAGE by defining the macro CFG on the command line. For example:
15!MESSAGE
16!MESSAGE NMAKE /f "uart_boot.mak" CFG="uart_boot - Win32 Debug"
17!MESSAGE
18!MESSAGE Possible choices for configuration are:
19!MESSAGE
20!MESSAGE "uart_boot - Win32 Release" (based on "Win32 (x86) Console Application")
21!MESSAGE "uart_boot - Win32 Debug" (based on "Win32 (x86) Console Application")
22!MESSAGE
23
24# Begin Project
25# PROP AllowPerConfigDependencies 0
26# PROP Scc_ProjName ""
27# PROP Scc_LocalPath ""
28CPP=cl.exe
29RSC=rc.exe
30
31!IF "$(CFG)" == "uart_boot - Win32 Release"
32
33# PROP BASE Use_MFC 0
34# PROP BASE Use_Debug_Libraries 0
35# PROP BASE Output_Dir "Release"
36# PROP BASE Intermediate_Dir "Release"
37# PROP BASE Target_Dir ""
38# PROP Use_MFC 0
39# PROP Use_Debug_Libraries 0
40# PROP Output_Dir "Release"
41# PROP Intermediate_Dir "Release"
42# PROP Target_Dir ""
43# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c
44# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FR /FD /c
45# SUBTRACT CPP /YX /Yc /Yu
46# ADD BASE RSC /l 0x407 /d "NDEBUG"
47# ADD RSC /l 0x407 /d "NDEBUG"
48BSC32=bscmake.exe
49# ADD BASE BSC32 /nologo
50# ADD BSC32 /nologo
51LINK32=link.exe
52# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
53# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
54
55!ELSEIF "$(CFG)" == "uart_boot - Win32 Debug"
56
57# PROP BASE Use_MFC 0
58# PROP BASE Use_Debug_Libraries 1
59# PROP BASE Output_Dir "Debug"
60# PROP BASE Intermediate_Dir "Debug"
61# PROP BASE Target_Dir ""
62# PROP Use_MFC 0
63# PROP Use_Debug_Libraries 1
64# PROP Output_Dir "Debug"
65# PROP Intermediate_Dir "Debug"
66# PROP Target_Dir ""
67# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c
68# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /FD /GZ /c
69# SUBTRACT CPP /YX /Yc /Yu
70# ADD BASE RSC /l 0x407 /d "_DEBUG"
71# ADD RSC /l 0x407 /d "_DEBUG"
72BSC32=bscmake.exe
73# ADD BASE BSC32 /nologo
74# ADD BSC32 /nologo
75LINK32=link.exe
76# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
77# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
78
79!ENDIF
80
81# Begin Target
82
83# Name "uart_boot - Win32 Release"
84# Name "uart_boot - Win32 Debug"
85# Begin Group "Source Files"
86
87# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
88# Begin Source File
89
90SOURCE=.\client.c
91# End Source File
92# Begin Source File
93
94SOURCE=.\flash.c
95# End Source File
96# Begin Source File
97
98SOURCE=.\uart_boot.c
99# End Source File
100# Begin Source File
101
102SOURCE=.\uart_win.c
103# End Source File
104# End Group
105# Begin Group "Header Files"
106
107# PROP Default_Filter "h;hpp;hxx;hm;inl"
108# Begin Source File
109
110SOURCE=.\client.h
111# End Source File
112# Begin Source File
113
114SOURCE=.\flash.h
115# End Source File
116# Begin Source File
117
118SOURCE=.\minimon.h
119# End Source File
120# Begin Source File
121
122SOURCE=.\scalar_types.h
123# End Source File
124# Begin Source File
125
126SOURCE=.\uart.h
127# End Source File
128# End Group
129# End Target
130# End Project
diff --git a/flash/uart_boot/uart_win.c b/flash/uart_boot/uart_win.c
deleted file mode 100644
index 6e82e9580c..0000000000
--- a/flash/uart_boot/uart_win.c
+++ /dev/null
@@ -1,139 +0,0 @@
1// UART wrapper implementation for the Win32 platform
2// make a new version of this file for different systems, e.g. Linux
3
4#include <windows.h>
5#include "scalar_types.h" // (U)INT8/16/32
6#include "Uart.h"
7
8// COMx for windows, returns NULL on error
9tUartHandle UartOpen(char* szPortName)
10{
11 HANDLE serial_handle;
12 DCB dcb;
13 COMMTIMEOUTS cto = { 0, 0, 0, 0, 0 };
14
15 memset(&dcb,0,sizeof(dcb));
16
17 /* -------------------------------------------------------------------- */
18 // set DCB to configure the serial port
19 dcb.DCBlength = sizeof(dcb);
20
21 dcb.fOutxCtsFlow = 0;
22 dcb.fOutxDsrFlow = 0;
23 dcb.fDtrControl = DTR_CONTROL_ENABLE; // enable for power
24 dcb.fDsrSensitivity = 0;
25 dcb.fRtsControl = RTS_CONTROL_ENABLE; // enable for power
26 dcb.fOutX = 0;
27 dcb.fInX = 0;
28
29 /* ----------------- misc parameters ----- */
30 dcb.fErrorChar = 0;
31 dcb.fBinary = 1;
32 dcb.fNull = 0;
33 dcb.fAbortOnError = 0;
34 dcb.wReserved = 0;
35 dcb.XonLim = 2;
36 dcb.XoffLim = 4;
37 dcb.XonChar = 0x13;
38 dcb.XoffChar = 0x19;
39 dcb.EvtChar = 0;
40
41 /* ----------------- defaults ----- */
42 dcb.BaudRate = 4800;
43 dcb.Parity = NOPARITY;
44 dcb.fParity = 0;
45 dcb.StopBits = ONESTOPBIT;
46 dcb.ByteSize = 8;
47
48
49 /* -------------------------------------------------------------------- */
50 // opening serial port
51 serial_handle = CreateFile(szPortName, GENERIC_READ | GENERIC_WRITE,
52 0, NULL, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, NULL);
53
54 if (serial_handle == INVALID_HANDLE_VALUE)
55 {
56 //printf("Cannot open port \n");
57 return NULL;
58 }
59
60 SetCommMask(serial_handle, 0);
61 SetCommTimeouts(serial_handle, &cto);
62
63 if(!SetCommState(serial_handle, &dcb))
64 {
65 //printf("Error setting up COM params\n");
66 CloseHandle(serial_handle);
67 return NULL;
68 }
69
70 return serial_handle;
71}
72
73// returns true on success, false on error
74bool UartConfig(tUartHandle handle, long lBaudRate, tParity nParity, tStopBits nStopBits, int nByteSize)
75{
76 DCB dcb;
77
78 if (!GetCommState (handle, &dcb))
79 {
80 return false;
81 }
82
83 dcb.BaudRate = lBaudRate;
84 dcb.Parity = nParity;
85 dcb.StopBits = nStopBits;
86 dcb.ByteSize = nByteSize;
87
88 if(!SetCommState(handle, &dcb))
89 {
90 //DWORD dwErr = GetLastError();
91 //printf("Error %d setting up COM params for baudrate byte\n", dwErr);
92 return false;
93 }
94
95 return true;
96}
97
98// returns how much data was actually transmitted
99long UartWrite(tUartHandle handle, unsigned char* pData, long lSize)
100{
101 BOOL success;
102 DWORD result_nbr;
103
104 success = WriteFile(handle, pData, lSize, &result_nbr, NULL);
105
106 if(!success)
107 {
108 return 0;
109 }
110
111 return result_nbr;
112}
113
114// returns how much data was actually received
115long UartRead(tUartHandle handle, unsigned char* pBuffer, long lSize)
116{
117 BOOL success;
118 DWORD read_nbr;
119
120 success = ReadFile(handle, pBuffer, lSize, &read_nbr, NULL);
121 if(!success)
122 {
123 return 0;
124 }
125
126 return read_nbr;
127}
128
129
130void UartClose(tUartHandle handle)
131{
132 if (handle != NULL)
133 {
134 CloseHandle(handle);
135 }
136
137 return;
138}
139