From patchwork Tue Aug 17 01:36:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 12440229 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5835C43216 for ; Tue, 17 Aug 2021 01:37:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BBEBE60E90 for ; Tue, 17 Aug 2021 01:37:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235894AbhHQBhh (ORCPT ); Mon, 16 Aug 2021 21:37:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229773AbhHQBhg (ORCPT ); Mon, 16 Aug 2021 21:37:36 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B734C061764; Mon, 16 Aug 2021 18:37:04 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id y7so30290790ljp.3; Mon, 16 Aug 2021 18:37:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kM2r3O6lLw7n0SLWPjQDjWc/9/9RRSabPEe6y/wgg7E=; b=sj15Xh/m3EoLFT7HXSjITxWtKIUNzGLW3fCpfpEOvJENkd9g6xyQYGrZkxvXJCgMgD 09sF+ch5Kz5kjRpDPl5wkVqesdTxC+8K+seyv67yyiWKPZRf6SsTe4aptAL72k6y30cm kWubM9yo+7gn2wa6DEXnCglKN40dZ31iMBbRWLpAavDdAeD/ick+YNgYaspQqrAhlVfA IM0gjIYU7BfRmJ98IKWh7kkH1u8bok4dVh8DUVZqHbdeienFqI3LRsNb4SczizNSSqJN q593JSFxKzq0R3sYHja01oYQwNhhVX4wWEqasvdiGpjBdjlJiGWBgvgrhVV2OhyGZ4Or KOVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kM2r3O6lLw7n0SLWPjQDjWc/9/9RRSabPEe6y/wgg7E=; b=gHozKv8xmGvrymiDHUsF4MsepTeeWcvaQlfoXi2Fb6pE0yBQIN0HZv51QRafuTL2G6 KhDhHKMbmwHKIesX+brKmR3uAu9w+es3cyBbj8PT2m6xe0S5hu+MpOQyWqY9MIetAV15 yYaL8A5mJEMHqfwhLz7QW5AE/jH+BvUiJwmwEejN/uaYoWDJkE6jplAM0WYc8TbzrlI/ T/0lUE6oVCaHFodryN96Zy1kncXLAdooUDmunZ8lJ9DKQSXDTfqO1mOsk6aJ0k2EmF/j sJFWXAS2W3GT+sUo1U8DrCrbNHn7aCWiFW2ZC0ziG47Kw3371wDvlOXBp9vcwXcHcnom deZA== X-Gm-Message-State: AOAM533b0w8PAHYKvt7KPMLARu1UsN51rb2ZBeH5fEWwBG/1gMew8kap dzD6HG8KgZA03ZX6uFTP23M= X-Google-Smtp-Source: ABdhPJwTcz+bg/NGdCJjEr7SQ/YgmaLytRbt8w9eOka5Lea3KijckzbbslUhKHxWJPc6tYlcpfGslA== X-Received: by 2002:a05:651c:160b:: with SMTP id f11mr921098ljq.496.1629164222548; Mon, 16 Aug 2021 18:37:02 -0700 (PDT) Received: from localhost.localdomain (46-138-85-91.dynamic.spd-mgts.ru. [46.138.85.91]) by smtp.gmail.com with ESMTPSA id br33sm49699lfb.46.2021.08.16.18.37.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Aug 2021 18:37:02 -0700 (PDT) From: Dmitry Osipenko To: Jens Axboe , Thierry Reding , Jonathan Hunter , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , David Heidelberg , Peter Geis , Ulf Hansson , Adrian Hunter , Christoph Hellwig , Davidlohr Bueso , Ion Agorria , Svyatoslav Ryhel Cc: linux-tegra@vger.kernel.org, linux-block@vger.kernel.org, linux-efi Subject: [PATCH v4 1/3] mmc: core: Add raw_boot_mult field to mmc_ext_csd Date: Tue, 17 Aug 2021 04:36:41 +0300 Message-Id: <20210817013643.13061-2-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210817013643.13061-1-digetx@gmail.com> References: <20210817013643.13061-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Bootloader of NVIDIA Tegra devices linearizes the boot0/boot1/main partitions into a single virtual space, and thus, all partition addresses are shifted by the size of boot0 + boot1 partitions. The offset needs to be known in order to find the EFI entry on EMMC storage of Tegra devices. Signed-off-by: Dmitry Osipenko --- drivers/mmc/core/mmc.c | 2 ++ include/linux/mmc/card.h | 1 + 2 files changed, 3 insertions(+) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 838726b68ff3..29e58ffae379 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -418,6 +418,8 @@ static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd) ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]; card->ext_csd.raw_hc_erase_grp_size = ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; + card->ext_csd.raw_boot_mult = + ext_csd[EXT_CSD_BOOT_MULT]; if (card->ext_csd.rev >= 3) { u8 sa_shift = ext_csd[EXT_CSD_S_A_TIMEOUT]; card->ext_csd.part_config = ext_csd[EXT_CSD_PART_CONFIG]; diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index 74e6c0624d27..37f975875102 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -109,6 +109,7 @@ struct mmc_ext_csd { u8 raw_hc_erase_gap_size; /* 221 */ u8 raw_erase_timeout_mult; /* 223 */ u8 raw_hc_erase_grp_size; /* 224 */ + u8 raw_boot_mult; /* 226 */ u8 raw_sec_trim_mult; /* 229 */ u8 raw_sec_erase_mult; /* 230 */ u8 raw_sec_feature_support;/* 231 */ From patchwork Tue Aug 17 01:36:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 12440231 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80E25C19F37 for ; Tue, 17 Aug 2021 01:37:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6B58D60E09 for ; Tue, 17 Aug 2021 01:37:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235945AbhHQBhh (ORCPT ); Mon, 16 Aug 2021 21:37:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235917AbhHQBhh (ORCPT ); Mon, 16 Aug 2021 21:37:37 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0A89C061764; Mon, 16 Aug 2021 18:37:04 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id c12so17191668ljr.5; Mon, 16 Aug 2021 18:37:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=epz5hIEfcZWefFNXUO9u5VneKbvgYW0xfKT7eYaUy3c=; b=CJi/9bFTsi43mAGl74cxiUR6IeB5HdzOZBF8QmtF/wb0Lcoc2K4moxrKzIMUjfsG8h x22ju4PxnCVYp3R5IuCQYR6P0CKrIjVwNhcpaWXuAxcP2xTOisNyK2r3FlOZtwFgYFXR gosd6i/g0Rk0MlFpFnAyQnjLcLfVOiKeuE6Oq3NGKMrDZZq3M782i4+HxLMCYWQXBVAS fDrCwp5P38bDhjw/flRuHarlIxm4pfP/ggIFrGC4qY7BRxdsZCBZRTohK2s50Ie1vSfX 9+aqijSY3henkKfE4+WSUyVOnr9rUoRiP0Udo8/c4Gtn0z9n899VJcHSfSUeUWu6BUwF iOVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=epz5hIEfcZWefFNXUO9u5VneKbvgYW0xfKT7eYaUy3c=; b=t/aadCt6OMY9hb1jcS0mQJk3JjtyJd5I3KCX4lb2dS0bdg080jc8WC8lUyzaWY9kAs Gjeo8JHXtUX6lUrOfBHCYaHIQcC2g2GGab3V1Pv8fhvMM/cQfA16XtyN+hHyVvjU7Ib3 toohVXEPnSzkIMhMz5471KqoF90CHdaxDvGvhAlibJkWWZKuHoGw6zaECyb7uuRhHhai DePfLnSCDnHO6PIyNDRDBvdqlm4JoWVkEb4Ujs0bMnMq60GwlPLILrEn64wOjzzv2pyk oT96/f4fJnZoMGH2oGgelpyf1Ivk8F7s3NvxkHgotJ9ib2v5GVCcfc5bSIITEnav4xxo R+8g== X-Gm-Message-State: AOAM532aVljK5h/v7bqZdyi1u2V2w5SIYVrgXdsQUdgdM+ksqmCVj2Hw NYZ512QdEluMlDwLvMKlKdY= X-Google-Smtp-Source: ABdhPJxDIf5h9kbJ0vgT1oPnwvs9EiOGbT9JiiZA0k2oLO1j+3PxHpB2utUxyZQ3EW+T3JPRoMdIRQ== X-Received: by 2002:a05:651c:542:: with SMTP id q2mr902083ljp.192.1629164223294; Mon, 16 Aug 2021 18:37:03 -0700 (PDT) Received: from localhost.localdomain (46-138-85-91.dynamic.spd-mgts.ru. [46.138.85.91]) by smtp.gmail.com with ESMTPSA id br33sm49699lfb.46.2021.08.16.18.37.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Aug 2021 18:37:03 -0700 (PDT) From: Dmitry Osipenko To: Jens Axboe , Thierry Reding , Jonathan Hunter , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , David Heidelberg , Peter Geis , Ulf Hansson , Adrian Hunter , Christoph Hellwig , Davidlohr Bueso , Ion Agorria , Svyatoslav Ryhel Cc: linux-tegra@vger.kernel.org, linux-block@vger.kernel.org, linux-efi Subject: [PATCH v4 2/3] mmc: block: Add mmc_bdev_to_card() helper Date: Tue, 17 Aug 2021 04:36:42 +0300 Message-Id: <20210817013643.13061-3-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210817013643.13061-1-digetx@gmail.com> References: <20210817013643.13061-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Add mmc_bdev_to_card() helper which is needed for checking EMMC parameters by partition table parser in order to find EFI entry on NVIDIA Tegra devices. Signed-off-by: Dmitry Osipenko --- drivers/mmc/core/block.c | 15 +++++++++++++++ include/linux/mmc/blkdev.h | 13 +++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 include/linux/mmc/blkdev.h diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 672cc505ce37..7e9a486073fd 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -42,6 +42,7 @@ #include #include +#include #include #include #include @@ -357,6 +358,20 @@ static const struct attribute_group *mmc_disk_attr_groups[] = { NULL, }; +struct mmc_card *mmc_bdev_to_card(struct block_device *bdev) +{ + struct mmc_blk_data *md; + + if (bdev->bd_disk->major != MMC_BLOCK_MAJOR) + return NULL; + + md = mmc_blk_get(bdev->bd_disk); + if (!md) + return NULL; + + return md->queue.card; +} + static int mmc_blk_open(struct block_device *bdev, fmode_t mode) { struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk); diff --git a/include/linux/mmc/blkdev.h b/include/linux/mmc/blkdev.h new file mode 100644 index 000000000000..67608c58de70 --- /dev/null +++ b/include/linux/mmc/blkdev.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * linux/include/linux/mmc/blkdev.h + */ +#ifndef LINUX_MMC_BLOCK_DEVICE_H +#define LINUX_MMC_BLOCK_DEVICE_H + +struct block_device; +struct mmc_card; + +struct mmc_card *mmc_bdev_to_card(struct block_device *bdev); + +#endif /* LINUX_MMC_BLOCK_DEVICE_H */ From patchwork Tue Aug 17 01:36:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 12440233 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74771C19F3A for ; Tue, 17 Aug 2021 01:37:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4415460EAF for ; Tue, 17 Aug 2021 01:37:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235973AbhHQBhi (ORCPT ); Mon, 16 Aug 2021 21:37:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235967AbhHQBhi (ORCPT ); Mon, 16 Aug 2021 21:37:38 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DC20C061764; Mon, 16 Aug 2021 18:37:05 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id h9so30241491ljq.8; Mon, 16 Aug 2021 18:37:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QlON8BMCDUDtLl4Dwj//VdNgR1mbqL1M7bCROFZfcuo=; b=kYG/KVNa8B296+/5Tleq7WuByYDAfSnsemaC4zPkQe6mVS2aycoBVxuTs2aoMb1i4q A/4AryALJgUJlZhnp8RVX4kevFTgtCtF4YZY9SFOwM69BrphxjGVi+pMFF/sJRdX2a// gZkAfxCrpaK7eD2SUDxmhhS8rgnZ8sjyDP1Fi+Zo4KEgRECzjhGBofDMXBPcwJZRuITF q8qDUwJ6wgwu9DgkdTvyCQsdPn3pO18sLXze3RpeJmNCHtTtjKcgcBL2oMXa88fNypDr nUHIud46TRKf1nP9ncvp51C6DNTrDMlDiPCdSPmL6JAnOJQm0eRB5RwWswDWRSoCn5tr odWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QlON8BMCDUDtLl4Dwj//VdNgR1mbqL1M7bCROFZfcuo=; b=TonzYZjEicM0Mr5jzeNjlOQ8CIIDUo1lA870mnY1ocUX40muOjdu2R8unyz+e67g0O p8AahDld1GkncMSg2w9WSAzGFdZFxCb7fQx7HJG+Ta5NaR723PJoBgtpc+t8glVkhb/R pcjSUyInhhJtKr8kdg0buuLBX6tAeD4q+/lJg6wQDkXRksJTdMxfjozc1PgS0r6ugfFL 7tJ7L+3A/OyjdhCgIuKS9G5KPvRwAJIR/OA1FuDd3l2OwaG56hAo649rgNlxcF8MLfkV ITCtI2UikV5IyktJITWWJWW5ZEXYrl1kyiYd5+dK2yasYKb2xN8YuFIpC3K2RfeRViTC 9uDg== X-Gm-Message-State: AOAM531xSGhSheUYQwx1dwDG92n/GJFCXm9ifYixQ93pJJPHx9PzV1Da cD3/lXn6KtZOZHqm5l4H5Cs= X-Google-Smtp-Source: ABdhPJyHLvzKbjg8I2G+jgERHfBq2A/5+Ob8HUfLaAcCVl/foTUOCcOSaiEMth4da1X0ubFDMpVl6g== X-Received: by 2002:a05:651c:33b:: with SMTP id b27mr925838ljp.314.1629164224031; Mon, 16 Aug 2021 18:37:04 -0700 (PDT) Received: from localhost.localdomain (46-138-85-91.dynamic.spd-mgts.ru. [46.138.85.91]) by smtp.gmail.com with ESMTPSA id br33sm49699lfb.46.2021.08.16.18.37.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Aug 2021 18:37:03 -0700 (PDT) From: Dmitry Osipenko To: Jens Axboe , Thierry Reding , Jonathan Hunter , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , David Heidelberg , Peter Geis , Ulf Hansson , Adrian Hunter , Christoph Hellwig , Davidlohr Bueso , Ion Agorria , Svyatoslav Ryhel Cc: linux-tegra@vger.kernel.org, linux-block@vger.kernel.org, linux-efi Subject: [PATCH v4 3/3] partitions/efi: Support NVIDIA Tegra devices Date: Tue, 17 Aug 2021 04:36:43 +0300 Message-Id: <20210817013643.13061-4-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210817013643.13061-1-digetx@gmail.com> References: <20210817013643.13061-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org NVIDIA Tegra consumer devices have EMMC storage that has GPT entry at a non-standard location. Support looking up GPT entry at a special sector to enable such devices. Signed-off-by: Dmitry Osipenko --- block/partitions/Kconfig | 8 +++++ block/partitions/Makefile | 1 + block/partitions/check.h | 2 ++ block/partitions/core.c | 3 ++ block/partitions/efi.c | 9 +++++ block/partitions/tegra.c | 75 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 98 insertions(+) create mode 100644 block/partitions/tegra.c diff --git a/block/partitions/Kconfig b/block/partitions/Kconfig index 278593b8e4e9..5db25e7efbb7 100644 --- a/block/partitions/Kconfig +++ b/block/partitions/Kconfig @@ -267,3 +267,11 @@ config CMDLINE_PARTITION help Say Y here if you want to read the partition table from bootargs. The format for the command line is just like mtdparts. + +config TEGRA_PARTITION + bool "NVIDIA Tegra Partition support" if PARTITION_ADVANCED + default y if ARCH_TEGRA + depends on EFI_PARTITION && MMC_BLOCK && (ARCH_TEGRA || COMPILE_TEST) + help + Say Y here if you would like to be able to read the hard disk + partition table format used by NVIDIA Tegra machines. diff --git a/block/partitions/Makefile b/block/partitions/Makefile index a7f05cdb02a8..83cb70c6d08d 100644 --- a/block/partitions/Makefile +++ b/block/partitions/Makefile @@ -20,3 +20,4 @@ obj-$(CONFIG_IBM_PARTITION) += ibm.o obj-$(CONFIG_EFI_PARTITION) += efi.o obj-$(CONFIG_KARMA_PARTITION) += karma.o obj-$(CONFIG_SYSV68_PARTITION) += sysv68.o +obj-$(CONFIG_TEGRA_PARTITION) += tegra.o diff --git a/block/partitions/check.h b/block/partitions/check.h index d5b28e309d64..bd4b66443cf4 100644 --- a/block/partitions/check.h +++ b/block/partitions/check.h @@ -22,6 +22,7 @@ struct parsed_partitions { int limit; bool access_beyond_eod; char *pp_buf; + sector_t force_gpt_sector; }; typedef struct { @@ -67,4 +68,5 @@ int osf_partition(struct parsed_partitions *state); int sgi_partition(struct parsed_partitions *state); int sun_partition(struct parsed_partitions *state); int sysv68_partition(struct parsed_partitions *state); +int tegra_partition_forced_gpt(struct parsed_partitions *state); int ultrix_partition(struct parsed_partitions *state); diff --git a/block/partitions/core.c b/block/partitions/core.c index 9265936df77e..bbfbb1621581 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -82,6 +82,9 @@ static int (*check_part[])(struct parsed_partitions *) = { #endif #ifdef CONFIG_SYSV68_PARTITION sysv68_partition, +#endif +#ifdef CONFIG_TEGRA_PARTITION + tegra_partition_forced_gpt, #endif NULL }; diff --git a/block/partitions/efi.c b/block/partitions/efi.c index aaa3dc487cb5..4ad151176204 100644 --- a/block/partitions/efi.c +++ b/block/partitions/efi.c @@ -619,6 +619,15 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt, if (!good_agpt && force_gpt) good_agpt = is_gpt_valid(state, lastlba, &agpt, &aptes); + /* + * The force_gpt_sector is used by NVIDIA Tegra partition parser in + * order to convey a non-standard location of the GPT entry for lookup. + * By default force_gpt_sector is set to 0 and has no effect. + */ + if (!good_agpt && force_gpt && state->force_gpt_sector) + good_agpt = is_gpt_valid(state, state->force_gpt_sector, + &agpt, &aptes); + /* The obviously unsuccessful case */ if (!good_pgpt && !good_agpt) goto fail; diff --git a/block/partitions/tegra.c b/block/partitions/tegra.c new file mode 100644 index 000000000000..4937e9f62398 --- /dev/null +++ b/block/partitions/tegra.c @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define pr_fmt(fmt) "tegra-partition: " fmt + +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include "check.h" + +static const struct of_device_id tegra_sdhci_match[] = { + { .compatible = "nvidia,tegra20-sdhci", }, + { .compatible = "nvidia,tegra30-sdhci", }, + { .compatible = "nvidia,tegra114-sdhci", }, + { .compatible = "nvidia,tegra124-sdhci", }, + {} +}; + +int tegra_partition_forced_gpt(struct parsed_partitions *state) +{ + struct gendisk *disk = state->disk; + struct block_device *bdev = disk->part0; + struct mmc_card *card = mmc_bdev_to_card(bdev); + int ret, boot_offset; + + if (!soc_is_tegra()) + return 0; + + /* filter out unrelated and untested boot sources */ + if (!card || card->ext_csd.rev < 3 || + !mmc_card_is_blockaddr(card) || + mmc_card_is_removable(card->host) || + bdev_logical_block_size(bdev) != SZ_512 || + !of_match_node(tegra_sdhci_match, card->host->parent->of_node)) { + pr_debug("%s: unexpected boot source\n", disk->disk_name); + return 0; + } + + /* + * eMMC storage has two special boot partitions in addition to the + * main one. NVIDIA's bootloader linearizes eMMC boot0->boot1->main + * accesses, this means that the partition table addresses are shifted + * by the size of boot partitions. In accordance with the eMMC + * specification, the boot partition size is calculated as follows: + * + * boot partition size = 128K byte x BOOT_SIZE_MULT + * + * This function returns number of sectors occupied by the both boot + * partitions. + */ + boot_offset = card->ext_csd.raw_boot_mult * SZ_128K / + SZ_512 * MMC_NUM_BOOT_PARTITION; + + /* + * The fixed GPT entry address is calculated like this: + * + * gpt_sector = ext_csd.sectors_num - ext_csd.boot_sectors_num - 1 + * + * This algorithm is defined by NVIDIA and used by Android devices. + */ + state->force_gpt_sector = get_capacity(disk); + state->force_gpt_sector -= boot_offset + 1; + + ret = efi_partition(state); + state->force_gpt_sector = 0; + + return ret; +}