From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0C41DECAAD3 for ; Mon, 5 Sep 2022 14:14:46 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B3D5784913; Mon, 5 Sep 2022 16:14:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="mxw8Elar"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E473084870; Mon, 5 Sep 2022 16:14:41 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BF3EC8492D for ; Mon, 5 Sep 2022 16:14:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=jitloonl@ecsmtp.png.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662387278; x=1693923278; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=R9dPJ3NauAjos5OlIHLTXVITd22A2znL/yDC/VKFUvw=; b=mxw8ElarokWUCubb3vJToRhn6Hi7f1lgMbuybyGDUXgaJv1JZjit4a25 NgABCXxQ/2KDdAA+1r2CdsQ82ACo0FIk+yqceANxi51yvFBSmDbBbHklo g3AYwajpwD3IxTPILcwuzHsrDSvQxzMTwjHs+bZzHjmlLBgBF5uVDHo/I sulUs+AGCXh73ADGJG17w8Es2Ue89vUOOJuCS30DXA7af7ZS9Yaj7+Rnz Yo2fL97RvT3ItKCeC1RXHspTDwPQJKzIdXF19zQw/pcAwYh7EhuiEpLBE jZLxn9pMVVx22LiJWCoulAO44uwMNt6nznu2DiAG6e5Bvsb+dyR6T1ZwA Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10461"; a="382696788" X-IronPort-AV: E=Sophos;i="5.93,291,1654585200"; d="scan'208";a="382696788" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Sep 2022 07:14:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,291,1654585200"; d="scan'208";a="858971709" Received: from pglmail07.png.intel.com ([10.221.193.207]) by fmsmga006.fm.intel.com with ESMTP; 05 Sep 2022 07:14:31 -0700 Received: from localhost (pgli0117.png.intel.com [10.221.240.80]) by pglmail07.png.intel.com (Postfix) with ESMTP id 37E5132EB; Mon, 5 Sep 2022 22:14:31 +0800 (+08) Received: by localhost (Postfix, from userid 12048045) id 345943D4F; Mon, 5 Sep 2022 22:14:31 +0800 (+08) From: Jit Loon Lim To: u-boot@lists.denx.de Cc: Jagan Teki , Vignesh R , Marek , Simon , Tien Fong , Kok Kiang , Siew Chin , Sin Hui , Raaj , Dinesh , Boon Khai , Alif , Teik Heng , Hazim , Sieu Mun Tang , Jit Loon Lim Subject: [PATCH] mtd: nand: denali: Add SPL image loader Date: Mon, 5 Sep 2022 22:14:29 +0800 Message-Id: <20220905141429.28532-1-jit.loon.lim@intel.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean From: Tien Fong Chee Add image loader used by the NAND SPL into the full Denali NAND driver. This allows usage of the full Denali NAND driver in SPL instead of the reduced SPL-only version. Signed-off-by: Tien Fong Chee Signed-off-by: Jit Loon Lim --- drivers/mtd/nand/raw/denali.c | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/drivers/mtd/nand/raw/denali.c b/drivers/mtd/nand/raw/denali.c index c827f80281..499b4acc6e 100644 --- a/drivers/mtd/nand/raw/denali.c +++ b/drivers/mtd/nand/raw/denali.c @@ -7,7 +7,9 @@ #include #include +#include #include +#include #include #include #include @@ -1374,3 +1376,56 @@ free_buf: return ret; } + +#ifdef CONFIG_SPL_BUILD +int nand_spl_load_image(u32 offset, u32 len, void *dst) +{ + size_t count = len, actual = 0, page_align_overhead = 0; + u32 page_align_offset = 0; + u8 *page_buffer; + int err = 0; + struct mtd_info *mtd; + + if (!len || !dst) + return -EINVAL; + + mtd = get_nand_dev_by_index(nand_curr_device); + if (!mtd) + hang(); + + if ((offset & (mtd->writesize - 1)) != 0) { + page_buffer = malloc_cache_aligned(mtd->writesize); + if (!page_buffer) { + debug("Error: allocating buffer\n"); + return -ENOMEM; + } + + page_align_overhead = offset % mtd->writesize; + page_align_offset = (offset / mtd->writesize) * mtd->writesize; + count = mtd->writesize; + + err = nand_read_skip_bad(mtd, page_align_offset, &count, + &actual, mtd->size, page_buffer); + + if (err) + return err; + + count -= page_align_overhead; + count = min((size_t)len, count); + memcpy(dst, page_buffer + page_align_overhead, count); + free(page_buffer); + + len -= count; + if (!len) + return err; + + offset += count; + dst += count; + count = len; + } + + return nand_read_skip_bad(mtd, offset, &count, &actual, mtd->size, dst); +} + +void nand_deselect(void) {} +#endif -- 2.26.2