From patchwork Mon Nov 30 09:12:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 334692 Delivered-To: patch@linaro.org Received: by 2002:a92:5e16:0:0:0:0:0 with SMTP id s22csp4467476ilb; Mon, 30 Nov 2020 01:13:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJzo34wg8WQH4jejHUp+tU2s3VSeJiCN84CAnnzBVWr5mw4Cmfyf/kudJrble0WxU08qyLUd X-Received: by 2002:a17:906:9613:: with SMTP id s19mr3740394ejx.351.1606727590208; Mon, 30 Nov 2020 01:13:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606727590; cv=none; d=google.com; s=arc-20160816; b=JDkikQ5xLBQ6zrmMw8KdvR95a9z/5OnBOBl2DWHtoad14bD9KQyp8uLVSDfqafJoTA twQgVQk7fYg/d6omr/ya98iXhKiNNI5wMhKa7tD4W8aFF6QS2IZU7+FcQGoJ+7zSg2rx sIavfnvqkNq11lX+UxueHb7VKVIf8jkgmdsDPghZXBlqUoJHt8Czx7udPE8v6c6miBsa JA43y23zVVRjueEjrtvWPHLek8AiSG7dtKVcYvqL0wT9e1t6u63NHqNe5EFnwtq6CVPB mCdny/GungAicvKwpwg10QBwejBvhtmhC+2ytnryFsqwlT0Q6svHYT7CUBqhBEcURCTv X4iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=I7bGaJyRJ78UK2wuolki0QCLfiHXwIz25RPCSwMy2Kk=; b=HhdbaXeRTIuh2qanD+T4oQd2xQe8MQGNdFbSn+ddB3b+EIMy2EZP+DR1KtLRHpnWdW OrjsOPEAzuWSIFl9XQHhiPN2R6hF2/p5QRyjDzugjjpO1VUaTx38kgkjHXug3v6kd4pK HySKIQE/yU22Z/mtprZjMcfiYvGAgUypEPp0YYjkaNAmHmUWHgagd4FI/q9cvSj59tBQ 8EsWmyqM/5gqvq7ZkSvQMEQo0OQpTtiB9rZGOp9AT+h+2Jm7JhlUNAc4p74xCHqD8cLd BaRvbFT5S/ywODFsHHC4jxRfQsAdUJfIpK1jibkYrZSifV8u1bokUeipEz80Q++9LQna uI/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Hdwv2N0g; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id i8si8259048ejj.424.2020.11.30.01.13.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2020 01:13:10 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Hdwv2N0g; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A82E1827B9; Mon, 30 Nov 2020 10:13:03 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Hdwv2N0g"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CBABA82611; Mon, 30 Nov 2020 10:12:52 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 77BA082611 for ; Mon, 30 Nov 2020 10:12:38 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pf1-x435.google.com with SMTP id w187so10001020pfd.5 for ; Mon, 30 Nov 2020 01:12:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=I7bGaJyRJ78UK2wuolki0QCLfiHXwIz25RPCSwMy2Kk=; b=Hdwv2N0gtotjN6AA0fF9fmrqSfM6DwZ21e8TgAbH3FAP/+JZ2xF2JCICrx1jLXjL05 yJgAwYV+NW9hnGQbM0cdOdQmQtQdtMMBoQyshZtI0w6rJ3KgFlsmmC+gfGpqUDjQw5bQ xn7XCftP6cPzeRZzQEKz/74nihcT6EPcUkqmAGXEDLLmFKRNLQe0Kgl9L62wT86ojB25 f0tnjZyrCBL9HZ1OO7s3NAHocTmykNjepu/FRXoOopKM1EDDULtmF6zw9A4EUSBNRljm 0p+zm47bcAIPc6Dk46LhUFX15HbLp6NsJxsa0k7gQHoiHEUYbbLcayaXOI3BlBy22Xis Xtcw== 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=I7bGaJyRJ78UK2wuolki0QCLfiHXwIz25RPCSwMy2Kk=; b=LvtvIRi1mW2DNM2ACDwzibyio2S8fT+duGTQSyUzmXlmkMEQNutTFcEmj/SJ9AWNeZ G6PIKIGGbZX3eYYjv9gcgRDb1mfuE1qNJXjXPdSL77WsQ9vCZur2VnGdxm6TIYhO8Seo e4XgJweVH3pKoPpNT+Ynl38/c9RsMBWWgBzIO52zTSwEMkJC8Ui/6nBvOdnQ4vqj+yMR Hc0oKV3S5k9uf3B/AaOSZGljkHh33m+pF4xE5L4qOVhiPyrl+CS6BuOQ2b11oiXSRV4g 4h6NUMUrgIQBUUP6ydGxJsSv3WIE6n2AjDZfw6YEsLPtdaUY6PMVZsoKvi3Nvaag3JbZ /k2Q== X-Gm-Message-State: AOAM530rG59IyjbTKyI6iOi16Z3bOgC1Jr5oMnvEYKJPdOPxnXZkz6Wd cSAPb0HxFLshSwpVoWbAsgNvJg== X-Received: by 2002:a63:f317:: with SMTP id l23mr16624575pgh.384.1606727556552; Mon, 30 Nov 2020 01:12:36 -0800 (PST) Received: from localhost.localdomain (p784a5642.tkyea130.ap.so-net.ne.jp. [120.74.86.66]) by smtp.gmail.com with ESMTPSA id y19sm16015792pfn.147.2020.11.30.01.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2020 01:12:35 -0800 (PST) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v10 00/11] efi_loader: add capsule update support Date: Mon, 30 Nov 2020 18:12:07 +0900 Message-Id: <20201130091218.66413-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Summary ======= 'UpdateCapsule' is one of runtime services defined in UEFI specification and its aim is to allow a caller (OS) to pass information to the firmware, i.e. U-Boot. This is mostly used to update firmware binary on devices by instructions from OS. While 'UpdateCapsule' is a runtime services function, it is, at least initially, supported only before exiting boot services alike other runtime functions, [Get/]SetVariable. This is because modifying storage which may be shared with OS must be carefully designed and there is no general assumption that we can do it. Therefore, we practically support only "capsule on disk"; any capsule can be handed over to UEFI subsystem as a file on a specific file system. In this patch series, all the related definitions and structures are given as UEFI specification describes, and basic framework for capsule support is provided. Currently supported is * firmware update (Firmware Management Protocol or simply FMP) Most of functionality of firmware update is provided by FMP driver and it can be, by nature, system/platform-specific. So you can and should implement your own FMP driver(s) based on your system requirements. Under the current implementation, we provide two basic but generic drivers with two formats: * FIT image format (as used in TFTP update and dfu) * raw image format It's totally up to users which one, or both, should be used on users' system depending on user requirements. Quick usage =========== 1. You can create a capsule file with the following host command: $ mkeficapsule [--fit | --raw ] 2. Put the file under: /EFI/UpdateCapsule of UEFI system partition 3. Specify firmware storage to be updated in "dfu_alt_info" variable (Please follow README.dfu for details.) ==> env set dfu_alt_info '...' 4. After setting up UEFI's OsIndications variable, reboot U-Boot: OsIndications <= EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED Patch structure =============== Patch#1-#6: main part of implementation Patch#7-#8: utilities Patch#9-#10: pytests Patch#11: for sandbox test [1] https://git.linaro.org/people/takahiro.akashi/u-boot.git efi/capsule Prerequisite patches ==================== None Test ==== * 'build' passed with gcc 10.2 for (qemu-)arm64 locally. * passed all the pytests which are included in this patch series on sandbox build locally. * In Travis CI, tests skipped (or 'S', but it's not a failure, 'E' nor 'F') because "virt-make-fs" cannot be executed. Issues ====== * Timing of executing capsules-on-disk Currently, processing a capsule is triggered only as part of UEFI subsystem initialization. This means that, for example, firmware update, may not take place at system booting time and will potentially be delayed until a first call of any UEFI functions. => See patch#5 for my proposal * A bunch of warnings like WARNING: Use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef' where possible I don't think that fixing those improves anything. * Add a document in uefi.rst TODO's ====== (Won't be addressed in this series.) * capsule authentication * capsule dependency (dependency expression instruction set, or depex) * loading drivers in a capsule * handling RESET flag in a capsule and QeuryCapsuleCaps * full semantics of ESRT (EFI System Resource Table) * enabling capsule API at runtime * json capsule * recovery from update failure Changes ======= v10 (November 30, 2020) * allow for only the latest version of descriptor/format (Patch#4) * replace all 'printf'/'EFI_PRINT' with log_xxx() (Patch#4,#5) * fix a potential bug of overrunning 'struct efi_firmware_management_capsule_header' (Patch#8) * fix the version of a created capsule image to "3", removing "--version" option of mkeficapsule command (Patch#8-#10) v9 (November 17, 2020) * rebased on v2021.01-rc2 * removed already-merged patches * aligned with a function prototype change of efi_create_indexed_name() (Patch#1-2) # See Travis CI status in v8 below v8 (November 13, 2020) * fix a "not used" warning against update_load() in some configuration (Patch#3) * fix failures (marked as 'F') in *secure boot* test in Travis CI by making "EFI_CAPSULE_ON_DISK_EARLY" 'default n' (Patch#8) * fix failures (marked as 'E') at pytest setup in Travis CI by changing a python file's name along with removing unused definitions (Patch#16) * add Patch#18 to enable tests to be run with default sandbox config (Patch#18) v7 (October 29, 2020) * rename CONFIG_DFU_ALT to CONFIG_DFU_WRITE_ALT (Patch#1,#3,#13) v6 RESEND (October 29, 2020) * rebased on v2021.01-rc1 v6 (September 7, 2020) * temporarily drop the prerequisite patch[2] * add a missing field (dependencies) in efi_api.h (but never used) (Patch#10) * add a missing field (image_capsule_support) and related definitions in efi_api.h (Patch#10, #15) * cosmetic changes on constant definitions in efi_api.h (Patch#10) * strict check for INVALID_PARAMETER at GET_IMAGE_INFO api (Patch#11,#13) * fix warnings in pytest (Patch#16,#17) v5 (August 3, 2020) * removed superfluous type conversion at dfu_write_from_mem_addr() (Patch#2) * introduced a common helper function, efi_create_indexed_name() (Patch#6,#7,#8) * use efi_[get|set]_variable_int(), if necessary, with READ_ONLY (Patch#7,#8) * return EFI_UNSUPPORTED at Patch#7 * changed the word, number, to 'index' (Patch#7,#8) * removed 'ifdef CONFIG_EFI_CAPSULE_ON_DISK' from a header (Patch#8) * initialize 'CapsuleLast' in efi_init_obj_list() (Patch#7,#8) * added 'const' qualifier for filename argument at efi_capsule_[read|delete]_file() (Patch#8) v4 (July 22, 2020) * rebased to Heinrich's current efi-2020-10 * rework dfu-related code to align with Heinrich's change (Patch#1,#3) * change a type of 'addr' argument from int to 'void *' per Sughosh's comment (Patch#2-#3,#11-#12) * rework/simplify pytests (Patch#15-#16) - utilize virt-make-fs - drop Test Case 1 (updating U-Boot environment data) - remove useless definitions (MNT_PNT, EFI_CAPSULE_IMAGE_NAME) - apply autopep8 v3 (July 10, 2020) * rebased to Heinrich's current efi-2020-10-rc1 * refactor efi_firmware_[fit|raw]_get_image_info() (patch#11,#13) v2 (June 17, 2020) * rebased to v2020.07-rc4 * add preparatory patches for dfu (Patch#1-#5, #12) * rework FIT capsule driver to utilize dfu_alt_info instead of CONFIG_xxx (patch#11) * extend get_image_info() to correspond to dfu_alt_info (patch#11) * add a 'raw binary' capsule support (patch#13, #17) * allow multiple capsule formats (with different GUIDs) to be installed (patch#11, #13) * extend mkeficapsule command to accept additional parameters, like version/index/hardware instance for a capsule header info. (patch#15) * mkeficapsule can now also generate raw-binary capsule (patch#16) * add function descriptions * apply autopep8 to pytests and fix more against pylint v1 (April 27, 2020) * rebased to v2020.07-rc * removed already-merged patches (RFC's #1 to #4) * dropped 'variable update' capsule support (RFC's patch#10) * dropped 'variable configuration table' support (RFC's patch#11) (Those two should be discussed separately.) * add preparatory patches (patch#1/#2) * fix several build errors * rename some Kconfig options to be aligned with UEFI specification's terms (patch#3,4,6,7) * enforce UpdateCapsule API to be disabled after ExitBootServices (patch#3) * use config table, runtime_services_supported, instead of variable (patch#3) * make EFI_CAPSULE_ON_DISK buildable even if UpdateCapsule API is disabled (patch4) * support OsIndications, invoking capsule-on-disk only if the variable indicates so (patch#4) * introduced EFI_CAPSULE_ON_DISK_EARLY to invoke capsule-on-disk in U-Boot initialization (patch#4) * detect capsule files only if they are on EFI system partition (patch#4) * use printf, rather than EFI_PRINT, in error cases (patch#4) * use 'header_size' field to retrieve capsule data, adding sanity checks against capsule size (patch#6) * call fmpt driver interfaces with EFI_CALL (patch#6) * remove 'variable update capsule'-related code form mkeficapsule (patch#9) * add a test case of OsIndications not being set properly (patch#10) * adjust test scenario for EFI_CAPSULE_ON_DISK_EARLY (patch#10) * revise pytest scripts (patch#10) Initial release as RFC (March 17, 2020) AKASHI Takahiro (11): efi_loader: define UpdateCapsule api efi_loader: capsule: add capsule_on_disk support efi_loader: capsule: add memory range capsule definitions efi_loader: capsule: support firmware update efi_loader: add firmware management protocol for FIT image efi_loader: add firmware management protocol for raw image cmd: add "efidebug capsule" command tools: add mkeficapsule command for UEFI capsule update test/py: efi_capsule: test for FIT image capsule test/py: efi_capsule: test for raw image capsule sandbox: enable capsule update for testing cmd/efidebug.c | 235 +++++ common/main.c | 4 + configs/sandbox64_defconfig | 6 + configs/sandbox_defconfig | 6 + include/efi_api.h | 166 ++++ include/efi_loader.h | 27 + lib/efi_loader/Kconfig | 68 ++ lib/efi_loader/Makefile | 2 + lib/efi_loader/efi_capsule.c | 909 ++++++++++++++++++ lib/efi_loader/efi_firmware.c | 403 ++++++++ lib/efi_loader/efi_runtime.c | 104 +- lib/efi_loader/efi_setup.c | 76 +- .../py/tests/test_efi_capsule/capsule_defs.py | 5 + test/py/tests/test_efi_capsule/conftest.py | 74 ++ .../test_efi_capsule/test_capsule_firmware.py | 241 +++++ .../tests/test_efi_capsule/uboot_bin_env.its | 36 + tools/Makefile | 2 + tools/mkeficapsule.c | 237 +++++ 18 files changed, 2547 insertions(+), 54 deletions(-) create mode 100644 lib/efi_loader/efi_capsule.c create mode 100644 lib/efi_loader/efi_firmware.c create mode 100644 test/py/tests/test_efi_capsule/capsule_defs.py create mode 100644 test/py/tests/test_efi_capsule/conftest.py create mode 100644 test/py/tests/test_efi_capsule/test_capsule_firmware.py create mode 100644 test/py/tests/test_efi_capsule/uboot_bin_env.its create mode 100644 tools/mkeficapsule.c -- 2.28.0