From patchwork Wed Aug 8 09:54:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 954875 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41lmwj43F1z9s0n for ; Wed, 8 Aug 2018 19:55:49 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 370FAC21FBD; Wed, 8 Aug 2018 09:55:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id D415BC21FC4; Wed, 8 Aug 2018 09:54:42 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 72623C21D72; Wed, 8 Aug 2018 09:54:41 +0000 (UTC) Received: from mail-it0-f74.google.com (mail-it0-f74.google.com [209.85.214.74]) by lists.denx.de (Postfix) with ESMTPS id E0556C21F5E for ; Wed, 8 Aug 2018 09:54:40 +0000 (UTC) Received: by mail-it0-f74.google.com with SMTP id h5-v6so2031158itb.3 for ; Wed, 08 Aug 2018 02:54:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=s663ocLRt0MAG1ZxTlIyLJFfwB53/NKxUY64Ac+pQmU=; b=OiNKiArfgNixA21MX3um+TJAfOPpjLtufjge0LlH+wiwa0oc+bDrz6rjh/WfK0mraa w4o5s02mc6X3YQ+CTk7V2Co9URDvmxU8QjDQ7yNUp5yLV3KA8tU1PAlVCkcaI9vHWOHt IWdbcpUxbOPGJNMxJA/VXEFnReU0iJgnqNwPyQEDuhILmbQTQrg/6XrouxuICTqnq/u7 JEqkhvF8SRVJG9cjx3OpEvzXrHDHwwcPDJDRbv1DZXvRI6b+ERPZTy1/x986OlIauQbD dAD6E/hIIqEgObwlpyLjiEiaPuv1QC/PF2b4Rh15BW7sEtsPMB2ZR5MEiaR7nRfq0aVQ 8yPg== X-Gm-Message-State: AOUpUlGAwHLY4uCpqksLBO8q2IEUgZaOzqll53OTCTHSxv1bC3lifTZt 6QbOyh6tluUpCf9THnwFy0AQdCk= X-Google-Smtp-Source: AA+uWPzl9b/SRMfhendoabKLTf9G1lrJ8Kgj9GX/EcFyRxnbu/DOui2aWE4dJiq7lPzKwazXQB9p6qc= X-Received: by 2002:a24:9458:: with SMTP id j85-v6mr863568ite.18.1533722079695; Wed, 08 Aug 2018 02:54:39 -0700 (PDT) Date: Wed, 8 Aug 2018 03:54:16 -0600 In-Reply-To: <20180808095433.230882-1-sjg@chromium.org> Message-Id: <20180808095433.230882-2-sjg@chromium.org> Mime-Version: 1.0 References: <20180808095433.230882-1-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v9 01/18] Revert "efi_loader: Rename sections to allow for implicit data" X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" This partially reverts commit 7e21fbca26d18327cf7cabaad08df276a06a07d8. That change broke sandbox EFI support for unknown reasons. It also changes sandbox to use--gc-sections which we don't want. For now I am just reverting the sandbox portion as presumably this change is safe on other architectures. Fixes: 7e21fbca26 (efi_loader: Rename sections to allow for implicit data) Signed-off-by: Simon Glass --- Changes in v9: - Add revert for "efi_loader: Rename sections to allow for implicit data" Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None arch/sandbox/config.mk | 3 --- arch/sandbox/cpu/u-boot.lds | 9 ++++----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk index 5e7077bfe75..2babcde8815 100644 --- a/arch/sandbox/config.mk +++ b/arch/sandbox/config.mk @@ -5,9 +5,6 @@ PLATFORM_CPPFLAGS += -D__SANDBOX__ -U_FORTIFY_SOURCE PLATFORM_CPPFLAGS += -DCONFIG_ARCH_MAP_SYSMEM PLATFORM_LIBS += -lrt -LDFLAGS_FINAL += --gc-sections -PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections - # Define this to avoid linking with SDL, which requires SDL libraries # This can solve 'sdl-config: Command not found' errors ifneq ($(NO_SDL),) diff --git a/arch/sandbox/cpu/u-boot.lds b/arch/sandbox/cpu/u-boot.lds index 727bcc35981..3a6cf55eb99 100644 --- a/arch/sandbox/cpu/u-boot.lds +++ b/arch/sandbox/cpu/u-boot.lds @@ -24,9 +24,8 @@ SECTIONS } .efi_runtime : { - *(.text.efi_runtime*) - *(.rodata.efi_runtime*) - *(.data.efi_runtime*) + *(efi_runtime_text) + *(efi_runtime_data) } .__efi_runtime_stop : { @@ -39,8 +38,8 @@ SECTIONS } .efi_runtime_rel : { - *(.rel*.efi_runtime) - *(.rel*.efi_runtime.*) + *(.relefi_runtime_text) + *(.relefi_runtime_data) } .efi_runtime_rel_stop : From patchwork Wed Aug 8 09:54:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 954876 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41lmxS2ZDqz9s0n for ; Wed, 8 Aug 2018 19:56:28 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id E6EB5C21FF3; Wed, 8 Aug 2018 09:55:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 0886EC21FE7; Wed, 8 Aug 2018 09:54:52 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0B980C21FED; Wed, 8 Aug 2018 09:54:46 +0000 (UTC) Received: from mail-io0-f201.google.com (mail-io0-f201.google.com [209.85.223.201]) by lists.denx.de (Postfix) with ESMTPS id 99421C21FBD for ; Wed, 8 Aug 2018 09:54:42 +0000 (UTC) Received: by mail-io0-f201.google.com with SMTP id e8-v6so1218695ioq.11 for ; Wed, 08 Aug 2018 02:54:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=3+jAMjrPUR01VNj42Zip+Fp1fN8MUbNoiNfDwmkHyFc=; b=F7iz74kXItCM6BmJ6XSyIRDAmar9Ben3F248JgLYJDN4vRXZdSF1W93eV4H/APaXnj OIpQ8hdoe4xjsrzYY02zvAyI7LzMp2t12Vmozy+qakMpno1pTDiEnV0U5ibU8NvSlo/d d6VN0HZQsr4WI/lz6lSGwe8xk1qHQ+9KT8QncwAoD3H13xBUokcMqA+UOZSgJAWjoejA y3af0a5gXcUH6BBhzaPMyv5bXk8D5L6Ro2+0A5Lm5SSxvWwAMkB0QNk5hTzcBu2GK58L qGzECdqjntYJH05YXaCmqdilFGjMfJ8NQ9Q3fVj318SRR/3+w54d24x4N8g2qV+WrSlb mADg== X-Gm-Message-State: AOUpUlHpI3Gd2lkV/HX30TaV/FiagoeHo639FHqLPmUtKG3sww9bIwVN 6lWks8Qt/PkHmowP5BTq2TJVkQY= X-Google-Smtp-Source: AA+uWPzzPXWvfqxkJy2PuHYs2DYYJZOm2HqJKzMXQsnJomdeGyx6T5FdDaCmIBbC1UktNLXot11AmBg= X-Received: by 2002:a6b:4608:: with SMTP id t8-v6mr771795ioa.141.1533722081125; Wed, 08 Aug 2018 02:54:41 -0700 (PDT) Date: Wed, 8 Aug 2018 03:54:17 -0600 In-Reply-To: <20180808095433.230882-1-sjg@chromium.org> Message-Id: <20180808095433.230882-3-sjg@chromium.org> Mime-Version: 1.0 References: <20180808095433.230882-1-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v9 02/18] efi: Don't allow CMD_BOOTEFI_SELFTEST on sandbox X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" This does not work at present and gives the following error: output: 'ld.bfd: read in flex scanner failed scripts/Makefile.lib:390: recipe for target 'lib/efi_selftest/efi_selftest_miniapp_return_efi.so' failed It may be possible to figure this out with suitable linker magic but it does not seem to be easy. Also, we will be able to run the tests on sandbox without using the miniapp. So for now at least, disable this option. Signed-off-by: Simon Glass --- Changes in v9: None Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: - Add new patch to disallow CMD_BOOTEFI_SELFTEST on sandbox Changes in v4: None Changes in v3: None Changes in v2: None lib/efi_selftest/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/efi_selftest/Kconfig b/lib/efi_selftest/Kconfig index 59f9f36801c..b52696778dd 100644 --- a/lib/efi_selftest/Kconfig +++ b/lib/efi_selftest/Kconfig @@ -1,6 +1,6 @@ config CMD_BOOTEFI_SELFTEST bool "Allow booting an EFI efi_selftest" - depends on CMD_BOOTEFI + depends on CMD_BOOTEFI && !SANDBOX imply FAT imply FAT_WRITE help From patchwork Wed Aug 8 09:54:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 954888 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41lnWS2Fscz9s1x for ; Wed, 8 Aug 2018 20:22:28 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 36A70C21FCF; Wed, 8 Aug 2018 09:57:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id B2BAEC22003; Wed, 8 Aug 2018 09:55:26 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E1BC5C21FE3; Wed, 8 Aug 2018 09:54:48 +0000 (UTC) Received: from mail-qk0-f202.google.com (mail-qk0-f202.google.com [209.85.220.202]) by lists.denx.de (Postfix) with ESMTPS id E045BC21FDA for ; Wed, 8 Aug 2018 09:54:43 +0000 (UTC) Received: by mail-qk0-f202.google.com with SMTP id 17-v6so1728231qkz.15 for ; Wed, 08 Aug 2018 02:54:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=KwOv/PTUbUKY2CGjfeJJ93of7uWE2IN9FoZFhVFSBI8=; b=anQLvwjGS7H/SixJpBGvcDAi0l16qWAAuIagNKm25dgLV7VVS1OCsTkGruvoDzFDxj CD4GOEdWCUF87LDGlSJXSl11kGAq/e/1vzO1mKJ9ynEwEA/2PgPCUY17riqQUM9ToYiC UhQP9uXzpu3JNjWRUExLW/W8TH3LgNC69s6lGEa3H7Qu8XaOcdFFuYVvQA8iDt/Cl2+Q L77tHxwK4XkNYkCsBmvoWmNSV5pgVuQ/I1G3SppMvtzgNFtTaFL3KzXM+TecaS+pLpAG 8T837aNhOJOQujAw47L4jkRRJE6ZcnNmyBgHNAx9xFc/zI5PP/CQBXVwHUob+XjnkzsQ 68SQ== X-Gm-Message-State: AOUpUlG/V0L5xnrjpI4bUBCDABEfF5tYnFC+cr3Bpdw/epmJze+Wfpos EwwPficnLCVTQrrlHZ1rFeE+50I= X-Google-Smtp-Source: AA+uWPyoZISl1hjxhmYOlwbotm6qwflhD4GE8Vn034MTBVJlMe1ahyFdYpPje4UcuQdtXIOZV8GH42E= X-Received: by 2002:a37:e109:: with SMTP id c9-v6mr1142749qkm.54.1533722082812; Wed, 08 Aug 2018 02:54:42 -0700 (PDT) Date: Wed, 8 Aug 2018 03:54:18 -0600 In-Reply-To: <20180808095433.230882-1-sjg@chromium.org> Message-Id: <20180808095433.230882-4-sjg@chromium.org> Mime-Version: 1.0 References: <20180808095433.230882-1-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v9 03/18] efi: sandbox: Add distroboot support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" With sandbox these values depend on the host system. Let's assume that it is x86_64 for now. Signed-off-by: Simon Glass --- Changes in v9: None Changes in v8: None Changes in v7: - Drop an unnecessary comment Changes in v6: - Warn about building sandbox EFI support on something other than __x86_64__ Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None include/config_distro_bootcmd.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/config_distro_bootcmd.h b/include/config_distro_bootcmd.h index d672e8ebe65..75866f2abf9 100644 --- a/include/config_distro_bootcmd.h +++ b/include/config_distro_bootcmd.h @@ -261,6 +261,17 @@ #elif defined(CONFIG_CPU_RISCV_64) #define BOOTENV_EFI_PXE_ARCH "0x1b" #define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00027:UNDI:003000" +#elif defined(CONFIG_SANDBOX) +/* + * TODO(sjg@chromium.org): Consider providing a way to enable sandbox features + * based on the host architecture + */ +# ifndef __x86_64__ +# warning "sandbox EFI support is only tested on 64-bit x86" +# endif +/* To support other *host* architectures this should be changed */ +#define BOOTENV_EFI_PXE_ARCH "0x7" +#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00007:UNDI:003000" #else #error Please specify an EFI client identifier #endif From patchwork Wed Aug 8 09:54:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 954889 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41lnXs52Kdz9s4Z for ; Wed, 8 Aug 2018 20:23:41 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 585A1C21FB5; Wed, 8 Aug 2018 09:57:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 3B51AC21FCB; Wed, 8 Aug 2018 09:55:24 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3AB44C21FF4; Wed, 8 Aug 2018 09:54:49 +0000 (UTC) Received: from mail-ua0-f201.google.com (mail-ua0-f201.google.com [209.85.217.201]) by lists.denx.de (Postfix) with ESMTPS id 893E6C21FED for ; Wed, 8 Aug 2018 09:54:45 +0000 (UTC) Received: by mail-ua0-f201.google.com with SMTP id x17-v6so1268619uap.12 for ; Wed, 08 Aug 2018 02:54:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=vPY5bVxP0IrJJUSEkTYdY43bFIztUCNfcJjCFMgZZA4=; b=fhuRqkQqpBY/g1Nho0CtAcOVkUHQUeXVe3kSQWUnKK5IJbyJF90OEx0efD+RVR4Tiy DSOE6Lr335tXzl8dO4ZEwvRjhyqZNt+ZHHAzQrj3LL1L9Ud5xH3M5TGSdqsMsd+qMl0t 9mEW4jA9/gnDo5floALzv2fVoX5NUNB9FDpGjYwiWOTl3/L7OoaB7L9VQBdiACkRmApP 8lyiCSKikw0wWQPcsRQUgwlCrw1q5YtDmTz2E0j57H8OEHNsD2Y/n5Wh51+Bl1n0IqD5 qVdZI2cHkY5pl8B55NP/BZHxVt0j8wwowprMXP+DeiYTFIk43zjGnAPggoEZxQbaf6xK 4ZJA== X-Gm-Message-State: AOUpUlGIsGRaphf4W+bpRkvkFxVUqUQofYKq2iVIMtkRk8qW+vib20Qf FCDbdJ/XplDsDA/OYWtetFN5GzY= X-Google-Smtp-Source: AA+uWPxVxoZdcOFFz9FQAaDY7LC2ti5pLC+SYL2f1tyVuKDIFf7QRI9/2d/YPBkdoZNjksWxyZhSkr8= X-Received: by 2002:a1f:a10a:: with SMTP id k10-v6mr1119592vke.27.1533722084702; Wed, 08 Aug 2018 02:54:44 -0700 (PDT) Date: Wed, 8 Aug 2018 03:54:19 -0600 In-Reply-To: <20180808095433.230882-1-sjg@chromium.org> Message-Id: <20180808095433.230882-5-sjg@chromium.org> Mime-Version: 1.0 References: <20180808095433.230882-1-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v9 04/18] efi: sandbox: Enable EFI loader build for sandbox X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" This allows this feature to build within sandbox. This is for testing purposes only since it is not possible for sandbox to load native code. Signed-off-by: Simon Glass --- Changes in v9: None Changes in v8: None Changes in v7: - Update patch subject s/builder/build/ Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: - Init the 'rows' and 'cols' vars to avoid a compiler error (gcc 4.8.4) Changes in v2: None lib/efi_loader/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index ce6a09f0b43..bfd7b19d791 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -1,6 +1,6 @@ config EFI_LOADER bool "Support running EFI Applications in U-Boot" - depends on (ARM || X86 || RISCV) && OF_LIBFDT + depends on (ARM || X86 || RISCV || SANDBOX) && OF_LIBFDT # We need EFI_STUB_64BIT to be set on x86_64 with EFI_STUB depends on !EFI_STUB || !X86_64 || EFI_STUB_64BIT # We need EFI_STUB_32BIT to be set on x86_32 with EFI_STUB From patchwork Wed Aug 8 09:54:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 954881 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41ln3S3pfGz9s0n for ; Wed, 8 Aug 2018 20:01:40 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 3BF22C21FE0; Wed, 8 Aug 2018 09:56:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 11D32C2200A; Wed, 8 Aug 2018 09:55:12 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 4DC89C22002; Wed, 8 Aug 2018 09:54:52 +0000 (UTC) Received: from mail-yw1-f74.google.com (mail-yw1-f74.google.com [209.85.161.74]) by lists.denx.de (Postfix) with ESMTPS id CF890C21FF9 for ; Wed, 8 Aug 2018 09:54:47 +0000 (UTC) Received: by mail-yw1-f74.google.com with SMTP id p8-v6so1879707ywl.14 for ; Wed, 08 Aug 2018 02:54:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=/a8D5oEOq8+I1GXspsT69DPVmTrqTHFSgJxoDIdYwPs=; b=PcvwwxN0fwuCb56LyPJSxBFakWgSTedc44Db4veQfKjQ7L6dBYtUmmEe28Olkl93+n tvBUZ4SiLWPgu4vMa/uoOrWvUQNhnn0mjb5DkIgCltlWZquErSuaPx6Fr4JoUxDPBgCb zcNKNnBHqVGkatf3z/8UdvZlgSwXQ794C2bX74+kEYE/gZtKD5zuZdcZNGuFpobaYvX1 JhAiIRA2f/wCfdSYvuOYPkubDNyNM/aSw2GZiKKuAYXM9CEMswbCu2fAd4pgBFH9XWKn 8QfMYYzKCvfUJq1VimdsD6Ig4HCmgu4GwuFNoxmqiIklJVISNdgNpZ17xCsJUK81vOMQ Kj1Q== X-Gm-Message-State: AOUpUlElHX71omvb2GU5He2ZzaKXPCNUmKMeE3qiqInUgtHBMbVz1yxc jPcjHUtTcMWDytq2wmeVYWFUqmg= X-Google-Smtp-Source: AA+uWPwobFYI/QptWd8HYgtPQUS76ptwqSySga6X2bcFLMcrrvhFxEeb0zeym1AaDmbl3HrU6KK0ei8= X-Received: by 2002:a25:9185:: with SMTP id w5-v6mr451272ybl.78.1533722086659; Wed, 08 Aug 2018 02:54:46 -0700 (PDT) Date: Wed, 8 Aug 2018 03:54:20 -0600 In-Reply-To: <20180808095433.230882-1-sjg@chromium.org> Message-Id: <20180808095433.230882-6-sjg@chromium.org> Mime-Version: 1.0 References: <20180808095433.230882-1-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v9 05/18] efi: Split out test init/uninit into functions X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" We plan to run more than one EFI test. In order to avoid duplicating code, create functions which handle preparing for running the test and cleaning up afterwards. Also shorten the awfully long variable names here. Signed-off-by: Simon Glass --- Changes in v9: - Add comments to bootefi_test_prepare() about the memset()s Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: - Drop call to efi_init_obj_list() which is now done in do_bootefi() Changes in v4: None Changes in v3: - Add new patch to split out test init/uninit into functions Changes in v2: None cmd/bootefi.c | 91 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 24 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index b60c151fb4a..af13492836d 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -409,6 +409,64 @@ exit: return ret; } +#ifdef CONFIG_CMD_BOOTEFI_SELFTEST +/** + * bootefi_test_prepare() - prepare to run an EFI test + * + * This sets things up so we can call EFI functions. This involves preparing + * the 'gd' pointer and setting up the load ed image data structures. + * + * @image: Pointer to a struct which will hold the loaded image info. + * This struct will be inited by this function before use. + * @obj: Pointer to a struct which will hold the loaded image object + * This struct will be inited by this function before use. + * @path: File path to the test being run (often just the test name with a + * backslash before it + * @test_func: Address of the test function that is being run + * @return 0 if OK, -ve on error + */ +static efi_status_t bootefi_test_prepare(struct efi_loaded_image *image, + struct efi_object *obj, + const char *path, ulong test_func) +{ + /* Zero out the structures since the caller did not */ + memset(image, '\0', sizeof(*image)); + memset(obj, '\0', sizeof(*obj)); + + /* Construct a dummy device path */ + bootefi_device_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, + (uintptr_t)test_func, + (uintptr_t)test_func); + bootefi_image_path = efi_dp_from_file(NULL, 0, path); + efi_setup_loaded_image(image, obj, bootefi_device_path, + bootefi_image_path); + /* + * gd lives in a fixed register which may get clobbered while we execute + * the payload. So save it here and restore it on every callback entry + */ + efi_save_gd(); + + /* Transfer environment variable efi_selftest as load options */ + set_load_options(image, "efi_selftest"); + + return 0; +} + +/** + * bootefi_test_finish() - finish up after running an EFI test + * + * @image: Pointer to a struct which holds the loaded image info + * @obj: Pointer to a struct which holds the loaded image object + */ +static void bootefi_test_finish(struct efi_loaded_image *image, + struct efi_object *obj) +{ + efi_restore_gd(); + free(image->load_options); + list_del(&obj->link); +} +#endif /* CONFIG_CMD_BOOTEFI_SELFTEST */ + static int do_bootefi_bootmgr_exec(void) { struct efi_device_path *device_path, *file_path; @@ -489,31 +547,16 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) #endif #ifdef CONFIG_CMD_BOOTEFI_SELFTEST if (!strcmp(argv[1], "selftest")) { - struct efi_loaded_image loaded_image_info = {}; - struct efi_object loaded_image_info_obj = {}; - - /* Construct a dummy device path. */ - bootefi_device_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, - (uintptr_t)&efi_selftest, - (uintptr_t)&efi_selftest); - bootefi_image_path = efi_dp_from_file(NULL, 0, "\\selftest"); - - efi_setup_loaded_image(&loaded_image_info, - &loaded_image_info_obj, - bootefi_device_path, bootefi_image_path); - /* - * gd lives in a fixed register which may get clobbered while we - * execute the payload. So save it here and restore it on every - * callback entry - */ - efi_save_gd(); - /* Transfer environment variable efi_selftest as load options */ - set_load_options(&loaded_image_info, "efi_selftest"); + struct efi_loaded_image image; + struct efi_object obj; + + if (bootefi_test_prepare(&image, &obj, "\\selftest", + (uintptr_t)&efi_selftest)) + return CMD_RET_FAILURE; + /* Execute the test */ - r = efi_selftest(loaded_image_info_obj.handle, &systab); - efi_restore_gd(); - free(loaded_image_info.load_options); - list_del(&loaded_image_info_obj.link); + r = efi_selftest(obj.handle, &systab); + bootefi_test_finish(&image, &obj); return r != EFI_SUCCESS; } else #endif From patchwork Wed Aug 8 09:54:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 954877 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41ln0N2CNxz9s0n for ; Wed, 8 Aug 2018 19:59:00 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id C94E2C21F5E; Wed, 8 Aug 2018 09:56:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 1BFC4C21FEF; Wed, 8 Aug 2018 09:55:09 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6B4E3C21FB5; Wed, 8 Aug 2018 09:54:53 +0000 (UTC) Received: from mail-it0-f73.google.com (mail-it0-f73.google.com [209.85.214.73]) by lists.denx.de (Postfix) with ESMTPS id 40511C21FE0 for ; Wed, 8 Aug 2018 09:54:49 +0000 (UTC) Received: by mail-it0-f73.google.com with SMTP id n194-v6so1965291itn.0 for ; Wed, 08 Aug 2018 02:54:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=WcWDqEnYRHv9EDP7nNjeShCB8xYkSg33S6iuKMm9KLk=; b=Y9lSldZu/yBLFujiVl9d5CoB+3RFd2HNgwiYaDDzL9HhMVHF7SoBHL8p3l2A8Y8f+9 a1gZCBwnyfnsEbnkk3xf9JqOFdVSjylwbnANVQpaIM8DOmB40CPsz/78kDiuus5b+VHD dqdq6+wKhOrqWczT0Fk3Fhf/6gZbyTZZCLd5Vyfb+71yHi1MsB4gKh0oTmMnAqLtyK59 raKcsG4pGU2JFTVV3Jul81kHmQ5Kf3s4U37XeKBsk2Gy0En+suoOQyRo+nFqcijhJba1 ua8NKxJ5uSSy8pXkZpcXNyppbVJuOyeVy/4nRBtBqMpSZlCiMzkbp+8nPjJoCiGAH64a OHAA== X-Gm-Message-State: AOUpUlEIymzoAP5rw2JveuczA6QVhHO5/ANLXP+xBT+YDwVICWvR5+o+ WpMyVauYsH84avam4K81Muy6ozc= X-Google-Smtp-Source: AA+uWPweX1gUbGtjjKTsv02beOX5duHlS39P/iaIA3yBYHesObw4amEwms71wSV07gBrsWf4dUTM2PA= X-Received: by 2002:a5e:930a:: with SMTP id k10-v6mr830584iom.37.1533722088310; Wed, 08 Aug 2018 02:54:48 -0700 (PDT) Date: Wed, 8 Aug 2018 03:54:21 -0600 In-Reply-To: <20180808095433.230882-1-sjg@chromium.org> Message-Id: <20180808095433.230882-7-sjg@chromium.org> Mime-Version: 1.0 References: <20180808095433.230882-1-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v9 06/18] efi: sandbox: Add a simple 'bootefi test' command X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" This jumps to test code which can call directly into the EFI support. It does not need a separate image so it is easy to write tests with it. This test can be executed without causing problems to the run-time environment (e.g. U-Boot does not need to reboot afterwards). For now the test just outputs a message. To try it: ./sandbox/u-boot -c "bootefi test" U-Boot 2017.09-00204-g696c9855fe (Sep 17 2017 - 16:43:53 -0600) DRAM: 128 MiB MMC: Using default environment In: serial Out: serial Err: serial SCSI: Net: No ethernet found. IDE: Bus 0: not available Found 0 disks WARNING: booting without device tree Hello, world! Test passed Signed-off-by: Simon Glass --- Changes in v9: None Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None cmd/bootefi.c | 26 ++++++++++++++++++++------ include/efi_loader.h | 3 +++ lib/efi_loader/Kconfig | 10 ++++++++++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_test.c | 16 ++++++++++++++++ 5 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 lib/efi_loader/efi_test.c diff --git a/cmd/bootefi.c b/cmd/bootefi.c index af13492836d..edb7f786a27 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -409,7 +409,6 @@ exit: return ret; } -#ifdef CONFIG_CMD_BOOTEFI_SELFTEST /** * bootefi_test_prepare() - prepare to run an EFI test * @@ -465,7 +464,6 @@ static void bootefi_test_finish(struct efi_loaded_image *image, free(image->load_options); list_del(&obj->link); } -#endif /* CONFIG_CMD_BOOTEFI_SELFTEST */ static int do_bootefi_bootmgr_exec(void) { @@ -497,8 +495,10 @@ static int do_bootefi_bootmgr_exec(void) /* Interpreter command to boot an arbitrary EFI image from memory */ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - unsigned long addr; + struct efi_loaded_image image; + struct efi_object obj; char *saddr; + unsigned long addr; efi_status_t r; unsigned long fdt_addr; void *fdt; @@ -545,11 +545,25 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) memcpy(map_sysmem(addr, size), __efi_helloworld_begin, size); } else #endif + if (IS_ENABLED(CONFIG_BOOTEFI_TEST) && !strcmp(argv[1], "test")) { + int ret; + + if (bootefi_test_prepare(&image, &obj, "\\test", + (ulong)&efi_test)) + return CMD_RET_FAILURE; + + ret = efi_test(&image, &systab); + bootefi_test_finish(&image, &obj); + if (ret) { + printf("Test failed: err=%d\n", ret); + return CMD_RET_FAILURE; + } + printf("Test passed\n"); + + return 0; + } #ifdef CONFIG_CMD_BOOTEFI_SELFTEST if (!strcmp(argv[1], "selftest")) { - struct efi_loaded_image image; - struct efi_object obj; - if (bootefi_test_prepare(&image, &obj, "\\selftest", (uintptr_t)&efi_selftest)) return CMD_RET_FAILURE; diff --git a/include/efi_loader.h b/include/efi_loader.h index 57ca5502726..616dfae7b70 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -457,6 +457,9 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name, efi_guid_t *vendor, void *efi_bootmgr_load(struct efi_device_path **device_path, struct efi_device_path **file_path); +/* Perform EFI tests */ +int efi_test(efi_handle_t image_handle, struct efi_system_table *systab); + #else /* defined(EFI_LOADER) && !defined(CONFIG_SPL_BUILD) */ /* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */ diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index bfd7b19d791..254b18da744 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -23,3 +23,13 @@ config EFI_LOADER_BOUNCE_BUFFER Some hardware does not support DMA to full 64bit addresses. For this hardware we can create a bounce buffer so that payloads don't have to worry about platform details. + +config BOOTEFI_TEST + bool "Provide a test for the EFI loader" + depends on EFI_LOADER && SANDBOX + default y + help + Provides a test of the EFI loader functionality accessed via the + command line ('bootefi test'). This runs within U-Boot so does not + need a separate EFI application to work. It aims to include coverage + of all EFI code which can be accessed within sandbox. diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index 1ffbf52a898..e6a23d96122 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -27,3 +27,4 @@ obj-$(CONFIG_PARTITIONS) += efi_disk.o obj-$(CONFIG_NET) += efi_net.o obj-$(CONFIG_GENERATE_ACPI_TABLE) += efi_acpi.o obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += efi_smbios.o +obj-$(CONFIG_BOOTEFI_TEST) += efi_test.o diff --git a/lib/efi_loader/efi_test.c b/lib/efi_loader/efi_test.c new file mode 100644 index 00000000000..4b8d49f324b --- /dev/null +++ b/lib/efi_loader/efi_test.c @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2017, Google Inc. + */ + +#include +#include + +int efi_test(efi_handle_t image_handle, struct efi_system_table *systable) +{ + struct efi_simple_text_output_protocol *con_out = systable->con_out; + + con_out->output_string(con_out, L"Hello, world!\n"); + + return 0; +} From patchwork Wed Aug 8 09:54:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 954883 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41ln4p2g33z9s1x for ; Wed, 8 Aug 2018 20:02:50 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 014CEC21FDE; Wed, 8 Aug 2018 09:56:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 9AE4DC21FDB; Wed, 8 Aug 2018 09:55:07 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id DF923C21FDB; Wed, 8 Aug 2018 09:54:55 +0000 (UTC) Received: from mail-ua0-f202.google.com (mail-ua0-f202.google.com [209.85.217.202]) by lists.denx.de (Postfix) with ESMTPS id D0097C21FCF for ; Wed, 8 Aug 2018 09:54:50 +0000 (UTC) Received: by mail-ua0-f202.google.com with SMTP id k5-v6so1281467ual.10 for ; Wed, 08 Aug 2018 02:54:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=D2oJc2YwHq6nd3baXyE84ncvhOrXj2FWNFMOkFAyJDc=; b=p0to80bm1ELS67E6fvd8wBDZ48iJ3IiDIB3OLaPQVeJMzLLiK7P5SpehsB4I3/rxsk fO0LC+LRio+k46oKI/f53SCGAlUl7g4leRzOOZYha3BqyKjNeulhYvK1URt49r0ZUWCy 2W0TNc9URUjcgFwpHdTLq+mDyn49Dbjt6r7ggEuuueZNneFT/NKNI3OKqqRgJ/SjM9u1 ZmZSSX7DwBvr0fTgAlGPRcxdxPUhSLGoKiyLD6DNY9/K2WnM/Ua2xvViZfMjwd+ZSjXM AqIQPyJB4rI+SVlOBOGryVigQGLsw1aFZrwKAilHEfSJV8ULGRdgvLZ5dCYl5x/UaNM6 X5Og== X-Gm-Message-State: AOUpUlEDaIfuLG1yvecpJOTq8piKGr34BklrcvnCaTjR5UQaiubkDsFC 2NyxsRAH10WT9gi4ngdwfooZp6E= X-Google-Smtp-Source: AA+uWPy9diRp4EgA44tr0yCUwcuNEksUPnFHbDO9nvVYESMDPkQOyQq9MhAqN1yZNYO2IJ1pXy3VTuo= X-Received: by 2002:a1f:898f:: with SMTP id l137-v6mr1053487vkd.33.1533722089940; Wed, 08 Aug 2018 02:54:49 -0700 (PDT) Date: Wed, 8 Aug 2018 03:54:22 -0600 In-Reply-To: <20180808095433.230882-1-sjg@chromium.org> Message-Id: <20180808095433.230882-8-sjg@chromium.org> Mime-Version: 1.0 References: <20180808095433.230882-1-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v9 07/18] efi: Create a function to set up for running EFI code X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Add a new bootefi_run_prepare() function which holds common code used to set up U-Boot to run EFI code. Make use of this from the existing bootefi_test_prepare() function, as well as do_bootefi_exec(). Also shorten a few variable names. Signed-off-by: Simon Glass --- Changes in v9: None Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: - Drop call to efi_init_obj_list() which is now done in do_bootefi() - Introduce load_options_path to specifyc U-Boot env var for load_options_path Changes in v4: - Rebase to master Changes in v3: - Add patch to create a function to set up for running EFI code Changes in v2: None cmd/bootefi.c | 81 ++++++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index edb7f786a27..54732ba3f37 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -290,6 +290,26 @@ static efi_status_t efi_install_fdt(void *fdt) return ret; } +static efi_status_t bootefi_run_prepare(struct efi_loaded_image *image, + struct efi_object *obj, + const char *load_options_path, + struct efi_device_path *device_path, + struct efi_device_path *image_path) +{ + efi_setup_loaded_image(image, obj, device_path, image_path); + + /* + * gd lives in a fixed register which may get clobbered while we execute + * the payload. So save it here and restore it on every callback entry + */ + efi_save_gd(); + + /* Transfer environment variable as load options */ + set_load_options(image, load_options_path); + + return 0; +} + /* * Load an EFI payload into a newly allocated piece of memory, register all * EFI objects it would want to access and jump to it. @@ -298,8 +318,8 @@ static efi_status_t do_bootefi_exec(void *efi, struct efi_device_path *device_path, struct efi_device_path *image_path) { - struct efi_loaded_image loaded_image_info = {}; - struct efi_object loaded_image_info_obj = {}; + struct efi_loaded_image image; + struct efi_object obj; struct efi_object mem_obj = {}; struct efi_device_path *memdp = NULL; efi_status_t ret; @@ -327,19 +347,13 @@ static efi_status_t do_bootefi_exec(void *efi, assert(device_path && image_path); } - efi_setup_loaded_image(&loaded_image_info, &loaded_image_info_obj, - device_path, image_path); + ret = bootefi_run_prepare(&image, &obj, "bootargs", device_path, + image_path); + if (ret) + return ret; - /* - * gd lives in a fixed register which may get clobbered while we execute - * the payload. So save it here and restore it on every callback entry - */ - efi_save_gd(); - - /* Transfer environment variable bootargs as load options */ - set_load_options(&loaded_image_info, "bootargs"); /* Load the EFI payload */ - entry = efi_load_pe(efi, &loaded_image_info); + entry = efi_load_pe(efi, &image); if (!entry) { ret = EFI_LOAD_ERROR; goto exit; @@ -347,10 +361,10 @@ static efi_status_t do_bootefi_exec(void *efi, if (memdp) { struct efi_device_path_memory *mdp = (void *)memdp; - mdp->memory_type = loaded_image_info.image_code_type; - mdp->start_address = (uintptr_t)loaded_image_info.image_base; + mdp->memory_type = image.image_code_type; + mdp->start_address = (uintptr_t)image.image_base; mdp->end_address = mdp->start_address + - loaded_image_info.image_size; + image.image_size; } /* we don't support much: */ @@ -360,8 +374,8 @@ static efi_status_t do_bootefi_exec(void *efi, /* Call our payload! */ debug("%s:%d Jumping to 0x%lx\n", __func__, __LINE__, (long)entry); - if (setjmp(&loaded_image_info.exit_jmp)) { - ret = loaded_image_info.exit_status; + if (setjmp(&image.exit_jmp)) { + ret = image.exit_status; goto exit; } @@ -373,7 +387,7 @@ static efi_status_t do_bootefi_exec(void *efi, /* Move into EL2 and keep running there */ armv8_switch_to_el2((ulong)entry, - (ulong)&loaded_image_info_obj.handle, + (ulong)&obj.handle, (ulong)&systab, 0, (ulong)efi_run_in_el2, ES_TO_AARCH64); @@ -390,7 +404,7 @@ static efi_status_t do_bootefi_exec(void *efi, secure_ram_addr(_do_nonsec_entry)( efi_run_in_hyp, (uintptr_t)entry, - (uintptr_t)loaded_image_info_obj.handle, + (uintptr_t)obj.handle, (uintptr_t)&systab); /* Should never reach here, efi exits with longjmp */ @@ -398,11 +412,11 @@ static efi_status_t do_bootefi_exec(void *efi, } #endif - ret = efi_do_enter(loaded_image_info_obj.handle, &systab, entry); + ret = efi_do_enter(obj.handle, &systab, entry); exit: /* image has returned, loaded-image obj goes *poof*: */ - list_del(&loaded_image_info_obj.link); + list_del(&obj.link); if (mem_obj.handle) list_del(&mem_obj.link); @@ -422,11 +436,13 @@ exit: * @path: File path to the test being run (often just the test name with a * backslash before it * @test_func: Address of the test function that is being run + * @load_options_path: U-Boot environment variable to use as load options * @return 0 if OK, -ve on error */ static efi_status_t bootefi_test_prepare(struct efi_loaded_image *image, struct efi_object *obj, - const char *path, ulong test_func) + const char *path, ulong test_func, + const char *load_options_path) { /* Zero out the structures since the caller did not */ memset(image, '\0', sizeof(*image)); @@ -437,18 +453,8 @@ static efi_status_t bootefi_test_prepare(struct efi_loaded_image *image, (uintptr_t)test_func, (uintptr_t)test_func); bootefi_image_path = efi_dp_from_file(NULL, 0, path); - efi_setup_loaded_image(image, obj, bootefi_device_path, - bootefi_image_path); - /* - * gd lives in a fixed register which may get clobbered while we execute - * the payload. So save it here and restore it on every callback entry - */ - efi_save_gd(); - - /* Transfer environment variable efi_selftest as load options */ - set_load_options(image, "efi_selftest"); - - return 0; + return bootefi_run_prepare(image, obj, load_options_path, + bootefi_device_path, bootefi_image_path); } /** @@ -549,7 +555,7 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) int ret; if (bootefi_test_prepare(&image, &obj, "\\test", - (ulong)&efi_test)) + (ulong)&efi_test, "efi_test")) return CMD_RET_FAILURE; ret = efi_test(&image, &systab); @@ -565,7 +571,8 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) #ifdef CONFIG_CMD_BOOTEFI_SELFTEST if (!strcmp(argv[1], "selftest")) { if (bootefi_test_prepare(&image, &obj, "\\selftest", - (uintptr_t)&efi_selftest)) + (uintptr_t)&efi_selftest, + "efi_selftest")) return CMD_RET_FAILURE; /* Execute the test */ From patchwork Wed Aug 8 09:54:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 954885 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41lnCS32Xjz9s1x for ; Wed, 8 Aug 2018 20:08:35 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 0DED9C21FE4; Wed, 8 Aug 2018 09:55:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 2FD39C21FDE; Wed, 8 Aug 2018 09:55:06 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id CC993C21FCF; Wed, 8 Aug 2018 09:54:57 +0000 (UTC) Received: from mail-ua0-f202.google.com (mail-ua0-f202.google.com [209.85.217.202]) by lists.denx.de (Postfix) with ESMTPS id E992CC21FF7 for ; Wed, 8 Aug 2018 09:54:52 +0000 (UTC) Received: by mail-ua0-f202.google.com with SMTP id h11-v6so1242800uao.22 for ; Wed, 08 Aug 2018 02:54:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=zNcROBsg1KFaC0SsrS+pimzcglxt0IeAU/+JNiKFHH0=; b=k83Qu3G+mzd/C2aP3E2k4Q8ZaTS1rrm3Cp+zh/M+Aq7A9KHJXXSMVTITcHzCiMHzic seHDDH5IJJFmDfCis+IOFORxQBWnl/kEtMcp9D+RCtcA0J//PJRYBCPsZdgKMRO1Goje 5yL1g/yIYcqkMlCBlHmxOjzu57pa4Swcsrl7FQX+l4LcGLhC2aAnMP5zKrX4FGiD8MMX RXdJ3LXwZNENP3ELL7XV6y3JkuasH1HyTcbX4hHQWJDQMfNSl7WmFl1o2N25dr7GS4EQ J3LG7Xl4XZyw+ZO56pPnWPRoumK6DQ266Ppev6DfAP5eGw8Wr96NR8cEjPzp6piIEiKK v48w== X-Gm-Message-State: AOUpUlGc8cZdygx+cdjsPQ8Y/MayujtJWsURSEnZ5GOG5fa8Xik2+hjT FHR8GAx/Xvr9/+dCqPQ7IaqRJfA= X-Google-Smtp-Source: AA+uWPxujczjnFI92wGF1CZ55ELe2rahLyvd+/lc4AK363bLLBlUvGsh7i9HbBWGlrVWk9qmbZLoN2M= X-Received: by 2002:ab0:7388:: with SMTP id l8-v6mr879122uap.89.1533722092066; Wed, 08 Aug 2018 02:54:52 -0700 (PDT) Date: Wed, 8 Aug 2018 03:54:23 -0600 In-Reply-To: <20180808095433.230882-1-sjg@chromium.org> Message-Id: <20180808095433.230882-9-sjg@chromium.org> Mime-Version: 1.0 References: <20180808095433.230882-1-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v9 08/18] efi: Rename bootefi_test_finish() to bootefi_run_finish() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" This function can be used from do_bootefi_exec() so that we use mostly the same code for a normal EFI application and an EFI test. Rename the function and use it in both places. Signed-off-by: Simon Glass --- Changes in v9: None Changes in v8: None Changes in v7: - Drop patch "efi: Init the 'rows' and 'cols' variables" - Drop patches previous applied Changes in v6: None Changes in v5: - Rebase to master Changes in v4: - Rebase to master Changes in v3: - Add new patch to rename bootefi_test_finish() to bootefi_run_finish() Changes in v2: None cmd/bootefi.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 54732ba3f37..905e659da42 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -310,6 +310,20 @@ static efi_status_t bootefi_run_prepare(struct efi_loaded_image *image, return 0; } +/** + * bootefi_run_finish() - finish up after running an EFI test + * + * @image: Pointer to a struct which holds the loaded image info + * @obj: Pointer to a struct which holds the loaded image object + */ +static void bootefi_run_finish(struct efi_loaded_image *image, + struct efi_object *obj) +{ + efi_restore_gd(); + free(image->load_options); + list_del(&obj->link); +} + /* * Load an EFI payload into a newly allocated piece of memory, register all * EFI objects it would want to access and jump to it. @@ -415,8 +429,7 @@ static efi_status_t do_bootefi_exec(void *efi, ret = efi_do_enter(obj.handle, &systab, entry); exit: - /* image has returned, loaded-image obj goes *poof*: */ - list_del(&obj.link); + bootefi_run_finish(&image, &obj); if (mem_obj.handle) list_del(&mem_obj.link); @@ -457,20 +470,6 @@ static efi_status_t bootefi_test_prepare(struct efi_loaded_image *image, bootefi_device_path, bootefi_image_path); } -/** - * bootefi_test_finish() - finish up after running an EFI test - * - * @image: Pointer to a struct which holds the loaded image info - * @obj: Pointer to a struct which holds the loaded image object - */ -static void bootefi_test_finish(struct efi_loaded_image *image, - struct efi_object *obj) -{ - efi_restore_gd(); - free(image->load_options); - list_del(&obj->link); -} - static int do_bootefi_bootmgr_exec(void) { struct efi_device_path *device_path, *file_path; @@ -559,7 +558,7 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return CMD_RET_FAILURE; ret = efi_test(&image, &systab); - bootefi_test_finish(&image, &obj); + bootefi_run_finish(&image, &obj); if (ret) { printf("Test failed: err=%d\n", ret); return CMD_RET_FAILURE; @@ -577,7 +576,7 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) /* Execute the test */ r = efi_selftest(obj.handle, &systab); - bootefi_test_finish(&image, &obj); + bootefi_run_finish(&image, &obj); return r != EFI_SUCCESS; } else #endif From patchwork Wed Aug 8 09:54:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 954884 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41ln6J217Gz9s0n for ; Wed, 8 Aug 2018 20:04:08 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id D699DC21D72; Wed, 8 Aug 2018 09:58:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 9FB86C21FDB; Wed, 8 Aug 2018 09:56:36 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 93746C21FF3; Wed, 8 Aug 2018 09:54:58 +0000 (UTC) Received: from mail-it0-f73.google.com (mail-it0-f73.google.com [209.85.214.73]) by lists.denx.de (Postfix) with ESMTPS id BA87CC21FEB for ; Wed, 8 Aug 2018 09:54:54 +0000 (UTC) Received: by mail-it0-f73.google.com with SMTP id h5-v6so2031943itb.3 for ; Wed, 08 Aug 2018 02:54:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=EGNtFZX0049AEFnXXCatG+9aOPrFVfkqsiQy+ADLGLg=; b=dIa7N4tPVKr6DKEA4M07NsJyC8TGaTSNVGHaiPYi+w4E3oikwGUl1/l5rLekP/dP2L ZNjR6QigcPqSZX1WPO6t367pQDub9TLEZG8XkypHOGb6aVDlODGLp6u07bZj2uhcC0e6 B/TAZKAyCVMvsKsjeS/DpXj79zj8BVqh+4LA90Pp7UAEN7uOckdekQ4+4r6HaCpoEWCo SJ/NB+PqX2CTQC9F1sLUXWy0FuMX+RPElMXg7F8aAHrwwbjLa29tV9I9YGTDQRbDj+nx CuZcDc6wLkmZWcGpr5ISuYmTZaL1z98VPy7erskSZa7fSIQ+WJHczGNb4SOaq8QG+1AK 7Afg== X-Gm-Message-State: AOUpUlGxRMm21xi7Q0BKehufUR5IvLZnv5E4oGemAzLwCOngYFeVooEF 8Un0zjWARJ+1LEp4whFhlv0iLGM= X-Google-Smtp-Source: AA+uWPwnjerLXkoGB8JxAj2hOSwz/Iu/rkBdlkAlO6bDI9orlWAR6Srgv05bnA8fUWKbU/JP0wEfUVo= X-Received: by 2002:a24:391:: with SMTP id e139-v6mr818361ite.29.1533722093803; Wed, 08 Aug 2018 02:54:53 -0700 (PDT) Date: Wed, 8 Aug 2018 03:54:24 -0600 In-Reply-To: <20180808095433.230882-1-sjg@chromium.org> Message-Id: <20180808095433.230882-10-sjg@chromium.org> Mime-Version: 1.0 References: <20180808095433.230882-1-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v9 09/18] sandbox: Align RAM buffer to the machine page size X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" At present the sandbox RAM buffer is not aligned to any particular address boundary. This makes the internal pointers somewhat random with respect to the associated RAM buffer addresses. Align the buffer to the page size of the machine to help with this. Signed-off-by: Simon Glass --- Changes in v9: None Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None arch/sandbox/cpu/os.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 5839932b005..a1a982af2de 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -143,14 +143,15 @@ void os_tty_raw(int fd, bool allow_sigs) void *os_malloc(size_t length) { struct os_mem_hdr *hdr; + int page_size = getpagesize(); - hdr = mmap(NULL, length + sizeof(*hdr), PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + hdr = mmap(NULL, length + page_size, + PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (hdr == MAP_FAILED) return NULL; hdr->length = length; - return hdr + 1; + return (void *)hdr + page_size; } void os_free(void *ptr) From patchwork Wed Aug 8 09:54:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 954891 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41lndD2shwz9s4V for ; Wed, 8 Aug 2018 20:27:28 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 63D41C21FEF; Wed, 8 Aug 2018 09:57:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id CFE22C21FB5; Wed, 8 Aug 2018 09:55:53 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 35558C21FF4; Wed, 8 Aug 2018 09:55:00 +0000 (UTC) Received: from mail-qk0-f201.google.com (mail-qk0-f201.google.com [209.85.220.201]) by lists.denx.de (Postfix) with ESMTPS id 5B380C21FD6 for ; Wed, 8 Aug 2018 09:54:56 +0000 (UTC) Received: by mail-qk0-f201.google.com with SMTP id z18-v6so1649086qki.22 for ; Wed, 08 Aug 2018 02:54:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=PfqF0y5E/R+5RiroycikscgTsxu50l9IAJUBvr5dsvo=; b=ZFJvjZb974z8dQk/bKuapOefi22WJ8x/SdaFI+VtDtjzA1ZQlf43YV0uVyfjwIhFF4 YgMwcZQ/+Lvs2mb4ksv6vc2Z/8X3uS7kSvlNR/FO4FABnw8Rf1gDzAkCC5INStxQY7LC 3DrWOLuEGp94wmyBdG1ykfghPds/76F/xOaEBYsT66C+k3zETyegqD1FnxpGTjnQjnep gnFLR0XPsuZQptq4g6SsHV4nalK32UsYVTMykxMTrDFF8XQpqKoMy2XXi9FTQdybwnzT 8+pcgDkU7InBqDF0rGqpQz6ozWvxw8nFA1ZMul4tHhrBBCk0peuzbOx7I7GlOJCIQrax txxQ== X-Gm-Message-State: AOUpUlF7gocLx6Y+FEc0a/gUKgOJQgBdVZxAafxr771WM2ORcTmk4Izx 0m1jL8XlqeB0msDWl8+7fRJ3saE= X-Google-Smtp-Source: AA+uWPxmhMHrS/GSqFJDfGU1QVbL+JOUv4PdV+Uqv0mD0XuhsRk/ZIS7m54dw5zRy00GJPHmUY/ZmXU= X-Received: by 2002:a37:b185:: with SMTP id a127-v6mr1113301qkf.6.1533722095519; Wed, 08 Aug 2018 02:54:55 -0700 (PDT) Date: Wed, 8 Aug 2018 03:54:25 -0600 In-Reply-To: <20180808095433.230882-1-sjg@chromium.org> Message-Id: <20180808095433.230882-11-sjg@chromium.org> Mime-Version: 1.0 References: <20180808095433.230882-1-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v9 10/18] sandbox: Try to start the RAM buffer at a particular address X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Use a starting address of 256MB which should be available. This helps to make sandbox RAM buffers pointers more recognisable. Signed-off-by: Simon Glass --- Changes in v9: None Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None arch/sandbox/cpu/os.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index a1a982af2de..1553aa687df 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -145,7 +145,12 @@ void *os_malloc(size_t length) struct os_mem_hdr *hdr; int page_size = getpagesize(); - hdr = mmap(NULL, length + page_size, + /* + * Use an address that is hopefully available to us so that pointers + * to this memory are fairly obvious. If we end up with a different + * address, that's fine too. + */ + hdr = mmap((void *)0x10000000, length + page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (hdr == MAP_FAILED) return NULL; From patchwork Wed Aug 8 09:54:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 954880 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41ln242mD4z9s0n for ; Wed, 8 Aug 2018 20:00:28 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id E14C1C21FD6; Wed, 8 Aug 2018 09:59:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id CEE94C22000; Wed, 8 Aug 2018 09:56:43 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0171AC21FCE; Wed, 8 Aug 2018 09:55:04 +0000 (UTC) Received: from mail-ua0-f201.google.com (mail-ua0-f201.google.com [209.85.217.201]) by lists.denx.de (Postfix) with ESMTPS id 24E70C21FB2 for ; Wed, 8 Aug 2018 09:54:58 +0000 (UTC) Received: by mail-ua0-f201.google.com with SMTP id m26-v6so1254063uaq.18 for ; Wed, 08 Aug 2018 02:54:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=CRD/8pfUaPn4Dp2sjHXdiVwAB+YX8L7/rp+EQXOuKto=; b=ngBBKFB7klQDEBuiuqxuS1GD2x2yBxGAIWLToCS8aWQW1s2scCKETg+UuEEopLLkU+ DJpiPPuFLEf3Vaqerwvj4vDLNKJngJVL9WNQt49KlMblU5sn+DGUS00JrPtD3vD/sEeL ZCwWxLsdSm0GG+HxI0zEVcUkuHHhcP3KfUT9YLU+Z1dFa5KfWgl+NKDi37Uva5IP6ZvR ufMfaO/FtZUAmi1tLMuxM83KfvHdYVW6P21HleweCBOo0RodSWqDIjIMhTRgnTkTbHU+ 6X34beHdvqgN5cwS5inJzEpYxQJ+u/MCBPE8F4d3qZs6NqVyl9VWQ+8QqcV3kTTLxqAc PoOQ== X-Gm-Message-State: AOUpUlFWsoAGqCWFvzZgknurFhq7ONVXEtyyAhu0irNdUub0Jt+hvBYC woXnReYPrpDDVZwBEMLYO2fib1s= X-Google-Smtp-Source: AA+uWPzDfnY2xgQIqS08YZl2YGX++K5NycN2aKhvkymJhz9UGM+M+d2QCukLGHYgwkcEkhpiFMTmySY= X-Received: by 2002:ab0:7586:: with SMTP id q6-v6mr919579uap.111.1533722097306; Wed, 08 Aug 2018 02:54:57 -0700 (PDT) Date: Wed, 8 Aug 2018 03:54:26 -0600 In-Reply-To: <20180808095433.230882-1-sjg@chromium.org> Message-Id: <20180808095433.230882-12-sjg@chromium.org> Mime-Version: 1.0 References: <20180808095433.230882-1-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v9 11/18] sandbox: Add support for calling abort() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" This function is useful to signal that the application needs to exit immediate. It can be caught with a debugger (e.g. gdb). Add a stub for it so that it can be called from within sandbox when an internal error occurs. Signed-off-by: Simon Glass --- Changes in v9: None Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None arch/sandbox/cpu/os.c | 5 +++++ include/os.h | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 1553aa687df..f8d87df7b63 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -657,3 +657,8 @@ void os_longjmp(ulong *jmp, int ret) { longjmp((struct __jmp_buf_tag *)jmp, ret); } + +void os_abort(void) +{ + abort(); +} diff --git a/include/os.h b/include/os.h index c8e0f52d306..e850f879ec3 100644 --- a/include/os.h +++ b/include/os.h @@ -351,4 +351,8 @@ int os_setjmp(ulong *jmp, int size); */ void os_longjmp(ulong *jmp, int ret); +/** + * os_abort() - Raise SIGABRT to exit sandbox (e.g. to debugger) + */ +void os_abort(void); #endif From patchwork Wed Aug 8 09:54:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 954892 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41lndD2pg7z9s1x for ; Wed, 8 Aug 2018 20:27:28 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 9EFB2C21FFC; Wed, 8 Aug 2018 09:59:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id EB14FC21FCF; Wed, 8 Aug 2018 09:59:05 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id CA9ADC21FB5; Wed, 8 Aug 2018 09:55:04 +0000 (UTC) Received: from mail-yw1-f73.google.com (mail-yw1-f73.google.com [209.85.161.73]) by lists.denx.de (Postfix) with ESMTPS id 25E51C21FFB for ; Wed, 8 Aug 2018 09:55:00 +0000 (UTC) Received: by mail-yw1-f73.google.com with SMTP id l1-v6so1849212ywm.11 for ; Wed, 08 Aug 2018 02:55:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=+GIz+8DPIHaRSQ6SRzgo7DBQItNhvu/5WGsGE0BBu08=; b=rv9BZPodhHtGMlgSv/YPwb2NXNovcKagX7sObf2zDDr94GNhRvWpFOSGTtuKdC8lE0 AJ/gSc7F6J9n4qxjjhiPNvyT7yYtO+xHKBQ+9LUSxBkjL5rKB2H6S58XF/9Dhy6hHjU8 i5P1YqWbq2lHbIqfnrlqs7Dn7jI+3eenGNpOs3NONIbrenYtLdKHVZ+R7oUVEtjDpVS2 mo3OAe02XUsxHyxbYkWczPILx0jKiVVgHX6y3xYsRhiP+PxGNeKyzuicym2dYc0LYraF Uqnovs1uxH1xE+FFdUFD8YYjQiFAo+Hl9G40FqRb31OteVlIGgaMPnqX+OqM4oAyqI1x 1rxg== X-Gm-Message-State: AOUpUlHKgaXLolThzDgvuNv3BZXdVMKHLCVMJSp8y65aDZYpVglutLWP 1twc2DatRCD+1/rOsoTCSjyDOV0= X-Google-Smtp-Source: AA+uWPzr8tLWvwQFeZ+Sqs0TOpsxwYxOMt3DhFAiroExCbTCebb+wmA03qCDJ93O0E/8b4CV3dGCKvU= X-Received: by 2002:a25:3802:: with SMTP id f2-v6mr444736yba.76.1533722099251; Wed, 08 Aug 2018 02:54:59 -0700 (PDT) Date: Wed, 8 Aug 2018 03:54:27 -0600 In-Reply-To: <20180808095433.230882-1-sjg@chromium.org> Message-Id: <20180808095433.230882-13-sjg@chromium.org> Mime-Version: 1.0 References: <20180808095433.230882-1-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v9 12/18] sandbox: Enhance map_to_sysmem() to handle foreign pointers X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" At present map_sysmem() maps an address into the sandbox RAM buffer, return a pointer, while map_to_sysmem() goes the other way. The mapping is currently just 1:1 since a case was not found where a more flexible mapping was needed. PCI does have a separate and more complex mapping, but uses its own mechanism. However this arrange cannot handle one important case, which is where a test declares a stack variable and passes a pointer to it into a U-Boot function which uses map_to_sysmem() to turn it into a address. Since the pointer is not inside emulated DRAM, this will fail. Add a mapping feature which can handle any such pointer, mapping it to a simple tag value which can be passed around in U-Boot as an address. Signed-off-by: Simon Glass --- Changes in v9: - Fix 'thi' typo Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None arch/sandbox/cpu/cpu.c | 141 +++++++++++++++++++++++++++++-- arch/sandbox/cpu/state.c | 8 ++ arch/sandbox/include/asm/state.h | 21 +++++ 3 files changed, 161 insertions(+), 9 deletions(-) diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c index cde0b055a67..e523223ebf8 100644 --- a/arch/sandbox/cpu/cpu.c +++ b/arch/sandbox/cpu/cpu.c @@ -57,14 +57,104 @@ int cleanup_before_linux_select(int flags) return 0; } +/** + * is_in_sandbox_mem() - Checks if a pointer is within sandbox's emulated DRAM + * + * This provides a way to check if a pointer is owned by sandbox (and is within + * its RAM) or not. Sometimes pointers come from a test which conceptually runs + * output sandbox, potentially with direct access to the C-library malloc() + * function, or the sandbox stack (which is not actually within the emulated + * DRAM. + * + * Such pointers obviously cannot be mapped into sandbox's DRAM, so we must + * detect them an process them separately, by recording a mapping to a tag, + * which we can use to map back to the pointer later. + * + * @ptr: Pointer to check + * @return true if this is within sandbox emulated DRAM, false if not + */ +static bool is_in_sandbox_mem(const void *ptr) +{ + return (const uint8_t *)ptr >= gd->arch.ram_buf && + (const uint8_t *)ptr < gd->arch.ram_buf + gd->ram_size; +} + +/** + * phys_to_virt() - Converts a sandbox RAM address to a pointer + * + * Sandbox uses U-Boot addresses from 0 to the size of DRAM. These index into + * the emulated DRAM buffer used by sandbox. This function converts such an + * address to a pointer into this buffer, which can be used to access the + * memory. + * + * If the address is outside this range, it is assumed to be a tag + */ void *phys_to_virt(phys_addr_t paddr) { - return (void *)(gd->arch.ram_buf + paddr); + struct sandbox_mapmem_entry *mentry; + struct sandbox_state *state; + + /* If the address is within emulated DRAM, calculate the value */ + if (paddr < gd->ram_size) + return (void *)(gd->arch.ram_buf + paddr); + + /* + * Otherwise search out list of tags for the correct pointer previously + * created by map_to_sysmem() + */ + state = state_get_current(); + list_for_each_entry(mentry, &state->mapmem_head, sibling_node) { + if (mentry->tag == paddr) { + printf("%s: Used map from %lx to %p\n", __func__, + (ulong)paddr, mentry->ptr); + return mentry->ptr; + } + } + + printf("%s: Cannot map sandbox address %lx (SDRAM from 0 to %lx)\n", + __func__, (ulong)paddr, (ulong)gd->ram_size); + os_abort(); + + /* Not reached */ + return NULL; +} + +struct sandbox_mapmem_entry *find_tag(const void *ptr) +{ + struct sandbox_mapmem_entry *mentry; + struct sandbox_state *state = state_get_current(); + + list_for_each_entry(mentry, &state->mapmem_head, sibling_node) { + if (mentry->ptr == ptr) { + debug("%s: Used map from %p to %lx\n", __func__, ptr, + mentry->tag); + return mentry; + } + } + return NULL; } -phys_addr_t virt_to_phys(void *vaddr) +phys_addr_t virt_to_phys(void *ptr) { - return (phys_addr_t)((uint8_t *)vaddr - gd->arch.ram_buf); + struct sandbox_mapmem_entry *mentry; + + /* + * If it is in emulated RAM, don't bother looking for a tag. Just + * calculate the pointer using the provides offset into the RAM buffer. + */ + if (is_in_sandbox_mem(ptr)) + return (phys_addr_t)((uint8_t *)ptr - gd->arch.ram_buf); + + mentry = find_tag(ptr); + if (!mentry) { + /* Abort so that gdb can be used here */ + printf("%s: Cannot map sandbox address %p (SDRAM from 0 to %lx)\n", + __func__, ptr, (ulong)gd->ram_size); + os_abort(); + } + printf("%s: Used map from %p to %lx\n", __func__, ptr, mentry->tag); + + return mentry->tag; } void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags) @@ -87,24 +177,57 @@ void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags) return phys_to_virt(paddr); } -void unmap_physmem(const void *vaddr, unsigned long flags) +void unmap_physmem(const void *ptr, unsigned long flags) { #ifdef CONFIG_PCI if (map_dev) { - pci_unmap_physmem(vaddr, map_len, map_dev); + pci_unmap_physmem(ptr, map_len, map_dev); map_dev = NULL; } #endif } -void sandbox_set_enable_pci_map(int enable) +phys_addr_t map_to_sysmem(const void *ptr) { - enable_pci_map = enable; + struct sandbox_mapmem_entry *mentry; + + /* + * If it is in emulated RAM, don't bother creating a tag. Just return + * the offset into the RAM buffer. + */ + if (is_in_sandbox_mem(ptr)) + return (u8 *)ptr - gd->arch.ram_buf; + + /* + * See if there is an existing tag with this pointer. If not, set up a + * new one. + */ + mentry = find_tag(ptr); + if (!mentry) { + struct sandbox_state *state = state_get_current(); + + mentry = malloc(sizeof(*mentry)); + if (!mentry) { + printf("%s: Error: Out of memory\n", __func__); + os_exit(ENOMEM); + } + mentry->tag = state->next_tag++; + mentry->ptr = (void *)ptr; + list_add_tail(&mentry->sibling_node, &state->mapmem_head); + debug("%s: Added map from %p to %lx\n", __func__, ptr, + (ulong)mentry->tag); + } + + /* + * Return the tag as the address to use. A later call to map_sysmem() + * will return ptr + */ + return mentry->tag; } -phys_addr_t map_to_sysmem(const void *ptr) +void sandbox_set_enable_pci_map(int enable) { - return (u8 *)ptr - gd->arch.ram_buf; + enable_pci_map = enable; } void flush_dcache_range(unsigned long start, unsigned long stop) diff --git a/arch/sandbox/cpu/state.c b/arch/sandbox/cpu/state.c index cc50819ab93..04a11fed559 100644 --- a/arch/sandbox/cpu/state.c +++ b/arch/sandbox/cpu/state.c @@ -359,6 +359,14 @@ void state_reset_for_test(struct sandbox_state *state) memset(&state->wdt, '\0', sizeof(state->wdt)); memset(state->spi, '\0', sizeof(state->spi)); + + /* + * Set up the memory tag list. Use the top of emulated SDRAM for the + * first tag number, since that address offset is outside the legal + * range, and can be assumed to be a tag. + */ + INIT_LIST_HEAD(&state->mapmem_head); + state->next_tag = state->ram_size; } int state_init(void) diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h index 7ed4b512d2e..a612ce89447 100644 --- a/arch/sandbox/include/asm/state.h +++ b/arch/sandbox/include/asm/state.h @@ -9,6 +9,7 @@ #include #include #include +#include #include /** @@ -45,6 +46,23 @@ struct sandbox_wdt_info { bool running; }; +/** + * struct sandbox_mapmem_entry - maps pointers to/from U-Boot addresses + * + * When map_to_sysmem() is called with an address outside sandbox's emulated + * RAM, a record is created with a tag that can be used to reference that + * pointer. When map_sysmem() is called later with that tag, the pointer will + * be returned, just as it would for a normal sandbox address. + * + * @tag: Address tag (a value which U-Boot uses to refer to the address) + * @ptr: Associated pointer for that tag + */ +struct sandbox_mapmem_entry { + ulong tag; + void *ptr; + struct list_head sibling_node; +}; + /* The complete state of the test system */ struct sandbox_state { const char *cmd; /* Command to execute */ @@ -78,6 +96,9 @@ struct sandbox_state { /* Information about Watchdog */ struct sandbox_wdt_info wdt; + + ulong next_tag; /* Next address tag to allocate */ + struct list_head mapmem_head; /* struct sandbox_mapmem_entry */ }; /* Minimum space we guarantee in the state FDT when calling read/write*/ From patchwork Wed Aug 8 09:54:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 954878 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41ln0w5xK5z9s0n for ; Wed, 8 Aug 2018 19:59:28 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 5C0CCC21FBD; Wed, 8 Aug 2018 09:57:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 65F2EC21FDF; Wed, 8 Aug 2018 09:55:43 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 68FC0C21FC8; Wed, 8 Aug 2018 09:55:06 +0000 (UTC) Received: from mail-io0-f202.google.com (mail-io0-f202.google.com [209.85.223.202]) by lists.denx.de (Postfix) with ESMTPS id 0E22AC21FDE for ; Wed, 8 Aug 2018 09:55:02 +0000 (UTC) Received: by mail-io0-f202.google.com with SMTP id x5-v6so1229897ioa.6 for ; Wed, 08 Aug 2018 02:55:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=W0wceP8seQ7EImiFchvLglJkZohMypF0n/Jm2Pj+Gy8=; b=Rpf/SmP0wuBpRfyOMYjJlKj315d6nW01E2sBQR7Ay8qgCNGmf5rO2MSbXj9Ol4noWT 5qmrWp8vvsv4ZdJPWxhMHrelyK3EJxMpOk00LAest0lZmUhL3b1AmaMg8i4HCZ9Eij6C nVlWgKKvx6sbqEvCHfk51SAeKfTzlYFVgcHeHmvTu+9h3kpeei2kJluHdCStx6KMlW3O 0fNOiCnrLBgHg5LgnGSUKuga/+i4lRGI2rK+D4r6iulmpgJue2vxZYZ3Y/u6LhGBYFBD 4hRYXrtzh5TP1THO6Huvso5qMGrMDsA7u8kMVdmsthLOTiFyl6K5B1ZBuFa3g4v46kmf 2atg== X-Gm-Message-State: AOUpUlHyZ+4kQz9GLaN0DZeC1l5s+eCJIAFAmzCU5+jxxhaNmR3yJ8M4 7hwTSArVqo+deg99wtLGbV0Qe8A= X-Google-Smtp-Source: AA+uWPzbBofDUASBL13eyYlrrs7jEfGj5RzCGFEezFMpl2XyQxdSEKfTLtpXa7WIuB5MvAKr3Dcr9yI= X-Received: by 2002:a24:646:: with SMTP id 67-v6mr809786itv.54.1533722101108; Wed, 08 Aug 2018 02:55:01 -0700 (PDT) Date: Wed, 8 Aug 2018 03:54:28 -0600 In-Reply-To: <20180808095433.230882-1-sjg@chromium.org> Message-Id: <20180808095433.230882-14-sjg@chromium.org> Mime-Version: 1.0 References: <20180808095433.230882-1-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v9 13/18] efi: Add a call to exit() along with why we can't use it X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" The test should exit like any other EFI application, by calling exit() in the boot services API. But this crashes at present on sandbox. For now, add in the placeholder code. Signed-off-by: Simon Glass --- Changes in v9: None Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None lib/efi_loader/efi_test.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_test.c b/lib/efi_loader/efi_test.c index 4b8d49f324b..5401a0f4715 100644 --- a/lib/efi_loader/efi_test.c +++ b/lib/efi_loader/efi_test.c @@ -9,8 +9,18 @@ int efi_test(efi_handle_t image_handle, struct efi_system_table *systable) { struct efi_simple_text_output_protocol *con_out = systable->con_out; + struct efi_boot_services *boottime = systable->boottime; + int ret; - con_out->output_string(con_out, L"Hello, world!\n"); + ret = con_out->output_string(con_out, L"Hello, world!\n"); + + /* + * We should really call EFI's exit() here but this crashes at present + * on sandbox due to the incorrect use of setjmp() and longjmp(). Once + * we can figure out how to make that work, this can be enabled. + */ + if (0) + boottime->exit(image_handle, ret, 0, NULL); return 0; } From patchwork Wed Aug 8 09:54:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 954887 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41lnWS2JmNz9s3Z for ; Wed, 8 Aug 2018 20:22:28 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 72C57C21FF9; Wed, 8 Aug 2018 09:59:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 65AA9C21FCE; Wed, 8 Aug 2018 09:57:01 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 77AB1C2200D; Wed, 8 Aug 2018 09:55:07 +0000 (UTC) Received: from mail-it0-f73.google.com (mail-it0-f73.google.com [209.85.214.73]) by lists.denx.de (Postfix) with ESMTPS id E4F17C21FF8 for ; Wed, 8 Aug 2018 09:55:03 +0000 (UTC) Received: by mail-it0-f73.google.com with SMTP id g4-v6so1938172itf.6 for ; Wed, 08 Aug 2018 02:55:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=p5zsTiKMF4QtpSR0dUXJ2YaDy0+fSi3TXRPIPjHXmSg=; b=gm+eLp0vQDl8QFVJm46nB1tHnNc53/ZWqJxgoWHqwxzgN/zkXna3BDhxcvQIA4cw2p bc8/W+0PKrkYDClDlC9wYnVaXKzSLblNycr72WgDfZEpog8hV9Q6fG6Fx+xf3FogXbyh yzSI8ypXXl9KV6WNdf/qSvBWBaTddPS9nRIFotCe3D747hOpRoGBFa89IktXhkG6ffuY cp9d++RNQl0RcbNURfVpePBNTIz78hZ8rgHy/IgERDNIWhgjfl1kYQiZM0ig7eseGCxe oN6n9zF4WlI16cXF6s2zyobCjH8Y089C5Z0A5C19sKEZhRKBQO+nNVZSipXlbWg4KKsA 2TIA== X-Gm-Message-State: AOUpUlHoj4qlYN8DeJr+vTHWnBRlqMrj828xsEC6LodLWxVMLHuo9XNs le7CnI+J2wUMdDcFMTNT66qZMS8= X-Google-Smtp-Source: AA+uWPw4DYq9NYeNP7OvO5cWM/JcVJ9l9UaNbLzNamE4JHipeZq1yC/7bQz1u65tLQIKM+qgbmmdhgY= X-Received: by 2002:a24:1f93:: with SMTP id d141-v6mr787251itd.49.1533722102979; Wed, 08 Aug 2018 02:55:02 -0700 (PDT) Date: Wed, 8 Aug 2018 03:54:29 -0600 In-Reply-To: <20180808095433.230882-1-sjg@chromium.org> Message-Id: <20180808095433.230882-15-sjg@chromium.org> Mime-Version: 1.0 References: <20180808095433.230882-1-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v9 14/18] efi: Relocate FDT to 127MB instead of 128MB X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Sandbox only has 128MB of memory so we cannot relocate the device tree up to start at 128MB. Use 127MB instead, which should be safe. Signed-off-by: Simon Glass --- Changes in v9: None Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None cmd/bootefi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 905e659da42..6481444cca6 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -158,8 +158,8 @@ static void *copy_fdt(void *fdt) fdt_size = ALIGN(fdt_size + EFI_PAGE_SIZE - 1, EFI_PAGE_SIZE); fdt_pages = fdt_size >> EFI_PAGE_SHIFT; - /* Safe fdt location is at 128MB */ - new_fdt_addr = fdt_ram_start + (128 * 1024 * 1024) + fdt_size; + /* Safe fdt location is at 127MB */ + new_fdt_addr = fdt_ram_start + (127 * 1024 * 1024) + fdt_size; if (efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, EFI_RUNTIME_SERVICES_DATA, fdt_pages, &new_fdt_addr) != EFI_SUCCESS) { From patchwork Wed Aug 8 09:54:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 954893 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41lngw1DbFz9s0n for ; Wed, 8 Aug 2018 20:29:48 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id C0097C22008; Wed, 8 Aug 2018 10:00:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 180DBC21FE0; Wed, 8 Aug 2018 09:59:10 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id F317DC21FC8; Wed, 8 Aug 2018 09:55:09 +0000 (UTC) Received: from mail-qk0-f201.google.com (mail-qk0-f201.google.com [209.85.220.201]) by lists.denx.de (Postfix) with ESMTPS id E354DC21FBF for ; Wed, 8 Aug 2018 09:55:05 +0000 (UTC) Received: by mail-qk0-f201.google.com with SMTP id f64-v6so1687782qkb.20 for ; Wed, 08 Aug 2018 02:55:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=vRdJoeSzpSfhXN4PHRZIBY9xHrFhdoO0H0hrSuhlagM=; b=ZNqhPE5GslfPy0HCGhi6ZHQ87cScNTMvzXWK2AHzfte6R38oqZuGynYKlLHGaNt+Ap URYJu++CEijsq/nm7BLA44GusVZYXslMf+1nIL4aT+opeSopuk8hudyo0jS/izSNLQBZ vpH/NSI0jWv42/EKyqL1mbhTJo0lXgDTzhQNjBkG9mnKamKE26oyC1aJUhHRphCNb8R0 26qLXT7HtpKLiV+De8ZuWvE/HW3qaP4xKiXuQ8uiIvHlekZ98IsnXDiprUak2tjMnQ0/ wxi9NDwdvYstQawNipU/6NJr7h7l32TwQaS4GnX+S6AzeRi17T1OYU44yNSOPOBt5jY1 WOdg== X-Gm-Message-State: AOUpUlEzLsIgrKsisEMpt8cIcZirBO3SMJSYTUt95XfDforRB/dlZ57U HXQRTpl9v/EsUhltmfGoOBFxqpw= X-Google-Smtp-Source: AA+uWPwl3KvyMuHlxZ0J6EPiSXwxvPN6pzqyDp6p++QH1KBgp9jpJahGe7DXCijd2t5j+zwQxf890ZY= X-Received: by 2002:a0c:9649:: with SMTP id 9-v6mr1053206qvy.34.1533722104965; Wed, 08 Aug 2018 02:55:04 -0700 (PDT) Date: Wed, 8 Aug 2018 03:54:30 -0600 In-Reply-To: <20180808095433.230882-1-sjg@chromium.org> Message-Id: <20180808095433.230882-16-sjg@chromium.org> Mime-Version: 1.0 References: <20180808095433.230882-1-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v9 15/18] efi: sandbox: Tidy up copy_fdt() to work with sandbox X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" At present this function takes a pointer as its argument, then passes this to efi_allocate_pages(), which actually takes an address. It uses casts, which are not supported on sandbox. Also the function calculates the FDT size rounded up to the neared EFI page size, then its caller recalculates the size and adds a bit more to it. This function is much better written as something that works with addresses only, and returns both the address and the size of the relocated FDT. Also, copy_fdt() returns NULL on error, but really should propagate the error from efi_allocate_pages(). To do this it needs to return an efi_status_t, not a void *. Update the code in this way, so that it is easier to follow, and also supports sandbox. Signed-off-by: Simon Glass --- Changes in v9: - Drop fdt_end variable in efi_install_fdt() Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None cmd/bootefi.c | 79 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 29 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 6481444cca6..18378f2eacc 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -131,17 +131,30 @@ static void set_load_options(struct efi_loaded_image *loaded_image_info, loaded_image_info->load_options_size = size * 2; } -static void *copy_fdt(void *fdt) +/** + * copy_fdt() - Copy the device tree to a new location available to EFI + * + * The FDT is relocated into a suitable location within the EFI memory map. + * An additional 12KB is added to the space in case the device tree needs to be + * expanded later with fdt_open_into(). + * + * @fdt_addr: On entry, address of start of FDT. On exit, address of relocated + * FDT start + * @fdt_sizep: Returns new size of FDT, including + * @return new relocated address of FDT + */ +static efi_status_t copy_fdt(ulong *fdt_addrp, ulong *fdt_sizep) { - u64 fdt_size = fdt_totalsize(fdt); unsigned long fdt_ram_start = -1L, fdt_pages; + efi_status_t ret = 0; + void *fdt, *new_fdt; u64 new_fdt_addr; - void *new_fdt; + uint fdt_size; int i; - for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { - u64 ram_start = gd->bd->bi_dram[i].start; - u64 ram_size = gd->bd->bi_dram[i].size; + for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { + u64 ram_start = gd->bd->bi_dram[i].start; + u64 ram_size = gd->bd->bi_dram[i].size; if (!ram_size) continue; @@ -154,30 +167,37 @@ static void *copy_fdt(void *fdt) * Give us at least 4KB of breathing room in case the device tree needs * to be expanded later. Round up to the nearest EFI page boundary. */ - fdt_size += 4096; + fdt = map_sysmem(*fdt_addrp, 0); + fdt_size = fdt_totalsize(fdt); + fdt_size += 4096 * 3; fdt_size = ALIGN(fdt_size + EFI_PAGE_SIZE - 1, EFI_PAGE_SIZE); fdt_pages = fdt_size >> EFI_PAGE_SHIFT; /* Safe fdt location is at 127MB */ new_fdt_addr = fdt_ram_start + (127 * 1024 * 1024) + fdt_size; - if (efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, - EFI_RUNTIME_SERVICES_DATA, fdt_pages, - &new_fdt_addr) != EFI_SUCCESS) { + ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, + EFI_RUNTIME_SERVICES_DATA, fdt_pages, + &new_fdt_addr); + if (ret != EFI_SUCCESS) { /* If we can't put it there, put it somewhere */ new_fdt_addr = (ulong)memalign(EFI_PAGE_SIZE, fdt_size); - if (efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, - EFI_RUNTIME_SERVICES_DATA, fdt_pages, - &new_fdt_addr) != EFI_SUCCESS) { + ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, + EFI_RUNTIME_SERVICES_DATA, fdt_pages, + &new_fdt_addr); + if (ret != EFI_SUCCESS) { printf("ERROR: Failed to reserve space for FDT\n"); - return NULL; + goto done; } } - new_fdt = (void*)(ulong)new_fdt_addr; + new_fdt = map_sysmem(new_fdt_addr, fdt_size); memcpy(new_fdt, fdt, fdt_totalsize(fdt)); fdt_set_totalsize(new_fdt, fdt_size); - return new_fdt; + *fdt_addrp = new_fdt_addr; + *fdt_sizep = fdt_size; +done: + return ret; } static efi_status_t efi_do_enter( @@ -250,22 +270,27 @@ static void efi_carve_out_dt_rsv(void *fdt) } } -static efi_status_t efi_install_fdt(void *fdt) +static efi_status_t efi_install_fdt(ulong fdt_addr) { bootm_headers_t img = { 0 }; - ulong fdt_pages, fdt_size, fdt_start, fdt_end; + ulong fdt_pages, fdt_size, fdt_start; efi_status_t ret; + void *fdt; + fdt = map_sysmem(fdt_addr, 0); if (fdt_check_header(fdt)) { printf("ERROR: invalid device tree\n"); return EFI_INVALID_PARAMETER; } /* Prepare fdt for payload */ - fdt = copy_fdt(fdt); - if (!fdt) - return EFI_OUT_OF_RESOURCES; + ret = copy_fdt(&fdt_addr, &fdt_size); + if (ret) + return ret; + unmap_sysmem(fdt); + fdt = map_sysmem(fdt_addr, 0); + fdt_size = fdt_totalsize(fdt); if (image_setup_libfdt(&img, fdt, 0, NULL)) { printf("ERROR: failed to process device tree\n"); return EFI_LOAD_ERROR; @@ -279,14 +304,12 @@ static efi_status_t efi_install_fdt(void *fdt) return EFI_OUT_OF_RESOURCES; /* And reserve the space in the memory map */ - fdt_start = ((ulong)fdt) & ~EFI_PAGE_MASK; - fdt_end = ((ulong)fdt) + fdt_totalsize(fdt); - fdt_size = (fdt_end - fdt_start) + EFI_PAGE_MASK; + fdt_start = fdt_addr; fdt_pages = fdt_size >> EFI_PAGE_SHIFT; - /* Give a bootloader the chance to modify the device tree */ - fdt_pages += 2; + ret = efi_add_memory_map(fdt_start, fdt_pages, EFI_BOOT_SERVICES_DATA, true); + return ret; } @@ -506,7 +529,6 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) unsigned long addr; efi_status_t r; unsigned long fdt_addr; - void *fdt; /* Allow unaligned memory access */ allow_unaligned(); @@ -527,8 +549,7 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (!fdt_addr && *argv[2] != '0') return CMD_RET_USAGE; /* Install device tree */ - fdt = map_sysmem(fdt_addr, 0); - r = efi_install_fdt(fdt); + r = efi_install_fdt(fdt_addr); if (r != EFI_SUCCESS) { printf("ERROR: failed to install device tree\n"); return CMD_RET_FAILURE; From patchwork Wed Aug 8 09:54:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 954879 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41ln1H3NMVz9s0n for ; Wed, 8 Aug 2018 19:59:47 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id F1AA9C21FCE; Wed, 8 Aug 2018 09:58:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id E21F6C21FE2; Wed, 8 Aug 2018 09:56:22 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5874EC21FDB; Wed, 8 Aug 2018 09:55:11 +0000 (UTC) Received: from mail-qk0-f202.google.com (mail-qk0-f202.google.com [209.85.220.202]) by lists.denx.de (Postfix) with ESMTPS id AA9E1C21FF7 for ; Wed, 8 Aug 2018 09:55:07 +0000 (UTC) Received: by mail-qk0-f202.google.com with SMTP id u22-v6so1720642qkk.10 for ; Wed, 08 Aug 2018 02:55:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=PyDOmaP2Vb1YQnU9TwCjsDe8ddkyPSBLWr8dOtXfxJM=; b=HTFnCQhZ2Bxk2gKaC71f9g2hedhkwiz5EvlXPlP3G64J8aW6APIPpEfuy12UbuALqy MAO38dKvRj/s/BO+wv7nopncyhgsviWOrSQZ87sovvenY+no0ops5kLl8OUrffB9+oPa e4hlsXxTBAtdyLgnvIDsz/x7JdzgYERzNUhR3LU5ANJ1edjsPWmHvVec2x01arF/MS4A R7tEbcHWIx72qU3fwCYSsccMlJAQXEpF61OgST1gLeyTSGm22C/k5NVfcqLiHxuVQPqn 0BkWdYVZe/SRlKdNcpAwctQxrR/aBbnEKaouh/T9LScMqFsBA71HswvFgDLw+sbJrrl/ r3sw== X-Gm-Message-State: AOUpUlE83RrAgQcat/ChcR7XyH6fmiIXn41x4fkrQe6SSfh1LhwBMQzy mJRLfczCjucMpBVcnnDEv3VYojU= X-Google-Smtp-Source: AA+uWPxDuI/H1eMdpop/4kYNDri7vgEqcSDB/Ds57+CMjDh9e5L4gfHtpKBFR8ovZtTgmbnZEJk6P2A= X-Received: by 2002:ac8:6047:: with SMTP id k7-v6mr1076900qtm.19.1533722106770; Wed, 08 Aug 2018 02:55:06 -0700 (PDT) Date: Wed, 8 Aug 2018 03:54:31 -0600 In-Reply-To: <20180808095433.230882-1-sjg@chromium.org> Message-Id: <20180808095433.230882-17-sjg@chromium.org> Mime-Version: 1.0 References: <20180808095433.230882-1-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v9 16/18] efi: Add more debugging for memory allocations X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Add some more verbose debugging when doing memory allocations. This might help to find bugs later. Signed-off-by: Simon Glass --- Changes in v9: None Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None lib/efi_loader/efi_boottime.c | 15 +++++++++++++++ lib/efi_loader/efi_memory.c | 22 +++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index b9e54f551a4..851d282f79d 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -330,6 +330,7 @@ static efi_status_t EFIAPI efi_allocate_pages_ext(int type, int memory_type, EFI_ENTRY("%d, %d, 0x%zx, %p", type, memory_type, pages, memory); r = efi_allocate_pages(type, memory_type, pages, memory); + return EFI_EXIT(r); } @@ -379,11 +380,25 @@ static efi_status_t EFIAPI efi_get_memory_map_ext( uint32_t *descriptor_version) { efi_status_t r; + int i, entries; EFI_ENTRY("%p, %p, %p, %p, %p", memory_map_size, memory_map, map_key, descriptor_size, descriptor_version); r = efi_get_memory_map(memory_map_size, memory_map, map_key, descriptor_size, descriptor_version); + entries = *memory_map_size / sizeof(struct efi_mem_desc); + debug(" memory_map_size=%zx (%lx entries)\n", *memory_map_size, + (ulong)(*memory_map_size / sizeof(struct efi_mem_desc))); + if (memory_map) { + for (i = 0; i < entries; i++) { + struct efi_mem_desc *desc = &memory_map[i]; + + debug(" type %d, phys %lx, virt %lx, num_pages %lx, attribute %lx\n", + desc->type, (ulong)desc->physical_start, + (ulong)desc->virtual_start, + (ulong)desc->num_pages, (ulong)desc->attribute); + } + } return EFI_EXIT(r); } diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index 967c3f733e4..607152bc4e7 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -151,6 +151,24 @@ static s64 efi_mem_carve_out(struct efi_mem_list *map, return EFI_CARVE_LOOP_AGAIN; } +static void efi_mem_print(const char *name) +{ + struct list_head *lhandle; + + debug(" %s: memory map\n", name); + list_for_each(lhandle, &efi_mem) { + struct efi_mem_list *lmem = list_entry(lhandle, + struct efi_mem_list, link); + struct efi_mem_desc *desc = &lmem->desc; + + debug(" type %d, phys %lx, virt %lx, num_pages %lx, attribute %lx\n", + desc->type, (ulong)desc->physical_start, + (ulong)desc->virtual_start, (ulong)desc->num_pages, + (ulong)desc->attribute); + } + debug("\n"); +} + uint64_t efi_add_memory_map(uint64_t start, uint64_t pages, int memory_type, bool overlap_only_ram) { @@ -243,6 +261,7 @@ uint64_t efi_add_memory_map(uint64_t start, uint64_t pages, int memory_type, /* And make sure memory is listed in descending order */ efi_mem_sort(); + efi_mem_print(__func__); return start; } @@ -466,7 +485,8 @@ efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size, map_entries++; map_size = map_entries * sizeof(struct efi_mem_desc); - + debug("%s: map_size %lx, provided_map_size %lx\n", __func__, + (ulong)map_size, (ulong)provided_map_size); *memory_map_size = map_size; if (provided_map_size < map_size) From patchwork Wed Aug 8 09:54:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 954886 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41lnHG0Mhbz9s0n for ; Wed, 8 Aug 2018 20:11:53 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 9E6EDC21FAD; Wed, 8 Aug 2018 09:59:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 8B184C22002; Wed, 8 Aug 2018 09:57:17 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D176EC21FCB; Wed, 8 Aug 2018 09:55:13 +0000 (UTC) Received: from mail-qk0-f202.google.com (mail-qk0-f202.google.com [209.85.220.202]) by lists.denx.de (Postfix) with ESMTPS id 92973C21FFC for ; Wed, 8 Aug 2018 09:55:09 +0000 (UTC) Received: by mail-qk0-f202.google.com with SMTP id w8-v6so1699334qkf.8 for ; Wed, 08 Aug 2018 02:55:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=yrrtEbcsuylKdi/4rOk42gDcL7WRGE0A1lEkfsN9d0A=; b=penh85Y1FxbXo7GPEd5wS6ZKkw1aVBNBsZw+GgXZJa1vSL7CnVrTXKd5/t51FVK9Ad imUsAwxaKJyGHN/ZZECP0dxeRC4FNBlO7Dz4a3QF5ua34FrQkXRBeXGkZbnoZbCbWA+U g7bGvhSkb/1lRcf9qVGUYgqQeEO4dwo1WVtWnwcE0UlUSK2Zy6j/cOo5/rzwjy9FeijW ZG3xkGqZB8DLk0pq04/HOhAUFdoIfDfd62iX7MTo7U457rBL9nu7KiughckuOBIS+edK OTnU8+Caxnd85OtTi1lViXt/J2qoafM7++3Mg+dLFYj/u4mgi1hVFH4IM0xsoGqEIDhy Lbnw== X-Gm-Message-State: AOUpUlFGtrl7k9vXfTyFztWhUM3Qynguvh3PXQIAgZdqjVYFqEFGxSXF jDEOI1wIa7D9x1GVgGFWwcgUB6M= X-Google-Smtp-Source: AA+uWPzT5UfZi68xQYTfx8tQh3wHIOuPkpkF386ugBmwKmhCv3stKhawPTRpHGKdbnCggUn6NFhdW64= X-Received: by 2002:a37:8704:: with SMTP id j4-v6mr1178920qkd.9.1533722108789; Wed, 08 Aug 2018 02:55:08 -0700 (PDT) Date: Wed, 8 Aug 2018 03:54:32 -0600 In-Reply-To: <20180808095433.230882-1-sjg@chromium.org> Message-Id: <20180808095433.230882-18-sjg@chromium.org> Mime-Version: 1.0 References: <20180808095433.230882-1-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v9 17/18] efi_loader: Pass address to fs_read() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" From: Alexander Graf The fs_read() function wants to get an address rather than the pointer to a buffer. So let's convert the passed buffer from pointer back a the address to make efi_loader on sandbox happier. Signed-off-by: Alexander Graf Reviewed-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v9: None Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None lib/efi_loader/efi_file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c index e6a15bcb523..2107730ba5a 100644 --- a/lib/efi_loader/efi_file.c +++ b/lib/efi_loader/efi_file.c @@ -9,6 +9,7 @@ #include #include #include +#include #include /* GUID for file system information */ @@ -232,8 +233,10 @@ static efi_status_t file_read(struct file_handle *fh, u64 *buffer_size, void *buffer) { loff_t actread; + /* fs_read expects buffer address, not pointer */ + uintptr_t buffer_addr = (uintptr_t)map_to_sysmem(buffer); - if (fs_read(fh->path, (ulong)buffer, fh->offset, + if (fs_read(fh->path, buffer_addr, fh->offset, *buffer_size, &actread)) return EFI_DEVICE_ERROR; From patchwork Wed Aug 8 09:54:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 954882 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41ln4F07fbz9s0n for ; Wed, 8 Aug 2018 20:02:20 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id AF9A4C21FD4; Wed, 8 Aug 2018 09:58:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 3347DC21FEF; Wed, 8 Aug 2018 09:56:28 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 883EBC21FD1; Wed, 8 Aug 2018 09:55:15 +0000 (UTC) Received: from mail-io0-f202.google.com (mail-io0-f202.google.com [209.85.223.202]) by lists.denx.de (Postfix) with ESMTPS id 60EE2C21FE0 for ; Wed, 8 Aug 2018 09:55:11 +0000 (UTC) Received: by mail-io0-f202.google.com with SMTP id p12-v6so1224762iog.8 for ; Wed, 08 Aug 2018 02:55:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=p7mEiA+5E2WABpc3lj3fNE2z+F+AnuOyXeJYT6cp4r0=; b=WcJjgHPIYUACK9SCpR0TqIskFzpGC7f0RVLkZ0F/ltWVK4eyRQnMEOrO0OFFOAW9Nf KhKKm2QZdPEBwO7ITA2Ow7QhWpCxl6wp7cS1khEj54iv5rosA8n2itBdBhqSniLeJtBl UQQApHuUe0iXF784aHUCJsNcq4iNsksLRn46JakFkB/lZKVCHXCp2iDGJgukxINVNYwd WbitMDxNAZwAUuQBoXcJAy25TfkkfjKziV4x115JaODecHJZblbGyAvk1MGqEVkv4BQD UlVDl51WbSoN5L++zlO0GIpzk6Sq1NBSqlyMBzQdPri0f0rt7jcvM/obVAA5wJzLH5iP ZnoQ== X-Gm-Message-State: AOUpUlFvo3eDDLJzr9V0o43W60jq0doNvhMU4D5XVxvsSTFmR4qWaS9L ClIzKSximWdzqDo9jNwFIsXg/TE= X-Google-Smtp-Source: AA+uWPxE/ca8Qfkd0xZpZp6mchHADmSSGdOldFrSnGzykHA67GZGOpK/6fCGcV2/HA4rwiNtuO5Qd6Y= X-Received: by 2002:a24:4567:: with SMTP id y100-v6mr825011ita.37.1533722110436; Wed, 08 Aug 2018 02:55:10 -0700 (PDT) Date: Wed, 8 Aug 2018 03:54:33 -0600 In-Reply-To: <20180808095433.230882-1-sjg@chromium.org> Message-Id: <20180808095433.230882-19-sjg@chromium.org> Mime-Version: 1.0 References: <20180808095433.230882-1-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.597.ga71716f1ad-goog From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v9 18/18] efi: sandbox: Enable selftest command X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Enable this for sandbox since it passes now. Signed-off-by: Simon Glass --- Changes in v9: None Changes in v8: - Drop 'efi: Adjust memory handling to support sandbox' - Drop 'efi: sandbox: Add relocation constants' - Drop 'sandbox: smbios: Update to support sandbox' - Expand series substantially to support bootefi selftest - Rebase to master - Rebase to master, bringing in all EFI changes Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: - Rebase to master - Update SPDX tags Changes in v3: - Rebase to master Changes in v2: - Rebase to master configs/sandbox_defconfig | 1 + lib/efi_selftest/Kconfig | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 61302909191..7e75643bfe6 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -205,3 +205,4 @@ CONFIG_UT_ENV=y CONFIG_UT_OVERLAY=y CONFIG_SMEM=y CONFIG_SANDBOX_SMEM=y +CONFIG_CMD_BOOTEFI_SELFTEST=y diff --git a/lib/efi_selftest/Kconfig b/lib/efi_selftest/Kconfig index b52696778dd..59f9f36801c 100644 --- a/lib/efi_selftest/Kconfig +++ b/lib/efi_selftest/Kconfig @@ -1,6 +1,6 @@ config CMD_BOOTEFI_SELFTEST bool "Allow booting an EFI efi_selftest" - depends on CMD_BOOTEFI && !SANDBOX + depends on CMD_BOOTEFI imply FAT imply FAT_WRITE help