public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* CFI physmap - how to create partitions
@ 2005-05-18  8:05 Thorsten Haas
  2005-05-18 22:35 ` Ralph Siemsen
  2005-05-19  8:06 ` Thorsten Haas
  0 siblings, 2 replies; 7+ messages in thread
From: Thorsten Haas @ 2005-05-18  8:05 UTC (permalink / raw)
  To: linux-mtd

Hello everyone,

I have a board equipped with CFI-compatible NOR-flash, which is
physmapped and detected by the kernel (/dev/mtd0 in /proc/mtd). Now I am
trying to configure partitions. I read the HOWTO on
ftp://ftp.uk.linux.org/pub/people/dwmw2/mtd/cvs/mtd/mtd-jffs-HOWTO.txt,
googled and browsed kernel code (2.6.8.11) and a daily mtd-snapshot
(2005-05-15). From what i read, I understand:
a) Command line partition table parsing is not functional with
physmapped devices
b) I need to create and fill a 'struct mtd_partition' and call
physmap_configure() and physmap_set_partitions()
Is this correct so far?

I've seen people writing board-dependent mapping drivers, thus
clobbering the section "mapping driver for chip access". Is this
actually the way to go? Well, I am not too lazy to write some code, but
is there a more genric way?

Best regards,
Thorsten Haas

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: CFI physmap - how to create partitions
  2005-05-18  8:05 CFI physmap - how to create partitions Thorsten Haas
@ 2005-05-18 22:35 ` Ralph Siemsen
  2005-05-19  8:06 ` Thorsten Haas
  1 sibling, 0 replies; 7+ messages in thread
From: Ralph Siemsen @ 2005-05-18 22:35 UTC (permalink / raw)
  To: Thorsten Haas; +Cc: linux-mtd

Thorsten Haas wrote:

> I have a board equipped with CFI-compatible NOR-flash, which is
> physmapped and detected by the kernel (/dev/mtd0 in /proc/mtd). Now I am
> trying to configure partitions. I read the HOWTO on
> ftp://ftp.uk.linux.org/pub/people/dwmw2/mtd/cvs/mtd/mtd-jffs-HOWTO.txt,
> googled and browsed kernel code (2.6.8.11) and a daily mtd-snapshot
> (2005-05-15). From what i read, I understand:
> a) Command line partition table parsing is not functional with
> physmapped devices
> b) I need to create and fill a 'struct mtd_partition' and call     

Hmm, I have used both methods successfully, albeit not with NOR flash... 
  though I can't see how it would make any difference for partitioning. 
  I'm using the MTD code "as is" in kernel 2.6.11.3 from kernel.org. 
One minor bug with automatic buswidth probing, easily solved though.

> I've seen people writing board-dependent mapping drivers, thus
> clobbering the section "mapping driver for chip access". Is this
> actually the way to go? Well, I am not too lazy to write some code, but
> is there a more genric way?

Unless you have special requirements, such as paging or special unlock 
sequences, or multiple (different) kinds of flash chips, you probably do 
not need your own mapping driver.  Physmap should do fine I'd think.

