Subject: RFC: Flash memory device API
To: None <>
From: Jared D. McNeill <>
List: tech-kern
Date: 09/04/2006 20:27:58
Hey folks --

On the road to building a flash filesystem for NetBSD, I decided that  
a generic flash API was needed first. Feedback is welcome.

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;

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

After filling in the structure of function callbacks, the hardware  
driver must call flash_attach_mi.

Additionally, a userland utility is provided as flashctl(8) that  
allows you to query device info, erase blocks, and get or set block  

Source code is available here for review: