blob: e559ef894f46a137a00204da824cd5021d1e34cc [file] [log] [blame]
Dima Zavind0850132009-01-26 20:02:33 -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>
35#include <lib/ptable.h>
36#include <dev/flash.h>
37
38#define BOARD_FLASH_OFFSET 378
39
40static struct ptable flash_ptable;
41
42/* for these partitions, start will be offset by either what we get from
43 * smem, or from the above offset if smem is not useful. Also, we should
44 * probably have smem_ptable code populate our flash_ptable.
45 *
46 * When smem provides us with a full partition table, we can get rid of
47 * this altogether.
48 *
49 */
50static struct ptentry board_part_list[] = {
51 {
52 .start = 0,
Dima Zavind0850132009-01-26 20:02:33 -080053 .length = 40,
54 .name = "boot",
55 },
56 {
Dima Zavin1cf23632009-03-02 17:24:59 -080057 .start = 56,
Dima Zavind0850132009-01-26 20:02:33 -080058 .length = 608 /* 76MB */,
59 .name = "system",
60 },
61 {
Dima Zavin1cf23632009-03-02 17:24:59 -080062 .start = 664,
63 .length = 608 /* 76MB */,
64 .name = "cache",
Dima Zavind0850132009-01-26 20:02:33 -080065 },
66 {
Dima Zavin1cf23632009-03-02 17:24:59 -080067 .start = 1272,
68 .length = 0,
69 .name = "userdata",
Dima Zavind0850132009-01-26 20:02:33 -080070 },
71};
Dima Zavin1cf23632009-03-02 17:24:59 -080072static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry);
Dima Zavind0850132009-01-26 20:02:33 -080073
74void smem_ptable_init(void);
75unsigned smem_get_apps_flash_start(void);
76
77void keypad_init(void);
78
79void target_init(void)
80{
Dima Zavind0850132009-01-26 20:02:33 -080081 unsigned offset;
Dima Zavin1cf23632009-03-02 17:24:59 -080082 struct flash_info *flash_info;
83 int i;
Dima Zavind0850132009-01-26 20:02:33 -080084
85 dprintf(INFO, "target_init()\n");
86
87 keys_init();
88 keypad_init();
89
90 ptable_init(&flash_ptable);
91 smem_ptable_init();
92
Dima Zavine5f64352009-03-02 16:04:20 -080093 flash_init();
Dima Zavin1cf23632009-03-02 17:24:59 -080094 flash_info = flash_get_info();
95 ASSERT(flash_info);
Dima Zavine5f64352009-03-02 16:04:20 -080096
Dima Zavind0850132009-01-26 20:02:33 -080097 offset = smem_get_apps_flash_start();
98 if (offset == 0xffffffff)
99 offset = BOARD_FLASH_OFFSET;
100
Dima Zavin1cf23632009-03-02 17:24:59 -0800101 for (i = 0; i < num_parts; i++) {
102 struct ptentry *ptn = &board_part_list[i];
103 unsigned len = ptn->length;
104
105 if ((len == 0) && (i == num_parts - 1))
106 len = flash_info->num_blocks - offset - ptn->start;
Dima Zavind0850132009-01-26 20:02:33 -0800107 ptable_add(&flash_ptable, ptn->name, offset + ptn->start,
Dima Zavin1cf23632009-03-02 17:24:59 -0800108 len, ptn->flags);
Dima Zavind0850132009-01-26 20:02:33 -0800109 }
110
111 ptable_dump(&flash_ptable);
Dima Zavine5f64352009-03-02 16:04:20 -0800112 flash_set_ptable(&flash_ptable);
Dima Zavind0850132009-01-26 20:02:33 -0800113}