From patchwork Wed Dec 30 15:07:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 355277 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp11404262jai; Wed, 30 Dec 2020 07:09:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJzuiaBFbqWYTj+NiYGzmrxykoV5SHLTuZeVtfYrV/v0/NvTbVBCCnZbaWYXZSayh7TGp+2Q X-Received: by 2002:a17:906:1a4e:: with SMTP id j14mr49511649ejf.507.1609340946129; Wed, 30 Dec 2020 07:09:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609340946; cv=none; d=google.com; s=arc-20160816; b=E7RTgYMQJGl9J7m80V/vCrRlCRhjANSmPh44j8Dhdiab10UuUS7m3Hl0U+nRksFpbJ 8+l7g/gcp6N1OsHU8EJ0Kj2ft6dBNv3HZUx2xtd7W2svZAZP5jQA3nupMeYwizs7XY6S Vx1pPoMPnNZyUYM6awrsAIOtv2gmj2nESZYnFdONA3iGLxNYe/H379Yv9YmnnUF1ySXY RLLuCP1ty6pzggemGiLzmLUVmQjdNKhNxYJDQtlv/2M4gpky2a1tMmiwJSpo/xgFrJbk hsCA29zxEycrEO05YHVM2muaYJk/RcQf0My5nXF85Cw+B61gaGwZOEWFoNi41YEY8uYX G5HA== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Y7Zaw8cm3AC5QmPJgi6OxAtDshoSK79ytn2OB2lCse8=; b=rYB/bM2pNs7JYp2BHTD81HKwcoWNYj2n2smYpUwn9XjMrl6qq66jmkVhSmEuJ4YGt8 eMhYHvxFncCDJRh/z5B9ijAdmJQm/phWsNu9goXSuFv5Bo3gXlVRZIPzjDF8Gy6gLVFP jnzU9NbdnCwkQc3lvAGwuxGWCNzLp2XWG0yDbfY+KhNCR2ATY8XEBfSnQj4VdC5Yab6m rsO3+jVtJVNqjb2vSQmh1+cotUXHaF5qrqiRpSUVCZl4wq46bvSBtLmIYQ+s7Ny2ige3 RbfY5co0xXR5aQuXfGXX+qM3IUDdazl4fCl2Y0cgV4zHeG2bQES4cp3R/jh49stEMrBX O5Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YT9M6xN1; 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 y13si21842872ejw.564.2020.12.30.07.09.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 07:09:06 -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=YT9M6xN1; 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 BE35E82603; Wed, 30 Dec 2020 16:08:12 +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="YT9M6xN1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D0FA182628; Wed, 30 Dec 2020 16:07:51 +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,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450: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 6591E8257D for ; Wed, 30 Dec 2020 16:07:47 +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=ilias.apalodimas@linaro.org Received: by mail-wr1-x435.google.com with SMTP id t16so17694812wra.3 for ; Wed, 30 Dec 2020 07:07:47 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=Y7Zaw8cm3AC5QmPJgi6OxAtDshoSK79ytn2OB2lCse8=; b=YT9M6xN1cHIUpA64dHB3R1HpZTttrc/2yzpJ3ZFNVy+DSJ26ksYlKQdkY4LX5rXzyg 0ClM5w9o5IW0tvIiNvRhhcBUiZHoICBioBtosI63kf15KomWH+72NEEOJWBtEI7C8t9N GWFEiwOk2MgQ2NQoX/QzzQX0dMbmNgnIyM5LDBGC7s1quZYfo2hlQOVsnoW83cxhGLRf 2zrCV6IMSEkJjyfKtrmXgco8TN1CXAum8Ge87PQVFPfLPHF6Vwu58ZYm3JunnvMeVeQn DD5r3M5Pz3AQ5vopYW0XmE6ep0w1rQ6IgGfgPxCivO680IKs4M62ph3I8951GmmTvF+o qiDg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Y7Zaw8cm3AC5QmPJgi6OxAtDshoSK79ytn2OB2lCse8=; b=gwnvrDpR36RshHIlIlkhxcdOfZnhkoGRjHLeZ5yBSC2bdd8FoLT+6fIs2JxIyrXNaH XBCHNaNpKc4ie6rOvFjw40M05q3Bb4V1eGKTMkaxtnYG2rFly5o2ZDd1NmLqMCKTnmox PUkE3C2dssPDToMuSZeqET8oodcOlK8WMx5GVQ1divsi1yknBdtOwUp5JYv/oQ4g0A7O 9WYHCcnzNFXNpmFkcEm5k4LictYeTCwj3uVns9cJSBUGrdopcEWFEi6tJ4rMlkDw/Cx3 0ziuzTcNBfSg9zvXfbZpboIDyztLNPK2IdPdvd/NGiE40z/5QILxTk5CThLHZKwsVZTl EjfQ== X-Gm-Message-State: AOAM532x9218q15Pmvq6mLpgxluUAvTSkdErMQy4LVgFz2VZ5c/EB2HW hmACwGoF0Nkxc/fft4h7n/uQlg== X-Received: by 2002:a5d:58d3:: with SMTP id o19mr9071747wrf.250.1609340866841; Wed, 30 Dec 2020 07:07:46 -0800 (PST) Received: from localhost.localdomain (athedsl-4484548.home.otenet.gr. [94.71.57.204]) by smtp.gmail.com with ESMTPSA id k10sm62062721wrq.38.2020.12.30.07.07.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 07:07:46 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, ard.biesheuvel@arm.com, Ilias Apalodimas , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH 7/8 v2] efi_selftest: Modify self-tests for initrd loading via Loadfile2 Date: Wed, 30 Dec 2020 17:07:19 +0200 Message-Id: <20201230150722.154663-8-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20201230150722.154663-1-ilias.apalodimas@linaro.org> References: <20201230150722.154663-1-ilias.apalodimas@linaro.org> 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 We changed the logic of the initrd discovery and the installation of the protocol in the previous patch. Instead of a config now option it now resides in an EFI variable. Adjust the existing tests accordingly and add self-tests which will cover the new features. Signed-off-by: Ilias Apalodimas --- lib/efi_selftest/efi_selftest_load_initrd.c | 100 +++++++++++++++++++- 1 file changed, 97 insertions(+), 3 deletions(-) -- 2.30.0 diff --git a/lib/efi_selftest/efi_selftest_load_initrd.c b/lib/efi_selftest/efi_selftest_load_initrd.c index fe060a664402..1534c2ba24fa 100644 --- a/lib/efi_selftest/efi_selftest_load_initrd.c +++ b/lib/efi_selftest/efi_selftest_load_initrd.c @@ -14,10 +14,12 @@ * * CONFIG_EFI_SELFTEST=y * CONFIG_EFI_LOAD_FILE2_INITRD=y - * CONFIG_EFI_INITRD_FILESPEC="host 0:1 initrd" * - * * Run ./u-boot and execute + * * Create files + * mkdir init_test && cp initrd init_test/ + * virt-make-fs -t ext4 init_test test.img * + * * Run ./u-boot and execute * host bind 0 image * setenv efi_selftest load initrd * bootefi selftest @@ -43,6 +45,7 @@ #include static struct efi_boot_services *boottime; +static struct efi_runtime_services *runtime; static struct efi_initrd_dp dp = { .vendor = { @@ -76,10 +79,13 @@ static struct efi_initrd_dp dp_invalid = { } }; +static efi_handle_t handle; + static int setup(const efi_handle_t handle, const struct efi_system_table *systable) { boottime = systable->boottime; + runtime = systable->runtime; return EFI_ST_SUCCESS; } @@ -87,16 +93,97 @@ static int setup(const efi_handle_t handle, static int execute(void) { efi_guid_t lf2_proto_guid = EFI_LOAD_FILE2_PROTOCOL_GUID; + efi_guid_t efi_global_variable_guid = EFI_GLOBAL_VARIABLE_GUID; struct efi_load_file_protocol *lf2; struct efi_device_path *dp2, *dp2_invalid; efi_status_t status; - efi_handle_t handle; char buffer[64]; efi_uintn_t buffer_size; void *buf; u32 crc32; + u16 boot_current = 0; + efi_uintn_t boot_current_size = sizeof(boot_current); + char path[] = "host 0 initrd"; + char invalid_path[] = "host 1 initrd"; + efi_uintn_t path_size = sizeof(path); + efi_uintn_t invalid_path_size = sizeof(invalid_path); + u32 attrs = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS; memset(buffer, 0, sizeof(buffer)); + /* Set variable BootCurrent and Initrd#### to a wrong value */ + status = runtime->set_variable(L"BootCurrent", &efi_global_variable_guid, + attrs, boot_current_size, &boot_current); + if (status != EFI_SUCCESS) { + efi_st_error("SetVariable for BootCurrent failed\n"); + return EFI_ST_FAILURE; + } + + /* + * We don't need NV for Initrd here. + * Set the file to an invalid file path + */ + status = runtime->set_variable(L"Initrd0010", &efi_global_variable_guid, + attrs, invalid_path_size, invalid_path); + if (status != EFI_SUCCESS) { + efi_st_error("SetVariable for Initrd failed\n"); + return EFI_ST_FAILURE; + } + + /* We only install the protocol during efibootmgr */ + status = efi_initrd_register(&handle); + if (status != EFI_SUCCESS) { + efi_st_error("Failed to install initrd protocol\n"); + return EFI_ST_FAILURE; + } + + /* + * We should only install the protocol if the file's found + * Right now both BootCurrent and file path are invalid + */ + dp2 = (struct efi_device_path *)&dp; + status = boottime->locate_device_path(&lf2_proto_guid, &dp2, &handle); + if (status != EFI_NOT_FOUND) { + efi_st_error("Initrd protocol should't be installed\n"); + return EFI_ST_FAILURE; + } + + /* Update BootCurrent to the correct value */ + boot_current = 0x0010; + status = runtime->set_variable(L"BootCurrent", &efi_global_variable_guid, + attrs, boot_current_size, &boot_current); + if (status != EFI_SUCCESS) { + efi_st_error("SetVariable for BootCurrent failed\n"); + return EFI_ST_FAILURE; + } + + /* re-install with invalid file path */ + status = efi_initrd_register(&handle); + if (status != EFI_SUCCESS) { + efi_st_error("Failed to install initrd protocol\n"); + return EFI_ST_FAILURE; + } + + /* file path is invalid */ + dp2 = (struct efi_device_path *)&dp; + status = boottime->locate_device_path(&lf2_proto_guid, &dp2, &handle); + if (status != EFI_NOT_FOUND) { + efi_st_error("Initrd protocol should't be installed\n"); + return EFI_ST_FAILURE; + } + + /* re-install with correct values now */ + status = runtime->set_variable(L"Initrd0010", &efi_global_variable_guid, + attrs, path_size, path); + if (status != EFI_SUCCESS) { + efi_st_error("SetVariable for Initrd failed\n"); + return EFI_ST_FAILURE; + } + + status = efi_initrd_register(&handle); + if (status != EFI_SUCCESS) { + efi_st_error("Failed to install initrd protocol\n"); + return EFI_ST_FAILURE; + } dp2 = (struct efi_device_path *)&dp; status = boottime->locate_device_path(&lf2_proto_guid, &dp2, &handle); @@ -211,10 +298,17 @@ static int execute(void) return EFI_ST_SUCCESS; } +static int teardown(void) +{ + efi_delete_handle(handle); + return EFI_ST_SUCCESS; +} + EFI_UNIT_TEST(load_initrd) = { .name = "load initrd", .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, .setup = setup, .execute = execute, + .teardown = teardown, .on_request = true, };