From 064a13861c7760b1402e83b94fff01f75a2d9e79 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Fri, 28 Nov 2008 10:16:40 +0000 Subject: [PATCH] qi-refactor-for-multi-cpu-add-s3c6410-base.patch This patch makes qi source structure cpu-centric, and allows multiple CPUs to be handled with the board definitions inside the CPU dirs. You have to make a particular CPU version of Qi now, which you can do by a shell command like this: make clean ; make CPU=s3c2442 && make CPU=s3c6410 which gets you $ ls -l image/ total 744 -rwxrwxr-x 1 agreen agreen 25372 2008-10-17 18:25 qi-s3c2442-andy_77c1fcdddc3e2cbf -rw-rw-r-- 1 agreen agreen 237100 2008-10-17 18:25 qi-s3c2442-andy_77c1fcdddc3e2cbf.dis -rw-rw-r-- 1 agreen agreen 25388 2008-10-17 18:25 qi-s3c2442-andy_77c1fcdddc3e2cbf.udfu -rwxrwxr-x 1 agreen agreen 22736 2008-10-17 18:25 qi-s3c6410-andy_77c1fcdddc3e2cbf -rw-rw-r-- 1 agreen agreen 216294 2008-10-17 18:25 qi-s3c6410-andy_77c1fcdddc3e2cbf.dis -rw-rw-r-- 1 agreen agreen 22752 2008-10-17 18:25 qi-s3c6410-andy_77c1fcdddc3e2cbf.udfu The 6410 support in there is enough to send a character "U" on the 6410 SMDK Because the product naming is not defined, currently the device targeted for 6410 is called "TLA01" Signed-off-by: Andy Green --- qiboot/Makefile | 15 ++-- qiboot/include/qi.h | 7 ++ qiboot/src/gta03/gta03.c | 2 +- qiboot/src/nand_read.c | 153 --------------------------------------- qiboot/src/nand_read.h | 22 ------ qiboot/src/phase2.c | 25 ++++++- qiboot/src/qi.lds | 59 --------------- qiboot/src/start.S | 35 ++++++++- qiboot/src/start_qi.c | 129 --------------------------------- 9 files changed, 72 insertions(+), 375 deletions(-) delete mode 100644 qiboot/src/nand_read.c delete mode 100644 qiboot/src/nand_read.h delete mode 100644 qiboot/src/qi.lds delete mode 100644 qiboot/src/start_qi.c diff --git a/qiboot/Makefile b/qiboot/Makefile index 1adfaab..b43e958 100644 --- a/qiboot/Makefile +++ b/qiboot/Makefile @@ -22,7 +22,7 @@ BUILD_BRANCH := $(shell git branch | grep ^\* | cut -d' ' -f2) BUILD_HEAD := $(shell git show --pretty=oneline | head -n1 | cut -d' ' -f1 | cut -b1-16) BUILD_VERSION := ${BUILD_BRANCH}_${BUILD_HEAD} -LDS = src/qi.lds +LDS = src/cpu/$(CPU)/qi.lds INCLUDE = include IMAGE_DIR = image TOOLS = tools @@ -33,10 +33,11 @@ CFLAGS = -Wall -Werror -I $(INCLUDE) -g -c -Os -fno-strict-aliasing -mlong-calls -DBUILD_DATE="${BUILD_DATE}" LDFLAGS = -S_SRCS = src/start.S src/lowlevel_init.S +S_SRCS = src/cpu/$(CPU)/start.S src/lowlevel_init.S S_OBJS = $(patsubst %.S,%.o, $(S_SRCS)) -C_SRCS = $(wildcard src/*.c) $(wildcard src/gt*/*.c) \ - $(wildcard src/drivers/*.c) $(wildcard src/fs/*.c) +C_SRCS = $(wildcard src/*.c) \ + $(wildcard src/drivers/*.c) $(wildcard src/fs/*.c) \ + $(wildcard src/cpu/$(CPU)/*.c) C_OBJS = $(patsubst %.c,%.o, $(C_SRCS)) SRCS = ${S_SRCS} ${C_SRCS} @@ -48,9 +49,9 @@ UDFU_VID = 0x1d50 UDFU_PID = 0x5119 UDFU_REV = 0x350 -TARGET = image/start_qi_all -IMAGE = $(IMAGE_DIR)/qi-$(BUILD_VERSION) -UDFU_IMAGE = $(IMAGE_DIR)/qi-$(BUILD_VERSION).udfu +TARGET = image/start_qi_all-$(CPU) +IMAGE = $(IMAGE_DIR)/qi-$(CPU)-$(BUILD_VERSION) +UDFU_IMAGE = $(IMAGE_DIR)/qi-$(CPU)-$(BUILD_VERSION).udfu MKUDFU = $(TOOLS)/mkudfu diff --git a/qiboot/include/qi.h b/qiboot/include/qi.h index 1db3248..652bb23 100644 --- a/qiboot/include/qi.h +++ b/qiboot/include/qi.h @@ -78,6 +78,13 @@ struct board_api { struct kernel_source kernel_source[8]; }; +/* these are the boards we support for a given CPU */ + +struct cpu_supported_boards { + const u32 cpu_id; + const struct board_api **boards; +}; + /* this is the board we are running on */ extern struct board_api const * this_board; diff --git a/qiboot/src/gta03/gta03.c b/qiboot/src/gta03/gta03.c index 2ee037c..4c58ee3 100644 --- a/qiboot/src/gta03/gta03.c +++ b/qiboot/src/gta03/gta03.c @@ -220,7 +220,7 @@ static void putc_gta03(char c) * our API for bootloader on this machine */ const struct board_api board_api_gta03 = { - .name = "GTA03", + .name = "GTA03-2442", .linux_machine_id = 1866, .linux_mem_start = 0x30000000, .linux_mem_size = (128 * 1024 * 1024), diff --git a/qiboot/src/nand_read.c b/qiboot/src/nand_read.c deleted file mode 100644 index cb2a2de..0000000 --- a/qiboot/src/nand_read.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - * nand_read.c: Simple NAND read functions for booting from NAND - * - * This is used by cpu/arm920/start.S assembler code, - * and the board-specific linker script must make sure this - * file is linked within the first 4kB of NAND flash. - * - * Taken from GPLv2 licensed vivi bootloader, - * Copyright (C) 2002 MIZI Research, Inc. - * - * Author: Hwang, Chideok - * Date : $Date: 2004/02/04 10:37:37 $ - * - * u-boot integration and bad-block skipping (C) 2006 by OpenMoko, Inc. - * Author: Harald Welte - */ - -/* NOTE this stuff runs in steppingstone context! */ - -/* the API refers to 512-byte blocks */ - -#include -#include "nand_read.h" - -#define NAND_CMD_READ0 0 -#define NAND_CMD_READSTART 0x30 - -#define __REGb(x) (*(volatile unsigned char *)(x)) -#define __REGw(x) (*(volatile unsigned short *)(x)) -#define __REGi(x) (*(volatile unsigned int *)(x)) -#define NF_BASE 0x4e000000 -#define NFCONF __REGi(NF_BASE + 0x0) -#define NFCONT __REGi(NF_BASE + 0x4) -#define NFCMD __REGb(NF_BASE + 0x8) -#define NFADDR __REGb(NF_BASE + 0xc) -#define NFDATA __REGb(NF_BASE + 0x10) -#define NFDATA16 __REGw(NF_BASE + 0x10) -#define NFSTAT __REGb(NF_BASE + 0x20) -#define NFSTAT_BUSY 1 -#define nand_select() (NFCONT &= ~(1 << 1)) -#define nand_deselect() (NFCONT |= (1 << 1)) -#define nand_clear_RnB() (NFSTAT |= (1 << 2)) - -static inline void nand_wait(void) -{ - int i; - - while (!(NFSTAT & NFSTAT_BUSY)) - for (i=0; i<10; i++); -} - -/* configuration for 2440 with 2048byte sized flash */ -#define NAND_5_ADDR_CYCLE -#define NAND_PAGE_SIZE 2048 -#define BAD_BLOCK_OFFSET NAND_PAGE_SIZE -#define NAND_BLOCK_MASK (NAND_PAGE_SIZE - 1) -#define NAND_BLOCK_SIZE (NAND_PAGE_SIZE * 64) - -static int is_bad_block(unsigned long block_index) -{ - unsigned char data; - unsigned long page_num; - - nand_clear_RnB(); - page_num = block_index >> 2; /* addr / 2048 */ - NFCMD = NAND_CMD_READ0; - NFADDR = BAD_BLOCK_OFFSET & 0xff; - NFADDR = (BAD_BLOCK_OFFSET >> 8) & 0xff; - NFADDR = page_num & 0xff; - NFADDR = (page_num >> 8) & 0xff; - NFADDR = (page_num >> 16) & 0xff; - NFCMD = NAND_CMD_READSTART; - nand_wait(); - data = (NFDATA & 0xff); - - if (data != 0xff) - return 1; - - return 0; -} - -static int nand_read_page_ll(unsigned char *buf, unsigned long block512) -{ - unsigned short *ptr16 = (unsigned short *)buf; - unsigned int i, page_num; -#if 0 - unsigned char ecc[64]; - unsigned short *p16 = (unsigned short *)ecc; -#endif - - nand_clear_RnB(); - - NFCMD = NAND_CMD_READ0; - - page_num = block512 >> 2; /* 512 block -> 2048 block */ - /* Write Address */ - NFADDR = 0; - NFADDR = 0; - NFADDR = page_num & 0xff; - NFADDR = (page_num >> 8) & 0xff; - NFADDR = (page_num >> 16) & 0xff; - NFCMD = NAND_CMD_READSTART; - nand_wait(); - - for (i = 0; i < NAND_PAGE_SIZE/2; i++) - *ptr16++ = NFDATA16; -#if 0 - for (i = 0; i < 64 / 2; i++) { - *p16++ = NFDATA16; - } -#endif - return 4; -} - -/* low level nand read function */ -int nand_read_ll(unsigned char *buf, unsigned long start_block512, - int blocks512) -{ - int i, j; - int bad_count = 0; - - if (start_block512 & 3) /* inside 2048-byte block */ - return -1; - - /* chip Enable */ - nand_select(); - nand_clear_RnB(); - - for (i = 0; i < 10; i++) - ; - - while (blocks512 > 0) { - if (is_bad_block(start_block512) || - is_bad_block(start_block512 + 4)) { - start_block512 += 4; - blocks512 += 4; - if (bad_count++ == 4) - return -1; - continue; - } - - j = nand_read_page_ll(buf, start_block512); - start_block512 += j; - buf += j << 9; - blocks512 -= j; - } - - /* chip Disable */ - nand_deselect(); - - return 0; -} - diff --git a/qiboot/src/nand_read.h b/qiboot/src/nand_read.h deleted file mode 100644 index 71aeda5..0000000 --- a/qiboot/src/nand_read.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * nand_read.c: Simple NAND read functions for booting from NAND - * - * This is used by cpu/arm920/start.S assembler code, - * and the board-specific linker script must make sure this - * file is linked within the first 4kB of NAND flash. - * - * Taken from GPLv2 licensed vivi bootloader, - * Copyright (C) 2002 MIZI Research, Inc. - * - * Author: Hwang, Chideok - * Date : $Date: 2004/02/04 10:37:37 $ - * - * u-boot integration and bad-block skipping (C) 2006 by OpenMoko, Inc. - * Author: Harald Welte - */ -#ifndef __NAND_READ_H -#define __NAND_READ_H - -int nand_read_ll(unsigned char *buf, unsigned long start_addr, int size); - -#endif /* __NAND_READ_H */ diff --git a/qiboot/src/phase2.c b/qiboot/src/phase2.c index 8284541..40053ff 100644 --- a/qiboot/src/phase2.c +++ b/qiboot/src/phase2.c @@ -28,9 +28,12 @@ #define __ARM__ #include #include -#include "nand_read.h" #include +#define stringify2(s) stringify1(s) +#define stringify1(s) #s + + unsigned long partition_offset_blocks = 0; unsigned long partition_length_blocks = 0; @@ -44,6 +47,26 @@ void bootloader_second_phase(void) const struct board_variant * board_variant = (this_board->get_board_variant)(); + /* okay, do the critical port and serial init for our board */ + + this_board->port_init(); + + /* stick some hello messages on debug console */ + + puts("\n\n\nQi Bootloader "stringify2(BUILD_HOST)" " + stringify2(BUILD_VERSION)" " + stringify2(BUILD_DATE)"\n"); + + puts("Copyright (C) 2008 Openmoko, Inc.\n"); + puts("This is free software; see the source for copying conditions.\n" + "There is NO warranty; not even for MERCHANTABILITY or " + "FITNESS FOR A PARTICULAR PURPOSE.\n\n Detected: "); + + puts(this_board->name); + puts(", "); + board_variant = (this_board->get_board_variant)(); + puts(board_variant->name); + /* we try the possible kernels for this board in order */ this_kernel = &this_board->kernel_source[kernel++]; diff --git a/qiboot/src/qi.lds b/qiboot/src/qi.lds deleted file mode 100644 index bdc1d2c..0000000 --- a/qiboot/src/qi.lds +++ /dev/null @@ -1,59 +0,0 @@ -/* - * (C) Copyright 2002 - * Gary Jennejohn, DENX Software Engineering, - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") -/*OUTPUT_FORMAT("elf32-arm", "elf32-arm", "elf32-arm")*/ -OUTPUT_ARCH(arm) -ENTRY(_start) -SECTIONS -{ - . = 0x00000000; - - /* this is intended to take the first 4KBytes of stuff initially. - * We have to make sure we have .rodata* in there for everything - * because we do not compile PIC. - */ - - . = 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/drivers/serial-s3c24xx.o (.text .rodata* .data) - } - - . = ALIGN(4); - .everything_else ADDR (.text) + SIZEOF (.text) + 0x33000000 : - AT ( ADDR (.text) + SIZEOF (.text) ) { *(.text .rodata* .data) } - - . = 0x33800000 ; - __bss_start = .; - .bss (NOLOAD) : - { - *(.bss) - } - _end = .; -} diff --git a/qiboot/src/start.S b/qiboot/src/start.S index cf15645..a16e9a5 100644 --- a/qiboot/src/start.S +++ b/qiboot/src/start.S @@ -27,10 +27,12 @@ #define S3C2410_MISCCR_nEN_SCLKE (1 << 19) -.globl _start + +.globl _start, processor_id, is_jtag + _start: b start_code /* if we are injected by JTAG, the script sets _istag content to nonzero */ -_is_jtag: +is_jtag: .word 0 /* it's at a fixed address (+0x8) so we can breakpoint it in the JTAG script @@ -47,6 +49,11 @@ _start_armboot: _TEXT_BASE: .word TEXT_BASE +processor_id: + .word 0 + .word 0x41129200 /* s3c2442 ID */ + .word 0x410fb760 /* s3c6410 ID */ + /* * These are defined in the board-specific linker script. */ @@ -66,7 +73,29 @@ start_code: bic r0,r0,#0x1f orr r0,r0,#0xd3 msr cpsr,r0 - + + /* + * detect processor we are running on + * s3c2442: 0x4112920x + * s3c6410: 0x410fb76x + */ + MRC p15, 0 ,r0, c0, c0, 0 + ldr r1, =processor_id + str r0, [r1] + ldr r2, [r1, #4] + + and r0, #0xfffffff0 + cmp r0, r2 + beq startup_2442 + + /* 6410 startup */ +startup_6410: + + mov r0, #0 + str r0, [r1] + + /* 2442 startup */ +startup_2442: # define pWTCON 0x53000000 ldr r0, =pWTCON diff --git a/qiboot/src/start_qi.c b/qiboot/src/start_qi.c deleted file mode 100644 index ac7d42e..0000000 --- a/qiboot/src/start_qi.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * (C) Copyright 2007 OpenMoko, Inc. - * Author: xiangfu liu - * Andy Green - * - * Configuation settings for the OPENMOKO Neo GTA02 Linux GSM phone - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -/* NOTE this stuff runs in steppingstone context! */ - - -#include -#include "blink_led.h" -#include "nand_read.h" -#include -#include - -#define stringify2(s) stringify1(s) -#define stringify1(s) #s - -extern void bootloader_second_phase(void); - -const struct board_api * boards[] = { - &board_api_gta02, - &board_api_gta03, -}; - -struct board_api const * this_board; - -void start_qi(void) -{ - int n = 0; - int board = 0; - const struct board_variant * board_variant; - const u32 * p_is_jtag = (const u32 *)4; - - /* - * well, we can be running on this CPU two different ways. - * - * 1) We were copied into steppingstone and TEXT_BASE already - * by JTAG. We don't have to do anything else. JTAG script - * then sets data at address 0x4 to 0xffffffff as a signal we - * are running by JTAG. - * - * 2) We only got our first 4K into steppingstone, we need to copy - * the rest of ourselves into TEXT_BASE. - * - * So we do the copy out of NAND only if we see we did not come up - * under control of JTAG. - */ - - if (!*p_is_jtag) - /* - * We got the first 4KBytes of the bootloader pulled into the - * steppingstone SRAM for free. Now we pull the whole bootloader - * image into SDRAM. - * - * This code and the .S files are arranged by the linker script - * to expect to run from 0x0. But the linker script has told - * everything else to expect to run from 0x33000000+. That's - * why we are going to be able to copy this code and not have it - * crash when we run it from there. - */ - - /* We randomly pull 32KBytes of bootloader */ - if (nand_read_ll((u8 *)TEXT_BASE, 0, 32 * 1024 / 512) < 0) - goto unhappy; - - /* ask all the boards we support in turn if they recognize this - * hardware we are running on, accept the first positive answer - */ - - this_board = boards[board]; - while (!n) { - if (board > ARRAY_SIZE(boards)) - /* can't put diagnostic on serial... too early */ - goto unhappy; - - if (this_board->is_this_board()) - n = 1; - else - this_board = boards[board++]; - } - - /* okay, do the critical port and serial init for our board */ - - this_board->port_init(); - - /* stick some hello messages on debug console */ - - puts("\n\n\nQi Bootloader "stringify2(BUILD_HOST)" " - stringify2(BUILD_VERSION)" " - stringify2(BUILD_DATE)"\n"); - - puts("Copyright (C) 2008 Openmoko, Inc.\n"); - puts("This is free software; see the source for copying conditions.\n" - "There is NO warranty; not even for MERCHANTABILITY or " - "FITNESS FOR A PARTICULAR PURPOSE.\n\n Detected: "); - - puts(this_board->name); - puts(", "); - board_variant = (this_board->get_board_variant)(); - puts(board_variant->name); - - /* - * jump to bootloader_second_phase() running from DRAM copy - */ - bootloader_second_phase(); - -unhappy: - while(1) - blink_led(); - -}