Root/qiboot/src/cpu/s3c2442/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_gta02.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_gta02,
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    this_board->port_init();
100    set_putc_func(this_board->putc);
101
102    /* stick some hello messages on debug console */
103
104    puts("\n\n\nQi Bootloader "stringify2(QI_CPU)" "
105                   stringify2(BUILD_HOST)" "
106                   stringify2(BUILD_VERSION)" "
107                   "\n");
108
109    puts(stringify2(BUILD_DATE) " Copyright (C) 2008 Openmoko, Inc.\n");
110    puts("\n Detected: ");
111
112    puts(this_board->name);
113    puts(", ");
114    puts((this_board->get_board_variant)()->name);
115    puts("\n");
116
117    /*
118     * jump to bootloader_second_phase() running from DRAM copy
119     */
120    bootloader_second_phase();
121
122unhappy:
123    while(1)
124        ;
125
126}
127

Archive Download this file



interactive