From patchwork Mon Nov 28 11:23:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 1709679 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::138; helo=mail-lf1-x138.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbfnuskoamgqevqmhf5q@googlegroups.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20210112 header.b=XyrDv37+; dkim-atps=neutral Received: from mail-lf1-x138.google.com (mail-lf1-x138.google.com [IPv6:2a00:1450:4864:20::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NLNPR3w0Dz23nq for ; Mon, 28 Nov 2022 22:23:05 +1100 (AEDT) Received: by mail-lf1-x138.google.com with SMTP id w14-20020a19490e000000b004b12aab341csf3675237lfa.11 for ; Mon, 28 Nov 2022 03:23:05 -0800 (PST) ARC-Seal: i=3; a=rsa-sha256; t=1669634581; cv=pass; d=google.com; s=arc-20160816; b=sYxT67pFkfnlL5TUhiNiyLpJWMhd+Oc+Nbb2kOjePFjyVtKc2HjNuZvpDNbyqgrQf3 yveNbv5R7G39YkVj6AfgMvqyI+B9OTaYxd5CKdhrC7mfMzx8+hpQW3cmg93TGtJk1Eyu JiW1Ib8xTrFwk0ujsuUfFsv+7uQVwxzE9Nnaikfo1LQ0M9Rlu8impvx4P8fVz4DAAtiB QwiuPAgv5vmXIriZXMTrlc6QQ3Bj9R00STVFWeqEAQmdD9XDg7+A7uDQ9C4sl3fUPwOT 6L3iUxJmQ6tpTtGLDUK5GHMbyx1DTfzvylK+mM6sGSMpVqX9/WvZ3tGH1K/O0vdB9d3N mVjw== ARC-Message-Signature: i=3; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:message-id:date :subject:cc:to:from:sender:dkim-signature; bh=qHkH/oZtm1ZFNITLQM45JEgcOCPGjHZ2Kkk+S7MJxmQ=; b=Bzj4h59rQKVVJsyjvLdAGjhCpzMlp2Pjndb73OF6TVV/KBRhyo0q69Oft2zWH7D3uI Az5UUF6Z2jDFE90m6xEY4iP0UCraf6lG1Xismebh7/ZdSh0QbUJRBWtZaxJkWdYY9MVB 9c0Ad6GiiiU96qojnstBb8aKZJomyk0hYnFz6B1a2nQ5JFIR1x8lPaPSXENcwy7Clzg0 ng/0b2WuO6wtjDLhGkGNYYihb3/v0xOhItNE7SUBK5PAWB/HSM2O2WkpEVgZcQbLepG4 SHXMxPNh5vtESiBtNTp6DIJF3i++4FikdkIYXZWI3+A7R+Ux6yVz/G0+7pjLYO6MH/9s 9UMg== ARC-Authentication-Results: i=3; gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=selector2 header.b=hxpfcndI; arc=pass (i=1 spf=pass spfdomain=siemens.com dkim=pass dkdomain=siemens.com dmarc=pass fromdomain=siemens.com); spf=pass (google.com: domain of christian.storm@siemens.com designates 2a01:111:f400:7e1b::61e as permitted sender) smtp.mailfrom=christian.storm@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:message-id:date:subject:cc:to:from :sender:from:to:cc:subject:date:message-id:reply-to; bh=qHkH/oZtm1ZFNITLQM45JEgcOCPGjHZ2Kkk+S7MJxmQ=; b=XyrDv37+vuQKFtIMFdW4E/TeOI3ZeY+CrvmeAq77sbl3Ov2sxrCCxI6H+Rzo3ccILE A3z65429S3A26pJujtONDl6Db6Rol3ic8+LXGgEgxCSFoHegosjjgior2eNVdQtCmruT KqkG6wjBI8Rx4xG651CMnCVIR72pWpjkWygIzCyIWgunsIXRpgCR9Se5ydelvYAHxyIh 2RfyPbR2VYEZignp5CtJabLGHnTiLUz/JhM8jP8Y0LMAOLNvHiVfEsX6BD974+5eui2b IL6DDjxCnh117vTkEXi2K6dapPfvzjbKHzdNMuJnaqmA16N3RT5Jagqx579MrB9mnpiN phyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :message-id:date:subject:cc:to:from:x-gm-message-state:sender:from :to:cc:subject:date:message-id:reply-to; bh=qHkH/oZtm1ZFNITLQM45JEgcOCPGjHZ2Kkk+S7MJxmQ=; b=LEBmfZbnUy962ahjrn6mezmV+uyd63Az7T99nI0Lzi3xVYKcGRCIqK55zZQXXx6LIi kEfWYUWUy3QE0dScrO3ovyr9d0s2aLuO2R4wUUr0mw8pDtK4lBp2Or8wmd24EYThhrXf S2uyJs44W8DXCuFKH1tgNIuN9t3SCeLS7FZrj7BsGnzBHeApAEFHDiSzyZuuJDngbN/U VzUeYcMM8Ogon/wAxgPFhEaDxk3OJ9p3IsI9wco3nEGtUK3Tgpn8v92fMjJtwk/k92VZ mprtN5pyNTiZOVrrarzOWvk4hYsVhBM+iGU7OsYdbTobnDr8K6hfgYTS+NVtbDriOEgc VwgQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: ANoB5pleSPinBc1VBmZ+YpL2/dr4rqib8rVnHd8xW4xoYEGhTPbUnB7S R/3MIneYEalvV/ANDT6hB7Y= X-Google-Smtp-Source: AA0mqf667ZAQZwidrMD59BKKumdwa7gWd19HLzgRIEu7+uCENrcfnH7Sqlt0GJ7gUwTU3EDgJPPl9A== X-Received: by 2002:a05:651c:238e:b0:277:781a:c55d with SMTP id bk14-20020a05651c238e00b00277781ac55dmr10627494ljb.317.1669634581625; Mon, 28 Nov 2022 03:23:01 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:6512:2024:b0:48b:2227:7787 with SMTP id s4-20020a056512202400b0048b22277787ls636550lfs.3.-pod-prod-gmail; Mon, 28 Nov 2022 03:23:00 -0800 (PST) X-Received: by 2002:ac2:4c29:0:b0:497:a1fe:b0ef with SMTP id u9-20020ac24c29000000b00497a1feb0efmr19016021lfq.311.1669634580058; Mon, 28 Nov 2022 03:23:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669634580; cv=pass; d=google.com; s=arc-20160816; b=lUPzpU3/KsZiWCyee760dZVEwvfQUx6sXrx5N/wVVMoS8AXNZ4f/jpD+v68vtIMTyb hzCh/8LiRG1U3pQwGfpRTJRxdewzgoldWNJrs948r0qTkE/wepu3JhidK+RMF+fpgD5I J5Mn11ZD9pbsA3d8fcG2fOR38YHigPJQ9oQ2wfmzhYhq6ku/zGuorRzDOnba1D4DE9Cv 8y8Knzqy/I+IL03tqotasGtARTBrawBAvsYkdncW3ozYKfF9k3h6nayPi7JGxUX+OVND CVBB64q7QoUb9/WzK0MxP+nELEv8h6W9hyqAoUCnuxOI/DGJMaF+1QnGlJjnWmwbLiy/ sn7Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:content-transfer-encoding:message-id:date:subject:cc :to:from:dkim-signature; bh=+BfFVQT4uZcOjvogs/gwofG1T3G+npOzZ6nCXJCTNIM=; b=Zqy87aF7PrKPI2NMpLxXpZKvPoKGKSUh1BOfyLcmWjUBuH+PBnXE/N2FCdQezUmLJc yzhaqR6j8gx8Y05m39PODmi6rm7POTRlzsWtAINzD0TQgIXGIlRcvx7KcdA7xn8DmkID kDMXDGO7LZpkYcAm2oiDIY1CQVOYT7imzeWm1SX4wBK1tpfbJBUHpo/EPEsUQgZxUr8A SplK1iwCwgDkypIsWKCskpaADbfdzWDo+hJ5hSugABHXUlldMVCgN6t8w8f4mSCYr4qS NvzjtTvCZid0oVyC/ZqOj2h0113ZX/ie5CGQc6TZWoMU8hsH3/pf7eVsHp8eRVVwoDlF /Gew== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=selector2 header.b=hxpfcndI; arc=pass (i=1 spf=pass spfdomain=siemens.com dkim=pass dkdomain=siemens.com dmarc=pass fromdomain=siemens.com); spf=pass (google.com: domain of christian.storm@siemens.com designates 2a01:111:f400:7e1b::61e as permitted sender) smtp.mailfrom=christian.storm@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2061e.outbound.protection.outlook.com. [2a01:111:f400:7e1b::61e]) by gmr-mx.google.com with ESMTPS id q8-20020a056512210800b00499b6fc70ecsi526825lfr.1.2022.11.28.03.22.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Nov 2022 03:22:59 -0800 (PST) Received-SPF: pass (google.com: domain of christian.storm@siemens.com designates 2a01:111:f400:7e1b::61e as permitted sender) client-ip=2a01:111:f400:7e1b::61e; ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IkoIDQ4XT9k9hgrxq/goihlpGxENx9TvhdSR9RNIi00myxBUtpx9u5gYpxqSY5wZ48ABaN3gnEpk0RiJUWRKcHb2HdRJuWkTf7lMyuSqrO7Q4GsBMrtdxvRfzsVNDiBGKrzbv4vn8FOinB3hW2bac+J40TdSoQ/n0rkc3L/Uw5SoeIH4m9jSiIGcERlMPt0dSGXgKsmi9MSL6JcXm4ajhDfCSeAu0/BB2LjA1kpJDSsKmnHgsg0EIsu1FjSj/Oy7d/I7btsAUFm3n4WQGaJJ81XB0p32DoogOai2NUS7Ht5HY5L2NKeWLytT7LEqEnkOORYNdnXpFmfEqTxTP66rCw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+BfFVQT4uZcOjvogs/gwofG1T3G+npOzZ6nCXJCTNIM=; b=fqCqYQbql3i2RRVp0BolqX/PFqY3DmHzgk2frxeuH0p0H/N12+2YsrAOXOcmXOuBdYMruF70cshPf0UhY2ng/BrMIeNI2lW+dUpjOcN/IVZepDLeCfm0zlN8DTDLfOu5BnSg+szTMgEg9LPYOlRf6Gh/Ca7ilzR8Vou0JdMCacPUTzefYoMgY6WVy/zr6eofIO0/JBMoAbM5dKjjoKPAVJkyuVGALXzc4ZJWFY0Ugg+h0G/jGdXi+Gv854P0WEg+Fx5TQZ53LLnpwsz6DTvFC7/5VNfcl/L3t7g9k3O6atkEFpdTsOw1V33qgHoXUPnzWelPD1Xw05uaqxVTFYSDLw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=siemens.com; dmarc=pass action=none header.from=siemens.com; dkim=pass header.d=siemens.com; arc=none Received: from AS8PR10MB7042.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:5a9::19) by GV1PR10MB5940.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:150:5c::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.21; Mon, 28 Nov 2022 11:22:58 +0000 Received: from AS8PR10MB7042.EURPRD10.PROD.OUTLOOK.COM ([fe80::9cea:1033:958c:d92b]) by AS8PR10MB7042.EURPRD10.PROD.OUTLOOK.COM ([fe80::9cea:1033:958c:d92b%5]) with mapi id 15.20.5857.023; Mon, 28 Nov 2022 11:22:58 +0000 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH 1/3] bootloader: Add is_bootloader() to distinguish bootloaders Date: Mon, 28 Nov 2022 12:23:24 +0100 Message-Id: <20221128112326.27564-1-christian.storm@siemens.com> X-Mailer: git-send-email 2.38.1 X-ClientProxiedBy: FR0P281CA0095.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a9::12) To AS8PR10MB7042.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:5a9::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR10MB7042:EE_|GV1PR10MB5940:EE_ X-MS-Office365-Filtering-Correlation-Id: 1e06a9d2-7f18-4762-6ca7-08dad132e711 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kCZYqwhpOLYKB//K467H65G0dM2YZqUmn2c2wZLPhc3waMlt6srPu5bvRvS2r9FEQ16BKmKo7kbPhZEpDWIYLFdHbrfWVc4ubAGOexpmfkR2JmLgGj+pwAid2pgs2E1MB9rPcvHEgGOxPruQERcKzowEHwisX5/qqAAFesaOD6lSYCJnSzqPsBSRFxbOLtayadbcvNmcTvxFOmPcOZqbtMN97ajTgUbQsQIsF02WVRqzY3w3xGldNrMOnKWi3SSHe2BvIWwKKOa2MCmtG7O6E2twSehDv7AsZoUdqWPQ4VNxavH+sUbNw3DXKVMrKzmnuVGqzUrIQAY07QEQBWOgD00vqdfw+3JW3qraS3sFnVLzzGvRnCQCQbM7C38Pu4eChA+1Heh048pLLxYQ0US68I2fz+/B7JP0+9ZWWEmXAXHSsqIc0CUMN7DDKN3nFgHY7eT6yaF1qV1NfU+jOheCuifX7tGGIK98Q4bIGGMKpzcKmTtUFOPrRzZ8AQbpnscuspSN+9M5cvEQH7wWW9Fgfwl+iPniWmxifTqpHKanwgDOkxWpLCH6BXtebwza1TYx0Mj8tX+TzlySAdV2W7jT7YXNAdEihE7wlzyyditYGoFfrK2GI/ZX2KxSkWexiAmddVQX7II8Gk5BSyFQxZlodg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR10MB7042.EURPRD10.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(366004)(136003)(396003)(376002)(346002)(451199015)(66946007)(4326008)(66556008)(66476007)(8676002)(82960400001)(478600001)(38100700002)(6486002)(2616005)(6666004)(26005)(6512007)(6506007)(5660300002)(8936002)(316002)(44832011)(1076003)(36756003)(6916009)(41300700001)(186003)(83380400001)(86362001)(107886003)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: U7tUuarrXtizqYWAh7Nh4SME8ZprGljFiPz0wIKl8Ts0zRtmFxjWmVf62ZhA/KU4vHaCOgu6ooxlpUCaij9dwpIdXXp6aoMRRsszBShW+ezybd9JEggjyQwlmH2x0KCmfW8MbxsZ5xGiJSUbFSQTNI30Mf/XXXpsIVL3HxuqiLn3xAVCmbD2c3fgc3yJQxsN2igYkcVngd40nCjMOmBZd4wFyu3L0wYm1cCLTggWUxQSmofkJMCRGVHVm9m48sq3W4sK8zjAoAEFA8kz7XrSdBS5GssTAGcUiJEWvLVB9JgIjAQT9D6LEcr/q1RiLE5DBolbMMIORBAuwKfuars1/GFwDFzrDuep2KkOlEd3scGN+j7tGttWgymQCxykxKzt7ZRihmhXLLBrG0s5tSfLU+GRIrCCE/MMc3fyEAKH5fhZv1QkAYtwqutsoClaUCdgAkNxIlIQvEBn3qLQsIwl7HeClNomxW8Kffwi5qCy1B/mKeiIAox+01QYUJ1fLAaufAqrmuVsz37rJaz1VXHxLgy0AAUL0nlblw0FMI9aSzEFpGfKLb7NNXJrFsTHktfTeJjd/8uzMj0R5VlRe7HbTihPXm24ouyA241fzvT21yeEDL3PlirfreT8X99aWnJd7zY9qixB7yWShj8ftHmCKe5G9RS8BB3OVwJmmhzr+UInvkPI5+KSTo6fC/fcPIu0TstrkR4hN94WyyFjZHhSdEcNnFJeP+hkWOeW9HsEPJwgEwdPnc1yqj4P9rNeYAj0ITHSPwbP4LTG2rxlsbk0FUrVu/CLqjLY5D3LztN6NKq4pEAiR+kf4sw6Z6g8gZcn31tOSpfEaDH/9l0/eiy2iFQd2D+xRDE1NselSNG+ws/z7/gSGYWkjgwgCWOB1Oe7edXoMbDLg+Z7Iv41+tFODMprb7ABtboxanuzaSV2oqAotMX/0vy7SJk72TWHlwn4q0BQDcEXlIFlloL4gHt/JjYSUJhFaBVLyWRu+N4pX6tyjRZXGNLNtmdU7hynQddr34fWdUgjX4GfCirqTWvYRC08zFh/nKKRh6q9tEfalsS+LGE1daTnnSlFh7ggRV+wHYwAGLaN30xAXymO8l5xX5VhF0uxBQ6W/622PSR+J20DuqQV3SeHOHGXr8Ro/yrViiOG1a4ZZVzSPo0yHGorMKqNn5d/ZFekmQS8IYWGBolNgYc+uvvTvS+IOB04IzCQb2lGcJEuPKfYrERWDmh/9mfXctUWUxQ2Zim0kaU8iG1C9+b9XOtkeuDrvjX+U62u7rd4U8uCldHJ2iJ+kfIO9sAO0fZKoySYJB8ja0o62UkblzHhn0Whi1hRe6XwVU81vvHHYxxtSkLIcG0yO6/0KMRYSHrMDT2j3brJ3ixtYA97F4wcsOl6ILvoKzKaVaSm/xYLzorEqM67//NqEaoTYG088yrVQfYCXqG+aL9QOQlPifb4z/FvfVHizAY9r2ropqTqx5S6fcnnbypyezxtKsTE96Vz3AYpJeWNN9VyDNR0gIBusgzR49oS55ZJrZFrSDJt8UcCw2VrMfUHgtkDN3DASzTHWdTW3G24NPqsOVzt8UvRUJv6dyn821Zm67Ah8TCektxdjkV7yaEn61tKWg== X-OriginatorOrg: siemens.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1e06a9d2-7f18-4762-6ca7-08dad132e711 X-MS-Exchange-CrossTenant-AuthSource: AS8PR10MB7042.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Nov 2022 11:22:58.2220 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 38ae3bcd-9579-4fd4-adda-b42e1495d55a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: OyBoOrKCGZy/NapKykWrlYoaZih/193OMzMdlcAnJ4q2u7Zmj1mDFc8lGog4Z7RhNH3o3Wa9/tQnHvWOvgNxvnDVNMHa2n3aKoCxWuoCBnU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR10MB5940 X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=selector2 header.b=hxpfcndI; arc=pass (i=1 spf=pass spfdomain=siemens.com dkim=pass dkdomain=siemens.com dmarc=pass fromdomain=siemens.com); spf=pass (google.com: domain of christian.storm@siemens.com designates 2a01:111:f400:7e1b::61e as permitted sender) smtp.mailfrom=christian.storm@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Add bool is_bootloader(const char *name) to distinguish the currently selected bootloader and add central bootloader name #define's as well to the documentation to help in maintaining the uniqueness of bootloader names. Signed-off-by: Christian Storm --- bootloader/ebg.c | 2 +- bootloader/grub.c | 2 +- bootloader/none.c | 2 +- bootloader/uboot.c | 2 +- core/bootloader.c | 7 +++++++ doc/source/bootloader_interface.rst | 12 +++++++++++- include/bootloader.h | 16 ++++++++++++++++ 7 files changed, 38 insertions(+), 5 deletions(-) diff --git a/bootloader/ebg.c b/bootloader/ebg.c index 00dc5c5..4194a38 100644 --- a/bootloader/ebg.c +++ b/bootloader/ebg.c @@ -236,5 +236,5 @@ static bootloader* probe(void) __attribute__((constructor)) static void ebg_probe(void) { - (void)register_bootloader("ebg", probe()); + (void)register_bootloader(BOOTLOADER_EBG, probe()); } diff --git a/bootloader/grub.c b/bootloader/grub.c index 21bb6ac..7bda742 100644 --- a/bootloader/grub.c +++ b/bootloader/grub.c @@ -353,5 +353,5 @@ static bootloader grub = { __attribute__((constructor)) static void grub_probe(void) { - (void)register_bootloader("grub", &grub); + (void)register_bootloader(BOOTLOADER_GRUB, &grub); } diff --git a/bootloader/none.c b/bootloader/none.c index d9d1c0b..d996da3 100644 --- a/bootloader/none.c +++ b/bootloader/none.c @@ -54,5 +54,5 @@ static bootloader none = { __attribute__((constructor)) static void none_probe(void) { - (void)register_bootloader("none", &none); + (void)register_bootloader(BOOTLOADER_NONE, &none); } diff --git a/bootloader/uboot.c b/bootloader/uboot.c index ed4c516..2720b1e 100644 --- a/bootloader/uboot.c +++ b/bootloader/uboot.c @@ -144,5 +144,5 @@ static bootloader* probe(void) __attribute__((constructor)) static void uboot_probe(void) { - (void)register_bootloader("uboot", probe()); + (void)register_bootloader(BOOTLOADER_UBOOT, probe()); } diff --git a/core/bootloader.c b/core/bootloader.c index b8678b8..c02b249 100644 --- a/core/bootloader.c +++ b/core/bootloader.c @@ -55,6 +55,13 @@ int set_bootloader(const char *name) return -ENOENT; } +bool is_bootloader(const char *name) { + if (!name || !current) { + return false; + } + return strcmp(current->name, name) == 0; +} + const char* get_bootloader(void) { return current ? current->name : NULL; diff --git a/doc/source/bootloader_interface.rst b/doc/source/bootloader_interface.rst index 9066c74..b8c0182 100644 --- a/doc/source/bootloader_interface.rst +++ b/doc/source/bootloader_interface.rst @@ -82,9 +82,19 @@ registers this bootloader to SWUpdate at run-time: __attribute__((constructor)) static void trunk_probe(void) { - (void)register_bootloader("trunk", &trunk); + (void)register_bootloader(BOOTLOADER_TRUNK, &trunk); } +with + +.. code-block:: c + + #define BOOTLOADER_TRUNK "trunk" + +added to ``include/bootloader.h`` as a single central "trunk" bootloader +name definition aiding in maintaining the uniqueness of bootloader names. + + .. attention:: Take care to uniquely name the bootloader. diff --git a/include/bootloader.h b/include/bootloader.h index 8315759..529ec12 100644 --- a/include/bootloader.h +++ b/include/bootloader.h @@ -6,6 +6,12 @@ */ #pragma once +#include + +#define BOOTLOADER_EBG "ebg" +#define BOOTLOADER_NONE "none" +#define BOOTLOADER_GRUB "grub" +#define BOOTLOADER_UBOOT "uboot" #define load_symbol(handle, container, fname) \ *(void**)(container) = dlsym(handle, fname); \ @@ -50,6 +56,16 @@ int set_bootloader(const char *name); */ const char* get_bootloader(void); +/* + * is_bootloader - Test whether bootloader is currently selected + * + * @name : bootloader name to check if it's the currently selected one + * + * Return: + * true if name is currently selected bootloader, false otherwise + */ +bool is_bootloader(const char *name); + /* * print_registered_bootloaders - print registered bootloaders */ From patchwork Mon Nov 28 11:23:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 1709678 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::23d; helo=mail-lj1-x23d.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbfvuskoamgqep2j6qni@googlegroups.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20210112 header.b=qSjF/Yoy; dkim-atps=neutral Received: from mail-lj1-x23d.google.com (mail-lj1-x23d.google.com [IPv6:2a00:1450:4864:20::23d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NLNPR3vgKz23mg for ; Mon, 28 Nov 2022 22:23:06 +1100 (AEDT) Received: by mail-lj1-x23d.google.com with SMTP id q14-20020a2eb4ae000000b00279a24cd94fsf608047ljm.3 for ; Mon, 28 Nov 2022 03:23:05 -0800 (PST) ARC-Seal: i=3; a=rsa-sha256; t=1669634583; cv=pass; d=google.com; s=arc-20160816; b=gR6DG5EuZgwq2hDYEGuhzyNoCIlZmGws1Vs67igvJuojtyXcQUWOtKcTeCSdZwbdLQ CrAwpCQx9Q/2fuqVOVfP58v4hB6fWEMRyeSTIuyDKQCoO9PomahO+F/kYpqy5vvn2C87 2VBd/PzbLol9lUb2GYLfhcl+UvPVUG2Is9Kz2HambVVJnaZrKiP4O9/1fLFT+QP60/tv UZLndY6AbYaQikCPhUSWCemySKd4svLDm65F1jdX0SMTV2vQn26P6RUiWM/arMuLpXJd 1IzPM4KGksaGagSBwMRbiHU7jGU9mfmV5ZqVoSyoLclrW/luXMreTyBiht6/PzcjIePc 9hwA== ARC-Message-Signature: i=3; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=HkM6czB9fI58G8kapRmSuWyrE0BhO2ZUtSIH7Q1hYFU=; b=ddu1GvYjRpLl2RProacWv5/Tor5qRYGDUSqV3Z+O/Ka8X1Bc4oBewuQKObP7jMaeUA kA0N5Q+l+xqq5k/QMZ2yqN9vSyVAGZP88sUvgbhqvvWH6d19wPKrFB71t+CqUK0ciVtX xHiioO1l7/NrqNRI07rQQ95TuZSjoLvwgDj6hrrITBaf0FZf8EgDItxxs+robJC657cl dhpXvd2sqGvu0q9dSWJQh9JGfnOxOynAn+XkLivddD/CShnt75M5phEIWYTpXLpAexUI fl7HeCAkscjESPWEW8gX/4rCWGZbQgDa8mdPpAA5DW0C3gwyIAwi1NlTdOvQcOUPO5c9 cnoQ== ARC-Authentication-Results: i=3; gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=selector2 header.b=GdDsn16e; arc=pass (i=1 spf=pass spfdomain=siemens.com dkim=pass dkdomain=siemens.com dmarc=pass fromdomain=siemens.com); spf=pass (google.com: domain of christian.storm@siemens.com designates 2a01:111:f400:7e1b::614 as permitted sender) smtp.mailfrom=christian.storm@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:sender:from:to:cc:subject:date:message-id :reply-to; bh=HkM6czB9fI58G8kapRmSuWyrE0BhO2ZUtSIH7Q1hYFU=; b=qSjF/Yoy685gV/MzhRy9l7fElFk0BpGRdMOscgByhOCdURVhvHrbqpwfpRX5x5x2yC UU993e5zIKbYVvOlX6oQe0m6Pp+WBQR6Yw2l6mZedavmKASAdPIYegOkGd3CF9ZsBXlr 3gGMaEQ/2KDcUA1hAlBT479QyH7SQByVtIiK9TqencwlLaa54CEYxAos6M2TcXVNu/Tk nzPfX7CNJYHC7fWMfntTXfJvZ+XJaI2vfCPI3NrTlzCEpNV/KEHcVLLmcolsBqoTpBKl 6XVEcFcNH5F+B/b+ATR6XFVVzhMsAU0dnwVc/QjKElDqP2a3qRh6C6aTY91VMcfI/Vyb DXkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:sender:from:to:cc:subject:date:message-id :reply-to; bh=HkM6czB9fI58G8kapRmSuWyrE0BhO2ZUtSIH7Q1hYFU=; b=g4a63F+FD6SH/4cYVhaGCusGfe61wnXkoeqJRXVMp+2PwzTwHVtdeTr9A5xCtqsbtx F3h5XrtRqP180bsQYtI7tEfblfL5P1Bk2N3lzZ5LiWoEK3o4sHr1PB9N29iBMNiMFg8b +62hb5J5m4bi51TQv1rbdW7Ue2atmov7gtG+PSwtabc5C7/bq5RNJi9cEUBwO1sDPG3W jIDnD8ESLdzl4CtM7r27TkEKqqrIjUDlIIcnlaah3Tm3JyJzkcp4VpI4/teRE6GBSVt7 Oalc67wWIiw51OZervDcV5nZB6sujv05RATdrB3xTpD87o6tFd7O1WI6ukFllKNBqDhU IuiQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: ANoB5pkzjiotrHIkpGk3/58TpqSAI3QBBRmDWofm5JIu49eLzj8xSCSz Frxoe6WNjWEjnoBpZloAudw= X-Google-Smtp-Source: AA0mqf7SGTDszSV0hs9UfU6C5mxD6hHQw8h4f4wiXuOPPd+N6ZJFHGDnzXOX5OYD/tjQGoTqIVLtww== X-Received: by 2002:a05:6512:3c9c:b0:4a2:2f2f:449b with SMTP id h28-20020a0565123c9c00b004a22f2f449bmr11769234lfv.235.1669634582995; Mon, 28 Nov 2022 03:23:02 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:6512:2024:b0:48b:2227:7787 with SMTP id s4-20020a056512202400b0048b22277787ls636579lfs.3.-pod-prod-gmail; Mon, 28 Nov 2022 03:23:01 -0800 (PST) X-Received: by 2002:a05:6512:3ca9:b0:4b5:124d:eb6b with SMTP id h41-20020a0565123ca900b004b5124deb6bmr1743492lfv.571.1669634581734; Mon, 28 Nov 2022 03:23:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669634581; cv=pass; d=google.com; s=arc-20160816; b=cMz/kMFp9UuGicTZplpQESCdL1+qwvLRvFziu23F7/VnHfj++Y7r07iZyqpz+sReDo qrOGPwwvCNckNU14sNZV6RJftAeK8je/MwET2f0681YrWkckL8WNv+GJ9drWt+PQYx3G 5j1wieHfCz87uvEtxKagcTqfCYQIU2It9WreQls5HTNIxWxR2HtVDhlFPvZ948hAmu4k nPPS0eVXdRPNuF5Z/5uKRpGasKgK+Or6GcqcZi/eBe3kOm7V29cewJReyQaUMmZtyPQf nrlpNonZckpdtYuJ2EVDzTe/W//7buxeydSnBfhG2h92Yxuvfjekaw7JvGmu8/Bk5Gaz CMbg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:content-transfer-encoding:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=xgraa+BeJ+9ZOBSTyFtD4bPmRrIYLAB3futiLoTYflA=; b=pTn/Vn0QU6F16Gatzs/Cr9X8DYuBsPIFtDZFpLYvcJ1vMiLwF42EIb3UjkhSP0SuGZ dUPE+394nbgXpsdLEx7DbdjQbrhhD5uRfhQmRqfdy+0FLSzb2NHSa9meYm7PIzKNAZpt cAKgTzs0BLXpSAnOSXsWWVOUFkYm/HMi1XnaZZKL5uUiKUim3AFpfzfcDv6lqAtZ8juY +bYpPi6CLXJFXJwZnbrNK64/NwIGPP6kXPERroSzjs/Gzl8lvDA6ChQW6pbNQAXJgDmv JCKVGJXK0Gugh/1Y2seJVaZ+8R1Cv90QfgA0amsEJPWRxpYQm4sWn7r6WDxvQcOV5xng xAPA== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=selector2 header.b=GdDsn16e; arc=pass (i=1 spf=pass spfdomain=siemens.com dkim=pass dkdomain=siemens.com dmarc=pass fromdomain=siemens.com); spf=pass (google.com: domain of christian.storm@siemens.com designates 2a01:111:f400:7e1b::614 as permitted sender) smtp.mailfrom=christian.storm@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on20614.outbound.protection.outlook.com. [2a01:111:f400:7e1b::614]) by gmr-mx.google.com with ESMTPS id z11-20020a056512370b00b004a608a3d90asi464891lfr.6.2022.11.28.03.23.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Nov 2022 03:23:01 -0800 (PST) Received-SPF: pass (google.com: domain of christian.storm@siemens.com designates 2a01:111:f400:7e1b::614 as permitted sender) client-ip=2a01:111:f400:7e1b::614; ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FpvKGe8L1cu/jcaTKZCLCA7cz/hDfYin5AD7Cmcf3m0Oa1meV0nWx34zH5Zoh4Bd+3SQ+ucMOW7DNiq98R9ZeNsPgetHB7UPO8QO3t4FXe1FaWGdI5EC9MZARDZF4TCdHbyHUwIhz/ZhgYWub/7A1A5guteeRQEWcphUi6hAAiPqIUIXtcYrWOreK/pgc8Jl+B5IAoWfSOmcDJq/0l7mS6ZRwGe4wmTR5WytY1yxRi2wJ6k/lfPG4S5220sla9jWRaa/Nj6qGMnuQUHFbwtdWMyWuyDjcPUbCdAQsiaQc9EPwKvdOJGzuMG8SAF5fDiU+SvhHE6S2XaCWMAdJufIJQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xgraa+BeJ+9ZOBSTyFtD4bPmRrIYLAB3futiLoTYflA=; b=QRrG8bbzOFGKxNOdOphGctI7x1tKDwMv9EaCgMQRLFZ0zfFazi2Oaa5Q+ydNSr0ddrVhFaYlYJgCqIq/7uZir7VytoXh2In9gq4toFZi2OmvNZOLnO2yh8LK2JYRLdUmptFSv+Rba/cA6RnYQAVZcTi3cixmdKKlQJQRbTcciGB2uwH9W2KPJdwJ7nptEg6IywQ2fAYgaFeJ7fsDGJOPl9ssbDE8CTEF2AiqrXmr5kMfJi/EdfHCL3mMJiPjG6I09NkxEh3hg5QIdBGf5qFwkOrtKZrKmynHTCh1XSFJ/jpaWL41TvK1DZnWYCOQl2RHkPME1b6ruG/0xLe8+v9E5Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=siemens.com; dmarc=pass action=none header.from=siemens.com; dkim=pass header.d=siemens.com; arc=none Received: from AS8PR10MB7042.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:5a9::19) by GV1PR10MB5940.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:150:5c::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.21; Mon, 28 Nov 2022 11:23:00 +0000 Received: from AS8PR10MB7042.EURPRD10.PROD.OUTLOOK.COM ([fe80::9cea:1033:958c:d92b]) by AS8PR10MB7042.EURPRD10.PROD.OUTLOOK.COM ([fe80::9cea:1033:958c:d92b%5]) with mapi id 15.20.5857.023; Mon, 28 Nov 2022 11:23:00 +0000 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH 2/3] suricatta/lua: Expose bootloader interface Date: Mon, 28 Nov 2022 12:23:25 +0100 Message-Id: <20221128112326.27564-2-christian.storm@siemens.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221128112326.27564-1-christian.storm@siemens.com> References: <20221128112326.27564-1-christian.storm@siemens.com> X-ClientProxiedBy: FR0P281CA0147.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:96::11) To AS8PR10MB7042.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:5a9::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR10MB7042:EE_|GV1PR10MB5940:EE_ X-MS-Office365-Filtering-Correlation-Id: 53080aa1-ca4f-45ba-d70f-08dad132e850 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ggLU6vCWGmx1EVp5j0GOWLNDb2jgF1FTCoySU3ovzp8BpQqmMapraf56JdujlYHDLxLGUcPPFMJIPo/B2Hl9iQF7MkRQt8+sYbKJIH93ZCXvdJUQ6oY0/j/j0AD2MEqISCfcjsyzdFbRjiNS0Qx6VYXow5yg9wlQYOYc5LmamPuM7pXm1rvxrhdAP2YDafzIYA+w0w6kEYHJkWPEj0op1F+5OjyjSLsBFZLxAH8XVs1OzsOqxijDdFDwF/AluKCUMbvd3nNk7/iu/J25hA5tGq3CfjiiDPtk+6U3jl22n/FFTOR33smM24tgl90T0RTZI65W+Cg50gGq/oLYa4JC+gI7Q+9+0PMmLriBrdJ5jaKd+AcFCRaTyjl+FnlUEJ0JDZ7t8dgRq8OTK4DmtCh50N2EScfx+crLUrutCeqIP7ygUkbGpSXnrrhq6wB1Qv/FBEJKdfAksG7zt0gwqEWphSRuLz+/dnxv1FDr2lq7owNqqVE/WgSpK+5F9CYxZuu1SqaYUkEw2oBktoMZSNnpcdVUaA1UFJXnzjCG7ACZ7rFRcP5tfOgDSM4yIMiqjUF/Ma13/CQBQ8ceDzEDGw5Y9tDhIXrqVwevAT5av/1g8lKUVGbYuR8CCzU+G8TpF+bcrMBIwJ2C0IrpnKEUE2qyWA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR10MB7042.EURPRD10.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(366004)(136003)(396003)(376002)(346002)(451199015)(66946007)(4326008)(66556008)(66476007)(8676002)(82960400001)(478600001)(38100700002)(6486002)(2616005)(6666004)(26005)(6512007)(6506007)(5660300002)(8936002)(316002)(44832011)(1076003)(36756003)(6916009)(41300700001)(186003)(83380400001)(86362001)(107886003)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: juit+mcY1WOm66RZA4frnNKS6I4+AkiOg+6rIJayChJDpz/zqkr3ULfv7ZubBbrlImx7ibvnygFFtuCcRP0PcL4/TwA+H3Xlq3oNPtfs9ADmhTb0LMOgBH8tDb+hAKKKvGzlIqK5wyzmvYECtly00wOmy4h4Q8146iGyg+JyjsZUVTDGA3voS1ff6OMAa9b4/7OVJ3LrypGPxyMQBDz7KPo55qNxBNzYZYeDl0XB0Mxxfyqp6rgGkx62XOITj4vqydhLnhdOgH/Vfq7Oiz0uHyvZhB5E71cyOCdADJ3uzc3KwgS9fpgaJTsif6wXbCqw374GFiu5uIRgEu08IKhzn8GIzGEzhBNSMz2F5Y1MQiMVNNqgt+UpT7fqKr0ObBwM958ty/sBZ9TYqbTkBKUiIbV6OjVCetlqfZUADWl0XLMUHrg6gDy1vtjXJriK650RKWQFOW/lkf909rWvZpSI+7erIsI4K4BMDnGxSqdgN9WgMIWUOvkDfZJsXw2F15SFj2Scl5srKxVXyvsVLwM3kFy7QCvR+uV9y9RkSljYqyW4v7+OM4MJ62cCRugRhWOToD9TIapB/5NPvPjSvpFh51ixIUcFjjOfUFFatPiZnJhAvDlzrTXbjsYq6GduV8lACejptIkNEBBdpfi9YzKpUhDtW39RlqYIyfKYVl5woIvQfob3LSvmoAiLzBnWNEuNug6zARGGfEzo19rm3M5c4UiQMFWU9PJCObxU7nBaOTm7Y1DpTbRdC0CbgLESbxzdcl4w9P+xMMtZUJhopksms2iJoODuN0lpPzq/0d3VPuL63aiZJoUtmlBx99uQvPqNsbpJoD8hzUFBeVqJ69pybIC3Mm5P/x1mERijma4bARuP7DsnQSvfYaL5JILxj0oOvFaUeM4C/J6rJh6pAS6NxqBb5mqdHrGUKRHiMesft/FoG+g1JWytP3q58aJHTQKFvOHRPn3vaabZDNHD29UcAHJ2xIN6qd14QShbQbcgRnY1PXqqr2KKL00O0OnGOfc/aH05OZFOKGU6geohQFKfP4wI/xK0O42aqbRhBxOSxgs0o7N7f2WUNHf+3nXlJ2o3SJlbJWf5GUt75a9uP8PzIdxOu1FmkdXcsJ+1gtpqRBZuP5z4DeNdoim2nsF2opObHDgXkUWHnpj0CsbUbVPwa0Rcdya+Nn91VVkunHGstR4KW48hBZTfgAu2OvMBPCWqFJmt7nSW/XZv4cttzFnQIcZF8zM6Qeqz4f9OXjo/iag9BjXfPLgEwb/1mdpJ/mmFy11rAYt13O520Bz0KwZJbhex6PwXJuQSadQ8Zu07yjMcl7Dx3fwXJ1D48XDTHR7HMZxsojYFxW3Ssp0lN0N/iaGgJWy3WZgqQfAxKaPdXoamXWvDrp6ScoVb6UUFMjD0xftl/RiBbAcjaDTeXBpI3Tq41sYh0kkPWeSnFAtArC7a8GeJcqVCjeuMftyYIdqSzm+IOLCjUXXv0m4SMncbFkEsRp6ziBQObSZzus6wN6JGowbLjCYqhGmqORy7nixyc/e0OroU7wzjgq4iranymKQd5XUCeNqblnb748M2eYNm/Ww1MMqiFE2Ngf34/NcRspE4pTOg0qprM4epRRk9Wg== X-OriginatorOrg: siemens.com X-MS-Exchange-CrossTenant-Network-Message-Id: 53080aa1-ca4f-45ba-d70f-08dad132e850 X-MS-Exchange-CrossTenant-AuthSource: AS8PR10MB7042.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Nov 2022 11:23:00.3309 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 38ae3bcd-9579-4fd4-adda-b42e1495d55a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jnStVbTqsGnncphRJl+VvP4M10+eUgmRdF9zuVXJOtbnMoabWNHivMHSL8cUa72Bsa0Uk56ZpYvjRMfdzH0iS65h6T/jHNQuNIZK+KBjSg0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR10MB5940 X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=selector2 header.b=GdDsn16e; arc=pass (i=1 spf=pass spfdomain=siemens.com dkim=pass dkdomain=siemens.com dmarc=pass fromdomain=siemens.com); spf=pass (google.com: domain of christian.storm@siemens.com designates 2a01:111:f400:7e1b::614 as permitted sender) smtp.mailfrom=christian.storm@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Expose SWUpdate's bootloader interface to suricatta Lua modules. Signed-off-by: Christian Storm --- doc/source/bootloader_interface.rst | 4 + suricatta/server_lua.c | 109 ++++++++++++++++++++++++++++ suricatta/suricatta.lua | 56 ++++++++++++++ 3 files changed, 169 insertions(+) diff --git a/doc/source/bootloader_interface.rst b/doc/source/bootloader_interface.rst index b8c0182..8527aec 100644 --- a/doc/source/bootloader_interface.rst +++ b/doc/source/bootloader_interface.rst @@ -93,6 +93,10 @@ with added to ``include/bootloader.h`` as a single central "trunk" bootloader name definition aiding in maintaining the uniqueness of bootloader names. +This new "trunk" bootloader should also be added to the Suricatta Lua +Module interface specification's bootloader Table +``suricatta.bootloader.bootloaders = { ... }`` in +``suricatta/suricatta.lua``. .. attention:: Take care to uniquely name the bootloader. diff --git a/suricatta/server_lua.c b/suricatta/server_lua.c index 6dcf938..3d4bf70 100644 --- a/suricatta/server_lua.c +++ b/suricatta/server_lua.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include "suricatta_private.h" @@ -1388,6 +1389,85 @@ failure: return 2; } +/** + * @brief Test whether a bootloader is currently set. + * + * @param [Lua] Name of bootloader to test for being currently set. + * @return [Lua] True if given name is the currently set bootloader, false otherwise. + */ +static int lua_bootloader_is(lua_State *L) +{ + lua_pushboolean(L, is_bootloader(luaL_checkstring(L, -1))); + return 1; +} + +/** + * @brief Get currently set bootloader's name. + * + * @return [Lua] Name of currently set bootloader. + */ +static int lua_bootloader_get(lua_State *L) +{ + (void)lua_pushstring(L, get_bootloader()); + return 1; +} + +/** + * @brief Get value of a bootloader environment variable. + * + * @param [Lua] Name of the bootloader environment variable to get value of. + * @return [Lua] Value of the bootloader environment variable. + */ +static int lua_bootloader_env_get(lua_State *L) +{ + char* value = bootloader_env_get(luaL_checkstring(L, -1)); + (void)lua_pushstring(L, value); + free(value); + return 1; +} + +/** + * @brief Set value of a bootloader environment variable. + * + * @param [Lua] Name of the bootloader environment variable to set. + * @param [Lua] Value to set the bootloader environment variable to. + * @return [Lua] True, or, in case of error, nil. + */ +static int lua_bootloader_env_set(lua_State *L) +{ + bootloader_env_set(luaL_checkstring(L, -2), luaL_checkstring(L, -1)) == 0 + ? lua_pushboolean(L, true) + : lua_pushnil(L); + return 1; +} + +/** + * @brief Drop a bootloader environment variable. + * + * @param [Lua] Name of the bootloader environment variable to drop. + * @return [Lua] True, or, in case of error, nil. + */ +static int lua_bootloader_env_unset(lua_State *L) +{ + bootloader_env_unset(luaL_checkstring(L, -1)) == 0 + ? lua_pushboolean(L, true) + : lua_pushnil(L); + return 1; +} + +/** + * @brief Set multiple bootloader environment variables from local file. + * + * @param [Lua] Path to local file in format `=`. + * @return [Lua] True, or, in case of error, nil. + */ +static int lua_bootloader_env_apply(lua_State *L) +{ + bootloader_apply_list(luaL_checkstring(L, -1)) == 0 + ? lua_pushboolean(L, true) + : lua_pushnil(L); + return 1; +} /** * @brief Get update state from persistent storage (bootloader). @@ -1479,6 +1559,35 @@ static int suricatta_lua_module(lua_State *L) #undef MAP lua_settable(L, -3); + luaL_Reg lua_funcs_bootloader[] = { + { "is", lua_bootloader_is }, + { "get", lua_bootloader_get }, + { NULL, NULL } + }; + luaL_Reg lua_funcs_bootloader_env[] = { + { "get", lua_bootloader_env_get }, + { "set", lua_bootloader_env_set }, + { "unset", lua_bootloader_env_unset }, + { "apply", lua_bootloader_env_apply }, + { NULL, NULL } + }; + lua_pushstring(L, "bootloader"); + lua_newtable(L); + luaL_setfuncs(L, lua_funcs_bootloader, 0); + lua_pushstring(L, "bootloaders"); + lua_newtable(L); + push_to_table(L, "EBG", BOOTLOADER_EBG); + push_to_table(L, "NONE", BOOTLOADER_NONE); + push_to_table(L, "GRUB", BOOTLOADER_GRUB); + push_to_table(L, "UBOOT", BOOTLOADER_UBOOT); + lua_settable(L, -3); + lua_pushstring(L, "env"); + lua_newtable(L); + luaL_setfuncs(L, lua_funcs_bootloader_env, 0); + lua_settable(L, -3); + + lua_settable(L, -3); + lua_pushstring(L, "status"); lua_newtable(L); push_to_table(L, "OK", SERVER_OK); diff --git a/suricatta/suricatta.lua b/suricatta/suricatta.lua index 81988d2..bfcb3be 100644 --- a/suricatta/suricatta.lua +++ b/suricatta/suricatta.lua @@ -58,6 +58,62 @@ suricatta.notify = { } +--- SWUpdate's bootloader interface as in `include/bootloader.h`. +-- +--- @class suricatta.bootloader +suricatta.bootloader = { + --- Bootloaders supported by SWUpdate. + -- + --- @enum suricatta.bootloader.bootloaders + bootloaders = { + EBG = "ebg", + NONE = "none", + GRUB = "grub", + UBOOT = "uboot", + }, + --- Operations on the currently set bootloader's environment. + -- + --- @class suricatta.bootloader.env + env = {} +} + +--- Get currently set bootloader's name. +-- +--- @return suricatta.bootloader.bootloaders | nil # Name of currently set bootloader +suricatta.bootloader.get = function() end + +--- Test whether bootloader `name` is currently set. +-- +--- @param name suricatta.bootloader.bootloaders Name of bootloader to test for being currently selected +--- @return boolean # True if `name` is currently set bootloader, false otherwise +suricatta.bootloader.is = function(name) end + +--- Get value of a bootloader environment variable. +-- +--- @param variable string Name of the bootloader environment variable to get value for +--- @return string | nil # Value of the bootloader environment variable or nil if non-existent +suricatta.bootloader.env.get = function(variable) end + +--- Set value of a bootloader environment variable. +-- +--- @param variable string Name of the bootloader environment variable to set +--- @param value string Value to set the bootloader environment variable `variable` to +--- @return boolean | nil # True on success, nil on error +suricatta.bootloader.env.set = function(variable, value) end + +--- Drop a bootloader environment variable. +-- +--- @param variable string Name of the bootloader environment variable to drop +--- @return boolean | nil # True on success, nil on error +suricatta.bootloader.env.unset = function(variable) end + +--- Set multiple bootloader environment variables from local file. +-- +--- @param filename string Path to local file in format `=` +--- @return boolean | nil # True on success, nil on error +suricatta.bootloader.env.apply = function(filename) end + + --- SWUpdate's persistent state IDs as in `include/state.h` and reverse-lookup. -- --- @enum suricatta.pstate From patchwork Mon Nov 28 11:23:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 1709680 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::138; helo=mail-lf1-x138.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbjvuskoamgqeqghr7yq@googlegroups.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20210112 header.b=hMF3ys3G; dkim-atps=neutral Received: from mail-lf1-x138.google.com (mail-lf1-x138.google.com [IPv6:2a00:1450:4864:20::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NLNPj3bXfz23mg for ; Mon, 28 Nov 2022 22:23:21 +1100 (AEDT) Received: by mail-lf1-x138.google.com with SMTP id a26-20020ac25e7a000000b004b21ed7d4e4sf3702755lfr.15 for ; Mon, 28 Nov 2022 03:23:21 -0800 (PST) ARC-Seal: i=3; a=rsa-sha256; t=1669634598; cv=pass; d=google.com; s=arc-20160816; b=LpJtNy0Xu5Opu7l3srI3H2PS9MsJnvr7MLZbUeTNc2HpwlMwzZz7gmnGdlt/DPGJAN 6sJk7+ahS4wC/uUUYignfzzybmNsnwMTleAOCBSc9VxozZ2r3S7YhDYajiQgqVmGae5f hUJwQ1NbdEku0u3CR0oMzD95p7MpAf27MtwqCkdIhs4uB7bBcN1yvOi4sa297Tnj1qjB jMvTYE1hZJjauch2rD9TMFwzG3aVf/VfqfDDZdOUhCYeA+dv36z3Yd5LtI8XZtGHPfso nD04WPtNnXyIYIQIawBUOldWXzZqPjnQrx1UBX7sA8eL2KsinhqWoU5WC4k0ymX3wnDz hMvA== ARC-Message-Signature: i=3; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version :content-transfer-encoding:references:in-reply-to:message-id:date :subject:cc:to:from:sender:dkim-signature; bh=u5DzADzGqrTl7SbngUMt2TQzXN/nHmfGzDjTRCD2eas=; b=uBnHF9XrKgpoAhSLic4GlyBYq6ihyJPiEnCo1+D2z2MVOjF2FvPEXmoWfPOXnUfgEi FGq0OwJJ2GHW/TprRXt4s7z3CglVo6TRarjfM3sXBIM5nwmtb9lLm3fYz47scjTGVL4I dtHMTqrruqAu0TBxYa0XkL0BqGQUuo20vsaBYpoZncZW6OaSiw6sBwEH7xcqMgMGVWE9 ueRnB8+DntK+ZbLoxdA6axtvcDqie3a5le0DIMUyeHjFOgBZ4B1rUVPbWguThPC7ak0T e5oj7FL6ZwJMTGc3MX17EVGzRIACg5hyALbkxMc0EUrCu2g3h0lzhtzN6JBjCniggI1t q7lA== ARC-Authentication-Results: i=3; gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=selector2 header.b=to8nhfCm; arc=pass (i=1 spf=pass spfdomain=siemens.com dkim=pass dkdomain=siemens.com dmarc=pass fromdomain=siemens.com); spf=pass (google.com: domain of christian.storm@siemens.com designates 2a01:111:f400:7e1a::613 as permitted sender) smtp.mailfrom=christian.storm@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:content-transfer-encoding:references :in-reply-to:message-id:date:subject:cc:to:from:sender:from:to:cc :subject:date:message-id:reply-to; bh=u5DzADzGqrTl7SbngUMt2TQzXN/nHmfGzDjTRCD2eas=; b=hMF3ys3GbQowROwdY2Jomr20AgZktvVC3Cpw7o6IqSJx7zoGQXsd9v0g/bil0zSd0r 9BqEmakrY9sMTUTQkTnunHu5GxJBUkoM1meKJx3LDxrEkPxYbCu/EXZVH+9AImdpSRB2 tCyFBxlRApZ+zf2AaQwCvsDv6/8WUFV8rYH2dRlvrRZrYP4ezw/D0FXyF09kmpg1zLb7 P7oD+1SQF0+ZxFHOUPQfVtwhHIG72yrAwYf9ICOzwPN6td7t/DgFXmo0nSViaBqF++Rq 5JyOAtvuSoQAjG8PJIFJLcYgwoS1uwKep4s4h6UptW0711p3/QxeQpDVEPldyIAfxpuA wfFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :content-transfer-encoding:references:in-reply-to:message-id:date :subject:cc:to:from:x-gm-message-state:sender:from:to:cc:subject :date:message-id:reply-to; bh=u5DzADzGqrTl7SbngUMt2TQzXN/nHmfGzDjTRCD2eas=; b=E5aKCRp1Am+ZcCPD3sYwSelghVBMKCLgmR2tS04WqtjO3VgM0x3sgpqJiH15jJvfi0 zTmULV3uehNSO0k3F/fhh6Icv29bOF6bLirZYkYHCVhFaAvEJfqC6av2PpRe15sGGpY4 MtxMhzbyrHDDeWS83gnZuGHV/wNLPamrLvaOYfe6a8aiy2MUiTNbwao1DkMU1nZ3NLAT tyfBGOkJmpSy1r7zqkCHDro4W47p0uEh1ex9/f6QumY4U0QeR9txhg1/g3SlUjbd3W0S yRef8l8xYyJD6Sn2rC36G3kNI+O9mpGGbP6Jwu3lkkVMG1pKlNf0GCLIDeil8+v3rbaB TfEg== Sender: swupdate@googlegroups.com X-Gm-Message-State: ANoB5pkoSCCUOdj/nx9Rl2F28mNGRUvXPhBmSuop7LYJf2Fn8gBfTgBL BXmJWvJP/Cl6ZknQvTk7YiA= X-Google-Smtp-Source: AA0mqf49ZMhCuYVnXve3qmg8kXbHQMBMD6MkSkyZTpGIyQJmOHB8T4R6kLElX6lxQOiXeWX7kBE5GA== X-Received: by 2002:a2e:a594:0:b0:277:4150:b560 with SMTP id m20-20020a2ea594000000b002774150b560mr10965483ljp.299.1669634598612; Mon, 28 Nov 2022 03:23:18 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:651c:1788:b0:26f:8b88:ccbf with SMTP id bn8-20020a05651c178800b0026f8b88ccbfls1599640ljb.1.-pod-prod-gmail; Mon, 28 Nov 2022 03:23:17 -0800 (PST) X-Received: by 2002:a2e:bd87:0:b0:277:1cfe:398 with SMTP id o7-20020a2ebd87000000b002771cfe0398mr9632101ljq.10.1669634597152; Mon, 28 Nov 2022 03:23:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669634597; cv=pass; d=google.com; s=arc-20160816; b=UcsVMB8zvwAHdSkEZLb7RSc7nvqq/52T5+2wyW5LxOGSIyjYNcB+8OuPxPgjEb6fmV wwKVg1HGlZcwQwQIX3jLbLrKEcFS1abK0bSOIp2Zh4uZhLmsHxYFe9Gd1TZNFBy/xKOM Y7j6LYoQI8uJhLPHF9tzgSA1l+sZdNxDplRuIXIUmf0Z3U1vAujYtEgn0JTGVbe5qziX FuHtW1rzvuKGVFhiyImGHJOkWOQFW9Rujenljt7/RLQ2gKbm3uz5qoboAoheLaHoW2vP JmxUqc9WKYbKaELbl9OFQHQA8+VWLz/KwKEn5qS7Q+rMoWMHh9YbXkrc8qVD9toNX94f c+sQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:content-transfer-encoding:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=tl+/nNhiLPIFO3UK2FRqcoywR+Z4XzkTszFh8kcF3OA=; b=J//j73SxTKNFqxxRUDL7DGI+/wPLICKYhbrGjUUymX78sfbs437zGzqxL4mO5iYPRa l6d0gGTV+mCwkOd/Djdq5bgLJsyDK4PEVt7/IYB3XHOUxJ1ozzJy6SL/19+1NITRAoZA pLoLTCG+bo08qhSPRSdkoNWwc+fdIOxJa/+bWiUwAbiVaW6WG7+a6PHUIOq7j0jWG9oi odURPMIbYjCmegUNCPe2XGtS1pyCCGFGnUxPQLiiow0G/ziPQSLI1bVjvy4+c4Kun3Et uJlyZnncY7ufVm7FZzFaFkbjJWzw/+46hT4uRtcH7K8Bm+7cP4qB2QJszJi31h+04nu5 1clw== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=selector2 header.b=to8nhfCm; arc=pass (i=1 spf=pass spfdomain=siemens.com dkim=pass dkdomain=siemens.com dmarc=pass fromdomain=siemens.com); spf=pass (google.com: domain of christian.storm@siemens.com designates 2a01:111:f400:7e1a::613 as permitted sender) smtp.mailfrom=christian.storm@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on20613.outbound.protection.outlook.com. [2a01:111:f400:7e1a::613]) by gmr-mx.google.com with ESMTPS id f5-20020a056512360500b004a222ff195esi421794lfs.11.2022.11.28.03.23.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Nov 2022 03:23:16 -0800 (PST) Received-SPF: pass (google.com: domain of christian.storm@siemens.com designates 2a01:111:f400:7e1a::613 as permitted sender) client-ip=2a01:111:f400:7e1a::613; ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EY0IDXNUMVtvvT/ly1DNpkcnSNHaH4r+3nFBAm8Xlhf1uwuB9uN5EK8AOEnZAjr8CPDdEgBMr85qcqGydcV5zrLXAUH1jjRbrGX85VJb7o966/VOVb556FGj5JZnPXpC7Sjem2GJrVxAhrrrRXzzqD/PUXMYnTE5O12vEBaO1wAfCukbKup2/vKyLklDh7VFBbYJGdPVsA3k7vadBdAgxPFXcuI5bOk8qXEhVSv2q1dZ7mMahMIUXuSg5mwF5HkOAaTAsxK/b5JfiCkQCPRktNajZ1kQD8Mezy6/7faMH4GIj7n0P5IoJVYA8sVIFG7qdw/ENknod9OvGC4syItD+g== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tl+/nNhiLPIFO3UK2FRqcoywR+Z4XzkTszFh8kcF3OA=; b=MHEeA2xI/0d5zzs/MueaMOoVIOJPLVLxnlgg16cI+2KeJ0Va5igwnunBifNnOHSi6B35xwU9n82YSaNf4UJAJ1chh0cNzkL24SL+th6xIhBRMFs/59vGedZcygdKEOfjtFMzNfI2q/EAW3kbJU2HgwDeP34Rbyq+avgUDMRym8Ovq0GK78KR7tbEn2qtNh+EA6flUh6TLzp2FOp70mQz24yyAf/RLizYvcHkECwv9jhsIBdt2TMEdAgr9118h0HRHkusgAWCCq4gmHgd7aA+81+/6AgcGuH0S1LvlqPCwwKrelhfGv2zow0xRSQx8nk/eW6AUbCK1RD5UnyIFE0YQw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=siemens.com; dmarc=pass action=none header.from=siemens.com; dkim=pass header.d=siemens.com; arc=none Received: from AS8PR10MB7042.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:5a9::19) by DB9PR10MB5138.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:331::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.23; Mon, 28 Nov 2022 11:23:14 +0000 Received: from AS8PR10MB7042.EURPRD10.PROD.OUTLOOK.COM ([fe80::9cea:1033:958c:d92b]) by AS8PR10MB7042.EURPRD10.PROD.OUTLOOK.COM ([fe80::9cea:1033:958c:d92b%5]) with mapi id 15.20.5857.023; Mon, 28 Nov 2022 11:23:14 +0000 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH 3/3] bootloader: EBG: Complete rework Date: Mon, 28 Nov 2022 12:23:26 +0100 Message-Id: <20221128112326.27564-3-christian.storm@siemens.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221128112326.27564-1-christian.storm@siemens.com> References: <20221128112326.27564-1-christian.storm@siemens.com> X-ClientProxiedBy: FR0P281CA0094.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a9::14) To AS8PR10MB7042.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:5a9::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR10MB7042:EE_|DB9PR10MB5138:EE_ X-MS-Office365-Filtering-Correlation-Id: e65962bc-2cdc-46c8-96c6-08dad132f0a2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6tNzHDZSa5Le1rUP/Qq37Cte8pTfzrA0I1uZcvZpkWemj/1e3yHqI1TyvauyceiHcIL+kgX9ETsva9ufodxCLeQcDbxGcyLUtkGz2RMD6OII+dnyBBTbsoN/Ig6jNIcP3e1stTjcG5FV2yPpo3o/SDV9R/nT2hNV7KbKiYFXw6cpyVzFvWlD1B1aTTfRVhWcMDLU4G3U5VPAvDxlikNDvodKZdPiMIjvmM5zA0RHWS8oOnociGgBmPtUmjZtmWst7PD/fNbC+r+/6FHod5ICoOTP6/ppXSUmMxwGwquPBs3Kn0NE3zdQRX2mMgAReUUTqlijNMCxOfMuLTCIQpsZFvUvbrO153JaFN20ZgpB2N40qWVmLMOHS4jB6mlcb9j8cKkUA8lePFv3uNJ2LnHec9XoRYKd/iidKUbbkwasSJpbCDsavVS60tenDrIaSBHO3RjzFEp7xZ691Ox0w5/pjJqQ4sRB0Y6wt16F8pnSyAsyv3n5DdKlGhAVdAwjC/kOZy1uTQXSLWfA66kPEHBaP6zLch+OPDnCnkL6rXxhRsGRyzptrQG1hLh2KloLpJB1Du8zWzvJXzBLVXaClHzwVo1hOo8JEpkSxJMXxihPTwTBAIOAK2l5O8cvNt/lTbWslp8mNh3A789yiBa734CBKQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR10MB7042.EURPRD10.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230022)(4636009)(396003)(136003)(346002)(39860400002)(376002)(366004)(451199015)(2906002)(83380400001)(107886003)(6486002)(38100700002)(6666004)(478600001)(6506007)(26005)(6512007)(66556008)(41300700001)(8676002)(66946007)(66476007)(36756003)(82960400001)(1076003)(5660300002)(8936002)(186003)(4326008)(86362001)(2616005)(6916009)(44832011)(30864003)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lQsK+g27jGFVD/06/nsOIASISaI6TpJFrOVxLb8yqmyhk/moDwjiD6BdeuYVxW/mp7jjmhBfACcCL3xC4bAxdz6lQ6eNSJ/NmnMznOkVGjfTo8eejsJ95lUa72GLiE7+gCiSoQfbiVOhdUbZbtiJwByeSkrltPk4u552CT9bZSVYxEDc3Q7XCCValPghL574WgQDv6sVtWTaMUx/lyqmP8tPKKXbqsO5mB5SlgClWXqcUlVwnxBDhlmB7twzJdNxuu3mWDWMs26XkCstEAmdzhAzdT7uYAREHj/JsEunKYatRNLBsBYuRVgexzSRLLWAnckA2QVnODwEwj4skgB2SywhrazGUyGD9htU5RZSqrNEOO5WVYXYYWYNHSgUspRp9dyaAARAO05wJNOGKhjMGErN+mXUpebFtv9SyaX4+Oauw4sxYkP1b6DF39cFesr+NxvBL4cm8XfFQC7RPQ1MQcSi/vBY47xwh9tdJB2V9w6f2FX4YNNQ1hPoq7Sz/2GnAOz8FMCk8l5vNdGdvSwLz7alCh94lq805GN9iQDDpM2ZmW1a0uzf8ux79Qi1f4M26O89CKY9NaKUmLHuEF+2viiaZmVMoYzh9XM4ToPtEWRA4mUMfKUxde8hL9OL4LB29/3bMe8Xsp6MLU5Qp6e2+5Uo9TMKmXXd373nntGYPf3U0vhUsd6CvobSMydQf8Y9sHuF4cczwbGhXMYHQ1aCHJtKsvkOeDCZOJ++XaucQnAKIYDnFcx9YKTppC7qFEKkw9dReL8Zrcd1QmX9ct8jxa/5cijJR+hnfEDYQrCbvf/s6s1rVWU8LUGXWI5xZbKmThih9vruhGFqmcT0GVyQzGrR4YpfJ43+Uuoeu/mjD+EZmd4cgWijmuLnHGooS6W56XWYxSBua4xoHneQQ9HauTUeWHKyAUjqoGh1tJjBYwVqnTVLII5kFMjestV9e61zaEcZRDLApX7KJnXeRc+FRPSgdjaxuLKPslxPr1FphYnDZK9Dm/gvr6T3F7aaC3MNBvhK6fPUG+VOOJl1ZaAWiiqwUoOIz7ObGKsaXYz515gbSUI0Faj1+pVrmt1qhuwTtcaR8DJzEL9P74EbBUzcmX6oOmumf8cfzCjEkATJLQoz+iTZB1EQ39DJvckcMLvgduC8EbH8C9qi7X6aOAS4H0+RaWKG5t+8IfprAroEsfdgiXJ9uNI8lBjADOXgmJLiDD0KZlAu0DeKs0Y+PSCw3J6eMN/cUpBflr0E0HhgR7jtXY1VlXE07LI+/8oXK8LiUlPVKbYiFfHTWA6fGQvED86xEVFLxzz2KEe5xS1jd6XHNZztmJTzxsYtG5LT3DCNahcA7Th8fUQKSBWcWSJbKhtSLQ1BXTdK0rX/zJWcRUzFZkyJA4HW5NfdANH/lqw+eZwwBqXph63PDUbOmz/zMEgIZI/c3ncU5fHe9N1L1bntTHvgwF3U10SHzT6vQ7pWiFCOv5UVW8+uUWDazcQdKaBVxaOu+C12TOBKdVl2HWmkobQ6t+cRJQAF4etXD/VU/B07K5cpaW1s6MnpLx8xlu48o2GEvWQ3qjMeXHaUiTOkuYV4e35iytD5BV/fP46qHTKzmgTE9mCTuSK836rwiA== X-OriginatorOrg: siemens.com X-MS-Exchange-CrossTenant-Network-Message-Id: e65962bc-2cdc-46c8-96c6-08dad132f0a2 X-MS-Exchange-CrossTenant-AuthSource: AS8PR10MB7042.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Nov 2022 11:23:14.3041 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 38ae3bcd-9579-4fd4-adda-b42e1495d55a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /YR59TfkFdkfDhdNtOjDOtBYI5vr9uDnfapz6VBEc4u4N+NvM5a6oUSfmzN5QOlFSEy5uFO5QwKEvFcue0sXVda8rRB7OSeZSSiY++auDus= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR10MB5138 X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=selector2 header.b=to8nhfCm; arc=pass (i=1 spf=pass spfdomain=siemens.com dkim=pass dkdomain=siemens.com dmarc=pass fromdomain=siemens.com); spf=pass (google.com: domain of christian.storm@siemens.com designates 2a01:111:f400:7e1a::613 as permitted sender) smtp.mailfrom=christian.storm@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Completely rework the EFI Boot Guard Binding accommodating to libebgenv's implicit assumptions and actions. To this end, environment modification transactions are introduced. The assumptions and rationale is documented and in addition log messages are emitted for particular combinations of bootloader_transaction_marker and bootloader_state_marker. Signed-off-by: Christian Storm --- bootloader/ebg.c | 567 ++++++++++++++++++++++++++++++---------- core/stream_interface.c | 34 +++ 2 files changed, 469 insertions(+), 132 deletions(-) diff --git a/bootloader/ebg.c b/bootloader/ebg.c index 4194a38..99ee40b 100644 --- a/bootloader/ebg.c +++ b/bootloader/ebg.c @@ -1,22 +1,22 @@ /* * Author: Christian Storm - * Author: Andreas Reichel - * Copyright (C) 2018, Siemens AG + * Copyright (C) 2022, Siemens AG * * SPDX-License-Identifier: GPL-2.0-only */ +#include #include #include #include #include #include #include -#include +#include #include -#include -#include -#include "dlfcn.h" +#include "generated/autoconf.h" +#include "util.h" +#include "state.h" #include "bootloader.h" static struct { @@ -25,184 +25,481 @@ static struct { int (*env_open_current)(ebgenv_t *e); int (*env_get)(ebgenv_t *e, char *key, char* buffer); int (*env_set)(ebgenv_t *e, char *key, char *value); - int (*env_set_ex)(ebgenv_t *e, char *key, uint64_t datatype, uint8_t *value, uint32_t datalen); + int (*env_set_ex)(ebgenv_t *e, char *key, uint64_t datatype, + uint8_t *value, uint32_t datalen); uint16_t (*env_getglobalstate)(ebgenv_t *e); int (*env_setglobalstate)(ebgenv_t *e, uint16_t ustate); int (*env_close)(ebgenv_t *e); int (*env_finalize_update)(ebgenv_t *e); } libebg; -static ebgenv_t ebgenv = {0}; -static int do_env_set(const char *name, const char *value) +/* + * ---------------------------------------------------------------------------- + * | Logics, Assumptions & Rationale | + * ---------------------------------------------------------------------------- + * + * EFI Boot Guard boots the environment having `EBGENV_IN_PROGRESS == 0` + * and the highest revision number. If multiple environments have the highest + * revision number, environment probing order is decisive. + * This environment is called the *current boot path*. + * Sorted descending on revision numbers and arbitrated by probing order, the + * other environments are termed *alternative boot paths*. + * + * Environment modifications ― except blessing a successful update ― must not + * touch the current boot path. Instead, a new boot path is created by + * "upcycling" the least recent alternative boot path. + * More specifically, environment modifications are captured in a *transaction*: + * An in-memory working copy of the current boot path environment is created + * which has a by one incremented higher revision than the current boot path. + * Modifications are performed on this working copy environment. + * When committing the transaction, i.e., writing it to disk, the new current + * boot path is persisted and booted next. + * + * A transaction is started by setting + * `EBGENV_USTATE = STATE_IN_PROGRESS` or + * `BOOTVAR_TRANSACTION = STATE_IN_PROGRESS` + * which is idempotent. Then, `libebgenv` sets + * - `EBGENV_IN_PROGRESS = 1` and + * - `EBGENV_REVISION` to the current boot path's revision plus one, and + * - the transaction `inflight` marker is set to `true`. + * + * A transaction is committed when setting `EBGENV_USTATE = STATE_INSTALLED`. + * Then, `libebgenv` sets + * - `EBGENV_IN_PROGRESS = 0` and + * - `EBGENV_USTATE = USTATE_INSTALLED`, + * - the new current boot path is persisted to disk, and + * - the transaction `inflight` marker is reset to `false`. + * With this, the current boot path becomes the most recent alternative boot + * path serving as rollback boot path if the new current boot path fails to + * boot. In this case, the failed boot path is marked with + * - `EBGENV_USTATE = USTATE_FAILED` and + * - `EBGENV_REVISION = 0` + * by which the rollback boot path becomes the current boot path (again). + * If the new current boot path boots successfully, the /current/ boot path + * needs to be written to acknowledge the successful update via setting + * `EBGENV_USTATE = USTATE_OK`. + * + * Note: The modification of EFI Boot Guard's environment variable + * `EBGENV_IN_PROGRESS` cannot be disabled as it's hard-wired in EFI + * Boot Guard with particular semantics. + * Note: Successive calls to libebgenv's `env_open_current()` after the first + * invocation are no-ops and select the in-memory working copy's current + * environment. + * Note: libebgenv's `env_close()` first *writes* to the current environment and + * then closes it. There's currently no way to just close it, e.g., for re- + * loading the environment from disk. + * + */ + + +/* EFI Boot Guard hard-coded environment variable names. */ +#define EBGENV_IN_PROGRESS (char *)"in_progress" +#define EBGENV_REVISION (char *)"revision" +#define EBGENV_USTATE (char *)"ustate" + +static ebgenv_t ebgenv = { 0 }; +static bool inflight = false; + +static inline bool is(const char *s1, const char *s2) { - int ret; + return strcmp(s1, s2) == 0; +} - errno = 0; - libebg.beverbose(&ebgenv, loglevel > INFOLEVEL ? true : false); +static char *_env_get(const char *name) +{ + /* + * libebgenv's env_get() is two-staged: The first call yields the + * value's size in bytes, the second call, with an accordingly + * sized buffer, yields the actual value. + */ + size_t size = libebg.env_get(&ebgenv, (char *)name, NULL); + if (size == 0) { + WARN("Cannot find key %s", name); + return NULL; + } - if ((ret = libebg.env_open_current(&ebgenv)) != 0) { - ERROR("Cannot open current bootloader environment: %s.", strerror(ret)); - return ret; - } - - if (strncmp(name, BOOTVAR_TRANSACTION, strlen(name) + 1) == 0 && - strncmp(value, get_state_string(STATE_IN_PROGRESS), - strlen(get_state_string(STATE_IN_PROGRESS)) + 1) == 0) { - DEBUG("Setting %s=%s in bootloader environment", name, value); - /* Open or create a new environment to reflect - * EFI Boot Guard's representation of SWUpdate's - * recovery_status=in_progress. */ - if ((ret = libebg.env_create_new(&ebgenv)) != 0) { - ERROR("Cannot open/create new bootloader environment: %s.", - strerror(ret)); - } - } else if (strncmp(name, (char *)STATE_KEY, strlen((char *)STATE_KEY) + 1) == 0) { - /* Map update_state_t to EFI Boot Guard's API. */ - switch (*value) { - case STATE_IN_PROGRESS: - case STATE_FAILED: - case STATE_TESTING: - /* Fall-through for update_state_t values destined either - * for BOOTVAR_TRANSACTION or handled by EBG internally. */ - break; - case STATE_OK: - case STATE_INSTALLED: - DEBUG("Setting %s=%s in bootloader environment", name, value); - if ((ret = libebg.env_setglobalstate(&ebgenv, *value - '0')) != 0) { - ERROR("Cannot set %s=%s in bootloader environment.", STATE_KEY, value); - } - break; - default: - ret = -EINVAL; - ERROR("Unsupported bootloader environment assignment %s=%s.", STATE_KEY, value); - } - } else { - /* A new environment is created if EFI Boot Guard's - * representation of SWUpdate's recovery_status is - * not in_progress. */ - DEBUG("Setting %s=%s in bootloader environment", name, value); - if ((ret = libebg.env_create_new(&ebgenv)) != 0) { - ERROR("Cannot open/create new bootloader environment: %s.", - strerror(ret)); - return ret; - } - if ((ret = libebg.env_set(&ebgenv, (char *)name, (char *)value)) != 0) { - ERROR("Cannot set %s=%s in bootloader environment: %s.", - name, value, strerror(ret)); - } + char *value = malloc(size); + if (value == NULL) { + ERROR("Error allocating memory"); + return NULL; + } + + int result = libebg.env_get(&ebgenv, (char *)name, value); + if (result != 0) { + ERROR("Cannot get %s: %s", name, strerror(-result)); + free(value); + return NULL; + } + return value; +} + +/* Note: EFI Boot Guard Environment integers are at most uint32_t. */ +static inline uint32_t _env_to_uint32(char *value) +{ + if (!value) { + return UINT_MAX; } - (void)libebg.env_close(&ebgenv); + errno = 0; + uint32_t result = strtoul(value, NULL, 10); + free(value); + return errno != 0 ? UINT_MAX : result; +} - return ret; +static inline uint8_t ascii_to_uint8(unsigned char value) +{ + return value - '0'; } -static int do_env_unset(const char *name) +static inline unsigned char uint8_to_ascii(uint8_t value) { - int ret; + return value + '0'; +} +static char *do_env_get(const char *name) +{ + errno = 0; libebg.beverbose(&ebgenv, loglevel > INFOLEVEL ? true : false); - if ((ret = libebg.env_open_current(&ebgenv)) != 0) { - ERROR("Cannot open current bootloader environment: %s.", strerror(ret)); - return ret; + int result = libebg.env_open_current(&ebgenv); + if (result != 0) { + ERROR("Cannot open bootloader environment: %s", strerror(result)); + return NULL; } - DEBUG("Unsetting %s in bootloader environment", name); - if (strncmp(name, BOOTVAR_TRANSACTION, strlen(name) + 1) == 0) { - ret = libebg.env_finalize_update(&ebgenv); - if (ret) { - ERROR("Cannot unset %s in bootloader environment: %s.", BOOTVAR_TRANSACTION, strerror(ret)); + if (!inflight && is(name, EBGENV_USTATE)) { + /* + * When not in an in-flight transaction, get the "global significant" + * EBGENV_USTATE value: + * If rolled-back and successfully booted, there's an alternative + * boot path that has + * EBGENV_REVISION == 0 and + * EBGENV_USTATE == STATE_FAILED + * which is how EFI Boot Guard encodes a rolled-back condition. + * To act on this condition, e.g., report and clear it, STATE_FAILED + * as the global significant EBGENV_USTATE value is returned. + * + * If not rolled-back, the current boot path's EBGENV_USTATE value + * is returned. + */ + char *value = NULL; + if (asprintf(&value, "%u", libebg.env_getglobalstate(&ebgenv)) == -1) { + ERROR("Error allocating memory"); + return NULL; } - } else if (strncmp(name, (char *)STATE_KEY, strlen((char *)STATE_KEY) + 1) == 0) { - /* Unsetting STATE_KEY is semantically equivalent to setting it to STATE_OK. */ - if ((ret = libebg.env_setglobalstate(&ebgenv, STATE_OK - '0')) != 0) { - ERROR("Cannot unset %s in bootloader environment.", STATE_KEY); - } - } else { - ret = libebg.env_set_ex(&ebgenv, (char *)name, USERVAR_TYPE_DELETED, (uint8_t *)"", 1); + return value; } - (void)libebg.env_close(&ebgenv); - return ret; + return _env_get(name); } -static char *do_env_get(const char *name) +static int create_new_environment(void) { - char *value = NULL; - size_t size; + uint32_t revision = _env_to_uint32(_env_get(EBGENV_REVISION)); + uint8_t in_progress = (uint8_t)_env_to_uint32(_env_get(EBGENV_IN_PROGRESS)); + if ((revision == UINT_MAX) || (in_progress == UINT8_MAX)) { + ERROR("Cannot get environment revision or in-progress marker"); + return -EIO; + } + if (in_progress == 1) { + return 0; + } + int result = libebg.env_create_new(&ebgenv); + if (result != 0) { + ERROR("Cannot create new environment revision: %s", strerror(result)); + return -result; + } + /* + * libebgenv has now set: + * EBG_ENVDATA->in_progress = 1 + * EBG_ENVDATA->revision = ++ + */ + uint32_t new_revision = _env_to_uint32(_env_get(EBGENV_REVISION)); + if (new_revision == UINT_MAX) { + return -EIO; + } + if (++revision != new_revision) { + ERROR("No new environment revision was created!"); + return -ENOENT; + } + inflight = true; + DEBUG("Created new environment revision %d, starting transaction", + new_revision); + return 0; +} +static int do_env_set(const char *name, const char *value) +{ errno = 0; libebg.beverbose(&ebgenv, loglevel > INFOLEVEL ? true : false); - int ret; - if ((ret = libebg.env_open_current(&ebgenv)) != 0) { - ERROR("Cannot open current bootloader environment: %s.", - strerror(ret)); - return NULL; + if (!inflight) { + /* + * Without an in-flight transaction, only allow + * (1) starting a transaction or + * (2) acknowledging an update. + */ + if (!is(name, BOOTVAR_TRANSACTION) && !is(name, EBGENV_USTATE)) { + ERROR("Not setting %s=%s w/o in-flight transaction", + name, value); + return -EINVAL; + } + if (is(name, BOOTVAR_TRANSACTION) && + !is(value, get_state_string(STATE_IN_PROGRESS))) { + ERROR("Not setting %s=%s w/o in-flight transaction", + name, value); + return -EINVAL; + } + + if (is(name, EBGENV_USTATE)) { + switch (*value) { + case STATE_OK: /* Acknowledging an update. */ + case STATE_IN_PROGRESS: /* Starting a transaction. */ + break; + default: + ERROR("Not setting %s=%s w/o in-flight transaction", + name, value); + return -EINVAL; + } + } + } + + int result = libebg.env_open_current(&ebgenv); + if (result != 0) { + ERROR("Cannot open bootloader environment: %s", strerror(result)); + return -result; } - if (strncmp(name, (char *)STATE_KEY, strlen((char *)STATE_KEY) + 1) == 0) { - value = (char *)malloc(sizeof(char)); - *value = libebg.env_getglobalstate(&ebgenv); - /* Map EFI Boot Guard's int return to update_state_t's char value */ - *value = *value + '0'; - } else { - if ((size = libebg.env_get(&ebgenv, (char *)name, NULL)) != 0) { - value = malloc(size); - if (value) { - if (libebg.env_get(&ebgenv, (char *)name, value) != 0) { - value = NULL; + if (is(name, BOOTVAR_TRANSACTION)) { + /* + * Note: This gets called by core/stream_interface.c's + * update_transaction_state() with the update + * state's string representation. + */ + if (is(value, get_state_string(STATE_IN_PROGRESS))) { + return create_new_environment(); + } + + if (is(value, get_state_string(STATE_FAILED)) || + is(value, get_state_string(STATE_INSTALLED)) || + is(value, get_state_string(STATE_OK))) { + /* + * Irrespective of the value, set EBGENV_IN_PROGRESS = 0, + * else EFI Boot Guard will *NOT* consider this environment + * for booting at all. + */ + if ((result = libebg.env_set(&ebgenv, EBGENV_IN_PROGRESS, + (char *)"0")) != 0) { + ERROR("Error setting %s=0: %s", EBGENV_IN_PROGRESS, + strerror(-result)); + return result; + } + return 0; + } + + /* Fall-through for invalid EBGENV_IN_PROGRESS values. */ + ERROR("Unsupported setting %s=%s", EBGENV_IN_PROGRESS, value); + return -EINVAL; + } + + if (!is(name, EBGENV_USTATE)) { + if ((result = libebg.env_set(&ebgenv, (char *)name, (char *)value)) != 0) { + ERROR("Error setting %s=%s: %s", name, value, strerror(-result)); + return result; + } + return 0; + } + + switch (*value) { + case STATE_IN_PROGRESS: + return create_new_environment(); + case STATE_OK: + if (inflight) { + /* + * Environment modification within the in-flight transaction, + * i.e., the in-memory working copy, just set it. + */ + if ((result = libebg.env_set(&ebgenv, EBGENV_USTATE, + (char *)value)) != 0) { + ERROR("Error setting %s=%s: %s", EBGENV_USTATE, + get_state_string(STATE_OK), + strerror(-result)); + return result; + } + return 0; + } + + unsigned char global_ustate = uint8_to_ascii((uint8_t) + libebg.env_getglobalstate(&ebgenv)); + if (global_ustate == STATE_NOT_AVAILABLE) { + ERROR("Cannot read global %s", EBGENV_USTATE); + return -EIO; + } + unsigned char current_ustate = uint8_to_ascii((uint8_t) + _env_to_uint32( + _env_get(EBGENV_USTATE))); + if (!is_valid_state(current_ustate)) { + ERROR("Cannot read current %s", EBGENV_USTATE); + return -EIO; + } + + if (global_ustate == STATE_FAILED) { + TRACE("Found rolled-back condition, clearing marker"); + /* + * Clear rolled-back condition by setting + * EBGENV_USTATE = STATE_OK on all alternative + * boot paths having EBGENV_USTATE != STATE_OK + * and write them to disk. + * Note: Does not write to the current boot path (to + * which was rolled-back to). + */ + if ((result = libebg.env_setglobalstate(&ebgenv, + ascii_to_uint8(STATE_OK))) != 0) { + ERROR("Error resetting failure condition: %s", + strerror(-result)); + return result; + } + /* + * Restore prior current boot path's EBGENV_USTATE value + * (as there's no way to reload it from disk). + * Should be STATE_OK anyway but better play it safe... + */ + if (current_ustate != STATE_OK) { + if ((result = libebg.env_set(&ebgenv, EBGENV_USTATE, + (char[2]){ current_ustate, '\0' })) != 0) { + ERROR("Error restoring %s: %s", EBGENV_USTATE, + strerror(-result)); + return result; } } + return 0; + } + + if (current_ustate == STATE_TESTING) { + TRACE("Found successful update, blessing it"); + /* + * Acknowledge, update the /current/ boot path on disk. + */ + if ((result = libebg.env_set(&ebgenv, EBGENV_USTATE, + (char *)value)) != 0) { + ERROR("Error setting %s=%s: %s", EBGENV_USTATE, + value, strerror(-result)); + return result; + } + + if ((result = libebg.env_close(&ebgenv)) != 0) { + ERROR("Error persisting environment: %s", + strerror(result)); + return -result; + } + return 0; } + + WARN("Unsupported state for setting %s=%s", EBGENV_USTATE, + get_state_string(*value)); + return -EINVAL; + case STATE_INSTALLED: + if ((result = libebg.env_finalize_update(&ebgenv)) != 0) { + ERROR("Error finalizing environment: %s", strerror(result)); + return -result; + } + /* + * libebgenv has now set: + * EBG_ENVDATA->in_progress = 0 + * EBG_ENVDATA->ustate = USTATE_INSTALLED. + * Now, persist the in-memory working copy environment as new + * current boot path and terminate the transaction. + * Note: Does write to an alternative boot path "upcycled" to + * the new current boot path; Does *NOT* write to the current + * boot path. + */ + if ((result = libebg.env_close(&ebgenv)) != 0) { + ERROR("Error persisting environment: %s", strerror(result)); + return -result; + } + inflight = false; + return 0; + case STATE_FAILED: + /* + * SWUpdate sets this if the installation has failed. In this case, + * the transaction is simply not committed, so nothing to do. + */ + return 0; + default: + break; } - (void)libebg.env_close(&ebgenv); + /* + * Fall-through for invalid or EBGENV_USTATE values handled + * by EFI Boot Guard internally. + */ + WARN("Unsupported setting %s=%s", EBGENV_USTATE, get_state_string(*value)); + return -EINVAL; +} + +static int do_env_unset(const char *name) +{ + errno = 0; + libebg.beverbose(&ebgenv, loglevel > INFOLEVEL ? true : false); - if (value == NULL) { - ERROR("Cannot get %s from bootloader environment: %s", - name, strerror(errno)); + int result = libebg.env_open_current(&ebgenv); + if (result != 0) { + ERROR("Cannot open bootloader environment: %s", strerror(result)); + return -result; } - return value; + if (is(name, EBGENV_USTATE)) { + /* + * Unsetting EBGENV_USTATE is semantically equivalent to + * setting EBGENV_USTATE = STATE_OK. + */ + return do_env_set(EBGENV_USTATE, (char[2]){ STATE_OK, '\0' }); + } + + if (is(name, BOOTVAR_TRANSACTION)) { + /* + * Unsetting BOOTVAR_TRANSACTION is semantically equivalent to + * setting EBGENV_IN_PROGRESS = 0. + */ + return do_env_set(EBGENV_IN_PROGRESS, (char *)"0"); + } + + if ((result = libebg.env_set_ex(&ebgenv, (char *)name, USERVAR_TYPE_DELETED, + (uint8_t *)"", 1)) != 0) { + ERROR("Error unsetting %s: %s", name, strerror(-result)); + return result; + } + return 0; } static int do_apply_list(const char *filename) { - FILE *fp = NULL; - char *line = NULL; - char *key; - char *value; - size_t len = 0; - int ret = 0; - errno = 0; libebg.beverbose(&ebgenv, loglevel > INFOLEVEL ? true : false); - if (!(fp = fopen(filename, "rb"))) { - ERROR("Failed to open bootloader environment file %s: %s", - filename, strerror(errno)); - return -1; + FILE *file = fopen(filename, "rb"); + if (!file) { + ERROR("Cannot open bootloader environment source file %s: %s", + filename, strerror(errno)); + return -EIO; } - while ((getline(&line, &len, fp)) != -1) { - key = strtok(line, "="); - value = strtok(NULL, "\t\n"); - if (value != NULL && key != NULL) { - if ((ret = do_env_set(key, value)) != 0) { + char *line = NULL; + size_t length = 0; + int result = 0; + while ((getline(&line, &length, file)) != -1) { + char *key = strtok(line, "="); + char *value = strtok(NULL, "\t\n"); + if (key != NULL && value != NULL) { + if ((result = do_env_set(key, value)) != 0) { break; } } } - if (fp) { - fclose(fp); - } - if (line) { - free(line); - } - return ret; + fclose(file); + free(line); + return result; } static bootloader ebg = { @@ -212,9 +509,15 @@ static bootloader ebg = { .apply_list = &do_apply_list }; -static bootloader* probe(void) +static bootloader *probe(void) { - void* handle = dlopen("libebgenv.so.0", RTLD_NOW | RTLD_GLOBAL); + if (!is(STATE_KEY, EBGENV_USTATE)) { + ERROR("CONFIG_UPDATE_STATE_BOOTLOADER=%s is required for " + "EFI Boot Guard support", EBGENV_USTATE); + return NULL; + } + + void *handle = dlopen("libebgenv.so.0", RTLD_NOW | RTLD_GLOBAL); if (!handle) { return NULL; } diff --git a/core/stream_interface.c b/core/stream_interface.c index 81c26c3..9ba6332 100644 --- a/core/stream_interface.c +++ b/core/stream_interface.c @@ -611,6 +611,40 @@ void *network_initializer(void *data) if (!(inst.fd < 0)) close(inst.fd); + if (!software->parms.dry_run && is_bootloader(BOOTLOADER_EBG)) { + if (!software->bootloader_transaction_marker) { + /* + * EFI Boot Guard's "in_progress" environment variable + * has special semantics hard-coded, hence the + * bootloader transaction marker cannot be disabled. + */ + TRACE("Note: Setting EFI Boot Guard's 'in_progress' " + "environment variable cannot be disabled."); + } + if (!software->bootloader_state_marker) { + /* + * With a disabled update state marker, there's no + * transaction auto-commit via + * save_state(STATE_INSTALLED) + * which effectively calls + * bootloader_env_set(STATE_KEY, STATE_INSTALLED). + * Hence, manually calling save_state(STATE_INSTALLED) + * or equivalent is required to commit the transaction. + * This can be useful to, e.g., terminate the transaction + * from an according progress interface client or an + * SWUpdate suricatta module after it has received an + * update activation request from the remote server. + */ + TRACE("Note: EFI Boot Guard environment transaction " + "will not be auto-committed."); + } + if (!software->bootloader_transaction_marker && + !software->bootloader_state_marker) { + WARN("EFI Boot Guard environment modifications will " + "not be persisted."); + } + } + /* do carry out the installation (flash programming) */ if (ret == 0) { TRACE("Valid image found: copying to FLASH");