Received: by 10.213.65.68 with SMTP id h4csp534635imn; Sat, 7 Apr 2018 04:17:46 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+exppwZYtf7DgDf26CSOKb5FYkeVsSM/ex03t5UlpMsVI7mt+/Ndi3hbAB1bQtGrv8JTJr X-Received: by 10.99.109.75 with SMTP id i72mr19963262pgc.403.1523099866331; Sat, 07 Apr 2018 04:17:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523099866; cv=none; d=google.com; s=arc-20160816; b=Ib2P21FcZHkPRtAjvUc0uOjXP0cdNxm5WafDDnZuYx3ZC1q/VmV9KuSU7I00gdqc3d LU/bh9ZRO3XVfpTNkzuoEuVUkvumapyFpn/oxB0vqD8aIovlrou0uY4E39PzJPpioGfc /fHNvNmCK87UOlf52SXzyTA4xvYnTEQ3wpXs1FTv7DgxzQhjcwWH50VmUaQgNVMDOpBp AymNMo2KrX9X8DPzTVLeXUIvOuGdDn4lodz0nCM8aFzGvo7y4s8/TsFjjT0HJGa9quv3 ii5ozZ0NIH1RMLVuuxZArOTPdeuPI1OF4ZeOiv2lWLCqtY/Y2ZUz1IzQM+D2OathHDNj cTLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=ZGEQPzaeJqD2dGpAT+Gjrw63a23e1rMu6INqHKxS2f4=; b=O3745O6eOv6gWj+v4CnkoXX3ZwEUNGHmdhRZ6vI/HhUfMti1SM8A4QJ1rOLno2L3pg ztPzDnrDKYIj2z4QJq2xemih4X83pDnbmpAlL6B3SDJC3nVJRgB9Eb/Yn2eKoswV26BF ZQhAOt1A/qz1zq0QmxjL5rT/o9f2siF55VI4i7GmLfXCVjvN8IvtCW0J/dq/n0DfziIy y0g2yZlsgCFk1MUN4edHysDlRS8uq6psxsCe3jisGLPfhyV5WDn2ILov6TiTLsCl/BOY W0aw5zfy7QGNMNVR6cWmNrKPpBEeCy07c4ChjtZuUm9BuKYS1xbo4iyTF8vN86RHp1dS DbEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y136si9558206pfg.81.2018.04.07.04.16.57; Sat, 07 Apr 2018 04:17:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751429AbeDGLNg (ORCPT + 99 others); Sat, 7 Apr 2018 07:13:36 -0400 Received: from mail-wm0-f52.google.com ([74.125.82.52]:51610 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751334AbeDGLNe (ORCPT ); Sat, 7 Apr 2018 07:13:34 -0400 Received: by mail-wm0-f52.google.com with SMTP id u189so8019954wmd.1 for ; Sat, 07 Apr 2018 04:13:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ZGEQPzaeJqD2dGpAT+Gjrw63a23e1rMu6INqHKxS2f4=; b=rafAhkxq+Q/6tcWTqe0BFuVk0/+zQ2+KWST7c7zMKPjaMnfg0Z10unFMr3OLrpVCp0 hFebu1R7FKQGFCyt6FejSSZGEkDt8bdMJYjRrvZ1GsgIJEd3JQw17WHJz8RE0WhUjQs1 MFXNXWHCYecC3uYBcyGrzEnSIFCMncPKn30W0+6pK1y8mE6tdq8m1ba39GI9bgyhJh7w a1Bha4MN0/Wv0T2WKEVOOy8kdIn0biVH/bGAS1hRPDnx5+3TAS+J92x5YOUAxfsInPfL IG/vQENW3QlWa+/p0t7nuuBp7R1Vh3JUchGH+7kQN/TOZ5GnfS9PEXTG5jvf/KxcgJnM x3fw== X-Gm-Message-State: ALQs6tBBFPNVKMpMFWBhxtGxs0XrJv5bL0Us1LEVsfkZIAoK8WHRmhDe TDqyTF3QSJeZ9vCAkvB50Rr8BA== X-Received: by 10.80.192.28 with SMTP id r28mr11525099edb.222.1523099612940; Sat, 07 Apr 2018 04:13:32 -0700 (PDT) Received: from shalem.localdomain (546A5441.cm-12-3b.dynamic.ziggo.nl. [84.106.84.65]) by smtp.gmail.com with ESMTPSA id q55sm3110923edd.28.2018.04.07.04.13.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Apr 2018 04:13:32 -0700 (PDT) Subject: Re: [PATCH 2/2] efi: Add embedded peripheral firmware support To: "Luis R. Rodriguez" , Lukas Wunner Cc: Peter Jones , Ard Biesheuvel , Greg Kroah-Hartman , Thomas Gleixner , Kalle Valo , Arend Van Spriel , Ingo Molnar , "H . Peter Anvin" , linux-kernel@vger.kernel.org, Dave Olsthoorn , x86@kernel.org, linux-efi@vger.kernel.org, Will Deacon , Andy Lutomirski , Matt Fleming , David Howells , Mimi Zohar , Josh Triplett , Matthew Garrett , One Thousand Gnomes , Linus Torvalds , dmitry.torokhov@gmail.com, mfuzzey@parkeon.com, keescook@chromium.org, nbroeking@me.com, bjorn.andersson@linaro.org, Torsten Duwe References: <78ae4d18-8964-5748-a69f-0017d0dca5f7@redhat.com> <20180404171835.xvllgcqirl3b5gd5@redhat.com> <20180405054349.GA25653@wunner.de> <20180406140832.GF30543@wotan.suse.de> From: Hans de Goede Message-ID: Date: Sat, 7 Apr 2018 13:13:31 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180406140832.GF30543@wotan.suse.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 06-04-18 16:08, Luis R. Rodriguez wrote: > On Thu, Apr 05, 2018 at 07:43:49AM +0200, Lukas Wunner wrote: >> On Wed, Apr 04, 2018 at 01:18:36PM -0400, Peter Jones wrote: >>>> On Tue, Apr 03, 2018 at 08:07:11PM +0200, Lukas Wunner wrote: >>>>> * Add the EFI Firmware Volume Protocol to include/linux/efi.h: >>>>> https://www.intel.com/content/dam/doc/reference-guide/efi-firmware-file-volume-specification.pdf >>>>> >>>>> * Amend arch/x86/boot/compressed/eboot.c to read the files with the >>>>> GUIDs you're interested in into memory and pass the files to the >>>>> kernel as setup_data payloads. >>> >>> To be honest, I'm a bit skeptical about the firmware volume approach. >>> Tools like UEFITool[0] and uefi-firmware-parser[1] have existed for >>> years, still don't seem to reliably parse firmware images I see in the >>> wild, and have a fairly regular need for fixes. These are tools >>> maintained by smart people who are making a real effort, and it still >>> looks pretty hard to do a good job that applies across a lot of >>> platforms. >>> >>> So I'd rather use Hans's existing patches, at least for now, and if >>> someone is interested in hacking on making an efi firmware volume parser >>> for the kernel, switch them to that when such a thing is ready. >> >> Hello? As I've written in the above-quoted e-mail the kernel should >> read the files using EFI_FIRMWARE_VOLUME_PROTOCOL.ReadFile(). >> >> *Not* by parsing the firmware volume! >> >> Parsing the firmware volume is only necessary to find out the GUIDs >> of the files you're looking for. You only do that *once*. > > How do you get the GUIDs for each driver BTW? > > Hans, I do believe we should *try* this approach at the very least. Ok, so I've made a ROM dump of one of the tablets which I have with the touchscreen firmware embedded in the EFI code using flashrom, then I ran UEFIExtract on it, to get all the separate files. Then I wrote a little test.sh script using hexdump piped to grep to find the magic prefix, here is the result of running this on all files UEFIExtract generated: [hans@shalem chuwi-vi8-plus-cwi519-bios.bin.dump]$ find -type f -exec ./test.sh '{}' \; 0x00000c40 3136 B0 07 00 00 E4 07 00 00 found in ./2 BIOS region/6 8C8CE578-8A3D-4F1C-9935-896185C32DD3/31 I2cHid/1 EE4E5898-3914-4259-9D6E-DC7BD79403CF/0 PE32 image section/body.bin 0x00000be0 3040 B0 07 00 00 E4 07 00 00 found in ./2 BIOS region/5 8C8CE578-8A3D-4F1C-9935-896185C32DD3/31 I2cHid/1 EE4E5898-3914-4259-9D6E-DC7BD79403CF/0 PE32 image section/body.bin With the version found at offset 0xbe0 of the "5 8C8CE578-8A3D-4F1C-9935-896185C32DD3" section matching what we find in the efi_boot_services_code while running. As the I2cHid name suggests this is embedded in the driver (which is a PE executable), not in a separate file: [hans@shalem chuwi-vi8-plus-cwi519-bios.bin.dump]$ file './2 BIOS region/5 8C8CE578-8A3D-4F1C-9935-896185C32DD3/31 I2cHid/1 EE4E5898-3914-4259-9D6E-DC7BD79403CF/0 PE32 image section/body.bin' ./2 BIOS region/5 8C8CE578-8A3D-4F1C-9935-896185C32DD3/31 I2cHid/1 EE4E5898-3914-4259-9D6E-DC7BD79403CF/0 PE32 image section/body.bin: MS-DOS executable So using the EFI_FIRMWARE_VOLUME_PROTOCOL.ReadFile() is not really going to help here, since this is not in a separate file which we can consume in its entirety, we still need to scan for the prefix and do e.g. a CRC check to make sure we've actually got what we expect, at which point simply scanning all of efi_boot_services_code is a lot simpler and less error prone. Using an implementation specific EFI protocol for this means calling into EFI code and potentially triggering various bugs in there, breaking boot. This is esp. likely to happen since this is a protocol which is not used outside of the EFI ROMs internal code so there are likely little ABI guarantees making this approach extra error prone. Just scanning the efi_boot_services_code OTOH is quite safe TODO. As for the overhead of scanning the efi_boot_services_code, we are only doing this on a dmi match, so on most machines there is no overhead other then the dmi check. On machines where there is a dmi match, the price (I guess about 30 ms or so for the scan) is well worth the result of having the touchscreen OOTB. Regard, Hans