diff --git a/qiboot/include/ports-s3c24xx.h b/qiboot/include/ports-s3c24xx.h new file mode 100644 index 0000000..e784d85 --- /dev/null +++ b/qiboot/include/ports-s3c24xx.h @@ -0,0 +1,41 @@ +#ifndef __PORTS_S3C24XX_H__ +#define __PORTS_S3C24XX_H__ + + +// I/O PORT +#define rGPACON (*(volatile unsigned *)0x56000000) +#define rGPADAT (*(volatile unsigned *)0x56000004) + +#define rGPBCON (*(volatile unsigned *)0x56000010) +#define rGPBDAT (*(volatile unsigned *)0x56000014) +#define rGPBUP (*(volatile unsigned *)0x56000018) + +#define rGPCCON (*(volatile unsigned *)0x56000020) +#define rGPCDAT (*(volatile unsigned *)0x56000024) +#define rGPCUP (*(volatile unsigned *)0x56000028) + +#define rGPDCON (*(volatile unsigned *)0x56000030) +#define rGPDDAT (*(volatile unsigned *)0x56000034) +#define rGPDUP (*(volatile unsigned *)0x56000038) + +#define rGPECON (*(volatile unsigned *)0x56000040) +#define rGPEDAT (*(volatile unsigned *)0x56000044) +#define rGPEUP (*(volatile unsigned *)0x56000048) + +#define rGPFCON (*(volatile unsigned *)0x56000050) +#define rGPFDAT (*(volatile unsigned *)0x56000054) +#define rGPFUP (*(volatile unsigned *)0x56000058) + +#define rGPGCON (*(volatile unsigned *)0x56000060) +#define rGPGDAT (*(volatile unsigned *)0x56000064) +#define rGPGUP (*(volatile unsigned *)0x56000068) + +#define rGPHCON (*(volatile unsigned *)0x56000070) +#define rGPHDAT (*(volatile unsigned *)0x56000074) +#define rGPHUP (*(volatile unsigned *)0x56000078) + +#define rGPJCON (*(volatile unsigned *)0x560000d0) //Port J control +#define rGPJDAT (*(volatile unsigned *)0x560000d4) //Port J data +#define rGPJUP (*(volatile unsigned *)0x560000d8) //Port J data + +#endif diff --git a/qiboot/include/qi.h b/qiboot/include/qi.h index c4094d0..b168ae7 100644 --- a/qiboot/include/qi.h +++ b/qiboot/include/qi.h @@ -22,7 +22,6 @@ #define __QI_H__ #include -#include #include #define u32 unsigned int @@ -62,7 +61,6 @@ struct board_variant { struct board_api { const char * name; - int debug_serial_port; int linux_machine_id; unsigned long linux_mem_start; unsigned long linux_mem_size; @@ -70,6 +68,7 @@ struct board_api { const struct board_variant const * (*get_board_variant)(void); int (*is_this_board)(void); void (*port_init)(void); + void (*putc)(char); struct kernel_source kernel_source[8]; }; diff --git a/qiboot/include/qi-serial.h b/qiboot/include/serial-s3c24xx.h similarity index 67% rename from qiboot/include/qi-serial.h rename to qiboot/include/serial-s3c24xx.h index d674178..6209401 100644 --- a/qiboot/include/qi-serial.h +++ b/qiboot/include/serial-s3c24xx.h @@ -21,8 +21,8 @@ */ -#ifndef __SERIAL_H__ -#define __SERIAL_H__ +#ifndef __SERIAL_S3C24XX_H__ +#define __SERIAL_S3C24XX_H__ #define UART0 0 #define UART1 1 @@ -65,47 +65,8 @@ #define WrUTXH2(ch) (*(volatile unsigned char *)0x50008020)=(unsigned char)(ch) #define RdURXH2() (*(volatile unsigned char *)0x50008024) - - -// I/O PORT -#define rGPACON (*(volatile unsigned *)0x56000000) -#define rGPADAT (*(volatile unsigned *)0x56000004) - -#define rGPBCON (*(volatile unsigned *)0x56000010) -#define rGPBDAT (*(volatile unsigned *)0x56000014) -#define rGPBUP (*(volatile unsigned *)0x56000018) - -#define rGPCCON (*(volatile unsigned *)0x56000020) -#define rGPCDAT (*(volatile unsigned *)0x56000024) -#define rGPCUP (*(volatile unsigned *)0x56000028) - -#define rGPDCON (*(volatile unsigned *)0x56000030) -#define rGPDDAT (*(volatile unsigned *)0x56000034) -#define rGPDUP (*(volatile unsigned *)0x56000038) - -#define rGPECON (*(volatile unsigned *)0x56000040) -#define rGPEDAT (*(volatile unsigned *)0x56000044) -#define rGPEUP (*(volatile unsigned *)0x56000048) - -#define rGPFCON (*(volatile unsigned *)0x56000050) -#define rGPFDAT (*(volatile unsigned *)0x56000054) -#define rGPFUP (*(volatile unsigned *)0x56000058) - -#define rGPGCON (*(volatile unsigned *)0x56000060) -#define rGPGDAT (*(volatile unsigned *)0x56000064) -#define rGPGUP (*(volatile unsigned *)0x56000068) - -#define rGPHCON (*(volatile unsigned *)0x56000070) -#define rGPHDAT (*(volatile unsigned *)0x56000074) -#define rGPHUP (*(volatile unsigned *)0x56000078) - -#define rGPJCON (*(volatile unsigned *)0x560000d0) //Port J control -#define rGPJDAT (*(volatile unsigned *)0x560000d4) //Port J data -#define rGPJUP (*(volatile unsigned *)0x560000d8) //Port J data - -void serial_init(const int uart, const int ubrdiv_val); -void serial_putc(const int uart, const char c); -int printk(const char *fmt, ...); -int puts(const char *string); +extern void serial_init_115200_s3c24xx(const int uart, const int pclk_MHz); +extern void serial_putc_s3c24xx(const int uart, const char c); +extern int puts(const char *string); #endif diff --git a/qiboot/src/drivers/i2c-bitbang-s3c24xx.c b/qiboot/src/drivers/i2c-bitbang-s3c24xx.c index 353dedc..f71dfc4 100644 --- a/qiboot/src/drivers/i2c-bitbang-s3c24xx.c +++ b/qiboot/src/drivers/i2c-bitbang-s3c24xx.c @@ -23,6 +23,7 @@ #include #include +#include static char i2c_read_sda_s3c24xx(void) { diff --git a/qiboot/src/serial.c b/qiboot/src/drivers/serial-s3c24xx.c similarity index 85% rename from qiboot/src/serial.c rename to qiboot/src/drivers/serial-s3c24xx.c index 61b4762..206f0a1 100644 --- a/qiboot/src/serial.c +++ b/qiboot/src/drivers/serial-s3c24xx.c @@ -21,10 +21,11 @@ */ #include -#include "blink_led.h" +#include -void serial_init (const int uart, const int ubrdiv_val) +void serial_init_115200_s3c24xx(const int uart, const int pclk_MHz) { + int div = (((54 * pclk_MHz) + (pclk_MHz / 2)) / 100) -1; switch(uart) { case UART0: @@ -32,20 +33,20 @@ void serial_init (const int uart, const int ubrdiv_val) rUCON0 = 0x245; rUFCON0 = 0x0; rUMCON0 = 0x0; - rUBRDIV0 = ubrdiv_val; + rUBRDIV0 = div; break; case UART1: rULCON1 = 0x3; rUCON1 = 0x245; rUFCON1 = 0x0; rUMCON1 = 0x0; - rUBRDIV1 = ubrdiv_val; + rUBRDIV1 = div; break; case UART2: rULCON2 = 0x3; rUCON2 = 0x245; rUFCON2 = 0x1; - rUBRDIV2 = ubrdiv_val; + rUBRDIV2 = div; break; default: break; @@ -54,7 +55,7 @@ void serial_init (const int uart, const int ubrdiv_val) /* * Output a single byte to the serial port. */ -void serial_putc (const int uart, const char c) +void serial_putc_s3c24xx(const int uart, const char c) { switch(uart) { diff --git a/qiboot/src/gta02/gta02.c b/qiboot/src/gta02/gta02.c index 17c7338..6a2516d 100644 --- a/qiboot/src/gta02/gta02.c +++ b/qiboot/src/gta02/gta02.c @@ -25,8 +25,12 @@ #include #include +#include +#include #include +#define GTA02_DEBUG_UART 2 + #define PCF50633_I2C_ADS 0x73 static const struct board_variant board_variants[] = { @@ -180,11 +184,11 @@ void port_init_gta02(void) "nop\n"\ "nop\n"\ "nop\n"\ - ); + ); /* configure MPLL */ *MPLLCON = ((42 << 12) + (1 << 4) + 0); - serial_init(UART2, (((54 * 50) + 50) / 100) -1); + serial_init_115200_s3c24xx(GTA02_DEBUG_UART, 50 /* 50MHz PCLK */); } /** @@ -254,13 +258,17 @@ const struct board_variant const * get_board_variant_gta02(void) return &board_variants[gta02_get_pcb_revision()]; } +static void putc_gta02(char c) +{ + serial_putc_s3c24xx(GTA02_DEBUG_UART, c); +} + /* * our API for bootloader on this machine */ const struct board_api board_api_gta02 = { .name = "Freerunner / GTA02", - .debug_serial_port = 2, .linux_machine_id = 1304, .linux_mem_start = 0x30000000, .linux_mem_size = (128 * 1024 * 1024), @@ -268,6 +276,7 @@ const struct board_api board_api_gta02 = { .get_board_variant = get_board_variant_gta02, .is_this_board = is_this_board_gta02, .port_init = port_init_gta02, + .putc = putc_gta02, /* these are the ways we could boot GTA02 in order to try */ .kernel_source = { [0] = { diff --git a/qiboot/src/gta03/gta03.c b/qiboot/src/gta03/gta03.c index 1a2c00b..1738856 100644 --- a/qiboot/src/gta03/gta03.c +++ b/qiboot/src/gta03/gta03.c @@ -1,5 +1,13 @@ #include #include +#include +#include +#include + +#define GTA03_DEBUG_UART 2 + +#define PCF50633_I2C_ADS 0x73 + static const struct board_variant board_variants[] = { [0] = { @@ -108,7 +116,7 @@ void port_init_gta03(void) rGPJCON = 0x02AAAAAA; rGPJUP = 0x1FFFF; - serial_init(UART2, 0x11); + serial_init_115200_s3c24xx(GTA03_DEBUG_UART, 33 /*MHz PCLK */); } /** @@ -161,12 +169,18 @@ int is_this_board_gta03(void) /* FIXME: find something gta03 specific */ return 1; } + +static void putc_gta03(char c) +{ + serial_putc_s3c24xx(GTA03_DEBUG_UART, c); +} + + /* * our API for bootloader on this machine */ const struct board_api board_api_gta03 = { .name = "GTA03", - .debug_serial_port = 2, .linux_machine_id = 1808, .linux_mem_start = 0x30000000, .linux_mem_size = (128 * 1024 * 1024), @@ -174,6 +188,7 @@ const struct board_api board_api_gta03 = { .get_board_variant = get_board_variant_gta03, .is_this_board = is_this_board_gta03, .port_init = port_init_gta03, + .putc = putc_gta03, /* these are the ways we could boot GTA03 in order to try */ .kernel_source = { [0] = { diff --git a/qiboot/src/nand_read.c b/qiboot/src/nand_read.c index 6351173..94bf839 100644 --- a/qiboot/src/nand_read.c +++ b/qiboot/src/nand_read.c @@ -71,13 +71,6 @@ static int is_bad_block(unsigned long i) NFCMD = NAND_CMD_READSTART; nand_wait(); data = (NFDATA & 0xff); -#ifdef DEBUG - serial_putc(2, '$'); - serial_putc(2, '0'); - serial_putc(2, 'x'); - print32((unsigned int)data); - serial_putc(2, ' '); -#endif if (data != 0xff) return 1; @@ -138,20 +131,11 @@ int nand_read_ll(unsigned char *buf, unsigned long start_addr, int size) if ((i & (NAND_BLOCK_SIZE - 1)) == 0) { if (is_bad_block(i) || is_bad_block(i + NAND_PAGE_SIZE)) { - serial_putc(2, '!'); - serial_putc(2, '0'); - serial_putc(2, 'x'); - print32((unsigned int)i); - serial_putc(2, ' '); - i += NAND_BLOCK_SIZE; size += NAND_BLOCK_SIZE; - if (bad_count++ == 4) { - serial_putc(2, '+'); - serial_putc(2, '\n'); + if (bad_count++ == 4) return -1; - } - serial_putc(2, '\n'); + continue; } } diff --git a/qiboot/src/qi.lds b/qiboot/src/qi.lds index 29ec63f..bdc1d2c 100644 --- a/qiboot/src/qi.lds +++ b/qiboot/src/qi.lds @@ -37,12 +37,12 @@ SECTIONS . = ALIGN(4); .text : { - src/start.o (.text .rodata* .data) - src/lowlevel_init.o (.text .rodata* .data) - src/start_qi.o (.text .rodata* .data) - src/blink_led.o (.text .rodata* .data) - src/nand_read.o (.text .rodata* .data) - src/serial.o (.text .rodata* .data) + src/start.o (.text .rodata* .data) + src/lowlevel_init.o (.text .rodata* .data) + src/start_qi.o (.text .rodata* .data) + src/blink_led.o (.text .rodata* .data) + src/nand_read.o (.text .rodata* .data) + src/drivers/serial-s3c24xx.o (.text .rodata* .data) } . = ALIGN(4); diff --git a/qiboot/src/utils.c b/qiboot/src/utils.c index ccc14b4..5c945a8 100644 --- a/qiboot/src/utils.c +++ b/qiboot/src/utils.c @@ -57,7 +57,7 @@ unsigned int _ntohl(unsigned int n) { int puts(const char *string) { while (*string) - serial_putc(this_board->debug_serial_port, *string++); + this_board->putc(*string++); return 1; } @@ -66,9 +66,9 @@ int puts(const char *string) void printnybble(unsigned char n) { if (n < 10) - serial_putc(this_board->debug_serial_port, '0' + n); + this_board->putc('0' + n); else - serial_putc(this_board->debug_serial_port, 'a' + n - 10); + this_board->putc('a' + n - 10); } void printhex(unsigned char n) @@ -91,13 +91,13 @@ void hexdump(unsigned char *start, int len) while (len > 0) { print32((int)start); - serial_putc(this_board->debug_serial_port, ':'); - serial_putc(this_board->debug_serial_port, ' '); + this_board->putc(':'); + this_board->putc(' '); for (n = 0; n < 16; n++) { printhex(*start++); - serial_putc(this_board->debug_serial_port, ' '); + this_board->putc(' '); } - serial_putc(this_board->debug_serial_port, '\n'); + this_board->putc('\n'); len -= 16; } }