Root/qiboot/src/cpu/s3c2410/start_qi.c

1/*
2 * (C) Copyright 2007 OpenMoko, Inc.
3 * Author: xiangfu liu <xiangfu@openmoko.org>
4 * Andy Green <andy@openmoko.com>
5 *
6 * Configuation settings for the OPENMOKO Neo GTA02 Linux GSM phone
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24/* NOTE this stuff runs in steppingstone context! */
25
26
27#include <qi.h>
28#include "nand_read.h"
29#include <neo_gta01.h>
30
31#define stringify2(s) stringify1(s)
32#define stringify1(s) #s
33
34
35extern void bootloader_second_phase(void);
36
37const struct board_api *boards[] = {
38            &board_api_gta01,
39            NULL /* always last */
40};
41
42
43struct board_api const * this_board;
44extern int is_jtag;
45
46void start_qi(void)
47{
48    int flag = 0;
49    int board = 0;
50
51    /*
52     * well, we can be running on this CPU two different ways.
53     *
54     * 1) We were copied into steppingstone and TEXT_BASE already
55     * by JTAG. We don't have to do anything else. JTAG script
56     * then sets data at address 0x4 to 0xffffffff as a signal we
57     * are running by JTAG.
58     *
59     * 2) We only got our first 4K into steppingstone, we need to copy
60     * the rest of ourselves into TEXT_BASE.
61     *
62     * So we do the copy out of NAND only if we see we did not come up
63     * under control of JTAG.
64     */
65
66    if (!is_jtag)
67        /*
68        * We got the first 4KBytes of the bootloader pulled into the
69        * steppingstone SRAM for free. Now we pull the whole bootloader
70        * image into SDRAM.
71        *
72        * This code and the .S files are arranged by the linker script
73        * to expect to run from 0x0. But the linker script has told
74        * everything else to expect to run from 0x33000000+. That's
75        * why we are going to be able to copy this code and not have it
76        * crash when we run it from there.
77        */
78
79        /* We randomly pull 32KBytes of bootloader */
80        if (nand_read_ll((u8 *)TEXT_BASE, 0, 32 * 1024 / 512) < 0)
81            goto unhappy;
82
83    /* ask all the boards we support in turn if they recognize this
84     * hardware we are running on, accept the first positive answer
85     */
86
87    this_board = boards[board];
88    while (!flag && this_board) {
89
90        /* check if it is the right board... */
91        if (this_board->is_this_board()) {
92            flag = 1;
93            continue;
94        }
95
96        this_board = boards[board++];
97    }
98
99    /* No valid board found */
100    if (!this_board)
101        goto unhappy;
102
103    this_board->port_init();
104    set_putc_func(this_board->putc);
105
106    /* stick some hello messages on debug console */
107
108    puts("\n\n\nQi Bootloader "stringify2(QI_CPU)" "
109                   stringify2(BUILD_HOST)" "
110                   stringify2(BUILD_VERSION)" "
111                   "\n");
112
113    puts(stringify2(BUILD_DATE) " Copyright (C) 2008 Openmoko, Inc.\n");
114    puts("\n Detected: ");
115
116    puts(this_board->name);
117    puts(", ");
118    puts((this_board->get_board_variant)()->name);
119    puts("\n");
120
121    
122    /*
123     * jump to bootloader_second_phase() running from DRAM copy
124     */
125    bootloader_second_phase();
126
127unhappy:
128    while(1)
129        ;
130
131}
132

Archive Download this file



interactive