Advertisement
Guest User

droid001

a guest
Feb 2nd, 2010
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.73 KB | None | 0 0
  1. /*
  2.  * This modules maps additional mtd partions of the Motorola Milestone
  3.  *
  4.  * Copyright (C) 2010 Janne Grunau
  5.  * Copyright (C) 2010 Mike Baker
  6.  *
  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
  10.  * as published by the Free Software Foundation; either version 2
  11.  * of 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  21.  *
  22.  */
  23.  
  24.  
  25. #include <linux/module.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/err.h>
  28. #include <linux/mtd/mtd.h>
  29. #include <linux/mtd/partitions.h>
  30.  
  31. #define mtd_hack_part(pname, psize) .name       = pname,              \
  32.                     .size       = psize * 1024,       \
  33.                     .offset     = MTDPART_OFS_APPEND, \
  34.                     .mask_flags = MTD_WRITEABLE,
  35.  
  36. #define mtd_hack_partw(pname, psize)     .name       = pname,              \
  37.                     .size       = psize * 1024,       \
  38.                     .offset     = MTDPART_OFS_APPEND, \
  39.  
  40.  
  41. /* MTD partition layout:
  42.  *
  43.  * mtdparts=omap2-nand.0:
  44.  *     128k(mbmloader),
  45.  *     640k(mbm),
  46.  *     640k(mbmbackup),
  47.  *     384k(bploader),
  48.  *     384k(cdt),
  49.  *     1536k(pds),
  50.  *     384k(lbl),
  51.  *     384k(lbl_backup),
  52.  *     384k(cid),
  53.  *     1536k(sp),
  54.  *     384k(devtree),
  55.  *     640k(logo),
  56.  *     384k(misc),
  57.  *     3584k(boot),
  58.  *     3840k(bpsw),
  59.  *     4608k(recovery),
  60.  *     8960k(cdrom),
  61.  *     384k(unused0),
  62.  *     179840k(system),
  63.  *     384k(unused1),
  64.  *     106m(cache),
  65.  *     201856k(userdata),
  66.  *     1536k(cust),
  67.  *     384k(unused2),
  68.  *     2m(kpanic),
  69.  *     512k(rsv)
  70.  *
  71.  */
  72.  
  73.  
  74. struct mtd_partition part[] = {
  75.     {   mtd_hack_part("h_mbmloader", 128)},
  76.     {   mtd_hack_part("h_mbm",       640)},
  77.     {   mtd_hack_partw("h_mbmbackup", 640)},
  78.         {   mtd_hack_part("h_bploader",  384)},
  79.         {   mtd_hack_part("h_cdt",       384)},
  80.         {   mtd_hack_part("h_pds",       1536)},
  81.         {   mtd_hack_part("h_lbl",       384)},
  82.         {   mtd_hack_part("h_lblbackup", 384)},
  83.         {   mtd_hack_part("h_cid",       384)},
  84.         {   mtd_hack_part("h_sp",        1536)},
  85.         {   mtd_hack_part("h_devtree",   384)},
  86.         {   mtd_hack_part("h_logo",      640)},
  87.         {   mtd_hack_part("h_misc",      384)},
  88.     {   mtd_hack_part("h_boot",      3584)},
  89.     {       mtd_hack_part("h_bpsw",      3840)},
  90.     {       mtd_hack_part("h_recovery",  4608)},
  91.     {       mtd_hack_part("h_cdrom",     8960)},
  92.     {       mtd_hack_part("h_unused0",   384)},
  93.     {       mtd_hack_part("h_system",    179840)},
  94.     {       mtd_hack_part("h_unused1",   384)},
  95.     {       mtd_hack_part("h_cache",     106*1024)},
  96.     {       mtd_hack_part("h_userdata",  201856)},
  97.     {       mtd_hack_part("h_cust",      1536)},
  98.     {       mtd_hack_part("h_unused2",   384)},
  99.     {       mtd_hack_part("h_kpanic",    2048)},
  100.     {       mtd_hack_part("h_rsv",       512)},
  101. };
  102.  
  103. static int create_missing_flash_parts(struct device *dev, void *data)
  104. {
  105.  
  106.     struct mtd_info *mtd = NULL;
  107.  
  108.     printk(KERN_INFO "mtd-hack: device %s\n", dev->init_name);
  109.  
  110.     mtd = dev_get_drvdata(dev);
  111.  
  112.     if (!mtd)
  113.         return -1;
  114.  
  115.         printk(KERN_INFO "mtd-hack: mtd name %s, type %d, size %llu\n",
  116.                 mtd->name, mtd->type, mtd->size);
  117.  
  118.         /*
  119.         if (mtd->read) {
  120.                 size_t ret = 0;
  121.                 u_char buf[520];
  122.                 int i;
  123. //  int (*read) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
  124.                 mtd->read(mtd, 7995392, 512, &ret, buf);
  125.  
  126.                 printk(KERN_INFO "flash contents: ");
  127.                 for (i=0; i < ret; i++)
  128.                         printk(KERN_INFO "0x%x ", buf[i]);
  129.         }
  130.         */
  131.  
  132.     add_mtd_partitions(mtd, part, 26); 
  133.  
  134.     return 0;
  135. }
  136.  
  137. static int __init mtd_init(void)
  138. {
  139.     struct device_driver *devdrv;
  140.     int err = 0;
  141.  
  142.     //  struct device_driver *driver_find(const char *name, struct bus_type *bus);
  143.     devdrv = driver_find("omap2-nand", &platform_bus_type);
  144.  
  145.     printk(KERN_INFO "mtd-hack: found driver %s modname %s\n", devdrv->name, devdrv->mod_name);
  146.     //  int driver_for_each_device(struct device_driver *drv, struct device *start,
  147.     //                             void *data, int (*fn)(struct device *, void *))
  148.     err = driver_for_each_device(devdrv, NULL, NULL, create_missing_flash_parts);
  149.  
  150.  
  151.     printk(KERN_INFO "mtd hack loaded");
  152.  
  153.     return 0;
  154. }
  155.  
  156. module_init(mtd_init);
  157.  
  158. MODULE_LICENSE("GPL");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement