From patchwork Wed Feb 19 16:23:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 206557 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=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 174FEC34050 for ; Wed, 19 Feb 2020 16:25:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DA0B22465D for ; Wed, 19 Feb 2020 16:25:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="q0KvBn7A" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726712AbgBSQZ3 (ORCPT ); Wed, 19 Feb 2020 11:25:29 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:46566 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726659AbgBSQZ3 (ORCPT ); Wed, 19 Feb 2020 11:25:29 -0500 Received: by mail-lj1-f194.google.com with SMTP id x14so958693ljd.13; Wed, 19 Feb 2020 08:25:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LGUcIpTbEbd2gKzVZah8ywZm+EFWRECsbgMwE4dPkmc=; b=q0KvBn7A14JQWVR1QGa6Q4b8U95+mkJ2Huoy2MrpQLM+x3CC3hwCOoVa/kQCAa2W7e 3kjdB16EuvFpGvPNgwlDpVjhHCwgfyWIiw1IaGYXn1MSNL8IF1a1JjNAYTJc+172PpxZ 5Z7vqbxPTifdCh9BU79UqIkJLfQlOn9qwxbCAR6Y6bIYX48nmkIJrhr87EWUuP0cRAb1 nPTwI8k4maeYJnZeaHiA4yp3J1yLLkAkwPGFGHeMP8H9vTGdP7OdDBpI4g3rkVJ/FpVq d9m3b/L3RLClnokebu6bmvS9R0qn1q+RO2Ih2ptmAuXi2bVjMCusV2prdez3VivLhmuN AoAA== 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:mime-version :content-transfer-encoding; bh=LGUcIpTbEbd2gKzVZah8ywZm+EFWRECsbgMwE4dPkmc=; b=g5WZT/6mRjPY9xhI6zebnx+kYzTg0le6DugGvUo70NNVjyPNa0zMLoxZClzlyxziW2 K1xhLlBStU32Y/543boK6ghgI9CSmWJQrqfWxHSGw+FQfuaOAsDdGchZg/E88mhCgRN0 wnjpZQMQzoaxobpB8ObsBA06n0x9ICK8rg0YRTSLY0FFvirUJKcRBPfq0AAVhLyd+GN9 ldRWpkLun/T41fwlHO5cbl87VoB1dvx9jD/wj8o8oHkefcmX4CdYffwSb69ZZx3Gmy83 kdEGJ8UWvR/OPoQkQl4j1DdBn8HLIysSD7kvL7dNIU1I7TlYW0EWR+K11WIvpKuqrqor LErA== X-Gm-Message-State: APjAAAUaWjwToWqca0sUCObsG/gyBjzrWFYQWHAV0XZYOOp19uxiWDqQ vlO1QklsqYo0cW/lAh9Iv+jVrNUN X-Google-Smtp-Source: APXvYqzgQTpVrzmYj7+xZaS9PwsyHhb4+lZha07RnRL0jtLKr12a2UhG+kDKXAbBvaNwDh566wCCjg== X-Received: by 2002:a2e:b536:: with SMTP id z22mr15860746ljm.259.1582129526316; Wed, 19 Feb 2020 08:25:26 -0800 (PST) Received: from localhost.localdomain (79-139-233-37.dynamic.spd-mgts.ru. [79.139.233.37]) by smtp.gmail.com with ESMTPSA id i67sm26819lfd.38.2020.02.19.08.25.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 08:25:25 -0800 (PST) From: Dmitry Osipenko To: Jens Axboe , Davidlohr Bueso , Colin Cross , Thierry Reding , Jonathan Hunter , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , David Heidelberg , Peter Geis Cc: linux-efi@vger.kernel.org, linux-tegra@vger.kernel.org, linux-block@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1] partitions/efi: Add 'gpt_sector' kernel cmdline parameter Date: Wed, 19 Feb 2020 19:23:39 +0300 Message-Id: <20200219162339.16192-1-digetx@gmail.com> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The gpt_sector= causes the GPT partition search to look at the specified sector for a valid GPT header if the GPT is not found at the beginning or the end of block device. In particular this is needed for NVIDIA Tegra consumer-grade Android devices in order to make them usable with the upstream kernel because these devices use a proprietary / closed-source partition table format for the EMMC and it's impossible to change the partition's format. Luckily there is a GPT table in addition to the proprietary table, which is placed in uncommon location of the EMMC storage and bootloader passes the location to kernel using "gpt gpt_sector=" cmdline parameters. This patch is based on the original work done by Colin Cross for the downstream Android kernel. Cc: Colin Cross Signed-off-by: Dmitry Osipenko --- Documentation/admin-guide/kernel-parameters.txt | 5 +++++ block/partitions/efi.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 50138e6826a1..ee4781daa379 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1382,6 +1382,11 @@ primary GPT is corrupted, it enables the backup/alternate GPT to be used instead. + gpt_sector [EFI] Forces GPT partition search to look at the + specified sector for a valid GPT header if the GPT is + not found at the beginning or the end of the block + device. + grcan.enable0= [HW] Configuration of physical interface 0. Determines the "Enable 0" bit of the configuration register. Format: 0 | 1 diff --git a/block/partitions/efi.c b/block/partitions/efi.c index db2fef7dfc47..0c8926d76d7a 100644 --- a/block/partitions/efi.c +++ b/block/partitions/efi.c @@ -103,6 +103,17 @@ force_gpt_fn(char *str) } __setup("gpt", force_gpt_fn); +/* This allows a kernel command line option 'gpt_sector=' to + * enable GPT header lookup at a non-standard location. + */ +static u64 force_gpt_sector; +static int __init +force_gpt_sector_fn(char *str) +{ + WARN_ON(kstrtoull(str, 10, &force_gpt_sector) < 0); + return 1; +} +__setup("gpt_sector=", force_gpt_sector_fn); /** * efi_crc32() - EFI version of crc32 function @@ -621,6 +632,10 @@ 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); + if (!good_agpt && force_gpt && force_gpt_sector) + good_agpt = is_gpt_valid(state, force_gpt_sector, + &agpt, &aptes); + /* The obviously unsuccessful case */ if (!good_pgpt && !good_agpt) goto fail;