涉及源码文件:drivers/mtd/maps/alchemy-flash.c
10: #include <linux/config.h>
注解: 在 include/linux/config.h中,只有一句 #include <linux/autoconf.h>, 而在 include/linux/autoconf.h 中则有如下
59: #undef CONFIG_MIPS_PB1000
60: #undef CONFIG_MIPS_PB1100
61: #undef CONFIG_MIPS_PB1500
62: #undef CONFIG_MIPS_PB1550
63: #undef CONFIG_MIPS_PB1200
64: #undef CONFIG_MIPS_DB1000
65: #undef CONFIG_MIPS_DB1100
66: #undef CONFIG_MIPS_DB1500
67: #undef CONFIG_MIPS_DB1550
68: #define CONFIG_MIPS_DB1200 1
因此对应于alchemy-flash.c 的82行定义成立
#ifdef CONFIG_MIPS_DB1200
#define BOARD_MAP_NAME "Db1200 Flash"
#define BOARD_FLASH_SIZE 0x00800000 /* 8MB */
#define BOARD_FLASH_WIDTH 2 /* 16-bits */
#endif
其中 BOARD_FLASH_SIZE 表示嵌入式系统中使用的NorFlash的容量大小, BOARD_FLASH_WIDTH 表示NorFlash数据总线宽度(以byte为单位)。
在 include/linux/mtd/partitions.h中定义结构体
struct mtd_partition {
char *name; /* identifier string */
u_int32_t size; /* partition size */
u_int32_t offset; /* offset within the master MTD space */
u_int32_t mask_flags; /* master MTD flags to mask out for this partition */
struct nand_oobinfo *oobsel; /* out of band layout for this partition (NAND only)*/
struct mtd_info **mtdp; /* pointer to store the MTD object */
};
alchemy-flash.c 的 113行开始的定义则对应于NorFlash中的分区方案:
static struct mtd_partition alchemy_partitions[] = {
{
.name = "User FS",
.size = BOARD_FLASH_SIZE - 0x00400000, ——此处即使用宏 BOARD_FLASH_SIZE
.offset = 0x0000000
},
{
.name = "YAMON",
.size = 0x0100000,
.offset = MTDPART_OFS_APPEND,
// .mask_flags = MTD_WRITEABLE
——此处使用的宏 MTD_WRITEABLE 表示 本mtd分区起始偏移量紧跟上一分区结束位置
},
{
.name = "raw kernel",
.size = (0x300000 - 0x40000), /* last 256KB is yamon env */
.offset = MTDPART_OFS_APPEND,
}
};
在这个NorFlash分区的方案中,YAMON 开始于 NorFlash的最后 4MB 起始处,整个kernel 和 Yamon占据 NorFlash最后 4MB 空间,这可从"User FS" .size= BOARD_FLASH_SIZE - 0x00400000 看出
因此,当NorFlash类型更换之后,需要根据新NorFlash的容量、数据宽度相应的修改 alchemy-flash.c 82行开始的宏定义 BOARD_FLASH_SIZE 和 BOARD_FLASH_WIDTH