From patchwork Mon Mar 21 12:42:00 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Krause X-Patchwork-Id: 87765 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 8D855B6F73 for ; Mon, 21 Mar 2011 23:47:18 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1D38E280D6; Mon, 21 Mar 2011 13:47:13 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SEERK7bGmM-t; Mon, 21 Mar 2011 13:47:12 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 35B7D280CE; Mon, 21 Mar 2011 13:47:10 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4C5AB280CE for ; Mon, 21 Mar 2011 13:47:07 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Pnaz8owfFAFh for ; Mon, 21 Mar 2011 13:47:06 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail.tqs.de (mail.tqs.de [62.157.136.17]) by theia.denx.de (Postfix) with ESMTP id 091FB280C7 for ; Mon, 21 Mar 2011 13:47:04 +0100 (CET) Received: from unknown (HELO tq-mailsrv.tq-net.de) ([172.20.1.2]) by mail.tqs.de with ESMTP; 21 Mar 2011 13:47:04 +0100 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Date: Mon, 21 Mar 2011 13:42:00 +0100 Message-ID: <47F3F98010FF784EBEE6526EAAB078D10635EA18@tq-mailsrv.tq-net.de> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: cfi_flash - bug with flash banks with different sector numbers Thread-Index: AcvnxV9ok9tSqpckRSqbcbJm5/6MwA== From: "Martin Krause" To: Subject: [U-Boot] cfi_flash - bug with flash banks with different sector numbers X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Hi list, I encountered a problem with the cfi_flash driver on a board with two flash banks with a different number of flash secotrs. It seems that the function find_sector() which tries to speed up successive flash accesses does not take into account the current flash bank correctly. I created a patch with a fix (see blow), but since I do not work with current U-Boot, this patch likely will not apply cleanly to TOT (but is neccessary, since the bug is still present there). Best regards, Martin From 22454f09e058a3b0b8e86bc4d5566c21e23f5b63 Mon Sep 17 00:00:00 2001 From: Martin Krause Date: Mon, 21 Mar 2011 13:08:19 +0100 Subject: [PATCH] cfi_flash: fix bug with flash banks with different sector numbers The function find_sector() does not take into account if the flash bank has changed since the last call. This could lead to illegal accesses inside and beyond the flash_info_t info strcture. For example if the current flash bank has less sectors than the last used flash bank. This patch adds two cheks. One that insures, that the current sector does not exceed the allowed maximum (which is always a good idea). And one that checks if the current access is to the same flash bank as the last access. If not, the search loop will start with sector 0. Signed-off-by: Martin Krause --- drivers/mtd/cfi_flash.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) while ((info->start[sector] < addr) && (sector < info->sector_count - 1)) sector++; @@ -666,6 +670,7 @@ static flash_sect_t find_sector (flash_info_t * info, ulong addr) sector--; saved_sector = sector; + saved_info = info; return sector; } -- 1.6.6.1 diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 24eb33f..ff1457c 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -653,8 +653,12 @@ static void flash_add_byte (flash_info_t * info, cfiword_t * cword, uchar c) static flash_sect_t find_sector (flash_info_t * info, ulong addr) { static flash_sect_t saved_sector = 0; /* previously found sector */ + static flash_info_t *saved_info = 0; /* previously used flash bank */ flash_sect_t sector = saved_sector; + if ((info != saved_info) || (sector >= info->sector_count)) + sector = 0; +