From patchwork Fri Oct 25 22:52:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Young X-Patchwork-Id: 11213155 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 79EDD1515 for ; Fri, 25 Oct 2019 22:53:51 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4FD3E21D7B for ; Fri, 25 Oct 2019 22:53:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=durhamuniversity.onmicrosoft.com header.i=@durhamuniversity.onmicrosoft.com header.b="N3XIF6m1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4FD3E21D7B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=durham.ac.uk Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iO8RS-0004E8-0G; Fri, 25 Oct 2019 22:52:22 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iO8RR-0004Dy-7k for xen-devel@lists.xenproject.org; Fri, 25 Oct 2019 22:52:21 +0000 X-Inumbo-ID: 1916ed44-f77a-11e9-94cd-12813bfff9fa Received: from EUR04-DB3-obe.outbound.protection.outlook.com (unknown [40.107.6.130]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 1916ed44-f77a-11e9-94cd-12813bfff9fa; Fri, 25 Oct 2019 22:52:19 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ckMrotn2uZ8SmceBwdIfloeui/Dq/j9zBQaKB8iaWhIKJ/FVH81EfrKhHBBvCShiQgcOFVWAwyohwqattFDDjM9fRM0Oo3Etw+IAmPnw3LYJVHl/C8tvuga+C5vmR0Vun6jlkJE6gUtIu5CYcoYQiFWm7wtyiiVEbFVSlN8bFoWolSAQzMMgqwmIhovTtX5OS4yMT4QWLK+y1BUr3ob8BgJ4Ze8/wkOpRjGjjntT50mcfRNNAoSKKWvUGFiY6NoGD9xO8YesNhtutFa8PLbzI90RzFw8gxoYAIBdiJp9Kp4SMTB1++W+FezEc5papd86A8ZpnHcRRWtLDgswb+SVcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cqQssvL0QFp0PYbissrRB7wzp7O6AgiJU0bpAsVoq18=; b=oFXFkqCRJYt3ttE7wQQa0p5wBzji9ktFPTT08U0QMIdyVIk5Gl8Ue65Dna6ZYtoQRqwYGORX4Wg+2byhQzWOt3ztcG/xVh4dENoLskUajWsJhqSbR4+qrmaDArzr+LQBWXWDcuUDcCK/+/fFE5/A8mzjdBEB9nMwzVSHg4LghGOC+ZXflSQnYXVBleGtztstqUbUOn/4tE43E6pn9V46ocqcKd8L9baNwabYt/dz3kVCn76QAaUlm/mu4u3v9RYS34CFN5rEkcJdcxxOUBJOWxjNAV629Kt41HyHGbfb34z/GIKVAgeCGuMcKeSnO4tJX3nmOVBhb2s7l5xB4U+jgw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=durham.ac.uk; dmarc=pass action=none header.from=durham.ac.uk; dkim=pass header.d=durham.ac.uk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=durhamuniversity.onmicrosoft.com; s=selector2-durhamuniversity-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cqQssvL0QFp0PYbissrRB7wzp7O6AgiJU0bpAsVoq18=; b=N3XIF6m10e7O0PKECg3vYqdC6zoRwRReNllE/T/gIQoOcZSd5rne02Re0KA7sVoG0tgCbpbU/eeOcrUCu7rQa+diaScN9fOFmWN3uuRw+11wXF0aQm8dz+VLkRXkSMUrasKC8zhynGqx5S1GDr63Zu0fuC/EEKrmxV4ZkoAqqWY= Received: from VI1PR06MB4720.eurprd06.prod.outlook.com (20.177.200.18) by VI1PR06MB5583.eurprd06.prod.outlook.com (20.177.202.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2387.22; Fri, 25 Oct 2019 22:52:17 +0000 Received: from VI1PR06MB4720.eurprd06.prod.outlook.com ([fe80::d067:c8d1:e873:5632]) by VI1PR06MB4720.eurprd06.prod.outlook.com ([fe80::d067:c8d1:e873:5632%5]) with mapi id 15.20.2387.021; Fri, 25 Oct 2019 22:52:17 +0000 From: "YOUNG, MICHAEL A." To: "xen-devel@lists.xenproject.org" Thread-Topic: [XEN PATCH 1/3] set default kernel from grubenv next_entry or saved_entry Thread-Index: AQHVi4bZp6Rlls8E60iiZZ95hwr4Gg== Date: Fri, 25 Oct 2019 22:52:17 +0000 Message-ID: <30a4fb6bb023348af867a253f6ff1e80efc7e232.1572038720.git.m.a.young@durham.ac.uk> References: In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [2a00:23c4:921a:2100:1097:224c:243b:f186] x-mailer: git-send-email 2.21.0 x-clientproxiedby: LNXP123CA0016.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:d2::28) To VI1PR06MB4720.eurprd06.prod.outlook.com (2603:10a6:803:90::18) authentication-results: spf=none (sender IP is ) smtp.mailfrom=m.a.young@durham.ac.uk; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 6c9b051d-2318-411c-3c2b-08d7599dfc03 x-ms-traffictypediagnostic: VI1PR06MB5583: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1051; x-forefront-prvs: 02015246A9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(39860400002)(136003)(366004)(346002)(376002)(396003)(199004)(189003)(66476007)(66946007)(256004)(8676002)(8936002)(81156014)(50226002)(66556008)(305945005)(7736002)(2501003)(54906003)(36756003)(66446008)(186003)(5660300002)(14454004)(86362001)(76176011)(786003)(316002)(52116002)(102836004)(386003)(6506007)(6436002)(2616005)(6512007)(71200400001)(71190400001)(446003)(64756008)(99286004)(6486002)(11346002)(25786009)(486006)(5640700003)(478600001)(4326008)(476003)(2906002)(118296001)(46003)(6116002)(6916009)(2351001)(81166006)(14444005); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR06MB5583; H:VI1PR06MB4720.eurprd06.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: durham.ac.uk does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: zMJe54zRgfoNoS/SEAxRJZ3PMcXMIn+Uf8/jrterrvxLAdyy7rSkT5VPk0x5OWuEuNmqc9WnYoXsXMkz0TDXoYYH1NVQdOOKPIKWFWoCVUpOXT390N91i6oiVc5bFu+IuHdxUJRbEVYacoF8CktwOHQxQz5llKlNePDB+wrZgHtNOelsElgxt9JR3GIYsGJM58nBk0eFJ/LH7BCOY+1+iZ/VqCnQ3c7bxtY0GKbkj3W5PmTe8aMDVT5fP6gzn/FiPtpCcdtLyryK7BRtR73JdoViR/rHqRPtUc0hLtfD5UfPKjV3E19K0rZ+k/RUejY9PHJ9SoOaOIgI/JfJY+vig9xzkR6nLDq44PB3nZCMJoyhiJ47kkCZfkefKCzK5uDGHAKW53y3SOhB/tAwI1DUiHKgi0ed15ke5dtleZGOUxsGl0ygStsNYA0/2YIg3sq8 MIME-Version: 1.0 X-OriginatorOrg: durham.ac.uk X-MS-Exchange-CrossTenant-Network-Message-Id: 6c9b051d-2318-411c-3c2b-08d7599dfc03 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Oct 2019 22:52:17.0791 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 7250d88b-4b68-4529-be44-d59a2d8a6f94 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: yuFjdmEKyMrCQak5fkv3Hg6BAFYBb+M0bb+mBYukr99St9Hf0Jh+vW+N+8egzO+eYHzkcTTFtQ3OUgWWBO9bfQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR06MB5583 Subject: [Xen-devel] [XEN PATCH 1/3] set default kernel from grubenv next_entry or saved_entry X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , Wei Liu , "YOUNG, MICHAEL A." Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This patch reads the contents of a grubenv file if available, and uses the value of next_entry (in preference) or of saved_entry to set the default kernel if there is a matching title or if it is a number. If either next_entry or saved_entry is set and neither is used then the default is set to 0. Signed-off-by: Michael Young --- tools/pygrub/src/GrubConf.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tools/pygrub/src/GrubConf.py b/tools/pygrub/src/GrubConf.py index 73f1bbed2f..1fc68cadb2 100644 --- a/tools/pygrub/src/GrubConf.py +++ b/tools/pygrub/src/GrubConf.py @@ -368,7 +368,7 @@ class Grub2ConfigFile(_GrubConfigFile): def new_image(self, title, lines): return Grub2Image(title, lines) - def parse(self, buf = None): + def parse(self, buf = None, grubenv = None): if buf is None: if self.filename is None: raise ValueError("No config file defined to parse!") @@ -379,10 +379,17 @@ class Grub2ConfigFile(_GrubConfigFile): else: lines = buf.split("\n") + if grubenv is not None: + lines = grubenv.split("\n") + lines + in_function = False img = None title = "" menu_level=0 + img_count=0 + saved_entry = "" + next_entry = "" + entry_matched = False for l in lines: l = l.strip() # skip blank lines @@ -408,6 +415,13 @@ class Grub2ConfigFile(_GrubConfigFile): raise RuntimeError("syntax error: cannot nest menuentry (%d %s)" % (len(img),img)) img = [] title = title_match.group(1) + if title == next_entry: + setattr(self, 'default', img_count) + entry_matched = True + if title == saved_entry and not entry_matched: + setattr(self, 'default', img_count) + entry_matched = True + img_count += 1 continue if l.startswith("submenu"): @@ -432,6 +446,14 @@ class Grub2ConfigFile(_GrubConfigFile): (com, arg) = grub_exact_split(l, 2) + if com == "next_entry": + next_entry = arg + continue + + if com == "saved_entry": + saved_entry = arg + continue + if com == "set": (com,arg) = grub2_handle_set(arg) @@ -448,6 +470,13 @@ class Grub2ConfigFile(_GrubConfigFile): pass else: logging.warning("Unknown directive %s" %(com,)) + + if next_entry.isdigit(): + setattr(self, 'default', next_entry) + elif saved_entry.isdigit() and not entry_matched: + setattr(self, 'default', saved_entry) + elif (next_entry != "" or saved_entry != "") and not entry_matched: + setattr(self, 'default', 0) if img is not None: raise RuntimeError("syntax error: end of file with open menuentry(%d %s)" % (len(img),img))