From patchwork Fri Jun 22 12:44:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 139618 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp835171lji; Fri, 22 Jun 2018 05:50:33 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKIzLxPNNpZw3jCamjHbQaWwldb5tmuD5yzYyY83L04hAZBjKTYA2F6zosA0oz+u+E2tJw4 X-Received: by 2002:a50:e615:: with SMTP id y21-v6mr1731818edm.278.1529671833164; Fri, 22 Jun 2018 05:50:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529671833; cv=none; d=google.com; s=arc-20160816; b=O3rmJSmzYLZog5jMvuIYLQRNkEFXlFcYhIf/ZCEgwkwDXLzcbn7rnf/v8L2jWn6MVW z6HFrlVwUvWKV8Ej/ctKI4IctFBXHketVVgx724ZkU8C2eWphIsNTO6Qx3cBrqhiutyP 6HcM2fsCn/yE+xAxjHIoTJtri6VZUv+XXzRmSXHkozCoNX2n9g7b9urNz2eJHsPk0+Ox gI6E1Hzs/Z3d68BVguPxoDYAJfiUZILJMyNQmv00La1mV03bVflNDX8DALrIgcy621OM d0+5aJJvs3VeydcILVCFPACXw7S8xhQePOXLiYcudUSvUwL0V8GcGkN4TI2u7XymZMhz EUEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:arc-authentication-results; bh=NEb/APNOApaMzMzzPxch2tB9jPkNYF1efl8KNSFC2Ww=; b=FCPyzECSgko8BqsRkyCrTlLAywnACTNooTUD0XPlQysO9HhOzKp7pvmeGspKQ1ZjKo lRqqW6ao4GtUqgfONhsxN6HfF+j1jGH7ByZRBf+feaSpBFnMHwjhGXuFDI0C0An/mZy7 1GaONxkmN3O2CaEgWtJMXDvrdWRtdOniAovr0RU72KmsuLGHph7Azk76oZcZB1GzfJCo bZ3lmYovZAdt/GEz7TeAT7ZQ7JyDSrUPjk8SQHfH+SD9Q9kzbYKNsAUIR/TiQRxckUjw wo7rOhapeI1NIIPk6Ge0LNOVg33YoASg0fR8aJ03XlFPQqel8B904exucboUKVMcghBk xoZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id w2-v6si3993908edm.336.2018.06.22.05.50.32; Fri, 22 Jun 2018 05:50:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id C7A7DC21F7A; Fri, 22 Jun 2018 12:46:30 +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 EFE8EC2201E; Fri, 22 Jun 2018 12:44:27 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 86A26C21C2C; Fri, 22 Jun 2018 12:44:20 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id A2F40C21C57 for ; Fri, 22 Jun 2018 12:44:20 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id CF77DACB0; Fri, 22 Jun 2018 12:44:19 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Fri, 22 Jun 2018 14:44:09 +0200 Message-Id: <20180622124418.52892-2-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180622124418.52892-1-agraf@suse.de> References: <20180622124418.52892-1-agraf@suse.de> Cc: Heinrich Schuchardt , Andy Shevchenko Subject: [U-Boot] [PATCH v5 01/10] efi.h: Do not use config options 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Currently efi.h determines a few bits of its environment according to config options. This falls apart with the efi stub support which may result in efi.h getting pulled into the stub as well as real U-Boot code. In that case, one may be 32bit while the other one is 64bit. This patch changes the conditionals to use compiler provided defines instead. That way we always adhere to the build environment we're in and the definitions adjust automatically. Signed-off-by: Alexander Graf Reviewed-by: Bin Meng Tested-by: Bin Meng [bmeng: added some comments to describe the __x86_64__ check] Signed-off-by: Bin Meng Signed-off-by: Alexander Graf --- include/efi.h | 24 +++++++++++------------- lib/efi/Makefile | 4 ++-- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/include/efi.h b/include/efi.h index d4da65ce53..41530a7537 100644 --- a/include/efi.h +++ b/include/efi.h @@ -19,8 +19,15 @@ #include #include -#if CONFIG_EFI_STUB_64BIT || (!defined(CONFIG_EFI_STUB) && defined(__x86_64__)) -/* EFI uses the Microsoft ABI which is not the default for GCC */ +/* + * EFI on x86_64 uses the Microsoft ABI which is not the default for GCC. + * + * There are two scenarios for EFI on x86_64: building a 64-bit EFI stub + * codes (CONFIG_EFI_STUB_64BIT) and building a 64-bit U-Boot (CONFIG_X86_64). + * Either needs to be properly built with the '-m64' compiler flag, and hence + * it is enough to only check the compiler provided define __x86_64__ here. + */ +#ifdef __x86_64__ #define EFIAPI __attribute__((ms_abi)) #define efi_va_list __builtin_ms_va_list #define efi_va_start __builtin_ms_va_start @@ -32,7 +39,7 @@ #define efi_va_start va_start #define efi_va_arg va_arg #define efi_va_end va_end -#endif +#endif /* __x86_64__ */ struct efi_device_path; @@ -40,16 +47,7 @@ typedef struct { u8 b[16]; } efi_guid_t; -#define EFI_BITS_PER_LONG BITS_PER_LONG - -/* - * With 64-bit EFI stub, EFI_BITS_PER_LONG has to be 64. EFI_STUB is set - * in lib/efi/Makefile, when building the stub. - */ -#if defined(CONFIG_EFI_STUB_64BIT) && defined(EFI_STUB) -#undef EFI_BITS_PER_LONG -#define EFI_BITS_PER_LONG 64 -#endif +#define EFI_BITS_PER_LONG (sizeof(long) * 8) /* Bit mask for EFI status code with error */ #define EFI_ERROR_MASK (1UL << (EFI_BITS_PER_LONG - 1)) diff --git a/lib/efi/Makefile b/lib/efi/Makefile index f1a3929e32..a790d2d554 100644 --- a/lib/efi/Makefile +++ b/lib/efi/Makefile @@ -7,11 +7,11 @@ obj-$(CONFIG_EFI_STUB) += efi_info.o CFLAGS_REMOVE_efi_stub.o := -mregparm=3 \ $(if $(CONFIG_EFI_STUB_64BIT),-march=i386 -m32) -CFLAGS_efi_stub.o := -fpic -fshort-wchar -DEFI_STUB \ +CFLAGS_efi_stub.o := -fpic -fshort-wchar \ $(if $(CONFIG_EFI_STUB_64BIT),-m64) CFLAGS_REMOVE_efi.o := -mregparm=3 \ $(if $(CONFIG_EFI_STUB_64BIT),-march=i386 -m32) -CFLAGS_efi.o := -fpic -fshort-wchar -DEFI_STUB \ +CFLAGS_efi.o := -fpic -fshort-wchar \ $(if $(CONFIG_EFI_STUB_64BIT),-m64) extra-$(CONFIG_EFI_STUB) += efi_stub.o efi.o From patchwork Fri Jun 22 12:44:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 139619 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp835328lji; Fri, 22 Jun 2018 05:50:43 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKuJKfcB7df697PdG34hrY+Um/wHuPhQZCxkqRkGoc0wkpfvPJMABmwUc8gArd77nyKBEMB X-Received: by 2002:aa7:d84a:: with SMTP id f10-v6mr1734229eds.157.1529671843720; Fri, 22 Jun 2018 05:50:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529671843; cv=none; d=google.com; s=arc-20160816; b=BGyWl5VNJ7UlmsRy1JvfDVvjX/O/CMrU4BIfxtKl3m57x+m18wX2SVkkrPkam8LrhC wUo5FZKvmLEw7R9Gpc7+XYzcZRPfusvuPP2ted2BiuneKKuujM1Iavz7osv4NEtiP4zU l+hFZpce4U56vuL0Tp6jJW/LAChNp0F71yQFFtcXBs5Chia1jxQzpYNEvF5lnCCAs8JG mJBk3RtIQNQbkbgcd2Ph4mM/ABfHClGQTKopF71GvckU83KaVf1JTQWsuUoSCeL9pnRL kyYQgBGb5HPlYISsY0hwcycS9s2dyg6XTxqHchR4mNWw0/chTSx/W/rqg9ThsBbj6MKX eP+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:arc-authentication-results; bh=iP9fUUjIDZePizS10Wo6GRWdg1jSpA3KBHt+Vv/9Ob8=; b=S9j4p47z2SiYlVemDevdog/DU4e5br5Gc5YgstHS529V171I6Mw5DE5IWIVyjbshCL H0TWZNA7Gmww9x8wqSzuzTdxVbEmRUBqnMtwRcO8GXmO5X1OBu4mS+GYt7/Ir0H/Cdqv w2tUBzeBfpOrIFpy1Mmk0cnWW76YLN8B7auxJLGRDpYdDPmmh0InPd1FCgNeNFm9rron VhvW4/B99Ty1+czFY6srUiqrChbw4euAWJ7nnbf2M5Hkd+vVJzQn6IybFBR18/BD2IYq nswR1XTOxcnMKO1LBvtKCdP086uYuYpznqgnJOK8u7ZU1xh93+KrM7Ai2q7hOR2QmVUk MzxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id y5-v6si3667477edr.193.2018.06.22.05.50.43; Fri, 22 Jun 2018 05:50:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id 4C0BAC21F2A; Fri, 22 Jun 2018 12:47:26 +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 C3096C22093; Fri, 22 Jun 2018 12:44:30 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id CE270C21C2C; Fri, 22 Jun 2018 12:44:21 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id B0030C21E42 for ; Fri, 22 Jun 2018 12:44:20 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D1C7CADD1; Fri, 22 Jun 2018 12:44:19 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Fri, 22 Jun 2018 14:44:10 +0200 Message-Id: <20180622124418.52892-3-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180622124418.52892-1-agraf@suse.de> References: <20180622124418.52892-1-agraf@suse.de> Cc: Heinrich Schuchardt , Andy Shevchenko Subject: [U-Boot] [PATCH v5 02/10] distro: Move to compiler based target architecture determination 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Thanks to CONFIG_SANDBOX, we can not rely on config options to tell us what CPU architecture we're running on. The compiler however does know that, so let's just move the ifdefs over to compiler based defines rather than kconfig based options. Signed-off-by: Alexander Graf --- v3 -> v4: - Compile fix for dts --- include/config_distro_bootcmd.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/include/config_distro_bootcmd.h b/include/config_distro_bootcmd.h index d672e8ebe6..c35a42f6c5 100644 --- a/include/config_distro_bootcmd.h +++ b/include/config_distro_bootcmd.h @@ -245,22 +245,27 @@ #if defined(CONFIG_CMD_DHCP) #if defined(CONFIG_EFI_LOADER) /* http://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xml */ -#if defined(CONFIG_ARM64) +#if defined(__aarch64__) #define BOOTENV_EFI_PXE_ARCH "0xb" #define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00011:UNDI:003000" -#elif defined(CONFIG_ARM) +#elif defined(__arm__) #define BOOTENV_EFI_PXE_ARCH "0xa" #define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00010:UNDI:003000" -#elif defined(CONFIG_X86) -/* Always assume we're running 64bit */ +#elif defined(__x86_64__) #define BOOTENV_EFI_PXE_ARCH "0x7" #define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00007:UNDI:003000" -#elif defined(CONFIG_CPU_RISCV_32) +#elif defined(__i386__) +#define BOOTENV_EFI_PXE_ARCH "0x0" +#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00000:UNDI:003000" +#elif defined(__riscv) && (__riscv_xlen == 32) #define BOOTENV_EFI_PXE_ARCH "0x19" #define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00025:UNDI:003000" -#elif defined(CONFIG_CPU_RISCV_64) +#elif defined(__riscv) && (__riscv_xlen == 64) #define BOOTENV_EFI_PXE_ARCH "0x1b" #define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00027:UNDI:003000" +#elif defined(__ASSEMBLY__) +#define BOOTENV_EFI_PXE_ARCH "0xff" +#define BOOTENV_EFI_PXE_VCI "PXEClient:Arch:00255:UNDI:003000" #else #error Please specify an EFI client identifier #endif From patchwork Fri Jun 22 12:44:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 139609 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp829373lji; Fri, 22 Jun 2018 05:44:28 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI8KdSjR82LgpiLBTsaSrCRBgDs+VAd4CGgoCQs8lIgZt3KIV5TU79r1T6RqiB3mqvb9qGi X-Received: by 2002:a50:9ae2:: with SMTP id p89-v6mr1747453edb.112.1529671468644; Fri, 22 Jun 2018 05:44:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529671468; cv=none; d=google.com; s=arc-20160816; b=ue7vzWj44V7wra6mTTmCa20IHCaqk7EDKaQ+aA8/i6cKl2rgZUbYb9A4Vj1wuXwdwB Y47dAkW/gt2Baw+xuvqmHHhQtv7RUB+0XuIx0UvpmfjkTLd2X0GDx/o0X4WUQaMQanXY rbhbEABgDVd8lQDr+xxuYxx4tXxMEbS2GfiGFN2xCC/+1eUdU5KXjv5v3kMisQeZnj5W 0aT4SPcDGmLRpRNAy4v3h5p6YtdkJUzsOatYpyQ74gva3p0QtZiq615beGuilwXkTMeR jEAxddOQH1hKWu1pG8286u0XFJdfBySyhQs18wsFaa0QwSRU5gFUII3hKmlRjaN72SEA YaEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:arc-authentication-results; bh=v7/nTGGIcfELhkjy5S4ccAatm3+Yjpo54JlBv+5HqMk=; b=Gc7I7NZMoVwsvZG4nP/g2Aw16Y9r/jNMcUEdCr1GtmXV+ePGFfkkbi40ZTgIV7to9Y Gf2DPpFNhoLpY24AR0vxxn3/4ouZmvcu5aTp/Suh6RMqkvUyVd697+gf9o/NX5DGfb1P 3tL8WMx/dTjnG6wqt41WN5e52dSvluLnjGlA3ZqeNMDWA+8vrZN2Vjtsdz6zw1tBBHA3 qZxVtqfJKUQiaLN1wHrRSBb/q3BcmOW4oNmtZLQfnrXPEwjLLy4Whl+B94qevf62L1Is NoYW6Jir/7z13KEGk6atELeryXziaoe+cE/VPA+3Xgbf/iK/BHPHxh4LSGYUjQHiTY3M Pkxg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id w17-v6si3488173edr.238.2018.06.22.05.44.28; Fri, 22 Jun 2018 05:44:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id E40F6C22058; Fri, 22 Jun 2018 12:44: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 1BAD1C21C2C; Fri, 22 Jun 2018 12:44:22 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id DBBEBC21F2A; Fri, 22 Jun 2018 12:44:20 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id 743F5C21C2C for ; Fri, 22 Jun 2018 12:44:20 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id CF9C6ACF9; Fri, 22 Jun 2018 12:44:19 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Fri, 22 Jun 2018 14:44:11 +0200 Message-Id: <20180622124418.52892-4-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180622124418.52892-1-agraf@suse.de> References: <20180622124418.52892-1-agraf@suse.de> Cc: Heinrich Schuchardt , Andy Shevchenko Subject: [U-Boot] [PATCH v5 03/10] 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 --- 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 e6a15bcb52..2107730ba5 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 Fri Jun 22 12:44:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 139615 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp833041lji; Fri, 22 Jun 2018 05:48:13 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJSmgAbea5M1ipKDRVoF68cxtoyMLIe4we/jLbFnjKUckNSFX5EsoDmChUG12OV1IWZ7EKE X-Received: by 2002:a50:dac9:: with SMTP id s9-v6mr1706742edj.241.1529671693333; Fri, 22 Jun 2018 05:48:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529671693; cv=none; d=google.com; s=arc-20160816; b=wS0N3elnYl0g6HAGk6xm0XpDPgg3fADDOKmg2hidv17XnGX1F8xWdHNzUYZBuPv37q Lg0qXmWihZovUZbgscrR8rQVdAYiIuAIpAGaaVXomPNgMXEC+kRHEhNcQvx9XYELmt67 J2RWO95h8pXrYbmC2d2N+ezc8QDWsYXJuRhjPckFjIIhjhwYU/XYapbuJLj52DdzM0Pv QAObuKFuvA0qTYvEaLL7ZkNMHSpXU9/CBM1Enreb0sks3aY45Fl1zqly8qzApCFckBRX Y5v2xPkdQJtznw3zxeBbz9MgaEVlwj5Qna/VPbGFssym81X0CcVK/DK8Yf5DTSxIVgId fKgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:arc-authentication-results; bh=WZ8HzTa6kASv5WX3oY8Zycp+1E+QnitDzSSQWNJm6tc=; b=qYKSkIdhz+Job0PcjtPr3aDDccWmuNOXll2OwZUu9VM0brDPLCRWq5GkbK5ggZgGkf sHnrDArPJZYTSiRe8e/qazKjyKhdttb7xCqOmBNJYEIikmeA9AMNRqfK9pLcEWpy01Wn 6gbptIeEoHOjot8bG5rnA3aJq3bdSfdxQvO1fOpWHttjA/q0U/s7kq4PXRhuJTKFuWb7 vpwQa+iclNzoH/c6tsVkN2J2PCfEXOqjb2gByrvofLEEANyEN6IcN+lnI7598BH7dpho FYq2L1C/21/2bDm/nvK3Q18bbyyF6SnrwhGvElZiGfZ4oW9tHihMHf5EpWIPWcAAXtJY TTgQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id m3-v6si827780eda.90.2018.06.22.05.48.13; Fri, 22 Jun 2018 05:48:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id F1B27C21F6E; Fri, 22 Jun 2018 12:45:56 +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 45EABC21FB0; Fri, 22 Jun 2018 12:44:26 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5C3CCC21C57; Fri, 22 Jun 2018 12:44:21 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id AE25FC21E3A for ; Fri, 22 Jun 2018 12:44:20 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E05C6AE9A; Fri, 22 Jun 2018 12:44:19 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Fri, 22 Jun 2018 14:44:12 +0200 Message-Id: <20180622124418.52892-5-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180622124418.52892-1-agraf@suse.de> References: <20180622124418.52892-1-agraf@suse.de> Cc: Heinrich Schuchardt , Andy Shevchenko Subject: [U-Boot] [PATCH v5 04/10] sandbox: Fix setjmp/longjmp 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" In sandbox, longjmp returns to itself in an endless loop because os_longjmp() calls into longjmp() which is provided by U-Boot which again calls os_longjmp(). Setjmp on the other hand must not return because otherwise the return freees up stack elements that we need during longjmp(). The only straight forward fix that doesn't involve nasty hacks I could find is to directly link against the system setjmp/longjmp implementations. That means we just provide the compiler with hints that the symbol will be available and actually fill them out with versions from libc. This approach should be reasonably platform agnostic Signed-off-by: Alexander Graf Reviewed-by: Simon Glass --- v4 -> v5: - Use system setjmp/longjmp directly from target code --- arch/sandbox/cpu/cpu.c | 12 ------------ arch/sandbox/cpu/os.c | 22 ---------------------- arch/sandbox/include/asm/setjmp.h | 5 +++++ include/os.h | 21 --------------------- 4 files changed, 5 insertions(+), 55 deletions(-) diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c index cde0b055a6..e7d3c272a4 100644 --- a/arch/sandbox/cpu/cpu.c +++ b/arch/sandbox/cpu/cpu.c @@ -165,15 +165,3 @@ ulong timer_get_boot_us(void) return (count - base_count) / 1000; } - -int setjmp(jmp_buf jmp) -{ - return os_setjmp((ulong *)jmp, sizeof(*jmp)); -} - -void longjmp(jmp_buf jmp, int ret) -{ - os_longjmp((ulong *)jmp, ret); - while (1) - ; -} diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 5839932b00..fc2f9dbc7a 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -629,25 +629,3 @@ void os_localtime(struct rtc_time *rt) rt->tm_yday = tm->tm_yday; rt->tm_isdst = tm->tm_isdst; } - -int os_setjmp(ulong *jmp, int size) -{ - jmp_buf dummy; - - /* - * We cannot rely on the struct name that jmp_buf uses, so use a - * local variable here - */ - if (size < sizeof(dummy)) { - printf("setjmp: jmpbuf is too small (%d bytes, need %d)\n", - size, sizeof(jmp_buf)); - return -ENOSPC; - } - - return setjmp((struct __jmp_buf_tag *)jmp); -} - -void os_longjmp(ulong *jmp, int ret) -{ - longjmp((struct __jmp_buf_tag *)jmp, ret); -} diff --git a/arch/sandbox/include/asm/setjmp.h b/arch/sandbox/include/asm/setjmp.h index 1fe37c91cc..001c7ea322 100644 --- a/arch/sandbox/include/asm/setjmp.h +++ b/arch/sandbox/include/asm/setjmp.h @@ -24,6 +24,11 @@ struct jmp_buf_data { typedef struct jmp_buf_data jmp_buf[1]; +/* + * We have to directly link with the system versions of + * setjmp/longjmp, because setjmp must not return as otherwise + * the stack may become invalid. + */ int setjmp(jmp_buf jmp); __noreturn void longjmp(jmp_buf jmp, int ret); diff --git a/include/os.h b/include/os.h index c8e0f52d30..64e89a06c9 100644 --- a/include/os.h +++ b/include/os.h @@ -330,25 +330,4 @@ int os_spl_to_uboot(const char *fname); */ void os_localtime(struct rtc_time *rt); -/** - * os_setjmp() - Call setjmp() - * - * Call the host system's setjmp() function. - * - * @jmp: Buffer to store current execution state - * @size: Size of buffer - * @return normal setjmp() value if OK, -ENOSPC if @size is too small - */ -int os_setjmp(ulong *jmp, int size); - -/** - * os_longjmp() - Call longjmp() - * - * Call the host system's longjmp() function. - * - * @jmp: Buffer where previous execution state was stored - * @ret: Value to pass to longjmp() - */ -void os_longjmp(ulong *jmp, int ret); - #endif From patchwork Fri Jun 22 12:44:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 139613 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp832180lji; Fri, 22 Jun 2018 05:47:25 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLvs3x4ZPXxXH8Uz2P7b8jjvFsN+cUw+Lp4/1/dApE252YkazffrUzbpb2fHmu8hYpnBE8n X-Received: by 2002:a50:a944:: with SMTP id m4-v6mr1761223edc.180.1529671645213; Fri, 22 Jun 2018 05:47:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529671645; cv=none; d=google.com; s=arc-20160816; b=zQ3DyR5MDyHJrE/fCaJqq4bWBWkvnYTeUUqw/uhYfNtJpP96z9YjcN7baej7dAuSu2 c6cHoR0bM+H9qroR42aeyWYTLsCx3/J1g7jwWwwBgQdPPwwEDws95poUDSu16RqDK0iZ OoOJ4cypIj+Fb4+Z8acncbQn4c5x1R4hn7LPcEGZkiE8bdlVqJd/UUOHcVYbzSnrikZY Luxu9IXbbDGxqtS14hnSiEa6n5/ZKqTu1s3kEBHWOOFznF/IpEbNimsjMu1RzHM2UI+2 olaQzfj4e2wz6EGL0wSn99gNJqbX2gDJf/j/qyWwp1s4EUfje65/szm/5GAxLtyOvV5O nNgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:arc-authentication-results; bh=FnJPQaAHpVZeCF6/bqJttlGBeEK5aMlwkug53Ls3xHU=; b=g6I/3Nol5JJIgFCxVxsIdjTgwaKyVdbT6uH8pGY9fII7rRbRlq+rs/Sw2QtJvyr1WY 4WwviKhXiuvUtbYcfmP4tDlkg7lZ1lR6KFZANZq+YkgE0VDeegLkiRyhKk+cbw2G/2yz WuaHEo4wIYujz3hxh5l9tNDtEaxhJBKpToUEusAiyHMj0HavaQ7kbMaa/Qb8dHcKBVd8 6Ncj9qZXMI+vhMC37LwGi4pQLplSIYvWT3zYpexEZMBW1ZxncJbnrM1ct3W/iRUmKxuK DH8vHd1afSJQRM6PQD/1kinBVfx37xgl137QejP896PHi+GFxOJooF6X6uyDYHtQT8fy G/ug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id d90-v6si3678245edc.242.2018.06.22.05.47.24; Fri, 22 Jun 2018 05:47:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id D80D8C21F99; Fri, 22 Jun 2018 12:45: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 AB5C3C21F92; Fri, 22 Jun 2018 12:44:23 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 17F0EC21C2F; Fri, 22 Jun 2018 12:44:20 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id 9B168C21C50 for ; Fri, 22 Jun 2018 12:44:20 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id ED79DAF38; Fri, 22 Jun 2018 12:44:19 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Fri, 22 Jun 2018 14:44:13 +0200 Message-Id: <20180622124418.52892-6-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180622124418.52892-1-agraf@suse.de> References: <20180622124418.52892-1-agraf@suse.de> Cc: Heinrich Schuchardt , Andy Shevchenko Subject: [U-Boot] [PATCH v5 05/10] sandbox: Allow to execute from RAM 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" With efi_loader, we may want to execute payloads from RAM. By default, permissions on the RAM region don't allow us to execute from there though. So let's change the default allocation scheme for RAM to also allow execution from it. That way payloads that live in U-Boot RAM can be directly executed. Signed-off-by: Alexander Graf Reviewed-by: Simon Glass --- v4 -> v5: - Replace runtime mprotect() mechanism with mmap() flag --- arch/sandbox/cpu/os.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index fc2f9dbc7a..e3fe017b5f 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -144,7 +144,8 @@ void *os_malloc(size_t length) { struct os_mem_hdr *hdr; - hdr = mmap(NULL, length + sizeof(*hdr), PROT_READ | PROT_WRITE, + hdr = mmap(NULL, length + sizeof(*hdr), + PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (hdr == MAP_FAILED) return NULL; From patchwork Fri Jun 22 12:44:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 139612 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp832104lji; Fri, 22 Jun 2018 05:47:20 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKYT+9Dz0OzN2d+ozq7O8SEo+KSClnAQNnz/bJLVwhTcc4p41VLtbpGx6txFtF6XgSQgp8l X-Received: by 2002:a50:8c41:: with SMTP id p59-v6mr1726393edp.207.1529671640270; Fri, 22 Jun 2018 05:47:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529671640; cv=none; d=google.com; s=arc-20160816; b=rU6vNggMwlUq/Of/4TZMz+yxbuMiTUZ1qwqKBLyeMyUkMNs3IRNdhuKhkxz24NMXDu jQ+22VyJXZ98RloPB6YJmq7yA4YNlYZNmmwPFT7E7E/DEPRdHg9yLNR7B1Z8IfS1tJIu Xfo3Jrk+QzOgPebci7M7OsF5PEHXY9RpKwsnUc7eHHTPTu3PLQd1VSklQC/trUM5nHRn qb0S1XWyjZTtiNeBGTfxBFTkr2gyODMtrx3+SXUixyYramnYjHsJL2qy0dQlz7Ach3kW FMe32A593e8T2mNyqVhEDKqVxbTQHlDpAKJNmfiCsF1YvIAJO50h50C5BcceY+Va7mSP uobA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:arc-authentication-results; bh=3Ut+M3EdY8GDDCLsMrZanBpyhTprIcM5W82JFGrjy9Y=; b=wwvTQH5CiaZSTsP5vkJYg/07KTxpljXw9yCW/3orYzF8r4QoWaihfJuamM3v3miKLl yAVVUxCTQOTGvrLgayDgAWxYsdgvq3Sf+q0CCk4QYALzng11VWqK+vMABf0MQjgv/i6v +c5ZLbvqhVVvsNCj6+dUux7RJCD9pWm7/IWYvZ4YmGT0FySPFzPdw7UN/Rz/dtZscdJX J5IwbPdUs5yq49bho342bgOr0YZXVD/YVK6SWpXZ8vEeFvrsA73z4iUudCkca0UOcvbF D+YZ/R08AgdV1UlJwYLAWe/2Vg1v7LX8pACA9Ic8ShRRihYlmbRLZ0gcRH5H6WF/hxc4 M0PQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id 5-v6si3696536edn.30.2018.06.22.05.47.20; Fri, 22 Jun 2018 05:47:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id E34CEC21F93; Fri, 22 Jun 2018 12:45:38 +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 46164C21FD5; Fri, 22 Jun 2018 12:44:25 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 4C1F2C21C2C; Fri, 22 Jun 2018 12:44:21 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id B2DBDC21E74 for ; Fri, 22 Jun 2018 12:44:20 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id EA4B6AF2E; Fri, 22 Jun 2018 12:44:19 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Fri, 22 Jun 2018 14:44:14 +0200 Message-Id: <20180622124418.52892-7-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180622124418.52892-1-agraf@suse.de> References: <20180622124418.52892-1-agraf@suse.de> Cc: Heinrich Schuchardt , Andy Shevchenko Subject: [U-Boot] [PATCH v5 06/10] 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Simon Glass 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 Signed-off-by: Alexander Graf --- arch/sandbox/cpu/os.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index e3fe017b5f..3067503d51 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -143,15 +143,16 @@ 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), + hdr = mmap(NULL, length + page_size, PROT_READ | PROT_WRITE | PROT_EXEC, 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 Fri Jun 22 12:44:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 139610 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp830001lji; Fri, 22 Jun 2018 05:45:06 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLyTxMC4cH1x7hAP7PODdDmOl82JSL4cxAGmJ7E8EFjOv0wL0MQkeKqcrDC0rflomu8rrKJ X-Received: by 2002:a50:ace6:: with SMTP id x93-v6mr1732194edc.209.1529671505966; Fri, 22 Jun 2018 05:45:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529671505; cv=none; d=google.com; s=arc-20160816; b=jTDTyWdEvAXHhQ9+nd7biCHftlIM3/NzZkDntJ80Spx9FAVf2gYA6JMafP5W7XvmJO /xqytpLT4qqvbXeyknq8at8+PdDmVUIqsQF3OWu2tDObYDrfY6wUBhE6G2+OF9dc+XV3 IkaX+qdWx44rb8/v0qrLUIxHUSz225TiqRuqgBCBmJK8l8YV16UQ8o2enBO5cFKI5v7q iJ9crphrswRWu+AXJw2Zc7EXn7hoFYEiCXzK4PcpQpQxO34QSWWEnMECGYD4xL/ZXI5t gqEn4wUxVKDG5ynzHTVnrtLxKlGKvcnfk9Y4E+Ytxw5Y6M8QkJMlL8DjNr4+r8Z00CqO sonQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:arc-authentication-results; bh=eLy4511VaRN8wCVCm0jd+HYHEGEUBoxqEY/tcQe8oVg=; b=QZHAjU7xquvai0NG5o/G+VTN4L7YuzfefE1hpT6WcKx8oLf7KEhj9pHKQ0JU029lOh EDYd8cPTZ++TfkPVsNNGnVr409I88oL7pWDRCeA00wlC06Diy82G1ufkdv+J8pclPwdT 1fLzTKx7gDEpbrHJauTC+v2zUn2kEtDXmnDbOr+ciTHlzL2oVHOMGlQ2lUZEvqq5fMKN SfuGDf/xAXl7Jknguk7uWxUfHVvwv/hIgGmeXsUQSHSSbcWWh+PI6XkNDgvExs/8VGDd gGmz+KEAghy/tU1nzN9NImx1EWYXqMa5EqoyKclUYVubiyIszZ1r6y5defXRmuAvKdFj a+uw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id s8-v6si3781747edi.211.2018.06.22.05.45.05; Fri, 22 Jun 2018 05:45:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id 91011C22010; Fri, 22 Jun 2018 12:44: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=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 CAB36C21F2F; Fri, 22 Jun 2018 12:44:22 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 04384C21C2C; Fri, 22 Jun 2018 12:44:20 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id 87114C21C2F for ; Fri, 22 Jun 2018 12:44:20 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E63EBAEC7; Fri, 22 Jun 2018 12:44:19 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Fri, 22 Jun 2018 14:44:15 +0200 Message-Id: <20180622124418.52892-8-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180622124418.52892-1-agraf@suse.de> References: <20180622124418.52892-1-agraf@suse.de> Cc: Heinrich Schuchardt , Andy Shevchenko Subject: [U-Boot] [PATCH v5 07/10] sandbox: smbios: Update to support 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Simon Glass At present this code casts addresses to pointers so cannot be used with sandbox. Update it to use mapmem instead. Signed-off-by: Simon Glass [agraf: Adapt efi smbios api usage] Signed-off-by: Alexander Graf --- lib/efi_loader/efi_smbios.c | 18 ++++++++++++++---- lib/smbios.c | 32 ++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/lib/efi_loader/efi_smbios.c b/lib/efi_loader/efi_smbios.c index 932f7582ec..469068d34d 100644 --- a/lib/efi_loader/efi_smbios.c +++ b/lib/efi_loader/efi_smbios.c @@ -8,6 +8,7 @@ #include #include #include +#include #include static const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID; @@ -21,6 +22,8 @@ efi_status_t efi_smbios_register(void) { /* Map within the low 32 bits, to allow for 32bit SMBIOS tables */ u64 dmi = U32_MAX; + u64 dmi_addr; + void *dmi_ptr; efi_status_t ret; /* Reserve 4kiB page for SMBIOS */ @@ -37,14 +40,21 @@ efi_status_t efi_smbios_register(void) } /* + * efi_allocate_pages() returns the allocated pointer in dmi, + * which we need to convert back into a U-Boot address for + * write_smbios_table() + */ + dmi_ptr = (void *)(uintptr_t)dmi; + dmi_addr = map_to_sysmem(dmi_ptr); + + /* * Generate SMBIOS tables - we know that efi_allocate_pages() returns * a 4k-aligned address, so it is safe to assume that * write_smbios_table() will write the table at that address. */ - assert(!(dmi & 0xf)); - write_smbios_table(dmi); + assert(!(dmi_addr & 0xf)); + write_smbios_table(dmi_addr); /* And expose them to our EFI payload */ - return efi_install_configuration_table(&smbios_guid, - (void *)(uintptr_t)dmi); + return efi_install_configuration_table(&smbios_guid, dmi_ptr); } diff --git a/lib/smbios.c b/lib/smbios.c index df3d26b071..fc3dabcbc1 100644 --- a/lib/smbios.c +++ b/lib/smbios.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -72,9 +73,10 @@ static int smbios_string_table_len(char *start) static int smbios_write_type0(ulong *current, int handle) { - struct smbios_type0 *t = (struct smbios_type0 *)*current; + struct smbios_type0 *t; int len = sizeof(struct smbios_type0); + t = map_sysmem(*current, len); memset(t, 0, sizeof(struct smbios_type0)); fill_smbios_header(t, SMBIOS_BIOS_INFORMATION, len, handle); t->vendor = smbios_add_string(t->eos, "U-Boot"); @@ -101,16 +103,18 @@ static int smbios_write_type0(ulong *current, int handle) len = t->length + smbios_string_table_len(t->eos); *current += len; + unmap_sysmem(t); return len; } static int smbios_write_type1(ulong *current, int handle) { - struct smbios_type1 *t = (struct smbios_type1 *)*current; + struct smbios_type1 *t; int len = sizeof(struct smbios_type1); char *serial_str = env_get("serial#"); + t = map_sysmem(*current, len); memset(t, 0, sizeof(struct smbios_type1)); fill_smbios_header(t, SMBIOS_SYSTEM_INFORMATION, len, handle); t->manufacturer = smbios_add_string(t->eos, CONFIG_SMBIOS_MANUFACTURER); @@ -122,15 +126,17 @@ static int smbios_write_type1(ulong *current, int handle) len = t->length + smbios_string_table_len(t->eos); *current += len; + unmap_sysmem(t); return len; } static int smbios_write_type2(ulong *current, int handle) { - struct smbios_type2 *t = (struct smbios_type2 *)*current; + struct smbios_type2 *t; int len = sizeof(struct smbios_type2); + t = map_sysmem(*current, len); memset(t, 0, sizeof(struct smbios_type2)); fill_smbios_header(t, SMBIOS_BOARD_INFORMATION, len, handle); t->manufacturer = smbios_add_string(t->eos, CONFIG_SMBIOS_MANUFACTURER); @@ -140,15 +146,17 @@ static int smbios_write_type2(ulong *current, int handle) len = t->length + smbios_string_table_len(t->eos); *current += len; + unmap_sysmem(t); return len; } static int smbios_write_type3(ulong *current, int handle) { - struct smbios_type3 *t = (struct smbios_type3 *)*current; + struct smbios_type3 *t; int len = sizeof(struct smbios_type3); + t = map_sysmem(*current, len); memset(t, 0, sizeof(struct smbios_type3)); fill_smbios_header(t, SMBIOS_SYSTEM_ENCLOSURE, len, handle); t->manufacturer = smbios_add_string(t->eos, CONFIG_SMBIOS_MANUFACTURER); @@ -160,6 +168,7 @@ static int smbios_write_type3(ulong *current, int handle) len = t->length + smbios_string_table_len(t->eos); *current += len; + unmap_sysmem(t); return len; } @@ -198,9 +207,10 @@ static void smbios_write_type4_dm(struct smbios_type4 *t) static int smbios_write_type4(ulong *current, int handle) { - struct smbios_type4 *t = (struct smbios_type4 *)*current; + struct smbios_type4 *t; int len = sizeof(struct smbios_type4); + t = map_sysmem(*current, len); memset(t, 0, sizeof(struct smbios_type4)); fill_smbios_header(t, SMBIOS_PROCESSOR_INFORMATION, len, handle); t->processor_type = SMBIOS_PROCESSOR_TYPE_CENTRAL; @@ -214,32 +224,37 @@ static int smbios_write_type4(ulong *current, int handle) len = t->length + smbios_string_table_len(t->eos); *current += len; + unmap_sysmem(t); return len; } static int smbios_write_type32(ulong *current, int handle) { - struct smbios_type32 *t = (struct smbios_type32 *)*current; + struct smbios_type32 *t; int len = sizeof(struct smbios_type32); + t = map_sysmem(*current, len); memset(t, 0, sizeof(struct smbios_type32)); fill_smbios_header(t, SMBIOS_SYSTEM_BOOT_INFORMATION, len, handle); *current += len; + unmap_sysmem(t); return len; } static int smbios_write_type127(ulong *current, int handle) { - struct smbios_type127 *t = (struct smbios_type127 *)*current; + struct smbios_type127 *t; int len = sizeof(struct smbios_type127); + t = map_sysmem(*current, len); memset(t, 0, sizeof(struct smbios_type127)); fill_smbios_header(t, SMBIOS_END_OF_TABLE, len, handle); *current += len; + unmap_sysmem(t); return len; } @@ -268,7 +283,7 @@ ulong write_smbios_table(ulong addr) /* 16 byte align the table address */ addr = ALIGN(addr, 16); - se = (struct smbios_entry *)(uintptr_t)addr; + se = map_sysmem(addr, sizeof(struct smbios_entry)); memset(se, 0, sizeof(struct smbios_entry)); addr += sizeof(struct smbios_entry); @@ -297,6 +312,7 @@ ulong write_smbios_table(ulong addr) isize = sizeof(struct smbios_entry) - SMBIOS_INTERMEDIATE_OFFSET; se->intermediate_checksum = table_compute_checksum(istart, isize); se->checksum = table_compute_checksum(se, sizeof(struct smbios_entry)); + unmap_sysmem(se); return addr; } From patchwork Fri Jun 22 12:44:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 139611 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp831057lji; Fri, 22 Jun 2018 05:46:13 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJYGM76a5YAFoz74ENUJUFf37FQCNqvEy1eOXJrVEZhqhJ+2E4dsR2eeBpZmebp9mbp529B X-Received: by 2002:a50:9772:: with SMTP id d47-v6mr1768319edb.174.1529671573069; Fri, 22 Jun 2018 05:46:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529671573; cv=none; d=google.com; s=arc-20160816; b=xO/UEU9D4VIVTuYBLomxZ8V/IheXtm4XlUZZckwLZblRORjvHwrBfxCKJhaG/qj/lg FL2jk0Bn2FChz9YPm3JF0Zud7+QklOdLzZ7UdLS59vb1+AHGGmryKH+o5LHVweBrfaKv 7gG+54aY9XtpOIKFIAYraOp3eDK3OdqP3EUU3hvbcVtn+Bw7DaJxn3kPUVpana54vU/v ruP6OOOxswJiaLVX1YP4vVdU1v4gBReTbH6emdSzkNe2IQWijjbV8EOvVkyKVIg+vffG +vqYWDhpfiyH+UKi02+OBMDgP1OV7tnBFFvt1ti6i38qmOFcQeo91zQeileOsVx5tLoF Sbfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:arc-authentication-results; bh=yPEUlUDlkVKnJLK7CCyZ1uE9cyS+bc3n7BCsw7FlFoE=; b=yTv8iaJwRW9gg2UQtuVwey2xit/LkVGahB/DufbAgHFBy8IzFH7X7I37JjVNzDkC4r //wqSAzwaP8cylbgHhZx7QYkAzmQ3g26dEO15pd/JG3dE8boUqMjOZCFuvAz8eETkRkM IiXqqtX7vDofvN7EdHUZVbCVwDzn2n/9VYHjdK77BtYdADkxp5h4q4xoeADz1/JgGIh7 baHWP6PTpLzJ1HgjtLO/eWUPNhxOH5Ij4FXUW7VKZ/YZcBuUFbs458rxw4T87gvIR12/ fc2AiAYwovTbrJgMJUVXfk7SSdstSL53Z8uzKjvvwgahw4Q8EhyEMEdSWZ+AM3H3vOGJ XPSg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id x4-v6si527971edx.103.2018.06.22.05.46.12; Fri, 22 Jun 2018 05:46:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id 9616FC21F6E; Fri, 22 Jun 2018 12:45:21 +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 825CEC21F79; Fri, 22 Jun 2018 12:44:24 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 41CA2C21C50; Fri, 22 Jun 2018 12:44:21 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id B63AAC21EF1 for ; Fri, 22 Jun 2018 12:44:20 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id F1416AF39; Fri, 22 Jun 2018 12:44:19 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Fri, 22 Jun 2018 14:44:16 +0200 Message-Id: <20180622124418.52892-9-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180622124418.52892-1-agraf@suse.de> References: <20180622124418.52892-1-agraf@suse.de> Cc: Heinrich Schuchardt , Andy Shevchenko Subject: [U-Boot] [PATCH v5 08/10] 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Simon Glass 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 Signed-off-by: Alexander Graf --- arch/sandbox/cpu/os.c | 5 +++++ include/os.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 3067503d51..9fbcb9ef92 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -631,3 +631,8 @@ void os_localtime(struct rtc_time *rt) rt->tm_yday = tm->tm_yday; rt->tm_isdst = tm->tm_isdst; } + +void os_abort(void) +{ + abort(); +} diff --git a/include/os.h b/include/os.h index 64e89a06c9..8fb9d309d0 100644 --- a/include/os.h +++ b/include/os.h @@ -330,4 +330,9 @@ int os_spl_to_uboot(const char *fname); */ void os_localtime(struct rtc_time *rt); +/** + * os_abort() - Raise SIGABRT to exit sandbox (e.g. to debugger) + */ +void os_abort(void); + #endif From patchwork Fri Jun 22 12:44:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 139617 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp834787lji; Fri, 22 Jun 2018 05:50:09 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKj6UT9Lm2akWuElWZTK8HPPTBPcmxMGHR/aP95N2tEn6k9YjwHjRnT7a039/zRX17Zpyva X-Received: by 2002:a50:de0c:: with SMTP id z12-v6mr1721794edk.245.1529671809375; Fri, 22 Jun 2018 05:50:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529671809; cv=none; d=google.com; s=arc-20160816; b=lkf+KPFE+r/zO6qqMTac09abuCW3+Il5aNtLs3lskKIHa+fVlp1fygqeNu8f//68Y7 J+AzEWlUf2GdkxXtDSPSdRV5co0f+LKsv0J9T9G/lsf/DHq5ADupfRk9HgcjGkS9ZWbW Dg1M7YSaSg9jhUQnZoCPxvCOw/zq4SUukFH5GPN6HgZt8JrQy1+bRHAo82nqTGPsQIIG bZVLGTN+iaP4Wv+071z1L/JENxC/cJ695UESzsRP2Fu5mO3CV+h7ZAzJJOCyxSZoWz14 aluhZRtsgf8kobqjGTGECTDckrdhJJXs5TcEPESy4jN3V2ESFLHb6dMGdk1k3n6tEiqW 9Meg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:arc-authentication-results; bh=fk/wtDiWY5uYn3aa6lvrNNLWOub49YX2m66G+Cdv0Qo=; b=IeAIStA29QhArep9/+kxK+kKwc6vbWUhSNwBzu5n8ADGDbm2Tduk97Bz9AmjVAFb5L ayWRab9gVkelGY26dkegRQu+imrI6Uat+qJRO1b4KCvDfiuQVwHpWN2F/cL+nhn4LZ3O BZqHiwFpec6J8eL6ztcrvcQfzTkM+dygzsmqkrI4phIqYIg1gz9SkBb+Cz/mwom2o5PP 2pVm74w45qq/rUimpqeBOnuEFtO2E91+hGW4mOJeFoSKjI5oDypdH9UHjJ5jaUa1EmvC NcEMPlO4CntQop4TIM9A88jwLAQAb+RGefnNOC1vLG+HIRbbpnKGEp9rKGwRFMP5D4y+ Pm+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id v21-v6si3475074edq.455.2018.06.22.05.50.09; Fri, 22 Jun 2018 05:50:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id E0F8CC21FA3; Fri, 22 Jun 2018 12:46:47 +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 EDC46C21E42; Fri, 22 Jun 2018 12:44:28 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9FB44C21C50; Fri, 22 Jun 2018 12:44:21 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id C7B65C21EFF for ; Fri, 22 Jun 2018 12:44:20 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id F33E5AF3B; Fri, 22 Jun 2018 12:44:19 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Fri, 22 Jun 2018 14:44:17 +0200 Message-Id: <20180622124418.52892-10-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180622124418.52892-1-agraf@suse.de> References: <20180622124418.52892-1-agraf@suse.de> Cc: Heinrich Schuchardt , Andy Shevchenko Subject: [U-Boot] [PATCH v5 09/10] 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Simon Glass 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 Signed-off-by: Alexander Graf --- 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 e7d3c272a4..456cfa3faa 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 thi sbuffer, 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 cc50819ab9..04a11fed55 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 7ed4b512d2..a612ce8944 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 Fri Jun 22 12:44:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 139614 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp832563lji; Fri, 22 Jun 2018 05:47:45 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKezml760cYGETkzJips1xVOWKxgO3T6uStGNBr0cxpL2hPxhfrNPAnDkMqjmoAvnpDAKTE X-Received: by 2002:aa7:c147:: with SMTP id r7-v6mr1759837edp.143.1529671664968; Fri, 22 Jun 2018 05:47:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529671664; cv=none; d=google.com; s=arc-20160816; b=rzTH0aRfW25oRdL/chEAacRvh24Kc23QlqE+TeXwz4YI2AiRYLAO5fJkFeGuFPtHi1 ChPf6faSkdpF1nI57S8C2qmDKLRukikv1pZroT4xdOauyqaScqlMQGc3vr1FrbVPQdu1 oFRnjJyeXB9cCh2i2T+DayGL7/FAIjT/jyUUGWN31kilFAJ7GQJ1mWIlYy2tRijWxwch WmXNp4PS9KqbkgGbTnmwRX2Uetu/3cBvm2dudRBB1vKr9Ry96Lj7Suo8/a+bg2n1S6fP W1+ZIOSa3skqeMzEK2xeGV+A/GUG/v8gY423+PGMznZ+im7LpNk1C/K6btTtwLGbDJJ9 gq5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:arc-authentication-results; bh=75hwE0ZAnxr1gXLWm/eZRksrtKOR/1PsNDqa7nkfQoQ=; b=y5WnQgYYI2gMnkfFZMArw6jNkJa3QdJ7n2k3gCORF8IptMYMO20NNFthW0g4WFUQfX bb80lI60VNiARQSuDV164iGEHsVzc5hyHDB31RITbsM3xV/HYPS3QeQFUv+rUDf5UtCc heUXDz1h9/SqY6QSMQuKNZ7YM4nvxOg1gVLkhhHpSc2vAuEtpOrLmq4IFVfk/tZP5QsD tvhEHFb9PvXIkGi+yyjOp1FwN8FE972hu3D/KNs/Rc07jJ+Z0LM9/1ohoRPJBIqEPPLf f+OCkp0ThAuFMC05MKnWuS0B0P7KjYDkvL06hlND4tZQI3kIjRwFlbBiUJaB8/QfYPvD nSaw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id b26-v6si3471657edr.445.2018.06.22.05.47.44; Fri, 22 Jun 2018 05:47:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id 85D1FC21FA3; Fri, 22 Jun 2018 12:47:08 +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 D960EC22076; Fri, 22 Jun 2018 12:44:29 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B6EFAC21C2F; Fri, 22 Jun 2018 12:44:21 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id CB8F1C21F1F for ; Fri, 22 Jun 2018 12:44:20 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 35012AF3C; Fri, 22 Jun 2018 12:44:20 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Fri, 22 Jun 2018 14:44:18 +0200 Message-Id: <20180622124418.52892-11-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180622124418.52892-1-agraf@suse.de> References: <20180622124418.52892-1-agraf@suse.de> Cc: Heinrich Schuchardt , Andy Shevchenko Subject: [U-Boot] [PATCH v5 10/10] efi: sandbox: Enable EFI loader 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Simon Glass 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 Signed-off-by: Alexander Graf --- 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 ce6a09f0b4..bfd7b19d79 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