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 18468C433F5 for ; Mon, 4 Apr 2022 16:33:53 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 42B7881DD3; Mon, 4 Apr 2022 18:33:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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=kernel.org header.i=@kernel.org header.b="LjN9bdM7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 03E0E83678; Mon, 4 Apr 2022 18:33:50 +0200 (CEST) Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) (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 CF98781B5C for ; Mon, 4 Apr 2022 18:33:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7B66FB8101C; Mon, 4 Apr 2022 16:33:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28BA7C2BBE4; Mon, 4 Apr 2022 16:33:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649090021; bh=je2cEw52fewgZHno9Ec+o2/SXeoRL2EyVgstQVn7xsM=; h=From:To:Cc:Subject:Date:From; b=LjN9bdM7dmS3jpqVfnEG7P8iU5tnkS2cwG0et4H5532zpyReHS1FSAJKJo5xiG8v9 1l7mNBmZuXV5NNtsJV4Fy0HoucRt7RowdHoMigwdbIbNCpl+iOlI5KgJiJeZHM50YU 0Am4215/RozkVae67iY5OT4VNqFhsM6lyudD0THiwa4NUkPah9iGcPWtX4qsjFe7I0 uO6zmCB5PVw7uQ89yxmQk8Eifcd3rkv9MK6ntM/AR1NK8YktLgiA8cHi7UwQOdbca3 6Mwk8RAcS9LBXnPk3Ngmr7P6cUt+PUzM9aKkiREubn4JIMqfnr6FTCNtmXMyYv118O 8mVbVqmZ24iuA== Received: by pali.im (Postfix) id D2A6D768; Mon, 4 Apr 2022 18:33:38 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Priyanka Jain , Peng Fan , Jaehoon Chung Cc: u-boot@lists.denx.de Subject: [PATCH] mmc: fsl_esdhc_spl: pre-PBL: implement redundancy support Date: Mon, 4 Apr 2022 18:33:11 +0200 Message-Id: <20220404163311.5853-1-pali@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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.5 at phobos.denx.de X-Virus-Status: Clean QorIQ pre-PBL BootROM scans first 24 SD card sectors (each with fixed 512 bytes length) for boot signature. Implement same redundancy behavior in fsl_esdhc_spl driver to allow loading proper U-Boot when boot sector is not the first one. Signed-off-by: Pali Rohár --- drivers/mmc/fsl_esdhc_spl.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/mmc/fsl_esdhc_spl.c b/drivers/mmc/fsl_esdhc_spl.c index 0146a231b221..ea8f4cd66964 100644 --- a/drivers/mmc/fsl_esdhc_spl.c +++ b/drivers/mmc/fsl_esdhc_spl.c @@ -20,7 +20,6 @@ #define ESDHC_BOOT_IMAGE_ADDR 0x50 #define MBRDBR_BOOT_SIG_55 0x1fe #define MBRDBR_BOOT_SIG_AA 0x1ff -#define CONFIG_CFG_DATA_SECTOR 0 void mmc_spl_load_image(uint32_t offs, unsigned int size, void *vdst) @@ -62,11 +61,13 @@ void __noreturn mmc_boot(void) #ifndef CONFIG_FSL_CORENET uchar *tmp_buf; u32 blklen; + u32 blk_off; uchar val; #ifndef CONFIG_SPL_FSL_PBL u32 val32; #endif uint i, byte_num; + u32 sector; #endif u32 offset, code_len; struct mmc *mmc; @@ -86,30 +87,37 @@ void __noreturn mmc_boot(void) offset = CONFIG_SYS_MMC_U_BOOT_OFFS; #else blklen = mmc->read_bl_len; + if (blklen < 512) + blklen = 512; tmp_buf = malloc(blklen); if (!tmp_buf) { puts("spl: malloc memory failed!!\n"); hang(); } + + sector = 0; +again: memset(tmp_buf, 0, blklen); /* * Read source addr from sd card */ - err = mmc->block_dev.block_read(&mmc->block_dev, - CONFIG_CFG_DATA_SECTOR, 1, tmp_buf); + blk_start = (sector * 512) / mmc->read_bl_len; + blk_off = (sector * 512) % mmc->read_bl_len; + blk_cnt = DIV_ROUND_UP(512, mmc->read_bl_len); + err = mmc->block_dev.block_read(&mmc->block_dev, blk_start, blk_cnt, tmp_buf); if (err != 1) { puts("spl: mmc read failed!!\n"); hang(); } #ifdef CONFIG_SPL_FSL_PBL - val = *(tmp_buf + MBRDBR_BOOT_SIG_55); + val = *(tmp_buf + blk_off + MBRDBR_BOOT_SIG_55); if (0x55 != val) { puts("spl: mmc MBR/DBR signature is not valid!!\n"); hang(); } - val = *(tmp_buf + MBRDBR_BOOT_SIG_AA); + val = *(tmp_buf + blk_off + MBRDBR_BOOT_SIG_AA); if (0xAA != val) { puts("spl: mmc MBR/DBR signature is not valid!!\n"); hang(); @@ -123,10 +131,13 @@ void __noreturn mmc_boot(void) byte_num = 4; val32 = 0; for (i = 0; i < byte_num; i++) { - val = *(tmp_buf + ESDHC_BOOT_SIGNATURE_OFF + i); + val = *(tmp_buf + blk_off + ESDHC_BOOT_SIGNATURE_OFF + i); val32 = (val32 << 8) + val; } if (val32 != ESDHC_BOOT_SIGNATURE) { + /* BOOT signature may be on the first 24 sectors (each being 512 bytes) */ + if (++sector < 24) + goto again; puts("spl: mmc BOOT signature is not valid!!\n"); hang(); } @@ -135,7 +146,7 @@ void __noreturn mmc_boot(void) byte_num = 4; offset = 0; for (i = 0; i < byte_num; i++) { - val = *(tmp_buf + ESDHC_BOOT_IMAGE_ADDR + i); + val = *(tmp_buf + blk_off + ESDHC_BOOT_IMAGE_ADDR + i); offset = (offset << 8) + val; } offset += CONFIG_SYS_MMC_U_BOOT_OFFS; -- 2.20.1