手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux移植随笔:让内核支持nor flash

[日期:2011-03-17] 来源:Linux社区  作者:subfate [字体:大 中 小]

与前面不同的是,它打印了芯片的信息,如厂商ID、芯片ID等等。

这是我想不通的地方,也是我采用新内核的原因。

不过,在这片nor flash上使用jffs2文件系统却不成功,出现了大量的警告信息,提示说制作根文件系统时的erase block有问题。

s3c2440-flash.c源代码:

  1. /*  
  2. * $Id: s3c2410.c,v 1.00 2006/12/05 10:18:14 gleixner Exp $  
  3. *  
  4. * Handle mapping of the NOR flash on Cogent S3C2410 boards  
  5. *  
  6. * Copyright 2002 SYSGO Real-Time Solutions GmbH  
  7. *  
  8. * This program is free software; you can Redistribute it and/or modify  
  9. * it under the terms of the GNU General Public License version 2 as  
  10. * published by the Free Software Foundation.  
  11. */  
  12.   
  13. /*  
  14. *                 Late Lee<http://www.latelee.org>  
  15. * This file is modified and the file name has changed to 's3c2440-flash.c'.  
  16. * The SMDK2440 board has only one flash bank which is a 64Mbit(4Mx16) SST SST39VF6401B;  
  17. * 128 x 64 KiB blocks.  
  18. *  
  19. * This code is GPLed.  
  20. */  
  21.   
  22. #include <linux/module.h>   
  23. #include <linux/types.h>   
  24. #include <linux/kernel.h>   
  25. #include <linux/init.h>   
  26. #include <asm/io.h>   
  27. #include <linux/mtd/mtd.h>   
  28. #include <linux/mtd/map.h>   
  29. #include <linux/mtd/cfi.h>   
  30.   
  31. #ifdef CONFIG_MTD_PARTITIONS   
  32. #include <linux/mtd/partitions.h>   
  33. #endif   
  34.   
  35. #define WINDOW_ADDR 0x01000000      /* physical properties of flash */   
  36. #define WINDOW_SIZE 0x800000        /* 8MB */   
  37. #define BUSWIDTH    2       /* 2*8 = 16 */   
  38. #define FLASH_BLOCKSIZE_MAIN    0x10000 /* 64KB(0x10000) 128 blocks */   
  39. #define FLASH_NUMBLOCKS_MAIN    128   
  40.   
  41. /* can be "cfi_probe", "jedec_probe", "map_rom", NULL }; */  
  42. #define PROBETYPES { "cfi_probe", "jedec_probe", "map_rom", NULL }   
  43.   
  44. #define MSG_PREFIX "S3C2440-NOR:"   /* prefix for our printk()'s */   
  45. #define MTDID      "s3c2440-nor"    /* for mtdparts= partitioning */   
  46.   
  47. #define DEBUG_FLASH   
  48. #ifdef DEBUG_FLASH   
  49. #define flash_debug(fmt, args...) printk(KERN_NOTICE "## LL debug " MSG_PREFIX  fmt, ##args)   
  50. #else   
  51. #define flash_debug(fmt, args...)   
  52. #endif   
  53.   
  54. static struct mtd_info *mymtd;   
  55.   
  56. struct map_info s3c2440nor_map = {   
  57.     .name = "NOR Flash(SST39VF6401B) on S3C2440",   
  58.     .size = WINDOW_SIZE,   
  59.     .bankwidth = BUSWIDTH,   
  60.     .phys = WINDOW_ADDR,   
  61. };   
  62.   
  63. #ifdef CONFIG_MTD_PARTITIONS   
  64.   
  65. /*  
  66. * MTD partitioning stuff  
  67. */  
  68. static struct mtd_partition static_partitions[] = {   
  69.     /*0: U-Boot: 0-0x30000 0x30000=192KB*/  
  70.     {   
  71.     .name = "U-Boot",   
  72.     .size = 0x030000,   
  73.     .offset = 0x0,   
  74.     },   
  75.     /*1: Kernel: 0x30000-0x240000 0x210000=2112KB=2.0625MB*/  
  76.     {   
  77.     .name = "Kernel",   
  78.     .size = 0x210000,   
  79.     .offset = 0x30000,   
  80.     },   
  81.     /*2: Rootfs(jffs2): 0x240000-0x7f0000 0x5b0000=5824KB=5.6875MB*/  
  82.     {   
  83.     .name = "Rootfs(jffs2)",   
  84.     .size = 0x5b0000,   
  85.     .offset = 0x240000,   
  86.     },   
  87.     /*3: U-Boot Parameters: 0x7f0000-0x800000 0x10000=64KB*/  
  88.     {.name = "Parameter",   
  89.     .size = 0x010000,   
  90.     .offset = 0x7f0000,   
  91.     },   
  92. };   
  93.   
  94. //static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };   
  95. static const char *probes[] = { NULL };   
  96.   
  97. #endif   
  98.   
  99. static int mtd_parts_nb = 0;   
  100. static struct mtd_partition *mtd_parts = 0;   
  101.   
  102. int __init init_s3c2440nor(void)   
  103. {   
  104.     static const char *rom_probe_types[] = PROBETYPES;   
  105.     const char **type;   
  106.     const char *part_type = 0;   
  107.   
  108.     printk(KERN_NOTICE MSG_PREFIX "0x%08x at 0x%08x\n",   
  109.     WINDOW_SIZE, WINDOW_ADDR);   
  110.     s3c2440nor_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);   
  111.     if (!s3c2440nor_map.virt) {   
  112.         printk(MSG_PREFIX "failed to ioremap\n");   
  113.         return -EIO;   
  114.     }   
  115.   
  116.     simple_map_init(&s3c2440nor_map);   
  117.     mymtd = 0;   
  118.     type = rom_probe_types;   
  119.     for(; !mymtd && *type; type++) {   
  120.         mymtd = do_map_probe(*type, &s3c2440nor_map);   
  121.         flash_debug("func:%s[%d] mymtd:%x type:%s\n", __func__, __LINE__, mymtd, *type);   
  122.     }   
  123.   
  124.     if (mymtd) {   
  125.         mymtd->owner = THIS_MODULE;   
  126.   
  127.         #ifdef CONFIG_MTD_PARTITIONS   
  128.         mtd_parts_nb = parse_mtd_partitions(mymtd, probes, &mtd_parts, MTDID);   
  129.         if (mtd_parts_nb > 0)   
  130.             part_type = "detected";   
  131.   
  132.         if (mtd_parts_nb == 0){   
  133.             mtd_parts = static_partitions;   
  134.             mtd_parts_nb = ARRAY_SIZE(static_partitions);   
  135.             part_type = "static";   
  136.         }   
  137.         #endif   
  138.         add_mtd_device(mymtd);   
  139.         if (mtd_parts_nb == 0)   
  140.             printk(KERN_NOTICE MSG_PREFIX "no partition info available\n");   
  141.         else{   
  142.             printk(KERN_NOTICE MSG_PREFIX   
  143.             "using %s partition definition\n", part_type);   
  144.             add_mtd_partitions(mymtd, mtd_parts, mtd_parts_nb);   
  145.         }   
  146.         return 0;   
  147.     }   
  148.   
  149.     iounmap((void *)s3c2440nor_map.virt);   
  150.     return -ENXIO;   
  151. }   
  152.   
  153. static void __exit cleanup_s3c2440nor(void)   
  154. {   
  155.     if (mymtd) {   
  156.         del_mtd_device(mymtd);   
  157.         map_destroy(mymtd);   
  158.     }   
  159.     if (s3c2440nor_map.virt) {   
  160.         iounmap((void *)s3c2440nor_map.virt);   
  161.         s3c2440nor_map.virt = 0;   
  162.     }   
  163. }   
  164.   
  165. module_init(init_s3c2440nor);   
  166. module_exit(cleanup_s3c2440nor);   
  167.   
  168. MODULE_LICENSE("GPL");   
  169. MODULE_AUTHOR("GengYaoJun ");   
  170. MODULE_DESCRIPTION("Generic configurable MTD map driver");  
linux
相关资讯       Linux内核 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款