-R

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: CFI physmap - how to create partitions
  2005-05-18  8:05 CFI physmap - how to create partitions Thorsten Haas
  2005-05-18 22:35 ` Ralph Siemsen
@ 2005-05-19  8:06 ` Thorsten Haas
  2005-05-19 11:54   ` Ralph Siemsen
  1 sibling, 1 reply; 7+ messages in thread
From: Thorsten Haas @ 2005-05-19  8:06 UTC (permalink / raw)
  To: linux-mtd

Am Mittwoch, den 18.05.2005, 10:05 +0200 schrieb Thorsten Haas:
> Hello everyone,
> 
> I have a board equipped with CFI-compatible NOR-flash, which is
> physmapped and detected by the kernel (/dev/mtd0 in /proc/mtd). Now I am
> trying to configure partitions. I read the HOWTO on
> ftp://ftp.uk.linux.org/pub/people/dwmw2/mtd/cvs/mtd/mtd-jffs-HOWTO.txt,
> googled and browsed kernel code (2.6.8.11) and a daily mtd-snapshot
> (2005-05-15). From what i read, I understand:
> a) Command line partition table parsing is not functional with
> physmapped devices
> b) I need to create and fill a 'struct mtd_partition' and call
> physmap_configure() and physmap_set_partitions()
> Is this correct so far?
> 
> I've seen people writing board-dependent mapping drivers, thus
> clobbering the section "mapping driver for chip access". Is this
> actually the way to go? Well, I am not too lazy to write some code, but
> is there a more genric way?
> 
> Best regards,
> Thorsten Haas

Solved. I used mphysmap.c, because there are two banks of flash on my
board, but mphysmap.c does not support partitioning yet. Though,
physmap.c does provide commandline partition parsing.
Sadly, mtd-id's seem not to be well-documented. I looked the one for
mappings to the physical memory area up in the source. It's
"phys_mapped_flash". Huzaa.

Thus, I wrote some additional text into chapter "Making partitions with
CFI flash and working with multiple banks of FLASH" of
mtd-jffs-HOWTO.txt. ( retreived it from
ftp://ftp.uk.linux.org/pub/people/dwmw2/mtd/cvs/mtd/mtd-jffs-HOWTO.txt )

Here's a patch to it:

*** mtd-jffs-HOWTO.txt  2005-05-18 16:05:16.000000000 +0200
--- mtd-jffs-HOWTO-new.txt      2005-05-18 16:05:01.000000000 +0200
***************
*** 515,528 ****
  Unlike a "regular" block device, you cannot launch fdisk and create
  partitions on /dev/mtdblock0,1,2,3...
  
! (As far as I know) CFI flash partitions have to be created and
! compiled in the physmap.c file.
! 
! The same goes for multiple banks of flash memory. (IS THIS CORRECT????
! Check and correct.)
! 
! An example of creating partitions can be found in the file
! mtd/kernel/sbc_mediagx.c
  
  An example of multiple banks of flash chips being mapped into separate
  /dev/mtdn devices can be found in the file mtd/kernel/octagon_5066.c
--- 515,554 ----
  Unlike a "regular" block device, you cannot launch fdisk and create
  partitions on /dev/mtdblock0,1,2,3...
  
! CFI flash partitions have to be created on the kernel command line or
! have to be hard-coded into the kernel source. Before command line
partition
! table parsing was available, people had to write board-specific
mapping
! drivers. You still can find some of these below 'Mapping drivers for
chip
! access' in the kernel configuration.
! 
! To make use of command line partition table parsing enable
! CONFIG_MTD_CMDLINE_PARTS in the kernel configuration.
! 
! The format for the command line is as follows:
! 
!  mtdparts=<mtddef>[;<mtddef]
!  <mtddef>  := <mtd-id>:<partdef>[,<partdef>]
!  <partdef> := <size>[@offset][<name>][ro] 
!  <mtd-id>  := unique id used in mapping driver/device
!  <size>    := standard linux memsize OR "-" to denote all remaining
space
!  <name>    := (NAME)
! 
! Example:
! You have a CFI-flash (size 8M) mapped to the physical memory area at
! 0x38000000. Enable CONFIG_MTD_PHYSMAP, set start address to 0x38000000
and
! length to 0x800000.
! 
! You want two partitions like: one megabyte (not million bytes) to hold
a
! write-protected kernel image and the rest to hold a rootfs.
!   
! Add the following to the kernel command line:
! mtdparts=phys_mapped_flash:1M(kernel)ro,-(rootfs)
! 
! If you do not want to use command line partition table parsing you
might start
! off with the physmap.c file and create and compile the partitions
withing the
! kernel itself. You might chose to do so, or you might write a board
specific
! mapping 'driver', like mentioned above. An example of creating
partitions can
! be found in the file mtd/kernel/sbc_mediagx.c
  
  An example of multiple banks of flash chips being mapped into separate
  /dev/mtdn devices can be found in the file mtd/kernel/octagon_5066.c
***************
*** 530,536 ****
  registering the mtd device in "init_oct5066()". You may also add
  partitions to each bank by looking at code in mtd/kernel/sbc_mediagx.c
  
! 
  
  
  *** Mounting a JFFS(1 or 2) F/S as root device.
--- 556,591 ----
  registering the mtd device in "init_oct5066()". You may also add
  partitions to each bank by looking at code in mtd/kernel/sbc_mediagx.c
  
! Mapping multiple CFI flash devices into the physical memory map is
currently
! supported by CONFIG_MTD_MULTI_PHYSMAP. This lets you configure up to
four
! separate flash banks (file mphysmap.c). This also lets you have gaps
between
! flash chips, but partitioning support is not available out-of-the-box
yet, at
! least not from the command line. 
! 
! If you like to partition multiple banks of flash from the command
line, you do
! good to map your flash banks one after the other into the physical
memory area
! without leaving any gap between them. Let's assume you have two banks
of CFI
! flash (size 8M each) mapped to 0x38000000 and 0x38800000. Then do not
touch
! CONFIG_MTD_MULTI_PHYSMAP but configure CONFIG_MTD_PHYSMAP. Set the
starting
! address to 0x38000000 and length to 0x1000000 (16MBytes).
! On startup the kernel will still recognise two banks: 
!       
!  physmap flash device: 1000000 at 38000000
!  phys_mapped_flash: Found 1 x16 devices at 0x0 in 16-bit bank
!  phys_mapped_flash: Found 1 x16 devices at 0x800000 in 16-bit bank.
! 
! Now you may use a commandline like:
! mtdparts=phys_mapped_flash:1M(kernel)ro,7M(rootfs),8M(moredata).
! 
! Et voila, the kernel will create partitions:
! 
!  Creating 3 MTD partitions on "phys_mapped_flash":
!  0x00000000-0x00100000 : "kernel"
!  mtd: Giving out device 0 to kernel
!  0x00100000-0x00800000 : "root"
!  mtd: Giving out device 1 to root
!  0x00800000-0x01000000 : "moredata"
!  mtd: Giving out device 2 to moredata
  
  
  *** Mounting a JFFS(1 or 2) F/S as root device.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: CFI physmap - how to create partitions
  2005-05-19  8:06 ` Thorsten Haas
