From patchwork Thu Jun 6 08:59:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Saini X-Patchwork-Id: 449 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id DE49D3F086 for ; Thu, 6 Jun 2019 10:59:39 +0200 (CEST) Received: by mail-pl1-f200.google.com with SMTP id d19sf1142842pls.1 for ; Thu, 06 Jun 2019 01:59:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1559811577; cv=pass; d=google.com; s=arc-20160816; b=czwRXjSSz7QWPiDwJU3zaZ9BUwTmUEq8i52PRmyOWl1+oHwO4BjiWxpCxsbJNUrfKq zpvwymcHP8JKXyamjrzdvu4b7kuSv4NJEs4ojXiThfgE+xYTb72YC1YQEXwiXY/4Antg ZDs/rJF3r7Nek7PwpefeGlVTX1d8/PufUmJuU5zYAnOERMVF7lEDn1p3iZBxEBXhq+UN q8W5JKaZ6T9oykCdSQIIoCCrfF6pjVfE70AARU6rDkFee5/84hum9Z7EOgQO0m3vpE6w PRNZWPDRd+EN1ca6ftvgdbWktWJgXBtyIrRVWBfxxiZU4Z+gEA2umDriD1DytUmW5LYS kFgA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:message-id:date:subject:cc:to:from :mime-version:dkim-signature; bh=fK58HoYlJCnvSbr32Cow5de7kBiBHZIqPuNiEZF7S6I=; b=kkmT2Ucy9epXpi6vQaFbOwPtAMLnyZ7eQqCDEaliK9timdMmYqe5zEgKx/MQ7UR1TW BPWyEnjSaObuSOTVC7c0ebV8efQ1E0jZhHGCaacHaGL8/iERClg3+cWb2CMpvY/Ojn23 uBAA70clwBMD+f6bJFOr7GP9hbXGuQtoxALj3b81q3ljiuKvstBLrRIo/qjSoB/bo0xN PxwkCz0HitL/2dEqf89GlCcZaDAVvV6IOGdlepSbQWGoRR7yVE1I7X4BYH4IlgaStP2t VEzT9l6+eMkkK7UR01h/yKomLSReVJKQNL9k/0i+5RmHS6oE3HF3ap1ZbBdYlrPJaxPK 2pdQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=PLpi4wcN; spf=pass (google.com: domain of shyam.saini@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=shyam.saini@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=fK58HoYlJCnvSbr32Cow5de7kBiBHZIqPuNiEZF7S6I=; b=Eo50D7qHBlfbq2B1fa3tsTqSjpkTfzoCDam3mTuhat5bIHs+bs3IOJEPkhXIGGIA7a OTCUhkw6f/+In8h7kYscNK/sKCENUuPb+GcQJJDgBVANlvGMTfWge84zB5PJYCXBeSY3 Z8w1ZRWWFKexqcHNL3kBsyornMX6WS2I6OOj8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help :list-archive:list-unsubscribe; bh=fK58HoYlJCnvSbr32Cow5de7kBiBHZIqPuNiEZF7S6I=; b=uf9ZE1K9VUiz+X6R+ssKQRUVpapbRyTOqUb9Q1VUXtbdkNfrGDtcPnE4XlFV2gVgSu RklRK1Wlrb53zWXXFxYDY3hiElbcSx1qypJ3ch0GftEL8GTC7+Hro2Uxca8EThh4v1m0 Hwjl1werx/EqqIusZNHko2bYhe+aLkJcZMz3Vqi+gwMdfrlfciVZG0GdW2kJDft35Dvn kYpClpkIXSgYIYSJqmJgfn6mzGg6ISV2YsxxQSk0jkO5GNUB0FRH0m3dKkoLCM0ZkWQK Oy6Wv3KZYUzDuhQsxBK2lQmcMSEqG6cSxMCjupgmZ+vacG/x2cOpYJnxP5HyKvU8ZDOa rbnQ== X-Gm-Message-State: APjAAAUHtGMHsntchHQbge195yAmQUwzZyjIN2mRYUDOFaiO99cVR1C6 A0K7lCBv43Pr1/LBNzUb/RS9UraK X-Google-Smtp-Source: APXvYqxFtn8JTXortobcXG7I6/hbdQW/E6XHHGRzhbQXXigIZtocs9Ir/kUss/MAp2TXwIsWi3NF5A== X-Received: by 2002:a62:1ec3:: with SMTP id e186mr52528917pfe.197.1559811577645; Thu, 06 Jun 2019 01:59:37 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:902:b605:: with SMTP id b5ls1208880pls.12.gmail; Thu, 06 Jun 2019 01:59:37 -0700 (PDT) X-Received: by 2002:a17:902:aa08:: with SMTP id be8mr48307244plb.177.1559811577274; Thu, 06 Jun 2019 01:59:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559811577; cv=none; d=google.com; s=arc-20160816; b=QIsAxI5cjQuTxv843yxvXt1kLKQhiDfvoHZgGLZxK1iYUtng9vsCVRXeVpwCQQQ7nS DQ3lhcQ2i+KqYpXI59GKeGDl5iCGRm+hiKibYJmQv3kGe/M9L7r7lH6Ws55ZudKhPwSU V4qhhDHTZrW7c4ggeXJQkgsITpctrBFKNcL9xt+rzdzs2NzdgwkF/KUzLkprvRahksLw Xiokz7dVPbZnrP+55GRRQ2eRJJHoO1ysFuwJwUADPMvad64ODOqTmxGWPAf8W1LXxB3d bm3yWnOrv7bFIGpJObCCaJMi4BAGEqVjuWTZBmufDJSaC2MUfYSXSeR4CIYvArTVsoXJ ToQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=AWcNitRhdUFouyR5o381AJ3ppoHIHMSdIQOgH28lqqA=; b=BVK22Y4ybDeaZfrNEi0dl2kaN+auV9Y3cinzHwSiqX8nNyLlWyuXHCmtg+OEgBu1YL wG7R641uScKeWlQf/HunzF50zzqAHTKcF9OICo4c9ZmU2hOWYHcRvQBvI9kXdymhdwbm s824s5xo0Z8edU2IoZfv9liV/JUR40DSSIJQXlT4wyysB+IU13PRUEeNyY2OpCQ715UW 1yE1b/k7QJO15dLEPdfKIhywH6CbSJ+kKDTwHSLKSh2LzyVurz7vVPmkgb1A5kq3usAj xQPxYIQIatvDkNuDr7l61e+6s7W+VS3+WrvEyt4VJcJLiAPDS2rY7CoUefMptx2LDQxh RPXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=PLpi4wcN; spf=pass (google.com: domain of shyam.saini@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=shyam.saini@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id o2sor1068133pga.9.2019.06.06.01.59.36 for (Google Transport Security); Thu, 06 Jun 2019 01:59:36 -0700 (PDT) Received-SPF: pass (google.com: domain of shyam.saini@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a63:205b:: with SMTP id r27mr2430079pgm.330.1559811575883; Thu, 06 Jun 2019 01:59:35 -0700 (PDT) Received: from localhost.localdomain ([183.82.228.203]) by smtp.googlemail.com with ESMTPSA id 188sm2999482pfe.30.2019.06.06.01.59.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Jun 2019 01:59:35 -0700 (PDT) From: Shyam Saini To: u-boot@lists.denx.de Cc: stefan.agner@toradex.com, festevam@gmail.com, ksi@koi8.net, jagan@amarulasolutions.com, michael@amarulasolutions.com, sbabic@denx.de, linux-amarula@amarulasolutions.com, uboot-imx@nxp.com, Shyam Saini Subject: [PATCH 1/2] arm: i.MX: Add CMD_NANDBCB Kconfig entry Date: Thu, 6 Jun 2019 14:29:19 +0530 Message-Id: <20190606085920.17754-1-shyam.saini@amarulasolutions.com> X-Mailer: git-send-email 2.11.0 X-Original-Sender: shyam.saini@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=PLpi4wcN; spf=pass (google.com: domain of shyam.saini@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=shyam.saini@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add Kconfig entry for CMD_NANDBCB, and default y on i.MX6 platform with NAND_MXS defined. Signed-off-by: Jagan Teki Signed-off-by: Shyam Saini Reviewed-by: Stefano Babic --- Hi, This patch series is based on feedback gathered from this [1] discussion and [2] patch submitted by Stefan. [1] https://patchwork.ozlabs.org/patch/870467/ [2] https://patchwork.ozlabs.org/patch/897222/ Changes for v4: - No change Changes for v3: - Fixed Typo 'seprate' Changes for v2: - New patch arch/arm/mach-imx/Kconfig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig index ec09ef240f..5dd286f9a7 100644 --- a/arch/arm/mach-imx/Kconfig +++ b/arch/arm/mach-imx/Kconfig @@ -71,6 +71,17 @@ config CMD_HDMIDETECT This enables the 'hdmidet' command which detects if an HDMI monitor is connected. +config CMD_NANDBCB + bool "i.MX6 NAND Boot Control Block(BCB) command" + depends on NAND && CMD_MTDPARTS + default y if ARCH_MX6 && NAND_MXS + help + Unlike normal 'nand write/erase' commands, this command update + Boot Control Block(BCB) for i.MX6 platform NAND IP's. + + This is similar to kobs-ng, which is used in Linux as separate + rootfs package. + config NXP_BOARD_REVISION bool "Read NXP board revision from fuses" depends on ARCH_MX6 || ARCH_MX7 From patchwork Thu Jun 6 08:59:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Saini X-Patchwork-Id: 450 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 3E3093F086 for ; Thu, 6 Jun 2019 10:59:44 +0200 (CEST) Received: by mail-pf1-f198.google.com with SMTP id u7sf1376121pfh.17 for ; Thu, 06 Jun 2019 01:59:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1559811582; cv=pass; d=google.com; s=arc-20160816; b=TKEShLllzwm2XItg1M2eqYCt+vVuJzI9mluMR2u9JGGsoN8BKVuxHDF4w8qtUcIBt+ ACa4Ph5z76jcwC8AbtQMtd6er/RLoL8GSxwipQ5zvDG8013pLziWV+Wj9NY0yjotP9mo 5tslFofy4/HyizrqCqEqPo9DpSP+Lhky5QQ4Mg610ig52teAI7sDEjlJZCZDHG/WcAGF q+Q+zzlReOAv3ZROk3u3Cym9O0Nr62Bu5RuaTL6n0QpVZkAgHkKGoLzhycwdaHP02jkb I2UD2oeBVraABPKhFmHXe5cp76FMYRW+duBmlLeTFRRtwM8PMJf+r7y+Zk0QYZLoc3yN HTiA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:references:in-reply-to:message-id:date :subject:cc:to:from:mime-version:dkim-signature; bh=Kf5QZUZGOo+lKx5qsDTauweMTcYzxuT04ICbYSNetGI=; b=Ap0JFeppO2JewqRN1Zo1P1YjI82Te8DUIId8E0Hk++paUCViCGjln3x8QAXSfFvxeF 6qHmGVoKk26Fqkx6+lAZsJG4XlVQ2jx/UZWL+1NEEdxweOsaAkYGPRaclu4VCdSUoWXs iU0SDjj/evUKrN3ehUfjBGaJeGgTdc1TgXg7ibz1Z2JEqr5tZ6Vuoja1qeOePgVvC63V tPkVfGUpdiRRH5bYCzQsGuaV9yOXMyYOLzG+i9N18p0OZMc6DjED96ZlRXY9LygSau5U fzZwWsGPJOrBT06bC7NeH930ySnN4uK1KRzlfI3LWF5ToPdMXiZwHiYK+OvSUUkbWfb/ KXQA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=AjNkukKh; spf=pass (google.com: domain of shyam.saini@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=shyam.saini@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=Kf5QZUZGOo+lKx5qsDTauweMTcYzxuT04ICbYSNetGI=; b=LFl7DEjfq5LFBGzTFPstocp79NFNV+Drr8j/tA5pdNZwgLR6A+oIn5B948M3tBwFx/ V6l4wDAMdIW8mVNbJoClppDzkJv/ogFyUXeMFXqBcFj9VlmTReUak/jq3GcaUyf8nLlp oB6YeXTfTwZkGkOfpi/d3FzYdujbICfymX3tg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=Kf5QZUZGOo+lKx5qsDTauweMTcYzxuT04ICbYSNetGI=; b=oby0Tj5HXWAFkoPY8A7hnfdxoDe9Sl4D+H6TgSBEEEIfOvPkWNrIatGHFdPOXwvD5Y c8+p7OfYcgZ1jNIiUgqAacJ1gYkWuS3hFMYa5epZ3MlZWlexFaiHTBK4eN96WEuEr07q ZJgL+hZqL4FOT0pCO3Nf7vYh23E1vrvtIP4WJfyYZ4Trtx2Y1kvXXEr8aHpL7rgkp6hy VnLlqTIgP0twmYqWotziuNLSbqgyJIsUjrOYf7AvgCsoTVo8TePF2lPogt67cpGs47Cl /ORp/bzaumtDeWOg4A3dVlUkBzCbbKJXLh82MXDRAtmQYb5OI+XNf+aMMbtTjRihkDyE qHjg== X-Gm-Message-State: APjAAAWDVoWtuxGV9IAj1nFcq9Q8PqNiTjboTKWTSpvtCJGKzPAdomD+ 0c9CRVLtEKb74pKROfa5Lm02Y28z X-Google-Smtp-Source: APXvYqxF9h6NwoniZxRx4bw9pgSQmtrBl9BJ7J3RzeZ7O+Kpk4ulrpbzl7c5z7EFkUwQQtmruemo7g== X-Received: by 2002:a17:90a:a10f:: with SMTP id s15mr50834636pjp.30.1559811582015; Thu, 06 Jun 2019 01:59:42 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a63:2b0b:: with SMTP id r11ls1151996pgr.4.gmail; Thu, 06 Jun 2019 01:59:41 -0700 (PDT) X-Received: by 2002:a63:246:: with SMTP id 67mr2420583pgc.145.1559811581546; Thu, 06 Jun 2019 01:59:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559811581; cv=none; d=google.com; s=arc-20160816; b=p9cjFm3Kb5uiAwiJENA8REtp6E+CUZLQNbvmd5Wtxhiblcn/eJhcsB8vGpp0IKHDf4 sk32IJNWwng5vlVNoa97w2+sYFECVYc2su0CVYtf14d+hKK7CRO/kZVEbzXO6SDtxHGB ipRNt0rn5mkrhEEDjc6Tpi9pJ6RDJxyLzCbL80XPVrt9q47hYdPtzkB9fLC5QZ2Vmodx UzsDL33SJYAh3mBy/UY9cDTXzJU0y2nQmTsTqLFW7Y5KvTL573quNWIZc1o4BTIYxi8m uQiOX+b5twgKF1IeLMsSub7DKTrcKyIrKGc1falso2uvoMMb3LKZTz6PMPt0rQCZI/y9 0G5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=x/qASJoXXa+9Ns9dCSxqKMAGz0a/0ChDbs9V20dxzHg=; b=gnRioXrW6jm54QGk9zIr2i0tpGGwoM+QK3U48UYiIE2ZPqKg2uTVwDv65z5fmbPHg9 M2HQOxXrnOuwQW+2007vz+r0CIg5g8l4iCpxNBHpotD0fy+otvtHOgmteqHdK49nx935 ZYB+J8D4CATmKfA4SrW9f9WveetV4m1smI6cRz/0Ju7jyirxPB1Xb+yuKMXXjiu1h8Bp taDhGntCwu+o2YL84eDzSK67JENZteU2EKdqhsXqvkmQ4Q2f/po0DxDRabdDswsZL3hG c/I8tpRbYPyUNgFzHJkh9GynE5Cqj06cQEeIHpMsRC38PEN2YZtY92qzF4JDi3+yiw9b tMxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=AjNkukKh; spf=pass (google.com: domain of shyam.saini@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=shyam.saini@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id p31sor1381434pjp.0.2019.06.06.01.59.40 for (Google Transport Security); Thu, 06 Jun 2019 01:59:40 -0700 (PDT) Received-SPF: pass (google.com: domain of shyam.saini@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a17:90a:7343:: with SMTP id j3mr48085682pjs.84.1559811580382; Thu, 06 Jun 2019 01:59:40 -0700 (PDT) Received: from localhost.localdomain ([183.82.228.203]) by smtp.googlemail.com with ESMTPSA id 188sm2999482pfe.30.2019.06.06.01.59.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Jun 2019 01:59:39 -0700 (PDT) From: Shyam Saini To: u-boot@lists.denx.de Cc: stefan.agner@toradex.com, festevam@gmail.com, ksi@koi8.net, jagan@amarulasolutions.com, michael@amarulasolutions.com, sbabic@denx.de, linux-amarula@amarulasolutions.com, uboot-imx@nxp.com, Shyam Saini Subject: [PATCH 2/2] i.MX6: nand: add nandbcb command for imx Date: Thu, 6 Jun 2019 14:29:20 +0530 Message-Id: <20190606085920.17754-2-shyam.saini@amarulasolutions.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190606085920.17754-1-shyam.saini@amarulasolutions.com> References: <20190606085920.17754-1-shyam.saini@amarulasolutions.com> X-Original-Sender: shyam.saini@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=AjNkukKh; spf=pass (google.com: domain of shyam.saini@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=shyam.saini@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Writing/updating boot image in nand device is not straight forward in i.MX6 platform and it requires boot control block(BCB) to be configured. It becomes difficult to use uboot 'nand' command to write BCB since it requires platform specific attributes need to be taken care of. It is even difficult to use existing msx-nand.c driver by incorporating BCB attributes like mxs_dma_desc does because it requires change in mtd and nand command. So, cmd_nandbcb implemented in arch/arm/mach-imx BCB contains two data structures, Firmware Configuration Block(FCB) and Discovered Bad Block Table(DBBT). FCB has nand timings, DBBT search area, page address of firmware. On summary, nandbcb update will - erase the entire partition - create BCB by creating 2 FCB/DBBT block followed by 1 FW block based on partition size and erasesize. - fill FCB/DBBT structures - write FW/SPL on FW1 - write FCB/DBBT in first 2 blocks for nand boot, up on reset bootrom look for FCB structure in first block's if FCB found the nand timings are loaded for further reads. once FCB read done, DTTB will load and finally firmware will be loaded which is boot image. Refer section "NAND Boot" from doc/imx/common/imx6.txt for more usage information. Signed-off-by: Jagan Teki Signed-off-by: Sergey Kubushyn Signed-off-by: Shyam Saini --- Changes for v4: - Remove obselete apis and use bch_geometry structure for calculating ecc level, bad block start bit and bad block byte - Write firmware only once - Shorten variable names - Update commit message - Update docs as per current patch - Fix checkpatch warnings Changes for v3: - Fixed multi-line comments - Better error handling for failed allocations Changes for v2: - Fixed commit message notes - Updated proper commit message - Update doc/README.imx6 with NAND boot details - Fixed long length variable names. - Fixed Gigantic variable name. - NULL checks for kzalloc - Move Kconfig option in separate patch - Fixed checkpatch warninigs --- arch/arm/include/asm/mach-imx/imx-nandbcb.h | 111 +++++++ .../arm/include/asm/mach-imx/mxs-nand.h | 0 arch/arm/mach-imx/Makefile | 1 + arch/arm/mach-imx/cmd_nandbcb.c | 369 +++++++++++++++++++++ doc/imx/common/imx6.txt | 75 +++++ drivers/mtd/nand/raw/mxs_nand.c | 2 +- drivers/mtd/nand/raw/mxs_nand_spl.c | 3 +- 7 files changed, 559 insertions(+), 2 deletions(-) create mode 100644 arch/arm/include/asm/mach-imx/imx-nandbcb.h rename drivers/mtd/nand/raw/mxs_nand.h => arch/arm/include/asm/mach-imx/mxs-nand.h (100%) create mode 100644 arch/arm/mach-imx/cmd_nandbcb.c diff --git a/arch/arm/include/asm/mach-imx/imx-nandbcb.h b/arch/arm/include/asm/mach-imx/imx-nandbcb.h new file mode 100644 index 0000000000..033659a038 --- /dev/null +++ b/arch/arm/include/asm/mach-imx/imx-nandbcb.h @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2017 Jagan Teki + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef _IMX_NAND_BCB_H_ +#define _IMX_NAND_BCB_H_ + +#define FCB_FINGERPRINT 0x20424346 /* 'FCB' */ +#define FCB_VERSION_1 0x01000000 + +#define DBBT_FINGERPRINT2 0x54424244 /* 'DBBT' */ +#define DBBT_VERSION_1 0x01000000 + +struct dbbt_block { + u32 checksum; /* reserved on i.MX6 */ + u32 fingerprint; + u32 version; + u32 numberbb; /* reserved on i.MX6 */ + u32 dbbtpages; +}; + +struct fcb_block { + u32 checksum; /* First fingerprint in first byte */ + u32 fingerprint; /* 2nd fingerprint at byte 4 */ + u32 version; /* 3rd fingerprint at byte 8 */ + u8 datasetup; + u8 datahold; + u8 addr_setup; + u8 dsample_time; + + /* These are for application use only and not for ROM. */ + u8 nandtiming; + u8 rea; + u8 rloh; + u8 rhoh; + u32 pagesize; /* 2048 for 2K pages, 4096 for 4K pages */ + u32 oob_pagesize; /* 2112 for 2K pages, 4314 for 4K pages */ + u32 sectors; /* Number of 2K sections per block */ + u32 nr_nand; /* Total Number of NANDs - not used by ROM */ + u32 nr_die; /* Number of separate chips in this NAND */ + u32 celltype; /* MLC or SLC */ + u32 ecc_type; /* Type of ECC, can be one of BCH-0-20 */ + u32 ecc_nr; /* Number of bytes for Block0 - BCH */ + + /* Block size in bytes for all blocks other than Block0 - BCH */ + u32 ecc_size; + u32 ecc_level; /* Ecc level for Block 0 - BCH */ + u32 meta_size; /* Metadata size - BCH */ + /* Number of blocks per page for ROM use - BCH */ + u32 nr_blocks; + u32 ecc_type_sdk; /* Type of ECC, can be one of BCH-0-20 */ + u32 ecc_nr_sdk; /* Number of bytes for Block0 - BCH */ + /* Block size in bytes for all blocks other than Block0 - BCH */ + u32 ecc_size_sdk; + u32 ecc_level_sdk; /* Ecc level for Block 0 - BCH */ + /* Number of blocks per page for SDK use - BCH */ + u32 nr_blocks_sdk; + u32 meta_size_sdk; /* Metadata size - BCH */ + u32 erase_th; /* To set into BCH_MODE register */ + + /* + * 0: normal boot + * 1: to load patch starting next to FCB + */ + u32 bootpatch; + u32 patch_size; /* Size of patch in sectors */ + u32 fw1_start; /* Firmware image starts on this sector */ + u32 fw2_start; /* Secondary FW Image starting Sector */ + u32 fw1_pages; /* Number of sectors in firmware image */ + u32 fw2_pages; /* Number of sector in secondary FW image */ + u32 dbbt_start; /* Page address where dbbt search area begins */ + + /* + * Byte in page data that have manufacturer marked bad block marker, + * this will be swapped with metadata[0] to complete page data. + */ + u32 bb_byte; + + /* + * For BCH ECC sizes other than 8 and 16 the bad block marker does not + * start at 0th bit of bb_byte. This field is used to get to + * the start bit of bad block marker byte with in bb_byte + */ + u32 bb_start_bit; + + /* + * FCB value that gives byte offset for + * bad block marker on physical NAND page + */ + u32 phy_offset; + u32 bchtype; + + u32 readlatency; + u32 predelay; + u32 cedelay; + u32 postdelay; + u32 cmdaddpause; + u32 datapause; + u32 tmspeed; + u32 busytimeout; + + /* the flag to enable (1)/disable(0) bi swap */ + u32 disbbm; + + /* The swap position of main area in spare area */ + u32 spare_offset; +}; + +#endif /* _IMX_NAND_BCB_H_ */ diff --git a/drivers/mtd/nand/raw/mxs_nand.h b/arch/arm/include/asm/mach-imx/mxs-nand.h similarity index 100% rename from drivers/mtd/nand/raw/mxs_nand.h rename to arch/arm/include/asm/mach-imx/mxs-nand.h diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile index 37675d0558..e740d0c1e8 100644 --- a/arch/arm/mach-imx/Makefile +++ b/arch/arm/mach-imx/Makefile @@ -59,6 +59,7 @@ ifneq ($(CONFIG_SPL_BUILD),y) obj-$(CONFIG_CMD_BMODE) += cmd_bmode.o obj-$(CONFIG_CMD_HDMIDETECT) += cmd_hdmidet.o obj-$(CONFIG_CMD_DEKBLOB) += cmd_dek.o +obj-$(CONFIG_CMD_NANDBCB) += cmd_nandbcb.o endif ifneq ($(CONFIG_BOARD_SIZE_LIMIT),) diff --git a/arch/arm/mach-imx/cmd_nandbcb.c b/arch/arm/mach-imx/cmd_nandbcb.c new file mode 100644 index 0000000000..fd3df78fb4 --- /dev/null +++ b/arch/arm/mach-imx/cmd_nandbcb.c @@ -0,0 +1,369 @@ +/* + * i.MX6 nand boot control block(bcb). + * + * Based on the common/imx-bbu-nand-fcb.c from barebox and imx kobs-ng + * + * Copyright (C) 2017 Jagan Teki + * Copyright (C) 2016 Sergey Kubushyn + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#define BF_VAL(v, bf) (((v) & bf##_MASK) >> bf##_OFFSET) +#define GETBIT(v, n) (((v) >> (n)) & 0x1) + +static u8 calculate_parity_13_8(u8 d) +{ + u8 p = 0; + + p |= (GETBIT(d, 6) ^ GETBIT(d, 5) ^ GETBIT(d, 3) ^ GETBIT(d, 2)) << 0; + p |= (GETBIT(d, 7) ^ GETBIT(d, 5) ^ GETBIT(d, 4) ^ GETBIT(d, 2) ^ + GETBIT(d, 1)) << 1; + p |= (GETBIT(d, 7) ^ GETBIT(d, 6) ^ GETBIT(d, 5) ^ GETBIT(d, 1) ^ + GETBIT(d, 0)) << 2; + p |= (GETBIT(d, 7) ^ GETBIT(d, 4) ^ GETBIT(d, 3) ^ GETBIT(d, 0)) << 3; + p |= (GETBIT(d, 6) ^ GETBIT(d, 4) ^ GETBIT(d, 3) ^ GETBIT(d, 2) ^ + GETBIT(d, 1) ^ GETBIT(d, 0)) << 4; + + return p; +} + +static void encode_hamming_13_8(void *_src, void *_ecc, size_t size) +{ + int i; + u8 *src = _src; + u8 *ecc = _ecc; + + for (i = 0; i < size; i++) + ecc[i] = calculate_parity_13_8(src[i]); +} + +static u32 calc_chksum(void *buf, size_t size) +{ + u32 chksum = 0; + u8 *bp = buf; + size_t i; + + for (i = 0; i < size; i++) + chksum += bp[i]; + + return ~chksum; +} + +static void fill_fcb(struct fcb_block *fcb, struct mtd_info *mtd) +{ + struct nand_chip *chip = mtd_to_nand(mtd); + struct mxs_nand_info *nand_info = nand_get_controller_data(chip); + + fcb->fingerprint = FCB_FINGERPRINT; + fcb->version = FCB_VERSION_1; + fcb->pagesize = mtd->writesize; + fcb->oob_pagesize = mtd->writesize + mtd->oobsize; + fcb->sectors = mtd->erasesize / mtd->writesize; + + /* Divide ECC strength by two and save the value into FCB structure. */ + fcb->ecc_level = nand_info->bch_geometry.ecc_strength >> 1; + + fcb->ecc_type = fcb->ecc_level; + + /* Also hardcoded in kobs-ng */ + fcb->ecc_nr = 0x00000200; + fcb->ecc_size = 0x00000200; + fcb->datasetup = 80; + fcb->datahold = 60; + fcb->addr_setup = 25; + fcb->dsample_time = 6; + fcb->meta_size = 10; + + /* DBBT search area starts at second page on first block */ + fcb->dbbt_start = 1; + + fcb->bb_byte = nand_info->bch_geometry.block_mark_byte_offset; + fcb->bb_start_bit = nand_info->bch_geometry.block_mark_bit_offset; + + fcb->phy_offset = mtd->writesize; + + fcb->nr_blocks = mtd->writesize / fcb->ecc_nr - 1; + + fcb->checksum = calc_chksum((void *)fcb + 4, sizeof(*fcb) - 4); +} + +static int dbbt_fill_data(struct mtd_info *mtd, void *buf, int num_blocks) +{ + int n, n_bad_blocks = 0; + u32 *bb = buf + 0x8; + u32 *n_bad_blocksp = buf + 0x4; + + for (n = 0; n < num_blocks; n++) { + loff_t offset = n * mtd->erasesize; + if (mtd_block_isbad(mtd, offset)) { + n_bad_blocks++; + *bb = n; + bb++; + } + } + + *n_bad_blocksp = n_bad_blocks; + + return n_bad_blocks; +} + +static int nandbcb_update(struct mtd_info *mtd, loff_t off, size_t size, + size_t maxsize, const u_char *buf) +{ + nand_erase_options_t opts; + struct fcb_block *fcb; + struct dbbt_block *dbbt; + loff_t fw1_off; + void *fwbuf, *fcb_raw_page, *dbbt_page, *dbbt_data_page; + int nr_blks, nr_blks_fcb, fw1_blk; + size_t fwsize, dummy; + int i, ret; + + /* erase */ + memset(&opts, 0, sizeof(opts)); + opts.offset = off; + opts.length = maxsize - 1; + ret = nand_erase_opts(mtd, &opts); + if (ret) { + printf("%s: erase failed (ret = %d)\n", __func__, ret); + return ret; + } + + /* + * Reference documentation from i.MX6DQRM section 8.5.2.2 + * + * Nand Boot Control Block(BCB) contains two data structures, + * - Firmware Configuration Block(FCB) + * - Discovered Bad Block Table(DBBT) + * + * FCB contains, + * - nand timings + * - DBBT search page address, + * - start page address of primary firmware + * - start page address of secondary firmware + * + * setup fcb: + * - number of blocks = mtd partition size / mtd erasesize + * - two firmware blocks, primary and secondary + * - first 4 block for FCB/DBBT + * - rest split in half for primary and secondary firmware + * - same firmware will write two times + */ + nr_blks_fcb = 2; + nr_blks = maxsize / mtd->erasesize; + fw1_blk = nr_blks_fcb; + + /* write fw */ + fwsize = ALIGN(size + FLASH_OFFSET_STANDARD + mtd->writesize, + mtd->writesize); + fwbuf = kzalloc(fwsize, GFP_KERNEL); + if (!fwbuf) { + debug("failed to allocate fwbuf\n"); + ret = -ENOMEM; + goto err; + } + + memcpy(fwbuf + FLASH_OFFSET_STANDARD, buf, size); + fw1_off = fw1_blk * mtd->erasesize; + ret = nand_write_skip_bad(mtd, fw1_off, &fwsize, NULL, maxsize, + (u_char *)fwbuf, WITH_WR_VERIFY); + printf("NAND fw write: 0x%llx offset, 0x%x bytes written: %s\n", + fw1_off, fwsize, ret ? "ERROR" : "OK"); + if (ret) + goto fwbuf_err; + + /* fill fcb */ + fcb = kzalloc(sizeof(*fcb), GFP_KERNEL); + if (!fcb) { + debug("failed to allocate fcb\n"); + ret = -ENOMEM; + goto fwbuf_err; + } + + fcb->fw1_start = (fw1_blk * mtd->erasesize) / mtd->writesize; + fcb->fw1_pages = size / mtd->writesize + 1; + fill_fcb(fcb, mtd); + + /* fill dbbt */ + dbbt_page = kzalloc(mtd->writesize, GFP_KERNEL); + if (!dbbt_page) { + debug("failed to allocate dbbt_page\n"); + ret = -ENOMEM; + goto fcb_err; + } + + dbbt_data_page = kzalloc(mtd->writesize, GFP_KERNEL); + if (!dbbt_data_page) { + debug("failed to allocate dbbt_data_page\n"); + ret = -ENOMEM; + goto dbbt_page_err; + } + + dbbt = dbbt_page; + dbbt->checksum = 0; + dbbt->fingerprint = DBBT_FINGERPRINT2; + dbbt->version = DBBT_VERSION_1; + ret = dbbt_fill_data(mtd, dbbt_data_page, nr_blks); + if (ret < 0) + goto dbbt_data_page_err; + else if (ret > 0) + dbbt->dbbtpages = 1; + + /* write fcb/dbbt */ + fcb_raw_page = kzalloc(mtd->writesize + mtd->oobsize, GFP_KERNEL); + if (!fcb_raw_page) { + debug("failed to allocate fcb_raw_page\n"); + ret = -ENOMEM; + goto dbbt_data_page_err; + } + + memcpy(fcb_raw_page + 12, fcb, sizeof(struct fcb_block)); + encode_hamming_13_8(fcb_raw_page + 12, fcb_raw_page + 12 + 512, 512); + /* + * Set the first and second byte of OOB data to 0xFF, not 0x00. These + * bytes are used as the Manufacturers Bad Block Marker (MBBM). Since + * the FCB is mostly written to the first page in a block, a scan for + * factory bad blocks will detect these blocks as bad, e.g. when + * function nand_scan_bbt() is executed to build a new bad block table. + */ + memset(fcb_raw_page + mtd->writesize, 0xFF, 2); + + for (i = 0; i < nr_blks_fcb; i++) { + if (mtd_block_isbad(mtd, off)) { + printf("Block %d is bad, skipped\n", i); + continue; + } + + /* raw write */ + mtd_oob_ops_t ops = { + .datbuf = (u8 *)fcb_raw_page, + .oobbuf = ((u8 *)fcb_raw_page) + mtd->writesize, + .len = mtd->writesize, + .ooblen = mtd->oobsize, + .mode = MTD_OPS_RAW + }; + + ret = mtd_write_oob(mtd, mtd->erasesize * i, &ops); + if (ret) + goto fcb_raw_page_err; + debug("NAND fcb write: 0x%x offset, 0x%x bytes written: %s\n", + mtd->erasesize * i, ops.len, ret ? "ERROR" : "OK"); + + ret = mtd_write(mtd, mtd->erasesize * i + mtd->writesize, + mtd->writesize, &dummy, dbbt_page); + if (ret) + goto fcb_raw_page_err; + debug("NAND dbbt write: 0x%x offset, 0x%x bytes written: %s\n", + mtd->erasesize * i + mtd->writesize, dummy, + ret ? "ERROR" : "OK"); + + /* dbbtpages == 0 if no bad blocks */ + if (dbbt->dbbtpages > 0) { + loff_t to = (mtd->erasesize * i + mtd->writesize * 5); + + ret = mtd_write(mtd, to, mtd->writesize, &dummy, + dbbt_data_page); + if (ret) + goto fcb_raw_page_err; + } + } + +fcb_raw_page_err: + kfree(fcb_raw_page); +dbbt_data_page_err: + kfree(dbbt_data_page); +dbbt_page_err: + kfree(dbbt_page); +fcb_err: + kfree(fcb); +fwbuf_err: + kfree(fwbuf); +err: + return ret; +} + +static int do_nandbcb_update(int argc, char * const argv[]) +{ + struct mtd_info *mtd; + loff_t addr, offset, size, maxsize; + char *endp; + u_char *buf; + int dev; + int ret; + + if (argc != 4) + return CMD_RET_USAGE; + + dev = nand_curr_device; + if (dev < 0) { + printf("failed to get nand_curr_device, run nand device"); + return CMD_RET_FAILURE; + } + + addr = simple_strtoul(argv[1], &endp, 16); + if (*argv[1] == 0 || *endp != 0) + return CMD_RET_FAILURE; + + mtd = get_nand_dev_by_index(dev); + if (mtd_arg_off_size(argc - 2, argv + 2, &dev, &offset, &size, + &maxsize, MTD_DEV_TYPE_NAND, mtd->size)) + return CMD_RET_FAILURE; + + buf = map_physmem(addr, size, MAP_WRBACK); + if (!buf) { + puts("failed to map physical memory\n"); + return CMD_RET_FAILURE; + } + + ret = nandbcb_update(mtd, offset, size, maxsize, buf); + + return ret == 0 ? CMD_RET_SUCCESS : CMD_RET_FAILURE; +} + +static int do_nandbcb(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + const char *cmd; + int ret = 0; + + if (argc < 5) + goto usage; + + cmd = argv[1]; + --argc; + ++argv; + + if (strcmp(cmd, "update") == 0) { + ret = do_nandbcb_update(argc, argv); + goto done; + } + +done: + if (ret != -1) + return ret; +usage: + return CMD_RET_USAGE; +} + +static char nandbcb_help_text[] = + "update addr off|partition len - update 'len' bytes starting at\n" + " 'off|part' to memory address 'addr', skipping bad blocks"; + +U_BOOT_CMD(nandbcb, 5, 1, do_nandbcb, + "i.MX6 Nand BCB", + nandbcb_help_text +); diff --git a/doc/imx/common/imx6.txt b/doc/imx/common/imx6.txt index eab88353f6..5a354005f8 100644 --- a/doc/imx/common/imx6.txt +++ b/doc/imx/common/imx6.txt @@ -88,3 +88,78 @@ Reading bank 4: Word 0x00000002: 9f027772 00000004 + +NAND Boot on i.MX6 with SPL support +-------------------------------------- + +Writing/updating boot image in nand device is not straight forward in +i.MX6 platform and it requires boot control block(BCB) to be configured. + +BCB contains two data structures, Firmware Configuration Block(FCB) and +Discovered Bad Block Table(DBBT). FCB has nand timings, DBBT search area, +and firmware. See IMX6DQRM Section 8.5.2.2 +for more information. + +We can't use 'nand write' command to write SPL/firmware image directly +like other platforms does. So we need special setup to write BCB block +as per IMX6QDL reference manual 'nandbcb update' command do that job. + +for nand boot, up on reset bootrom look for FCB structure in +first block's if FCB found the nand timings are loaded for +further reads. once FCB read done, DTTB will be loaded and +finally firmware will be loaded which is boot image. + +cmd_nandbcb will create FCB these structures +by taking mtd partition as an example. +- initial code will erase entire partition +- followed by FCB setup, like first 2 blocks for FCB/DBBT write, + and next block for FW1/SPL +- write firmware at FW1 block and +- finally write fcb/dttb in first 2 block. + +Typical NAND BCB layout: +======================= + + no.of blocks = partition size / erasesize + no.of fcb/dbbt blocks = 2 + FW1 offset = no.of fcb/dbbt + +block 0 1 2 + ------------------------------- + |FCB/DBBT 0|FCB/DBBT 1| FW 1 | + -------------------------------- + +On summary, nandbcb update will +- erase the entire partition +- create BCB by creating 2 FCB/BDDT block followed by + 1 FW blocks based on partition size and erasesize. +- fill FCB/DBBT structures +- write FW/SPL in FW1 +- write FCB/DBBT in first 2 blocks + +step-1: write SPL + +icorem6qdl> fatload mmc 0:1 $loadaddr SPL +reading SPL +31744 bytes read in 15 ms (2 MiB/s) + +icorem6qdl> nandbcb update $loadaddr spl $filesize +device 0 offset 0x0, size 0x7c00 +Erasing at 0x1c0000 -- 100% complete. +NAND fw write: 0x100000 offset, 0x9000 bytes written: OK +NAND fw write: 0x180000 offset, 0x9000 bytes written: OK + +step-2: write u-boot-dtb.img + +icorem6qdl> nand erase.part uboot +NAND erase.part: device 0 offset 0x200000, size 0x200000 +Erasing at 0x3c0000 -- 100% complete. +OK + +icorem6qdl> fatload mmc 0:1 $loadaddr u-boot-dtb.img +reading u-boot-dtb.img +508967 bytes read in 48 ms (10.1 MiB/s) + +icorem6qdl> nand write ${loadaddr} uboot ${filesize} +NAND write: device 0 offset 0x200000, size 0x7c427 +508967 bytes written: OK diff --git a/drivers/mtd/nand/raw/mxs_nand.c b/drivers/mtd/nand/raw/mxs_nand.c index b93d77a395..91dcbc4d22 100644 --- a/drivers/mtd/nand/raw/mxs_nand.c +++ b/drivers/mtd/nand/raw/mxs_nand.c @@ -25,7 +25,7 @@ #include #include #include -#include "mxs_nand.h" +#include #define MXS_NAND_DMA_DESCRIPTOR_COUNT 4 diff --git a/drivers/mtd/nand/raw/mxs_nand_spl.c b/drivers/mtd/nand/raw/mxs_nand_spl.c index ee7d9cb957..1f072721aa 100644 --- a/drivers/mtd/nand/raw/mxs_nand_spl.c +++ b/drivers/mtd/nand/raw/mxs_nand_spl.c @@ -6,7 +6,8 @@ #include #include #include -#include "mxs_nand.h" +#include + static struct mtd_info *mtd; static struct nand_chip nand_chip;