From patchwork Sat Jul 31 18:36:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 490203 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.7 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 4D5B4C43216 for ; Sat, 31 Jul 2021 18:38:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F2C661059 for ; Sat, 31 Jul 2021 18:38:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229958AbhGaSiO (ORCPT ); Sat, 31 Jul 2021 14:38:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229708AbhGaSiG (ORCPT ); Sat, 31 Jul 2021 14:38:06 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 243BBC06175F; Sat, 31 Jul 2021 11:37:59 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id z2so25213665lft.1; Sat, 31 Jul 2021 11:37:59 -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=XEkqCEMePzc3DyOX93h/fXQ0QYmMDcwfB1n3cbRFUa3+dOjyEGlfvNpW0AmpWdGqR1 sLjdYHvVZckMfN8oHfZI6+y+GTKs0MMh4dnW6/F3VwmCE1lnYQ0wNPH06lDMRhXKa5t8 L2sKvAK3VtQHJnxlJqhCR6MqVR3DbcAB3/70DUys1WcyxErni0rdYidjZgzTZ2VpLq8B pnP44AoIeJ0bWb6LkXSoqpzWjL7O8EBrK5r1TtRHu8Vu6rI3l5NUTAOXqO3Q+eQSc0hE 0Xe4/d6EPFcytsA7ROqPyR7AaEgdYKf+hfRQ9gC47CT4BWR6ISYq6IIHqDi7yS3lk/h8 kX+w== 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=fvBY/xf8WQ8cwCyrOK667sZDzteJDNqh8+B8nLE+Noy1CaACDIKqLJzR03KB6OkQKz ga0TIqXF+lCJCMMVb0I+IyWRdH0Yg3bAzruSMXQ4RhRAuISaPn3Wv6tsw9bbWvYuWrW+ aSpVkxoJ6kxt9e8ALIBln5L+0GV/2Cop03LDvLzO/5oRBMEBWA7o7bMaUWrJefbJSfiK 8V7f9HcQgkyVsFD/nY44KTFPlsDjk2LGn04kjr6NX40WJPGM35Ol3A49FMyCG5MiXrcF tGPyt3d5oNIjb58ZZPaQ0Nbb6THI62OhToTJdIyLipHuUC8p1f+QR6jzt+dxapBn2Tl4 hZcw== X-Gm-Message-State: AOAM530E2C6vS6mKnh86iokxrs/RLNOsDBEtLhYtLTEMsVF2Nazy5q2Q WmvVygZ/M2jmIxkADEMCdno= X-Google-Smtp-Source: ABdhPJyT4pXvAYKOeRXsxYj/bX5/EhnjPSDlY7LNdqTS7a6IkJbtOGJBZDvuJVNnV6UUZB1skZ6Cig== X-Received: by 2002:ac2:53a3:: with SMTP id j3mr6456611lfh.479.1627756677062; Sat, 31 Jul 2021 11:37:57 -0700 (PDT) Received: from localhost.localdomain (94-29-22-96.dynamic.spd-mgts.ru. [94.29.22.96]) by smtp.gmail.com with ESMTPSA id s7sm456396lfg.297.2021.07.31.11.37.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Jul 2021 11:37:56 -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 , Ard Biesheuvel , Davidlohr Bueso , Ion Agorria , Svyatoslav Ryhel Cc: linux-tegra@vger.kernel.org, linux-block@vger.kernel.org, linux-efi Subject: [PATCH v2 1/3] mmc: core: Add raw_boot_mult field to mmc_ext_csd Date: Sat, 31 Jul 2021 21:36:24 +0300 Message-Id: <20210731183626.18568-2-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210731183626.18568-1-digetx@gmail.com> References: <20210731183626.18568-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-efi@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 Sat Jul 31 18:36:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 490204 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.7 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 EC200C43216 for ; Sat, 31 Jul 2021 18:38:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE07461050 for ; Sat, 31 Jul 2021 18:38:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229642AbhGaSiG (ORCPT ); Sat, 31 Jul 2021 14:38:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229475AbhGaSiG (ORCPT ); Sat, 31 Jul 2021 14:38:06 -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 61BE1C0613D3; Sat, 31 Jul 2021 11:37:59 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id b21so17746987ljo.13; Sat, 31 Jul 2021 11:37:59 -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=RWvwl8D8cTgFcx+4fHw3o3cHJEwxiQXIECV/bUKr4zM=; b=cA+wddHoup3g7CKDKb9rl8JNNFwDb1qR0PtdJwJ4ipid++WWOs62gQK0NF6S5VZmqv ts4UFvKAh+HwqHYeB0WeNnHjtgaimKxVKvwTBpNmBlDHjga3croZ0qT1maw/HcPAbjRL DOjoXfXHx9qeljvdG/DvoXVdlZDGGvgrMqnTVBxursRAfHz2ZCHS/535B2w3m2RAaV0X gmOO+86SljTnNfsM6EZ8QlYGgvnOM+fX5HaYQ5senueIXbX2bVKJpvuEeSy8wnUJ78Bm 3GMniTq9h/Lu/btpQxd4FUAyoxAXBuiQsDdTk4TZtV6O82qZABiQFiLroiOrDtC/2ipt 6yMg== 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=RWvwl8D8cTgFcx+4fHw3o3cHJEwxiQXIECV/bUKr4zM=; b=Cd+c+Cc9Q5EGIbIyfPjUnRQMxn+9UxAVBdPOCv3bWGOF7qJJhYuPwH3VlbSh0WO5iJ ju91O2lHciHv8+77FKNUu5Ce/1v1it29KqPp8z2k0PUBHgDjHzwWSKQwNj7fiOxzOC76 2MMFT1U7cgT3qtrNCEURWNnbr797Z4ArvcFa5vr1xTczsVorqEUvM3mM8CyU7F0RUh7E SFvfETjPr17MYSbD2GaRhoBiw6UP0OP8Jxrz8T8kBOOX0JfETWwWM36N8GvpB10myVRy K8MTva4d5qYyq+wpC1KecCruQ43XVXF3IQ2BZsGK3oigeTB3Wbj5+QaRgbsolw1g4Inf f2EQ== X-Gm-Message-State: AOAM533bcKmLsyBzr3qyVXYEk14T7NJ9G67XNMXd7ANghftSGWNW0MSi RN1hgQ795/Jojpqa3+mNIYs= X-Google-Smtp-Source: ABdhPJzcOs2xpAmfU2xRebD4+0sjJp1claIvcV90/FBRHqNl/iRyve4FTVK8SvqMrsv8hAeHg0/Cag== X-Received: by 2002:a2e:920f:: with SMTP id k15mr5892521ljg.357.1627756677817; Sat, 31 Jul 2021 11:37:57 -0700 (PDT) Received: from localhost.localdomain (94-29-22-96.dynamic.spd-mgts.ru. [94.29.22.96]) by smtp.gmail.com with ESMTPSA id s7sm456396lfg.297.2021.07.31.11.37.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Jul 2021 11:37:57 -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 , Ard Biesheuvel , Davidlohr Bueso , Ion Agorria , Svyatoslav Ryhel Cc: linux-tegra@vger.kernel.org, linux-block@vger.kernel.org, linux-efi Subject: [PATCH v2 2/3] mmc: block: Add mmc_bdev_to_card() helper Date: Sat, 31 Jul 2021 21:36:25 +0300 Message-Id: <20210731183626.18568-3-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210731183626.18568-1-digetx@gmail.com> References: <20210731183626.18568-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-efi@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 ce8aed562929..93ca25e97259 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -42,6 +42,7 @@ #include #include +#include #include #include #include @@ -313,6 +314,20 @@ static ssize_t force_ro_store(struct device *dev, struct device_attribute *attr, return ret; } +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 Sat Jul 31 18:36:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 489954 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.7 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=ham 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 B9C95C432BE for ; Sat, 31 Jul 2021 18:38:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9989061040 for ; Sat, 31 Jul 2021 18:38:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229896AbhGaSiO (ORCPT ); Sat, 31 Jul 2021 14:38:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229475AbhGaSiG (ORCPT ); Sat, 31 Jul 2021 14:38:06 -0400 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33772C0613CF; Sat, 31 Jul 2021 11:38:00 -0700 (PDT) Received: by mail-lj1-x235.google.com with SMTP id h9so17790185ljq.8; Sat, 31 Jul 2021 11:38:00 -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=8Z2xj19fFZR3UM1wJkaYc818wokD+RUP2G9IQhb3Eq4=; b=pscp1bruxRnJ3da8+Gj0e+PjHKiRCC1Ih+Kk7ikF1gKeXFMWfqWfoUuM6+hzabgfNv ncrxVX1AX4DjIZ64qvyPAU3GdHZAehz4IOg9QbmO1u6JlTOPohXZQ+dK1m1j++gJ9xeT iUmEMKPmjjf4c7Wf2B7u/IfEDtAXIKgWDdQowcfGZ8LteXQfBbLc1h+4Zl4QmaL/5vUD Z1pKGjo3BgR7WeTH49LUUP2yQub1g3ji19lqU2Lp9DSA3x409O+lWxStRzfAM4KLNos8 ADQ7I2z7hhCZRU7PH/DlMkkaC9szvKZu1esZKzeTVVdWJHrlWRkVpPdM+UFSHyt8J5PS OHQw== 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=8Z2xj19fFZR3UM1wJkaYc818wokD+RUP2G9IQhb3Eq4=; b=g/AzF+uweRuokZ5vqW2c29fz/JmzxmrOBCYarqQeCkgU+36kOnZ/SUwC5tpsqkWjRs onC+7iyeVOrlC2gc5SWec6btiRUxw/xOhXwlFNB2y0bExdqBNwk3AWOQEF9Z443EQqP6 fzNZkZAaietNQmB5k/owcqBjVr99fATFyU89gC2DswUcpuujKd3i0hILMgkuWo/ODwi4 ru/30Hc20J6cU9CiH4lcBNPNUrIsrHEts1jskcrKZbeoyaN0CtEJjoS5OwEJbvjIgxIk lxc6hhA96dqP4iCbpwf0z+viOKsqf1onpmSRvpDlBteBTILTxCwG84eBDyBpS/AUuRrt pnQQ== X-Gm-Message-State: AOAM532fcmSoijTAveKST2bZjnHXOvkU3lLhMU9pSMwQwUrOiFeX1rkw 0YyiYA/Jknk2FwFc2qxQsxY= X-Google-Smtp-Source: ABdhPJxUX0sOEbQbnh1tvY+COPwZm93m8vu4aSaOdFEXxq0nz7kFdp2Y31XetFhwCWD9Z4nFd5Upbg== X-Received: by 2002:a2e:7e05:: with SMTP id z5mr5927813ljc.342.1627756678600; Sat, 31 Jul 2021 11:37:58 -0700 (PDT) Received: from localhost.localdomain (94-29-22-96.dynamic.spd-mgts.ru. [94.29.22.96]) by smtp.gmail.com with ESMTPSA id s7sm456396lfg.297.2021.07.31.11.37.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Jul 2021 11:37:58 -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 , Ard Biesheuvel , Davidlohr Bueso , Ion Agorria , Svyatoslav Ryhel Cc: linux-tegra@vger.kernel.org, linux-block@vger.kernel.org, linux-efi Subject: [PATCH v2 3/3] partitions/efi: Support NVIDIA Tegra devices Date: Sat, 31 Jul 2021 21:36:26 +0300 Message-Id: <20210731183626.18568-4-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210731183626.18568-1-digetx@gmail.com> References: <20210731183626.18568-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-efi@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 | 18 ++++++++ block/partitions/tegra.c | 86 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 118 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 c577e9ee67f0..5fcc85087465 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 fb3a556cacce..2fb6db3134ee 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 e2716792ecc1..dced55c0d2e1 100644 --- a/block/partitions/efi.c +++ b/block/partitions/efi.c @@ -98,6 +98,15 @@ static int force_gpt; static int __init force_gpt_fn(char *str) { + /* + * This check allows to properly parse cmdline variants like + * "gpt gpt_sector=" and "gpt_sector= gpt" since + * "gpt" overlaps with the "gpt_sector=", see tegra_gpt_sector_fn(). + * The argument is absent for a boolean cmdline option. + */ + if (strlen(str)) + return 0; + force_gpt = 1; return 1; } @@ -621,6 +630,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..d8801a885a62 --- /dev/null +++ b/block/partitions/tegra.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define pr_fmt(fmt) "tegra-partition: " fmt + +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include "check.h" + +#define TEGRA_PT_ERR(_state, fmt, ...) \ + pr_debug("%s: " fmt, \ + (_state)->bdev->bd_disk->disk_name, ##__VA_ARGS__) + +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", }, + {} +}; + +static int +tegra_partition_table_emmc_boot_offset(struct parsed_partitions *state) +{ + struct mmc_card *card = mmc_bdev_to_card(state->bdev); + + /* 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(state->bdev) != SZ_512 || + !of_match_node(tegra_sdhci_match, card->host->parent->of_node)) { + TEGRA_PT_ERR(state, "unexpected boot source\n"); + return -1; + } + + /* + * 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. + */ + return card->ext_csd.raw_boot_mult * SZ_128K / + SZ_512 * MMC_NUM_BOOT_PARTITION; +} + +int tegra_partition_forced_gpt(struct parsed_partitions *state) +{ + int ret, boot_offset; + + if (!soc_is_tegra()) + return 0; + + boot_offset = tegra_partition_table_emmc_boot_offset(state); + if (boot_offset < 0) + return 0; + + /* + * 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(state->bdev->bd_disk); + state->force_gpt_sector -= boot_offset + 1; + + ret = efi_partition(state); + state->force_gpt_sector = 0; + + return ret; +}