@ 2005-05-19 11:54   ` Ralph Siemsen
  2005-05-20  7:26     ` Thorsten Haas
  0 siblings, 1 reply; 7+ messages in thread
From: Ralph Siemsen @ 2005-05-19 11:54 UTC (permalink / raw)
  To: Thorsten Haas; +Cc: linux-mtd

Thorsten Haas wrote:

> Solved. I used mphysmap.c, because there are two banks of flash on my
> board, but mphysmap.c does not support partitioning yet. Though,
> physmap.c does provide commandline partition parsing.
> Sadly, mtd-id's seem not to be well-documented. I looked the one for
> mappings to the physical memory area up in the source. It's
> "phys_mapped_flash". Huzaa.

Hmm, are the two banks the same (eg. two chips of same type), and are 
they consecutive in memory or parallel on the bus?  Then you can 
actually use physmap.  Just pass it the combined size of both chips, the 
MTD code will handle the rest.  There is no need to call probe function 
for each bank, or to partition each bank separately.  This seems to be 
another one of the MTD undocumented "features".

> Thus, I wrote some additional text into chapter "Making partitions with
> CFI flash and working with multiple banks of FLASH" of
> mtd-jffs-HOWTO.txt. ( retreived it from
> ftp://ftp.uk.linux.org/pub/people/dwmw2/mtd/cvs/mtd/mtd-jffs-HOWTO.txt )

Nice!
-R

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: CFI physmap - how to create partitions
  2005-05-19 11:54   ` Ralph Siemsen
@ 2005-05-20  7:26     ` Thorsten Haas
  2005-05-20 12:58       ` Ralph Siemsen
  0 siblings, 1 reply; 7+ messages in thread
From: Thorsten Haas @ 2005-05-20  7:26 UTC (permalink / raw)
  To: Ralph Siemsen; +Cc: linux-mtd

Am Donnerstag, den 19.05.2005, 07:54 -0400 schrieb Ralph Siemsen:
> Thorsten Haas wrote:
> 
> > Solved. I used mphysmap.c, because there are two banks of flash on my
> > board, but mphysmap.c does not support partitioning yet. Though,
> > physmap.c does provide commandline partition parsing.
> > Sadly, mtd-id's seem not to be well-documented. I looked the one for
> > mappings to the physical memory area up in the source. It's
> > "phys_mapped_flash". Huzaa.
> 
> Hmm, are the two banks the same (eg. two chips of same type), and are 
> they consecutive in memory or parallel on the bus?  Then you can 
> actually use physmap.  Just pass it the combined size of both chips, the 
> MTD code will handle the rest.  There is no need to call probe function 
> for each bank, or to partition each bank separately.  This seems to be 
> another one of the MTD undocumented "features".

Yes, they are the same. Yes, they are consecutive in memory. Yes, I
tried that. Yes, it's now less undocumented, because my diff contains
this information :)

Well, actually, when using physmap.c I am able to create partitions, but
there is still some trouble when using the mtd partitions: erasing and
mounting fails.

Does someone have an idea, what I am doing wrong?

# flash_erase /dev/mtd0
File open error
# flash_erase /dev/mtd4 0x0 0x40
Erase Total 64 Units
Performing Flash Erase of length 131072 at offset 0x160000
MTD Erase failure: Invalid argument
# ls -la /dev/mtd*
crw-r--r--    1 0        0         90,   0 Jan  9  2005 /dev/mtd0
crw-r--r--    1 0        0         90,   1 May 13  2005 /dev/mtd1
crw-r--r--    1 0        0         90,   2 May 15  2005 /dev/mtd2
crw-r--r--    1 0        0         90,   3 May 15  2005 /dev/mtd3
crw-r--r--    1 0        0         90,   4 May 18  2005 /dev/mtd4
crw-r--r--    1 0        0         90,   5 May 18  2005 /dev/mtd5
brw-r--r--    1 0        0         31,   0 May 15  2005 /dev/mtdblock0
brw-r--r--    1 0        0         31,   1 May 15  2005 /dev/mtdblock1
brw-r--r--    1 0        0         31,   2 May 15  2005 /dev/mtdblock2
brw-r--r--    1 0        0         31,   3 May 15  2005 /dev/mtdblock3
brw-r--r--    1 0        0         31,   4 May 18  2005 /dev/mtdblock4
brw-r--r--    1 0        0         31,   5 May 18  2005 /dev/mtdblock5
# cat /proc/partitions
major minor  #blocks  name
  31     0       5632 mtdblock0
  31     1       1024 mtdblock1
  31     2       1408 mtdblock2
  31     3        128 mtdblock3
  31     4       8192 mtdblock4
# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00580000 00020000 "root"
mtd1: 00100000 00020000 "kernel"
mtd2: 00160000 00020000 "initrd"
mtd3: 00020000 00020000 "reset"
mtd4: 00800000 00020000 "jffs2"

Here's the output of dmesg:
physmap flash device: 1000000 at 38000000
phys_mapped_flash: Found 1 x16 devices at 0x0 in 16-bit bank
phys_mapped_flash: Found 1 x16 devices at 0x800000 in 16-bit bank
 Intel/Sharp Extended Query Table at 0x0031
Using buffer write method
cfi_cmdset_0001: Erase suspend on write enabled
0: offset=0x0,size=0x20000,blocks=64
1: offset=0x800000,size=0x20000,blocks=64
5 cmdlinepart partitions found on MTD device phys_mapped_flash
Creating 5 MTD partitions on "phys_mapped_flash":
0x00000000-0x00580000 : "root"
0x00580000-0x00680000 : "kernel"
0x00680000-0x007e0000 : "initrd"
0x007e0000-0x00800000 : "reset"
0x00800000-0x01000000 : "jffs2"

Kernel version: 2.6.11.8, mtd cvs snapshot 2005-05-15.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: CFI physmap - how to create partitions
  2005-05-20  7:26     ` Thorsten Haas
@ 2005-05-20 12:58       ` Ralph Siemsen
  2005-05-20 13:20         ` Thorsten Haas
  0 siblings, 1 reply; 7+ messages in thread
From: Ralph Siemsen @ 2005-05-20 12:58 UTC (permalink / raw)
  To: Thorsten Haas; +Cc: linux-mtd

Thorsten Haas wrote:

> Yes, they are the same. Yes, they are consecutive in memory. Yes, I
> tried that. Yes, it's now less undocumented, because my diff contains
> this information :)

