Subject: Re: RFC: Flash memory device API
To: Jared D. McNeill <>
From: Allen Briggs <>
List: tech-kern
Date: 09/04/2006 22:40:25
On Mon, Sep 04, 2006 at 08:27:58PM -0300, Jared D. McNeill wrote:
> On the road to building a flash filesystem for NetBSD, I decided that  
> a generic flash API was needed first. Feedback is welcome.

Most excellent!

> Externally, flash(4) exposes the following ioctl operations:
> 	FLASH_ERASEBLOCK: erase a single block
> 	FLASH_GBLOCKSTATUS: get the status of a single block
> 	FLASH_SBLOCKSTATUS: set the status of a single block
> 	FLASH_GETINFO: query flash device capabilities
> Flash device capabilities is defined by flash_info_t, which provides:
> 	enum flash_type fi_type;		/* NOR or NAND */
> 	block_id_t fi_nblocks;
> 	size_t fi_bytesperblock;
> 	size_t fi_sectorsperblock;
> 	size_t fi_sectorsize;

There are devices out there with non-uniform erase block sizes.
These are often called "boot flashes" and have the first or last
erase block sub-divided up into smaller blocks.  Do you plan to
deal with those at all?

Another, perhaps interesting, thing to consider is devices that
are set up in parallel.  For example, two 16-bit devices on a
single 32-bit bus where bits 0-15 select one device and bits 16-31
select the other.  This can be detected for CFI devices, as I recall.

> Internally, a hardware flash device driver must implement the  
> following callbacks:
> 	init(void *)
> 	deinit(void *)
> 	get_info(void *, flash_info_t *)
> 	erase_block(void *, block_id_t)
> 	get_block_status(void *, block_id_t)
> 	set_block_status(void *, block_id_t, int)
> 	read_sector(void *, int, uint8_t *, sector_info_t *, int)
> 	write_sector(void *, int, uint8_t *, sector_info_t *, int)
> 	ioctl(void *, u_long, caddr_t, int, struct lwp *)	<-- optional

For a flash filesystem, I think you'll want a way to read/write
byte- or maybe word-size elements--taking advantage of the fact
that on NOR flash at least, you can rewrite a word as long as
you're just clearing bits (I've only dealt with flash parts that
erase to all bits set).  That can be useful.

I have no experience with NAND flash.

Thanks again for looking at this!


Allen Briggs  |  |