Re: [Balloon] Enabling NOR flash

Top Page
Attachments:
Message as email
+ (text/plain)
+ 0001-Added-support-for-NOR-FLASH-bootldr-partitions.patch (text/x-patch)
Delete this message
Reply to this message
Author: Patrick Doyle
Date:  
To: balloon
Subject: Re: [Balloon] Enabling NOR flash
On Tue, Jun 14, 2011 at 8:21 AM, Patrick Doyle <> wrote:
> OK, I've got 3 options here, and I really need to move on from this.
>
> 1) Enable CONFIG_MTD_PHYSMAP and live with the change in mtd blocks.
> Change the linuxargs bootldr param to point to the new root partition
> (in NAND) and get on with life.
>
> 2) Apply the ridiculous ugly, WRONG WAY TO DO THIS, patch (see
> attached) which preserves the partition order by virtue of calling the
> platform specific 'balloon3_nor_init()' procedure (defined in
> arch/arm/pxa-270/balloon3.c) from the NAND driver code procedure
> 'balloon3_nand_init()' (defined in drivers/mtd/nand/balloon3.c.
>
> 3) Arrange somehow for the NAND partition to be probed, recognized,
> and loaded from within balloon3_init().  I'm having trouble figuring
> out how to make this work.  Simply calling 'balloon3_nand_init()' (the
> one defined in drivers/mtd/nand/balloon.c, not the confusingly
> identically named one from within baloon3.c) doesn't work, probably
> because other stuff has not yet been initialized.
>

Err.... this is somewhat embaressing...

It turns out that the solution is really quite simple... just enable
CONFIG_MTD_PHYSMAP as a loadable module rather than as a compiled-in
module (which is what I started with). The NAND flash gets assigned
to partitions mtd0 and mtd1 first; then, once the root fs is mounted
(from mtd1), we can simply insmod the physmap.ko file to gain access
to the NOR flash.

In fact, through some magic I don't fully comprehend yet, the
physmap.ko module gets automatically loaded anyway during the boot
process.

Attached is my patch that defines the partitions to match those
defined in my bootldr. I am a little concerned that the partitions
scheme in bootldr could change and my patch would know nothing about
that, but I don't really know how to synchronize the two partition
schemes otherwise. I've done my best to make this as safe as possible
-- requiring CONFIG options to enable writes to the partitions, so
hopefully this should be pretty benign.

--wpd
From f6aaf41d1b0c770000dc4f6a5f9bb3031d60abc0 Mon Sep 17 00:00:00 2001
From: Patrick Doyle <>
Date: Tue, 14 Jun 2011 15:46:54 -0400
Subject: [PATCH] Added support for NOR FLASH bootldr partitions

---
 package/kernel/patches/2.6.37.6/balloon3-nor.patch |   95 ++++++++++++++++++++
 .../patches/2.6.37.6/series-balloon3.default       |    1 +
 2 files changed, 96 insertions(+), 0 deletions(-)
 create mode 100644 package/kernel/patches/2.6.37.6/balloon3-nor.patch


