blob: d448aed5cfa6fe620cadf3377f728e264837ddb0 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* arch/arm/mach-msm/nand_partitions.c
2 *
3 * Code to extract partition information from ATAG set up by the
4 * bootloader.
5 *
6 * Copyright (C) 2007 Google, Inc.
7 * Copyright (c) 2008-2009, Code Aurora Forum. All rights reserved.
8 * Author: Brian Swetland <swetland@google.com>
9 *
10 * This software is licensed under the terms of the GNU General Public
11 * License version 2, as published by the Free Software Foundation, and
12 * may be copied, distributed, and modified under those terms.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 */
20
21#include <linux/kernel.h>
22#include <linux/init.h>
23#include <linux/platform_device.h>
24
25#include <asm/mach/flash.h>
26#include <linux/io.h>
27
28#include <asm/setup.h>
29
30#include <linux/mtd/nand.h>
31#include <linux/mtd/partitions.h>
32
33#include <mach/msm_iomap.h>
34
35#include <mach/board.h>
36#include "smd_private.h"
37
38/* configuration tags specific to msm */
39
40#define ATAG_MSM_PARTITION 0x4d534D70 /* MSMp */
41
42struct msm_ptbl_entry {
43 char name[16];
44 __u32 offset;
45 __u32 size;
46 __u32 flags;
47};
48
49#define MSM_MAX_PARTITIONS 8
50
51static struct mtd_partition msm_nand_partitions[MSM_MAX_PARTITIONS];
52static char msm_nand_names[MSM_MAX_PARTITIONS * 16];
53
54extern struct flash_platform_data msm_nand_data;
55
56static int __init parse_tag_msm_partition(const struct tag *tag)
57{
58 struct mtd_partition *ptn = msm_nand_partitions;
59 char *name = msm_nand_names;
60 struct msm_ptbl_entry *entry = (void *) &tag->u;
61 unsigned count, n;
62
63 count = (tag->hdr.size - 2) /
64 (sizeof(struct msm_ptbl_entry) / sizeof(__u32));
65
66 if (count > MSM_MAX_PARTITIONS)
67 count = MSM_MAX_PARTITIONS;
68
69 for (n = 0; n < count; n++) {
70 memcpy(name, entry->name, 15);
71 name[15] = 0;
72
73 ptn->name = name;
74 ptn->offset = entry->offset;
75 ptn->size = entry->size;
76
77 printk(KERN_INFO "Partition (from atag) %s "
78 "-- Offset:%llx Size:%llx\n",
79 ptn->name, ptn->offset, ptn->size);
80
81 name += 16;
82 entry++;
83 ptn++;
84 }
85
86 msm_nand_data.nr_parts = count;
87 msm_nand_data.parts = msm_nand_partitions;
88
89 return 0;
90}
91
92__tagtable(ATAG_MSM_PARTITION, parse_tag_msm_partition);
93
94#define FLASH_PART_MAGIC1 0x55EE73AA
95#define FLASH_PART_MAGIC2 0xE35EBDDB
96#define FLASH_PARTITION_VERSION 0x3
97
98#define LINUX_FS_PARTITION_NAME "0:EFS2APPS"
99
100struct flash_partition_entry {
101 char name[16];
102 u32 offset; /* Offset in blocks from beginning of device */
103 u32 length; /* Length of the partition in blocks */
104 u8 attrib1;
105 u8 attrib2;
106 u8 attrib3;
107 u8 which_flash; /* Numeric ID (first = 0, second = 1) */
108};
109struct flash_partition_table {
110 u32 magic1;
111 u32 magic2;
112 u32 version;
113 u32 numparts;
114 struct flash_partition_entry part_entry[16];
115};
116
117static int get_nand_partitions(void)
118{
119 struct flash_partition_table *partition_table;
120 struct flash_partition_entry *part_entry;
121 struct mtd_partition *ptn = msm_nand_partitions;
122 char *name = msm_nand_names;
123 int part;
124
125 if (msm_nand_data.nr_parts)
126 return 0;
127
128 partition_table = (struct flash_partition_table *)
129 smem_alloc(SMEM_AARM_PARTITION_TABLE,
130 sizeof(struct flash_partition_table));
131
132 if (!partition_table) {
133 printk(KERN_WARNING "%s: no flash partition table in shared "
134 "memory\n", __func__);
135 return -ENOENT;
136 }
137
138 if ((partition_table->magic1 != (u32) FLASH_PART_MAGIC1) ||
139 (partition_table->magic2 != (u32) FLASH_PART_MAGIC2) ||
140 (partition_table->version != (u32) FLASH_PARTITION_VERSION)) {
141 printk(KERN_WARNING "%s: version mismatch -- magic1=%#x, "
142 "magic2=%#x, version=%#x\n", __func__,
143 partition_table->magic1,
144 partition_table->magic2,
145 partition_table->version);
146 return -EFAULT;
147 }
148
149 msm_nand_data.nr_parts = 0;
150
151 /* Get the LINUX FS partition info */
152 for (part = 0; part < partition_table->numparts; part++) {
153 part_entry = &partition_table->part_entry[part];
154
155 /* Find a match for the Linux file system partition */
156 if (strcmp(part_entry->name, LINUX_FS_PARTITION_NAME) == 0) {
157 strcpy(name, part_entry->name);
158 ptn->name = name;
159
160 /*TODO: Get block count and size info */
161 ptn->offset = part_entry->offset;
162
163 /* For SMEM, -1 indicates remaining space in flash,
164 * but for MTD it is 0
165 */
166 if (part_entry->length == (u32)-1)
167 ptn->size = 0;
168 else
169 ptn->size = part_entry->length;
170
171 msm_nand_data.nr_parts = 1;
172 msm_nand_data.parts = msm_nand_partitions;
173
174 printk(KERN_INFO "Partition(from smem) %s "
175 "-- Offset:%llx Size:%llx\n",
176 ptn->name, ptn->offset, ptn->size);
177
178 return 0;
179 }
180 }
181
182 printk(KERN_WARNING "%s: no partition table found!", __func__);
183
184 return -ENODEV;
185}
186
187device_initcall(get_nand_partitions);