ia64/linux-2.6.18-xen.hg

annotate drivers/mtd/redboot.c @ 893:f994bfe9b93b

linux/blktap2: reduce TLB flush scope

c/s 885 added very coarse TLB flushing. Since these flushes always
follow single page updates, single page flushes (when available) are
sufficient.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 04 10:32:57 2009 +0100 (2009-06-04)
parents 831230e53067
children
rev   line source
ian@0 1 /*
ian@0 2 * $Id: redboot.c,v 1.21 2006/03/30 18:34:37 bjd Exp $
ian@0 3 *
ian@0 4 * Parse RedBoot-style Flash Image System (FIS) tables and
ian@0 5 * produce a Linux partition array to match.
ian@0 6 */
ian@0 7
ian@0 8 #include <linux/kernel.h>
ian@0 9 #include <linux/slab.h>
ian@0 10 #include <linux/init.h>
ian@0 11 #include <linux/vmalloc.h>
ian@0 12
ian@0 13 #include <linux/mtd/mtd.h>
ian@0 14 #include <linux/mtd/partitions.h>
ian@0 15
ian@0 16 struct fis_image_desc {
ian@0 17 unsigned char name[16]; // Null terminated name
ian@0 18 uint32_t flash_base; // Address within FLASH of image
ian@0 19 uint32_t mem_base; // Address in memory where it executes
ian@0 20 uint32_t size; // Length of image
ian@0 21 uint32_t entry_point; // Execution entry point
ian@0 22 uint32_t data_length; // Length of actual data
ian@0 23 unsigned char _pad[256-(16+7*sizeof(uint32_t))];
ian@0 24 uint32_t desc_cksum; // Checksum over image descriptor
ian@0 25 uint32_t file_cksum; // Checksum over image data
ian@0 26 };
ian@0 27
ian@0 28 struct fis_list {
ian@0 29 struct fis_image_desc *img;
ian@0 30 struct fis_list *next;
ian@0 31 };
ian@0 32
ian@0 33 static int directory = CONFIG_MTD_REDBOOT_DIRECTORY_BLOCK;
ian@0 34 module_param(directory, int, 0);
ian@0 35
ian@0 36 static inline int redboot_checksum(struct fis_image_desc *img)
ian@0 37 {
ian@0 38 /* RedBoot doesn't actually write the desc_cksum field yet AFAICT */
ian@0 39 return 1;
ian@0 40 }
ian@0 41
ian@0 42 static int parse_redboot_partitions(struct mtd_info *master,
ian@0 43 struct mtd_partition **pparts,
ian@0 44 unsigned long fis_origin)
ian@0 45 {
ian@0 46 int nrparts = 0;
ian@0 47 struct fis_image_desc *buf;
ian@0 48 struct mtd_partition *parts;
ian@0 49 struct fis_list *fl = NULL, *tmp_fl;
ian@0 50 int ret, i;
ian@0 51 size_t retlen;
ian@0 52 char *names;
ian@0 53 char *nullname;
ian@0 54 int namelen = 0;
ian@0 55 int nulllen = 0;
ian@0 56 int numslots;
ian@0 57 unsigned long offset;
ian@0 58 #ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED
ian@0 59 static char nullstring[] = "unallocated";
ian@0 60 #endif
ian@0 61
ian@0 62 buf = vmalloc(master->erasesize);
ian@0 63
ian@0 64 if (!buf)
ian@0 65 return -ENOMEM;
ian@0 66
ian@0 67 if ( directory < 0 )
ian@0 68 offset = master->size + directory*master->erasesize;
ian@0 69 else
ian@0 70 offset = directory*master->erasesize;
ian@0 71
ian@0 72 printk(KERN_NOTICE "Searching for RedBoot partition table in %s at offset 0x%lx\n",
ian@0 73 master->name, offset);
ian@0 74
ian@0 75 ret = master->read(master, offset,
ian@0 76 master->erasesize, &retlen, (void *)buf);
ian@0 77
ian@0 78 if (ret)
ian@0 79 goto out;
ian@0 80
ian@0 81 if (retlen != master->erasesize) {
ian@0 82 ret = -EIO;
ian@0 83 goto out;
ian@0 84 }
ian@0 85
ian@0 86 numslots = (master->erasesize / sizeof(struct fis_image_desc));
ian@0 87 for (i = 0; i < numslots; i++) {
ian@0 88 if (!memcmp(buf[i].name, "FIS directory", 14)) {
ian@0 89 /* This is apparently the FIS directory entry for the
ian@0 90 * FIS directory itself. The FIS directory size is
ian@0 91 * one erase block; if the buf[i].size field is
ian@0 92 * swab32(erasesize) then we know we are looking at
ian@0 93 * a byte swapped FIS directory - swap all the entries!
ian@0 94 * (NOTE: this is 'size' not 'data_length'; size is
ian@0 95 * the full size of the entry.)
ian@0 96 */
ian@0 97 if (swab32(buf[i].size) == master->erasesize) {
ian@0 98 int j;
ian@0 99 for (j = 0; j < numslots && buf[j].name[0] != 0xff; ++j) {
ian@0 100 /* The unsigned long fields were written with the
ian@0 101 * wrong byte sex, name and pad have no byte sex.
ian@0 102 */
ian@0 103 swab32s(&buf[j].flash_base);
ian@0 104 swab32s(&buf[j].mem_base);
ian@0 105 swab32s(&buf[j].size);
ian@0 106 swab32s(&buf[j].entry_point);
ian@0 107 swab32s(&buf[j].data_length);
ian@0 108 swab32s(&buf[j].desc_cksum);
ian@0 109 swab32s(&buf[j].file_cksum);
ian@0 110 }
ian@0 111 }
ian@0 112 break;
ian@0 113 }
ian@0 114 }
ian@0 115 if (i == numslots) {
ian@0 116 /* Didn't find it */
ian@0 117 printk(KERN_NOTICE "No RedBoot partition table detected in %s\n",
ian@0 118 master->name);
ian@0 119 ret = 0;
ian@0 120 goto out;
ian@0 121 }
ian@0 122
ian@0 123 for (i = 0; i < numslots; i++) {
ian@0 124 struct fis_list *new_fl, **prev;
ian@0 125
ian@0 126 if (buf[i].name[0] == 0xff)
ian@0 127 continue;
ian@0 128 if (!redboot_checksum(&buf[i]))
ian@0 129 break;
ian@0 130
ian@0 131 new_fl = kmalloc(sizeof(struct fis_list), GFP_KERNEL);
ian@0 132 namelen += strlen(buf[i].name)+1;
ian@0 133 if (!new_fl) {
ian@0 134 ret = -ENOMEM;
ian@0 135 goto out;
ian@0 136 }
ian@0 137 new_fl->img = &buf[i];
ian@0 138 if (fis_origin) {
ian@0 139 buf[i].flash_base -= fis_origin;
ian@0 140 } else {
ian@0 141 buf[i].flash_base &= master->size-1;
ian@0 142 }
ian@0 143
ian@0 144 /* I'm sure the JFFS2 code has done me permanent damage.
ian@0 145 * I now think the following is _normal_
ian@0 146 */
ian@0 147 prev = &fl;
ian@0 148 while(*prev && (*prev)->img->flash_base < new_fl->img->flash_base)
ian@0 149 prev = &(*prev)->next;
ian@0 150 new_fl->next = *prev;
ian@0 151 *prev = new_fl;
ian@0 152
ian@0 153 nrparts++;
ian@0 154 }
ian@0 155 #ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED
ian@0 156 if (fl->img->flash_base) {
ian@0 157 nrparts++;
ian@0 158 nulllen = sizeof(nullstring);
ian@0 159 }
ian@0 160
ian@0 161 for (tmp_fl = fl; tmp_fl->next; tmp_fl = tmp_fl->next) {
ian@0 162 if (tmp_fl->img->flash_base + tmp_fl->img->size + master->erasesize <= tmp_fl->next->img->flash_base) {
ian@0 163 nrparts++;
ian@0 164 nulllen = sizeof(nullstring);
ian@0 165 }
ian@0 166 }
ian@0 167 #endif
ian@0 168 parts = kmalloc(sizeof(*parts)*nrparts + nulllen + namelen, GFP_KERNEL);
ian@0 169
ian@0 170 if (!parts) {
ian@0 171 ret = -ENOMEM;
ian@0 172 goto out;
ian@0 173 }
ian@0 174
ian@0 175 memset(parts, 0, sizeof(*parts)*nrparts + nulllen + namelen);
ian@0 176
ian@0 177 nullname = (char *)&parts[nrparts];
ian@0 178 #ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED
ian@0 179 if (nulllen > 0) {
ian@0 180 strcpy(nullname, nullstring);
ian@0 181 }
ian@0 182 #endif
ian@0 183 names = nullname + nulllen;
ian@0 184
ian@0 185 i=0;
ian@0 186
ian@0 187 #ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED
ian@0 188 if (fl->img->flash_base) {
ian@0 189 parts[0].name = nullname;
ian@0 190 parts[0].size = fl->img->flash_base;
ian@0 191 parts[0].offset = 0;
ian@0 192 i++;
ian@0 193 }
ian@0 194 #endif
ian@0 195 for ( ; i<nrparts; i++) {
ian@0 196 parts[i].size = fl->img->size;
ian@0 197 parts[i].offset = fl->img->flash_base;
ian@0 198 parts[i].name = names;
ian@0 199
ian@0 200 strcpy(names, fl->img->name);
ian@0 201 #ifdef CONFIG_MTD_REDBOOT_PARTS_READONLY
ian@0 202 if (!memcmp(names, "RedBoot", 8) ||
ian@0 203 !memcmp(names, "RedBoot config", 15) ||
ian@0 204 !memcmp(names, "FIS directory", 14)) {
ian@0 205 parts[i].mask_flags = MTD_WRITEABLE;
ian@0 206 }
ian@0 207 #endif
ian@0 208 names += strlen(names)+1;
ian@0 209
ian@0 210 #ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED
ian@0 211 if(fl->next && fl->img->flash_base + fl->img->size + master->erasesize <= fl->next->img->flash_base) {
ian@0 212 i++;
ian@0 213 parts[i].offset = parts[i-1].size + parts[i-1].offset;
ian@0 214 parts[i].size = fl->next->img->flash_base - parts[i].offset;
ian@0 215 parts[i].name = nullname;
ian@0 216 }
ian@0 217 #endif
ian@0 218 tmp_fl = fl;
ian@0 219 fl = fl->next;
ian@0 220 kfree(tmp_fl);
ian@0 221 }
ian@0 222 ret = nrparts;
ian@0 223 *pparts = parts;
ian@0 224 out:
ian@0 225 while (fl) {
ian@0 226 struct fis_list *old = fl;
ian@0 227 fl = fl->next;
ian@0 228 kfree(old);
ian@0 229 }
ian@0 230 vfree(buf);
ian@0 231 return ret;
ian@0 232 }
ian@0 233
ian@0 234 static struct mtd_part_parser redboot_parser = {
ian@0 235 .owner = THIS_MODULE,
ian@0 236 .parse_fn = parse_redboot_partitions,
ian@0 237 .name = "RedBoot",
ian@0 238 };
ian@0 239
ian@0 240 static int __init redboot_parser_init(void)
ian@0 241 {
ian@0 242 return register_mtd_parser(&redboot_parser);
ian@0 243 }
ian@0 244
ian@0 245 static void __exit redboot_parser_exit(void)
ian@0 246 {
ian@0 247 deregister_mtd_parser(&redboot_parser);
ian@0 248 }
ian@0 249
ian@0 250 module_init(redboot_parser_init);
ian@0 251 module_exit(redboot_parser_exit);
ian@0 252
ian@0 253 MODULE_LICENSE("GPL");
ian@0 254 MODULE_AUTHOR("Red Hat, Inc. - David Woodhouse <dwmw2@cambridge.redhat.com>");
ian@0 255 MODULE_DESCRIPTION("Parsing code for RedBoot Flash Image System (FIS) tables");