diff --git a/package/kernel/patches/2.6.37.6/balloon3-nor.patch b/package/kernel/patches/2.6.37.6/balloon3-nor.patch
new file mode 100644
index 0000000..dfc7583
--- /dev/null
+++ b/package/kernel/patches/2.6.37.6/balloon3-nor.patch
@@ -0,0 +1,95 @@
+Index: linux-2.6.37.6/arch/arm/mach-pxa/balloon3.c
+===================================================================
+--- linux-2.6.37.6.orig/arch/arm/mach-pxa/balloon3.c    2011-06-14 15:05:23.000000000 -0400
++++ linux-2.6.37.6/arch/arm/mach-pxa/balloon3.c    2011-06-14 15:45:14.000000000 -0400
+@@ -129,10 +129,37 @@
+ #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
+ static struct mtd_partition balloon3_nor_partitions[] = {
+     {
+-        .name        = "Flash",
++        .name        = "bootldr",
+         .offset        = 0x00000000,
+-        .size        = MTDPART_SIZ_FULL,
+-    }
++        .size        = 0x00040000,
++#ifndef CONFIG_MTD_PHYSMAP_BALLOON3_BOOTLDR_RW
++                .mask_flags     = MTD_WRITEABLE,
++#endif
++    },
++    {
++        .name        = "params",
++        .offset        = 0x00040000,
++        .size        = 0x00040000,
++#ifndef CONFIG_MTD_PHYSMAP_BALLOON3_PARAMS_RW
++                .mask_flags     = MTD_WRITEABLE,
++#endif
++    },
++    {
++        .name        = "fpga",
++        .offset        = 0x00100000,
++        .size        = 0x00100000,
++#ifndef CONFIG_MTD_PHYSMAP_BALLOON3_FPGA_RW
++                .mask_flags     = MTD_WRITEABLE,
++#endif
++    },
++    {
++        .name        = "kernel",
++        .offset        = 0x00200000,
++        .size        = 0x00400000,
++#ifndef CONFIG_MTD_PHYSMAP_BALLOON3_KERNEL_RW
++                .mask_flags     = MTD_WRITEABLE,
++#endif
++    },
+ };
+ 
+ static struct physmap_flash_data balloon3_flash_data[] = {
+Index: linux-2.6.37.6/drivers/mtd/maps/Kconfig
+===================================================================
+--- linux-2.6.37.6.orig/drivers/mtd/maps/Kconfig    2011-06-14 15:09:59.000000000 -0400
++++ linux-2.6.37.6/drivers/mtd/maps/Kconfig    2011-06-14 15:45:32.000000000 -0400
+@@ -21,6 +21,45 @@
+       To compile this driver as a module, choose M here: the
+       module will be called physmap.
+ 
++config MTD_PHYSMAP_BALLOON3_BOOTLDR_RW
++        bool "Writable Balloon3 MTD bootldr partition"
++    default false
++    depends on MACH_BALLOON3 && MTD_PHYSMAP
++    help
++      By default, the bootldr MTD partion is readonly.  Enabling this
++      option will make that partition RW and allow your kernel to
++      overwrite the bootloader, possibly with disastrous results.
++
++config MTD_PHYSMAP_BALLOON3_PARAMS_RW
++        bool "Writable Balloon3 MTD params partition"
++    default false
++    depends on MACH_BALLOON3 && MTD_PHYSMAP
++    help
++      By default, the params MTD partion is readonly.  Enabling
++      this option will make that partition RW and allow your
++      kernel to overwrite the bootloader parameters, possibly with
++      disasterous results.
++
++config MTD_PHYSMAP_BALLOON3_FPGA_RW
++        bool "Writable Balloon3 MTD FPGA partition"
++    default false
++    depends on MACH_BALLOON3 && MTD_PHYSMAP
++    help
++      By default, the FPGA MTD partion is readonly.  Enabling
++      this option will make that partition RW and allow your
++      kernel to overwrite the fpga/cpld image, possibly with
++      disastrous results.
++
++config MTD_PHYSMAP_BALLOON3_KERNEL_RW
++        bool "Writable Balloon3 MTD rescue kernel partition"
++    default false
++    depends on MACH_BALLOON3 && MTD_PHYSMAP
++    help
++      By default, the rescue kernel MTD partion is readonly.  Enabling
++      this option will make that partition RW and allow your
++      kernel to overwrite the rescue kernel, possibly with
++      disastrous results.
++
+ config MTD_PHYSMAP_COMPAT
+     bool "Physmap compat support"
+     depends on MTD_PHYSMAP
diff --git a/package/kernel/patches/2.6.37.6/series-balloon3.default b/package/kernel/patches/2.6.37.6/series-balloon3.default
index 091a26f..068aae5 100644
--- a/package/kernel/patches/2.6.37.6/series-balloon3.default
+++ b/package/kernel/patches/2.6.37.6/series-balloon3.default
@@ -4,3 +4,4 @@ balloon3.patch
 balloon3-cpufreq.patch
 balloon3-ac97.patch
 balloon3-nand.patch -p0
+balloon3-nor.patch
-- 
1.7.2.5