blob: ac21f565e99fe3bb9a805c7370b835ba92d5c076 [file] [log] [blame]
Dima Zavinf8cefec2009-01-20 19:25:51 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google, Inc. nor the names of its contributors
15 * may be used to endorse or promote products derived from this
16 * software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
25 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <debug.h>
33#include <dev/keys.h>
34#include <dev/gpio_keypad.h>
Dima Zavin9c6992d2009-01-23 16:43:03 -080035#include <lib/ptable.h>
36#include <dev/flash.h>
37
38#define BOARD_FLASH_OFFSET 378
39
Chandan Uddaraju885e4db2009-12-03 22:45:26 -080040#define LINUX_MACHTYPE 0x00000811
41
Dima Zavin9c6992d2009-01-23 16:43:03 -080042static struct ptable flash_ptable;
43
44/* for these partitions, start will be offset by either what we get from
45 * smem, or from the above offset if smem is not useful. Also, we should
46 * probably have smem_ptable code populate our flash_ptable.
47 *
48 * When smem provides us with a full partition table, we can get rid of
49 * this altogether.
50 *
51 */
52static struct ptentry board_part_list[] = {
53 {
54 .start = 0,
Dima Zavin9c6992d2009-01-23 16:43:03 -080055 .length = 40,
56 .name = "boot",
57 },
58 {
Dima Zavin1cf23632009-03-02 17:24:59 -080059 .start = 56,
Dima Zavin9c6992d2009-01-23 16:43:03 -080060 .length = 608 /* 76MB */,
61 .name = "system",
62 },
63 {
Dima Zavin1cf23632009-03-02 17:24:59 -080064 .start = 664,
65 .length = 608 /* 76MB */,
66 .name = "cache",
Dima Zavin9c6992d2009-01-23 16:43:03 -080067 },
68 {
Dima Zavin1cf23632009-03-02 17:24:59 -080069 .start = 1272,
70 .length = 0,
71 .name = "userdata",
Dima Zavin9c6992d2009-01-23 16:43:03 -080072 },
73};
Dima Zavin1cf23632009-03-02 17:24:59 -080074static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry);
Dima Zavin9c6992d2009-01-23 16:43:03 -080075
76void smem_ptable_init(void);
77unsigned smem_get_apps_flash_start(void);
Dima Zavinf8cefec2009-01-20 19:25:51 -080078
79void keypad_init(void);
80
81void target_init(void)
82{
Dima Zavin9c6992d2009-01-23 16:43:03 -080083 unsigned offset;
Dima Zavin1cf23632009-03-02 17:24:59 -080084 struct flash_info *flash_info;
85 int i;
Dima Zavin9c6992d2009-01-23 16:43:03 -080086
Dima Zavinf8cefec2009-01-20 19:25:51 -080087 dprintf(INFO, "target_init()\n");
Dima Zavin9c6992d2009-01-23 16:43:03 -080088
Dima Zavinf8cefec2009-01-20 19:25:51 -080089 keys_init();
90 keypad_init();
Dima Zavin9c6992d2009-01-23 16:43:03 -080091
92 ptable_init(&flash_ptable);
93 smem_ptable_init();
94
Dima Zavine5f64352009-03-02 16:04:20 -080095 flash_init();
Dima Zavin1cf23632009-03-02 17:24:59 -080096 flash_info = flash_get_info();
97 ASSERT(flash_info);
Dima Zavine5f64352009-03-02 16:04:20 -080098
Dima Zavin9c6992d2009-01-23 16:43:03 -080099 offset = smem_get_apps_flash_start();
100 if (offset == 0xffffffff)
101 offset = BOARD_FLASH_OFFSET;
102
Dima Zavin1cf23632009-03-02 17:24:59 -0800103 for (i = 0; i < num_parts; i++) {
104 struct ptentry *ptn = &board_part_list[i];
105 unsigned len = ptn->length;
106
107 if ((len == 0) && (i == num_parts - 1))
108 len = flash_info->num_blocks - offset - ptn->start;
Dima Zavin9c6992d2009-01-23 16:43:03 -0800109 ptable_add(&flash_ptable, ptn->name, offset + ptn->start,
Dima Zavin1cf23632009-03-02 17:24:59 -0800110 len, ptn->flags);
Dima Zavin9c6992d2009-01-23 16:43:03 -0800111 }
112
113 ptable_dump(&flash_ptable);
Dima Zavine5f64352009-03-02 16:04:20 -0800114 flash_set_ptable(&flash_ptable);
Dima Zavinf8cefec2009-01-20 19:25:51 -0800115}
Chandan Uddaraju885e4db2009-12-03 22:45:26 -0800116
117unsigned board_machtype(void)
118{
119 return LINUX_MACHTYPE;
120}