10.3.2. Kernel Command Line Partitioning

As detailed in Section 10.3, 'MTD Partitions,' the raw Flash partition information can be communicated to the kernel using other methods. Indeed, possibly the most straightforward, though perhaps not the simplest method is to manually pass the partition information directly on the kernel command line. Of course, as we have already learned, some bootloaders make that easy (for example U-Boot), whereas others do not have a facility to pass a kernel command line to the kernel upon boot. In these cases, the kernel command line must be configured at compile time and, therefore, is more difficult to change, requiring a recompile of the kernel itself each time the partitions are modified.

To enable command-line partitioning in the MTD subsystem, your kernel must be configured for this support. You can see this configuration option in Figure 10-2 under MTD partitioning support. Select the option for command-line partition table parsing, which defines the CONFIG_MTD_CMDLINE_PARTS option.

Listing 10-10 shows the format for defining a partition on the kernel command line (taken from .../drivers/mtd/cmdlinepart.c).

Listing 10-10. Kernel Command-Line MTD Partition Format

mtdparts=<mtddef>[;<mtddef]

 *<mtddef>  := <mtd-id>:<partdef>[,<partdef>]

 *<partdef> := <size>[@offset][<name>][ro]

 *<mtd-id>  := unique name used in mapping driver/device (mtd->name)

 *<size>    := std linux memsize OR '-' to denote all remaining space

 *<name>    := '(' NAME ')' 

Each mtddef parameter passed on the kernel command line defines a separate partition. As shown is Listing 10-10, each mtddef definition contains multiple parts. You can specify a unique ID, partition size, and offset from the start of the Flash. You can also pass the partition a name and, optionally, the read-only attribute. Referring back to our Redboot partition definitions in Listing 10-5, we could statically define these on the kernel command line as follows:

mtdparts=MainFlash:384K(Redboot),4K(config),128K(FIS),-(unused)

With this definition, the kernel would instantiate four MTD partitions, with an MTD ID of MainFlash, containing the sizes and layout matching that found in Listing 10-5.

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

Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату