From patchwork Fri Jul 10 01:25:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1326378 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=TbuMSadR; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B2wNf5xK7z9sRf for ; Fri, 10 Jul 2020 11:26:10 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7097481C2D; Fri, 10 Jul 2020 03:26:03 +0200 (CEST) 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="TbuMSadR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6E14781C2F; Fri, 10 Jul 2020 03:26:01 +0200 (CEST) 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,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) (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 6B39F81C1E for ; Fri, 10 Jul 2020 03:25:57 +0200 (CEST) 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-pl1-x62a.google.com with SMTP id w17so1557067ply.11 for ; Thu, 09 Jul 2020 18:25:57 -0700 (PDT) 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=MH+AbBRRAbEHBxxbcJ+5vg9ZxnNxvcDa+hkDjXeddUo=; b=TbuMSadR3cOpTkbChR9MRKmmPM/m/dgK6wNFcP1TlDMkYA6TUyh+RC9Lj8Xnq+kA74 1Kyrl6kB7WxRkYadtyD1xhpJFLPDjGQEtHNkzyo1R9k0/cE/Sj3KJlsq0CThuBBilUky 46mXLRzvW+AdsUJnu5cE3U0XI8IjuCPHotH2TPE3DVWnsf6Y5bxgARTJ19VHEXtzOPPb +JpUYea9xU6H6Pb6yv8AjzW3+wKzWrL7ugkbqM3/t034w96nRwtR9lFTm0s2CWHMb8Fj dGlwgWVlAwh5Q/uoyN+yPVKlmGkHJTGVFqaobgIgvICmsFa7Ks08enyx9ta22NVtSu+z aRIg== 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=MH+AbBRRAbEHBxxbcJ+5vg9ZxnNxvcDa+hkDjXeddUo=; b=EkEbbJAxo/1bg8YUCoGPOJA6SslLCEXH+dyFU37gXeyyCcyAgMe9KImvqsVAUUP9kM tl6ccaEYtGkuqG26SJXD+jii45qCl436SqHdxtxAE3MXq19RgryqYP8qWvW6LVQwCP5N pZKIyuALYwFpARuCycMMgG6gnE2f2oqfSMbWFrcoNO9TfCoHGabjT0CNW+DnJUjDsCzh NbhfK6VX8Qu0zmGV3gXY1CJTos9M31YLNp/V2fONrTaHq/Jrb1RY3V9l9xrL2v9qpdxR 3jt3NT9kVaRAAuAL2icFOhPictDkh07949tJFhpbfePW6FdHQ62HJmu5D/gdLToIvYy5 CPhQ== X-Gm-Message-State: AOAM531GFRisOHt30p0TpJO1eTw/OAE/GFnQqSbuz48LsAT8c562Hd7a +TYE9a7+T3Ye41JM//5Ybf1J2Q== X-Google-Smtp-Source: ABdhPJy+F5smegfcNY6cXbIwdy1coENan9Nqn8isKJ8Jq0lwg8uGltcmk4pe+H5PefB6pTtYINGpfw== X-Received: by 2002:a17:902:bb8a:: with SMTP id m10mr812098pls.137.1594344355491; Thu, 09 Jul 2020 18:25:55 -0700 (PDT) Received: from localhost.localdomain (p6e421564.tkyea130.ap.so-net.ne.jp. [110.66.21.100]) by smtp.gmail.com with ESMTPSA id c1sm3629006pgi.52.2020.07.09.18.25.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 18:25:54 -0700 (PDT) From: AKASHI Takahiro To: lukma@denx.de, trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v3 00/17] efi_loader: add capsule update support Date: Fri, 10 Jul 2020 10:25:20 +0900 Message-Id: <20200710012537.6264-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.27.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-#5,#12: preparatory patches Patch#6-#11,#13: main part of implementation Patch#14-#15: utilities Patch#16-#17: pytests [1] https://git.linaro.org/people/takahiro.akashi/u-boot.git efi/capsule Prerequisite patches ==================== (None as all have been merged as of v2020.07-rc4) Test ==== * passed all the pytests which are included in this patch series on sandbox build. * passed Travis CI, except "buildman samsumg softfpga". (I don't know what this build failed yet.) Please note that, while Travic CI passed, the capsule pytest itself won't be run in the CI because some specific configuration for sandbox build is required. See test_efi_capsule_firmware.py. 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#6 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) * 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 ======= 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 (17): common: update_tftp: remove unnecessary build check dfu: add a hidden reverse-dependency on UPDATE_TFTP dfu: rename dfu_tftp_write() to dfu_write_by_name() common: update: add a generic interface for FIT image dfu: export dfu_list efi_loader: add option to initialise EFI subsystem early 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 dfu: add dfu_write_by_alt() efi_loader: add firmware management protocol for raw image cmd: add "efidebug capsule" command tools: add mkeficapsule command for UEFI capsule update test/py: add a test for uefi firmware update capsule of FIT image test/py: add a test for uefi firmware update capsule of raw image cmd/efidebug.c | 235 +++++ common/Kconfig | 16 + common/Makefile | 2 +- common/board_r.c | 6 + common/main.c | 4 + common/update.c | 83 +- drivers/dfu/Kconfig | 6 + drivers/dfu/Makefile | 2 +- drivers/dfu/dfu.c | 2 +- drivers/dfu/dfu_alt.c | 125 +++ drivers/dfu/dfu_tftp.c | 65 -- include/dfu.h | 57 +- include/efi_api.h | 160 +++ include/efi_loader.h | 34 + include/image.h | 12 + lib/efi_loader/Kconfig | 72 ++ lib/efi_loader/Makefile | 2 + lib/efi_loader/efi_capsule.c | 925 ++++++++++++++++++ lib/efi_loader/efi_firmware.c | 398 ++++++++ lib/efi_loader/efi_runtime.c | 104 +- lib/efi_loader/efi_setup.c | 43 +- test/py/tests/test_efi_capsule/conftest.py | 102 ++ test/py/tests/test_efi_capsule/defs.py | 24 + .../test_efi_capsule/test_capsule_firmware.py | 383 ++++++++ .../tests/test_efi_capsule/uboot_bin_env.its | 36 + test/py/tests/test_efi_capsule/uboot_env.its | 25 + tools/Makefile | 3 + tools/mkeficapsule.c | 237 +++++ 28 files changed, 3022 insertions(+), 141 deletions(-) create mode 100644 drivers/dfu/dfu_alt.c delete mode 100644 drivers/dfu/dfu_tftp.c 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/conftest.py create mode 100644 test/py/tests/test_efi_capsule/defs.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 test/py/tests/test_efi_capsule/uboot_env.its create mode 100644 tools/mkeficapsule.c