Excellent.

> Well, actually, when using physmap.c I am able to create partitions, but
> there is still some trouble when using the mtd partitions: erasing and
> mounting fails.
> 
> Does someone have an idea, what I am doing wrong?
> 
> # flash_erase /dev/mtd0
> File open error

That's a bit worrysome... Not sure if it checks for this, but do you 
have this partition mounted at the time?

Also check in /proc/devices that major 90 is in fact registered.

> # flash_erase /dev/mtd4 0x0 0x40
> Erase Total 64 Units
> Performing Flash Erase of length 131072 at offset 0x160000
> MTD Erase failure: Invalid argument

Hmm, I always use "flash_eraseall" command myself, so I don't have to 
worry about the block numbers and such.  But I doubt this makes any 
difference, your problem seems to lie elsewhere.

-R

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: CFI physmap - how to create partitions
  2005-05-20 12:58       ` Ralph Siemsen
@ 2005-05-20 13:20         ` Thorsten Haas
  0 siblings, 0 replies; 7+ messages in thread
From: Thorsten Haas @ 2005-05-20 13:20 UTC (permalink / raw)
  To: Ralph Siemsen; +Cc: linux-mtd

Am Freitag, den 20.05.2005, 08:58 -0400 schrieb Ralph Siemsen:
> Thorsten Haas wrote:
> 
> > Yes, they are the same. Yes, they are consecutive in memory. Yes, I
> > tried that. Yes, it's now less undocumented, because my diff contains
> > this information :)
> 
> Excellent.
> 
> > Well, actually, when using physmap.c I am able to create partitions, but
> > there is still some trouble when using the mtd partitions: erasing and
> > mounting fails.
> > 
> > Does someone have an idea, what I am doing wrong?
> > 
> > # flash_erase /dev/mtd0
> > File open error
> 
> That's a bit worrysome... Not sure if it checks for this, but do you 
> have this partition mounted at the time?
Nope, not mounted.

> Also check in /proc/devices that major 90 is in fact registered.
It is registered. Device nodes are also present. 

> > # flash_erase /dev/mtd4 0x0 0x40
> > Erase Total 64 Units
> > Performing Flash Erase of length 131072 at offset 0x160000
> > MTD Erase failure: Invalid argument
> 
> Hmm, I always use "flash_eraseall" command myself, so I don't have to 
> worry about the block numbers and such.  But I doubt this makes any 
> difference, your problem seems to lie elsewhere.
> 
> -R

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2005-05-20 13:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-18  8:05 CFI physmap - how to create partitions Thorsten Haas
2005-05-18 22:35 ` Ralph Siemsen
2005-05-19  8:06 ` Thorsten Haas
2005-05-19 11:54   ` Ralph Siemsen
2005-05-20  7:26     ` Thorsten Haas
2005-05-20 12:58       ` Ralph Siemsen
2005-05-20 13:20         ` Thorsten Haas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox