use CFI-Flash and board depended driver together
PATCH 1/1 use CFI-Flash and board depended driver together
Hello,
i need to use cfi and board flash driver together. This Patch contains a simple way to do this with a minimun changes at cfi_flash.c. All changes will only enable if CFG_FLASH_BOARD_DRIVER defined.
CHANGELOG
* Rename flash_print_info, flash_erase, write_buff and flash_real_protect to cfi_xxxx, if CFG_FLASH_BOARD_DRIVER is defined. This will allow use cfi driver together with board a dependent flash driver (see README.board-dependent-flash for an example)
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch_mix_bdflash_cfi.diff
Url: http://lists.denx.de/pipermail/u-boot/attachments/20061130/9f0805c4/attachment.txt
PATCH 1/1 use CFI-Flash and board depended driver together
Review
Quoted 6 lines · Jens Scharsig
(quoted diff) +6
-0+#ifdef CFG_FLASH_BOARD_DRIVER +#define flash_print_info cfi_flash_print_info +#define flash_erase cfi_flash_erase +#define write_buff cfi_write_buff +#define flash_real_protect cfi_flash_real_protect +#endif
Ugh, I really dislike code like this. I know Wolfgang has the final say on these things, but I would rather you did something else. For instance, if CFG_FLASH_BOARD_DRIVER is not defined, then the cfi_xxx functions are defined here. Otherwise, they are declared as externs and they need to be defined in the board file. Like this:
#ifdef CFG_FLASH_BOARD_DRIVER
extern ... cfi_flash_print_info(...);
extern ... cfi_flash_erase(...);
extern ... cfi_write_buff(...);
extern ... cfi_flash_real_protect(...);
#else
... cfi_flash_print_info(...)
{
// original cfi_flash_print_info code here
}// and so on
#endif
Review
Quoted 5 lines
(quoted diff) +4
-0+#ifdef CFG_FLASH_BOARD_DRIVER + size += flash_info[i].size = board_flash_get_size (bank_base[i], i); +#else size += flash_info[i].size = flash_get_size (bank_base[i], i); +#endif
You could do the same thing here. Rename flash_get_size() to cfi_flash_get_size() and treat it like the other cfi_xxx functions above.
PATCH 1/1 use CFI-Flash and board depended driver together
Quoted 1 line · Timur Tabi
Ugh, I really dislike code like this.
I know,this code is dirty. But it's very simple and works for me.
Quoted 3 lines
on these things, but I would rather you did something else. For instance, if
CFG_FLASH_BOARD_DRIVERis not defined, then thecfi_xxxfunctions are defined here. Otherwise, they are declared as externs and
No, if CFG_FLASH_BOARD_DRIVER is not defined cfi_xxx functions are not defined in orginal cfi_flash.c. In this case all other uboot moduls can call functions under orginal names.
Quoted 2 lines
You could do the same thing here. Rename
flash_get_size()tocfi_flash_get_size()and treat it like the othercfi_xxxfunctions above.
A simple rename doesn't work.
flash_init calls board_flash_get_size
andboard_flash_getsize calls the orginal flash_get_size, if selected bank is suppored by cfi driver
PATCH 1/1 use CFI-Flash and board depended driver together
Quoted 3 lines · Jens Scharsig
No, if
CFG_FLASH_BOARD_DRIVERis not definedcfi_xxxfunctions are not defined in orginalcfi_flash.c. In this case all other uboot moduls can call functions under orginal names.
Ok, I get it now. But all you're basically doing is hiding the CFI flash routines. The flash commands in cmd_flash.c are only going to call the board-specific routines and not the CFI routines.
Signature · 2 lines
Timur Tabi Linux Kernel Developer @ Freescale
PATCH 1/1 use CFI-Flash and board depended driver together
Quoted 5 lines · Timur Tabi
Ok, I get it now. But all you're basically doing is hiding the CFI flash routines. The flash commands in
cmd_flash.care only going to call the board-specific routines and not the CFI routines.
That's my inspiration. The flash commands call board-specific routines and board-specific routines call back the orginal cfi routines, if i want this.
PATCH 1/1 use CFI-Flash and board depended driver together
In reply to Jens ScharsigQuoted 7 lines · Jens Scharsig
Hello,
i need to use cfi and board flash driver together. This Patch contains a simple way to do this with a minimun changes at
cfi_flash.c. All changes will only enable ifCFG_FLASH_BOARD_DRIVERdefined.
Quoted 7 lines
CHANGELOG
* Rename
flash_print_info,flash_erase,write_buffandflash_real_protecttocfi_xxxx, ifCFG_FLASH_BOARD_DRIVERis defined. This will allow use cfi driver together with board a dependent flash driver (see README.board-dependent-flash for an example)
I have to object to this patch. I will be providing a testing patch tonight or tomorrow that will address this issue properly which is teaching cfi_flash driver to deal with non-cfi flash. There is no need to have two flash drivers...
Tolunay
PATCH 1/1 use CFI-Flash and board depended driver together
Quoted 16 lines · Tolunay Orkun
Quoted 7 lines · Jens Scharsig
Hello,
i need to use cfi and board flash driver together. This Patch contains a simple way to do this with a minimun changes at
cfi_flash.c. All changes will only enable ifCFG_FLASH_BOARD_DRIVERdefined.Quoted 7 lines
CHANGELOG
* Rename
flash_print_info,flash_erase,write_buffandflash_real_protecttocfi_xxxx, ifCFG_FLASH_BOARD_DRIVERis defined. This will allow use cfi driver together with board a dependent flash driver (see README.board-dependent-flash for an example)
Quoted 4 lines
I have to object to this patch. I will be providing a testing patch tonight or tomorrow that will address this issue properly which is teaching
cfi_flashdriver to deal with non-cfi flash. There is no need to have two flash drivers...
I've started with this patch but ran into some roadblocks so it did not happen last friday as promised. I have been thinking better solutions that avoids two sets of flash drivers.
Basically, I was trying to detect the port and chip width by using a technique similar to flash_detect_cfi() but instead of checking for combinations of Q R Y etc., I was trying to see there was a change in the first 16 bytes of flash. Well that seemed workable until I actually tried the modified code :( The probe this way failed miserably with Intel flash responding to 0x90 in either in upper or lower byte even in 16-bit mode!
Thus, if the flash is not detected by CFI method the portwidth and chipwidth will have to be set manually for even jedec ids to be read properly. If the jedec probe worked, the jedec ids could be used to lookup a static list for proper configuration of info structure.
I have not given up yet. I would like to start over and take a simpler approach. Here is the idea:
The CFI driver will do CFI probe. If the probe is not successful and board configuration has defined a macro, CFI driver will call a board specific function to setup the flash_info_t for that bank.
I will pass the bank number to the function as argument. If the function returns non-zero, I will assume that board has setup the info structure successfully (hopefully) and move on. This still avoids driver code duplication by only passing the responsibility of setting up the info structure to the board.
A variation of this could be the callback function obtains the portwidth, chipwidth (and possibly the command set) for the specific bank and do flash_read_jedec_ids to get the ids and lookup the values from a statically compiled list like I originally intended. This list would be compiled in compiled only if this feature is enabled, say CFG_FLASH_CFI_JEDEC. Instead of a callback we could use the flash_base address list and augment the array to an array of structures which include base, portwidth and chipwidth but that would require a change in all boards that uses CFI driver. A callback to the board supplied function is the least invasive way in my opinion.
In either method, to cut the compiled image size a bit if there is definitely no cfi compliant flash on any bank we can omit the cfi detection and other cfi related setup code using a macro like CFG_FLASH_CFI_DISABLE (or something like that).
I would like to hear opinions regarding which choices looks more attractive...
Tolunay
PATCH 1/1 use CFI-Flash and board depended driver together
In reply to Tolunay OrkunQuoted 16 lines · Tolunay Orkun
Quoted 7 lines · Jens Scharsig
Hello,
i need to use cfi and board flash driver together. This Patch contains a simple way to do this with a minimun changes at
cfi_flash.c. All changes will only enable ifCFG_FLASH_BOARD_DRIVERdefined.Quoted 7 lines
CHANGELOG
* Rename
flash_print_info,flash_erase,write_buffandflash_real_protecttocfi_xxxx, ifCFG_FLASH_BOARD_DRIVERis defined. This will allow use cfi driver together with board a dependent flash driver (see README.board-dependent-flash for an example)
Quoted 4 lines
I have to object to this patch. I will be providing a testing patch tonight or tomorrow that will address this issue properly which is teaching
cfi_flashdriver to deal with non-cfi flash. There is no need to have two flash drivers...
I've started with this patch but ran into some roadblocks so it did not happen last Friday as promised. I have been thinking better solutions that avoids two sets of flash drivers.
Basically, I was trying to detect the port and chip width by using a technique similar to flash_detect_cfi() but instead of checking for combinations of Q R Y etc., I was trying to see there was a change in the first 16 bytes of flash. Well that seemed workable until I actually tried the modified code :( The probe this way failed miserably with Intel flash responding to 0x90 in either in upper or lower byte even in 16-bit mode!
Thus, if the flash is not detected by CFI method the portwidth and chipwidth will have to be set manually for even jedec ids to be read properly. If the jedec probe worked, the jedec ids could be used to lookup a static list for proper configuration of info structure.
I have not given up yet. I would like to start over and take a simpler approach. Here is the idea:
The CFI driver will do CFI probe. If the probe is not successful and board configuration has defined a macro, CFI driver will call a board specific function to setup the flash_info_t for that bank.
I will pass the bank number to the function as argument. If the function returns non-zero, I will assume that board has setup the info structure successfully (hopefully) and move on. This still avoids driver code duplication by only passing the responsibility of setting up the info structure to the board.
A variation of this could be the callback function obtains the portwidth, chipwidth (and possibly the command set) for the specific bank and do flash_read_jedec_ids to get the ids and lookup the values from a statically compiled list like I originally intended. This list would be compiled in compiled only if this feature is enabled, say CFG_FLASH_CFI_JEDEC. Instead of a callback we could use the flash_base address list and augment the array to an array of structures which include base, portwidth and chipwidth but that would require a change in all boards that uses CFI driver. A callback to the board supplied function is the least invasive way in my opinion.
In either method, to cut the compiled image size a bit if there is definitely no cfi compliant flash on any bank we can omit the cfi detection and other cfi related setup code using a macro like CFG_FLASH_CFI_DISABLE (or something like that).
I would like to hear opinions regarding which choices looks more attractive...
Tolunay