From patchwork Mon Dec 28 12:24:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 352615 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp9706245jai; Mon, 28 Dec 2020 04:25:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJz7iz2ZObU3weHWS1AaIH0p08b/CFdD5LaO4EY8yBexo/GtsKPtstwzxfPoqxeWn7PRjQHp X-Received: by 2002:a17:906:7687:: with SMTP id o7mr42195724ejm.209.1609158348718; Mon, 28 Dec 2020 04:25:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609158348; cv=none; d=google.com; s=arc-20160816; b=MjCDJshGANzB3RhJ3jlQt7hjTkp1wXoSU4SG6mLD/K9AueCpzXYnFHBjueC8ySdK9x QqltScidXUzAgVrRJFqZNDEG3KYHKPJaiwZpLTwabeKHOE+l9HZSTdwcJtU7h/XIoWJ+ HZ3JbrMvUWVkiiO+fXrXYkUR978QOduhgrnkb67vlQCHMcisjxnvsmO1lMUJ4fbPFq4v k+P4O2RNaAws6vPpeRUDK/ZmT0QoNDoRnMyzCJgc9Q7t7YZzhD7gbB8Idnd8xbbBuLu7 z4UDEtEqATq9SazUeXDyV1+Di6wrpg1r7PCKwixdQbQns7808zZ//0NBjD46gJtHqhL/ gz4Q== 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=3mRX3QJWmggl7OcQfkZb7kTWFb0Bs9EjftYpPbz50xA=; b=sfw/PhkBvx8oqo9lrlLOB32InV7JHiNsaKcqfZiJLlYh1oE8OnoZ33yyFwy/Hpj3Gy VE/WPS0LlEnf1PS6zN3HSl7bfiBNo2Ap8eS21XPeZ+GGTitXO0jmmOKaLdbi8vtYp6b9 qF6uLRUGwzuxcEI+5SlndzOknEuJOyywsu5I0/hck9ZQJtoU9WTW7E1HyJVnhbJSVNhR 4Oc2SBV3hoytgBpXy67tPNuClnnTDHp2Jei454opBdq05xY0ydvlbIQt88KP9pwTOEJc MvG42ecjIXLkX3c9FMTJraiCiOhYc33A+AMPYRUdLjGiFuNocjBdXPudP55+n1Czbu0N gZ0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NJa5RadH; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id z21si21385695edr.365.2020.12.28.04.25.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 04:25:48 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NJa5RadH; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 1F37B82540; Mon, 28 Dec 2020 13:25:22 +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="NJa5RadH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 38CA58244B; Mon, 28 Dec 2020 13:25:04 +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-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) (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 D9D30824C4 for ; Mon, 28 Dec 2020 13:24:56 +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-x429.google.com with SMTP id m5so11148252wrx.9 for ; Mon, 28 Dec 2020 04:24:56 -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=3mRX3QJWmggl7OcQfkZb7kTWFb0Bs9EjftYpPbz50xA=; b=NJa5RadHr4ifN7hgPtNslUxgjza/i982G3XtRNyR9vw4o98nFfaD+pOMo0CwPT27QG 6e+g+FuA8a3ttcHoJezEh5KcksjeVyPgEQaJm8Srm8B2cy4MOzVWos2PMHdiF7H9fy3e zw71aKWdaXPNYsemag6G1caFSIxxCZ178Ab/ShU8WfeymLNiQBDtNO3lVi/zoEvE8zsZ GR6aAStP4LV6hCHZWd927Yvx/kD92Sars5BZM6+pPufVJskYN6PgDXTbh6MKcRPiCp6E kQUdXdnyDFiaAC4fPgu2+AZT16YelsVQP/u7cfJDLm3KdRldVHHi2p8bBXedJCxDCF6U 297Q== 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=3mRX3QJWmggl7OcQfkZb7kTWFb0Bs9EjftYpPbz50xA=; b=c5PO+7Oz5g+d/GI/PLJS2r/8T2aGOE7BkqoXFmjcVfYoB5hZqyMm8Kib2xADULCXsr 4/yIPKk07YL3We7V/8cd8PQ894TJjWF+eQyE4ojP2y51EE2YgJ/5tfoLAtcNciM8THnt O9libsmP69TAXb8mg8V5YMfL22K+zceYSc0c3Q4BvYdMCIdXEtTCORPdBaxyyj34J4kg Dcjrf6sDLuvO+ZNcm3vKeZW6RHdzJx0dOBvCG9DO4j1YKAK33HdSWUxo627jgPUd8BBw vP6jzRZ4SmhmCMmtAT29dMS0aOyqNWlVzZiJcMVO9rrV0py5JhNiX1/prsF12JSKdSzR IP9A== X-Gm-Message-State: AOAM532VqZK5BVBoQTNVEqXrJF1F/pQh3V5wI4QOa2RML0i9vEPuStJm N6qVcKt2v+tsrzjEqwS8o8WoDg== X-Received: by 2002:adf:fd05:: with SMTP id e5mr51180211wrr.225.1609158296494; Mon, 28 Dec 2020 04:24:56 -0800 (PST) Received: from localhost.localdomain (athedsl-4484548.home.otenet.gr. [94.71.57.204]) by smtp.gmail.com with ESMTPSA id w21sm18710321wmi.45.2020.12.28.04.24.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Dec 2020 04:24:56 -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 5/6] efi_selftest: Modify self-tests for initrd loading Date: Mon, 28 Dec 2020 14:24:37 +0200 Message-Id: <20201228122440.316403-6-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.0.rc2 In-Reply-To: <20201228122440.316403-1-ilias.apalodimas@linaro.org> References: <20201228122440.316403-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 Previous patches change the logic of the initrd discovery and the registration of the protocol. Instead of a config now option it now resides in an EFI variable. Adjust the instructions of execution accordingly and add new self-tests which will cover the new functionality. Signed-off-by: Ilias Apalodimas --- lib/efi_selftest/efi_selftest_load_initrd.c | 90 ++++++++++++++++++++- 1 file changed, 88 insertions(+), 2 deletions(-) -- 2.30.0.rc2 diff --git a/lib/efi_selftest/efi_selftest_load_initrd.c b/lib/efi_selftest/efi_selftest_load_initrd.c index fe060a664402..85afed55425f 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 = { @@ -80,6 +83,7 @@ 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,6 +91,7 @@ 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; @@ -95,8 +100,89 @@ static int execute(void) 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 register the protocol during efibootmgr */ + status = efi_initrd_register(); + if (status != EFI_SUCCESS) { + efi_st_error("Failed to register initrd protocol\n"); + return EFI_ST_FAILURE; + } + + /* + * We should only register 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 registered\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-register with invalid file path */ + status = efi_initrd_register(); + if (status != EFI_SUCCESS) { + efi_st_error("Failed to register 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 registered\n"); + return EFI_ST_FAILURE; + } + + /* re-register 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(); + if (status != EFI_SUCCESS) { + efi_st_error("Failed to register initrd protocol\n"); + return EFI_ST_FAILURE; + } dp2 = (struct efi_device_path *)&dp; status = boottime->locate_device_path(&lf2_proto_guid, &dp2, &handle);