Received: by 10.213.65.68 with SMTP id h4csp1331062imn; Wed, 4 Apr 2018 17:29:36 -0700 (PDT) X-Google-Smtp-Source: AIpwx49Aboaxg5wm/Ndp9xNLnGsEnUBdtUW6WgQtAvX4vewLpzVWQy3eVYHzIMd39i5HJ/wCKCE4 X-Received: by 2002:a17:902:5204:: with SMTP id z4-v6mr20559198plh.385.1522888176709; Wed, 04 Apr 2018 17:29:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522888176; cv=none; d=google.com; s=arc-20160816; b=kZAVxIXYGT2J8XBLXjX+hx5KZYQ14+M8GjNjQiDQihilU5imtkE1eEuhWFe81fBxOi yS5DEspTjIqlu0CDZKcVfxpr0IFwYUtCVCMtEr9MugZEssd5wg7wOUYLir75xVaD7sTA dBd+hwsTi2BiCs1KImynVvsnjp73HKNIA4ZWa0jCkZNaevHqP5awGPlFRw/3GN6knzXe 4JlTMJjEV9ybzz2gEZfgM+JSZKwZg3BjZchSPAulyleOaOAzEQ6LN1nQmYdzq9Un+JLZ X8+mvFcdjssOqmwgDLncRAszfY8S1EXcimVMYvQ692UBe+QEGajkrRI2eeWtK3Obz+My fWNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=bSVt+ONG0/VM3mfz1OGDZbXY5xZ3k0OSCP9tmJI7n+4=; b=WaxAFP4YczC9mn+1UefV9Qqmaejj+cypOLiqjULAxeaAVx80hW+0OiUWY1lplKzvq6 H8WU3hm6X4Woi0Ri2rAJ9RY23zGicmvDLfeF1YXhEijxbtRDEIsH5ehuCtWQxg2+YMf7 CBOUjuMKv812G7DwAiWRl00VRKHvKKeyxI2s2nd5OcBMvEGCddTNa7Z1EIZeK09VyWkf 0RXYXFdzQ4JuNQoSoSuTuYUM5huy3t58IiXWhSEH2dz5B5HFixOtwydKxu4pbxEB7do8 iev4GUs/m49heA2SLYzvHfYMUB3ULKzSvKGt7gTDiJJCZfXAYUOSZc8jrl5K6XzkaZZe Cy6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IPfIELlX; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t18si5010421pfj.217.2018.04.04.17.29.22; Wed, 04 Apr 2018 17:29:36 -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; dkim=pass header.i=@linaro.org header.s=google header.b=IPfIELlX; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752610AbeDEA2K (ORCPT + 99 others); Wed, 4 Apr 2018 20:28:10 -0400 Received: from mail-io0-f172.google.com ([209.85.223.172]:34886 "EHLO mail-io0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752548AbeDEA2I (ORCPT ); Wed, 4 Apr 2018 20:28:08 -0400 Received: by mail-io0-f172.google.com with SMTP id x77so22225902ioi.2 for ; Wed, 04 Apr 2018 17:28:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=bSVt+ONG0/VM3mfz1OGDZbXY5xZ3k0OSCP9tmJI7n+4=; b=IPfIELlXbjfawl1grQ7JEVWczt/aRoQGB37Tfp+UYSLL8df3CbyCjs3SZKNR37Li8Q 6XEomlICzmtap0j3InwTHh6+U5Cb+iuiAiAgAloxAKxlnoweoYPwsg7c+vB2/wr8RdYl 0MjV6b3YxYaYQ88QpOlwCWLbb5yubEApuOxUc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=bSVt+ONG0/VM3mfz1OGDZbXY5xZ3k0OSCP9tmJI7n+4=; b=FemEBCjqXmWYCsNOGUJfnwHumjhw+C/CRX35l9lC13g2Z3qtIzOXfnCKGus2mmEWLg dU1S5um4J3n7lIWHnTue30FFU0mJSCx6LOuVh6G4oQNdRscUtydJA1c9KTwuCn26pbge AqDhge8LHfxfY/Z8pw84Kd1g4/NZV80OAX/ddcfzQzMm5Wqi+1apq/HjvKB+O0eZ6/c4 Bw3yH6l3UVICgg15SNjygke+UIWcomViqYjt1Xk5oQ9ocq2aQHKuX+LeDftlULVEKpyg MY68FAQSPxXs9tAqQrQbl7T4fqRiGtslC/Io6WhH4Sw+QiBroBowdKc/AZ8ckigAzQbw U9TQ== X-Gm-Message-State: ALQs6tCZAHvDOAesRmWkJ6puKJDitDpXcxkxBdkLxBidVVUvKy2a19LW DEl2R9pOTwlv4bf6y++nFmEutveDPdF4NNUdGfdDdg== X-Received: by 10.107.16.230 with SMTP id 99mr19228016ioq.60.1522888087098; Wed, 04 Apr 2018 17:28:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.187.67 with HTTP; Wed, 4 Apr 2018 17:28:06 -0700 (PDT) In-Reply-To: <78ae4d18-8964-5748-a69f-0017d0dca5f7@redhat.com> References: <20180331121944.8618-1-hdegoede@redhat.com> <20180331121944.8618-2-hdegoede@redhat.com> <20180402232333.GU30543@wotan.suse.de> <17fb3c28-78ff-2e1f-2ada-d33320567761@redhat.com> <20180403180711.GA7957@wunner.de> <20180403185848.GD30543@wotan.suse.de> <20180404171835.xvllgcqirl3b5gd5@redhat.com> <78ae4d18-8964-5748-a69f-0017d0dca5f7@redhat.com> From: Ard Biesheuvel Date: Thu, 5 Apr 2018 02:28:06 +0200 Message-ID: Subject: Re: [PATCH 2/2] efi: Add embedded peripheral firmware support To: Hans de Goede Cc: Peter Jones , "Luis R. Rodriguez" , Lukas Wunner , Greg Kroah-Hartman , Thomas Gleixner , Kalle Valo , Arend Van Spriel , Ingo Molnar , "H . Peter Anvin" , Linux Kernel Mailing List , Dave Olsthoorn , "the arch/x86 maintainers" , 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, Kees Cook , nbroeking@me.com, Bjorn Andersson , Torsten Duwe Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4 April 2018 at 22:25, Hans de Goede wrote: > HI, > > > On 04-04-18 19:18, Peter Jones wrote: >> >> On Tue, Apr 03, 2018 at 06:58:48PM +0000, Luis R. Rodriguez wrote: >>> >>> On Tue, Apr 03, 2018 at 08:07:11PM +0200, Lukas Wunner wrote: >>>> >>>> On Tue, Apr 03, 2018 at 10:33:25AM +0200, Hans de Goede wrote: >>>>> >>>>> I asked Peter Jones for suggestions how to extract this during boot and >>>>> he suggested seeing if there was a copy of the firmware in the >>>>> EFI_BOOT_SERVICES_CODE memory segment, which it turns out there is. >>>>> >>>>> My patch to add support for this contains a table of device-model (dmi >>>>> strings), firmware header (first 64 bits), length and crc32 and then if >>>>> we boot on a device-model which is in the table the code scans the >>>>> EFI_BOOT_SERVICES_CODE for the prefix, if found checks the crc and >>>>> caches the firmware for later use by request-firmware. >>>>> >>>>> So I just do a brute-force search for the firmware, this really is >>>>> hack, >>>>> nothing standard about it I'm afraid. But it works on 4 different x86 >>>>> tablets I have and makes the touchscreen work OOTB on them, so I >>>>> believe >>>>> it is a worthwhile hack to have. >>>> >>>> >>>> The EFI Firmware Volume contains a kind of filesystem with files >>>> identified by GUIDs. Those files include EFI drivers, ACPI tables, >>>> DMI data and so on. It is actually quite common for vendors to >>>> also include device firmware on the Firmware Volume. Apple is doing >>>> this to ship firmware updates e.g. for the GMUX controller found on >>>> dual GPU MacBook Pros. If they want to update the controller's >>>> firmware, they include it in a BIOS update, and an EFI driver checks >>>> on boot if the firmware update for the controller is necessary and >>>> if so, flashes it. >>>> >>>> The firmware files you're looking for are almost certainly included >>>> on the Firmware Volume as individual files. >>> >>> >>> What Hans implemented seems to have been for a specific x86 hack, best if >>> we >>> confirm if indeed they are present on the Firmware Volume. >> >> >> 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. >> >> [0] git@github.com:LongSoft/UEFITool.git >> [1] git@github.com:theopolis/uefi-firmware-parser.git >> >>>> Rather than scraping >>>> the EFI memory for firmware, I think it would be cleaner and more >>>> elegant if you just retrieve the files you're interested in from >>>> the Firmware Volume. >>>> >>>> We're doing something similar with Apple EFI properties, see >>>> 58c5475aba67 and c9cc3aaa0281. >>>> >>>> Basically what you need to do to implement this approach is: >>>> >>>> * Determine the GUIDs used by vendors for the files you're interested >>>> in. Either dump the Firmware Volume or take an EFI update as >>>> shipped by the vendor, then feed it to UEFIExtract: >>>> https://github.com/LongSoft/UEFITool >>>> * 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. >>>> >>>> * Once the kernel has booted, make the files you've retrieved >>>> available to device drivers as firmware blobs. >>> >>> >>> Happen to know if devices using Firmware Volumes also sign their firmware >>> and if hw checks the firmware at load time? >> >> >> It varies on a per-device basis, of course. Most new Intel machines as >> of Haswell *should* be verifying their system firmware via Boot Guard, >> which both checks an RSA signature and measures the firmware into the >> TPM, but as with everything of this nature, there are certainly vendors >> that screw it up. (I think AMD has something similar, but I'm really not >> sure.) > > > Lukas, thank you for your suggestions on this, but I doubt that these > devices use the Firmware Volume stuff. > Aren't Firmware Volumes a PI thing rather than a UEFI thing? > These are really cheap x86 Windows 10 tablets, everything about them is > simply hacked together by the manufacturer till it boots Windows10 and > then it is shipped to the customer without receiving any update > afterwards ever. > > What you are describing sounds like significantly more work then > the vendor just embedding the firmware as a char firmware[] in their > EFI mouse driver. > > That combined with Peter's worries about difficulties parsing the > Firmware Volume stuff, makes me believe that it is best to just > stick with my current approach as Peter suggests. > > Regards, > > Hans >