Книга: Embedded Linux Primer: A Practical, Real-World Approach

10.3.3. Mapping Driver

10.3.3. Mapping Driver

The final method for defining your board-specific Flash layout is to use a dedicated board-specific mapping driver. The Linux kernel source tree contains many examples of mapping drivers, located in .../drivers/mtd/maps. Any one of these will provide good examples for how to create your own. The implementation details vary by architecture.

The mapping driver is a proper kernel module, complete with module_init() and module_exit() calls, as described in Chapter 8, "Device Driver Basics." A typical mapping driver is small and easy to navigate, often containing fewer than a couple dozen lines of C.

Listing 10-11 reproduces a section of .../drivers/mtd/maps/pq2fads. This mapping driver defines the Flash device on a Freescale PQ2FADS evaluation board that supports the MPC8272 and other processors.

Listing 10-11. PQ2FADs Flash Mapping Driver

...
static struct mtd_partition pq2fads_partitions[] = {
 {
#ifdef CONFIG_ADS8272
  .name = "HRCW",
  .size = 0x40000,
  .offset = 0,
  .mask_flags= MTD_WRITEABLE, /* force read-only */
 }, {
  .name = "User FS",
  .size = 0x5c0000,
  .offset = 0x40000,
#else
  .name = "User FS",
  .size = 0x600000,
  .offset = 0,
#endif
 }, {
  .name = "uImage",
  .size = 0x100000,
  .offset = 0x600000,
  .mask_flags = MTD_WRITEABLE, /* force read-only */
 }, {
  .name = "bootloader",
  .size = 0x40000,
  .offset = 0x700000,
  .mask_flags = MTD_WRITEABLE, /* force read-only */
 }, {
  .name = "bootloader env",
  .size = 0x40000,
  .offset = 0x740000,
  .mask_flags = MTD_WRITEABLE, /* force read-only */
 }
};
/* pointer to MPC885ADS board info data */
extern unsigned char __res[];
static int __init init_pq2fads_mtd(void) {
 bd_t *bd = (bd_t *)__res;
 physmap_configure(bd->bi_flashstart, bd->bi_flashsize, PQ2FADS_BANK_WIDTH, NULL);
 physmap_set_partitions(pq2fads_partitions, sizeof (pq2fads_partitions) / sizeof (pq2fads_partitions[0]));
 return 0;
}
static void __exit cleanup_pq2fads_mtd(void) {}
module_init(init_pq2fads_mtd);
module_exit(cleanup_pq2fads_mtd);
... 

This simple but complete Linux device driver communicates the PQ2FADS Flash mapping to the MTD subsystem. Recall from Chapter 8 that when a function in a device driver is declared with the module_init() macro, it is automatically invoked during Linux kernel boot at the appropriate time. In this PQ2FADS mapping driver, the module initialization function init_pq2fads_mtd() performs just two simple calls:

• physmap_configure() passes to the MTD subsystem the Flash chip's physical address, size, and bank width, along with any special setup function required to access the Flash.

• physmap_set_partitions() passes the board's unique partition information to the MTD subsystem from the partition table defined in the pq2fads_partitions[] array found at the start of this mapping driver.

Following this simple example, you can derive a mapping driver for your own board.

Оглавление книги


Генерация: 0.808. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз