<<

- the free

vimacs

Linux Club of Peking University

May 19th, 2018

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 1 / 77 License

This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/.

You can find the of this presentation at: https://git.wehack.space/coreboot-talk/

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 2 / 77 Index

1 What is coreboot? History Why use coreboot

2 How coreboot works

3 Building and using coreboot Building Flashing

4 Utilities and Debugging

5 Join the community

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 3 / 77 Index

6 Porting coreboot with autoport ASRock B75 Pro3-M Sandy/Ivy Bridge HP Elitebooks Dell Latitude E6230

7 References

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 4 / 77 1 What is coreboot? History Why use coreboot

2 How coreboot works

3 Building and using coreboot Building Flashing

4 Utilities and Debugging

5 Join the community

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 5 / 77 What is coreboot?

coreboot is an extended firmware platform that delivers a lightning fast and secure boot experience on modern and embedded systems. As an Open Source project it provides auditability and maximum control over technology. The word ’coreboot’ should always be written in lowercase, even at the start of a sentence.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 6 / 77 History: from LinuxBIOS to coreboot

coreboot has a very long history, stretching back more than 18 years to when it was known as LinuxBIOS. While the project has gone through lots of changes over the years, many of the earliest developers still contribute today.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 7 / 77 LinuxBIOS v1: 1999-2000

The coreboot project originally started as LinuxBIOS in 1999 at Los Alamos National Labs (LANL) by Ron Minnich. Ron needed to boot a cluster made up of many mainboards without the hassles that are part of the PC BIOS. The goal was to do minimal hardware initilization in order to boot as fast as possible. Linux already had the drivers and support to initialize the majority of devices. Ron and a number of other key contributors from LANL, Linux NetworkX, and other open source firmware projects successfully booted Linux from flash. From there they were able to discover other nodes in the cluster, load a full kernel and , and start the clustering software.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 8 / 77 LinuxBIOS v2: 2000-2005

After the initial success of v1, the design was expanded to support more CPU architectures (x86, Alpha, PPC) and to support developers with increasingly diverse needs. One of the design goal is to have little assembly as possible. standard cannot be used because C requires memory for stack the new DDR memory controllers required significantly more configuration and a lot more ASM solution: ROMCC by Eric Biederman LinuxBIOS device tree was introduced. Many target systems had flash that were too small to hold both the hardware initialization code and the . Payloads were created. modified etherboot for clusters FILO for disk-based boot

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 9 / 77 LinuxBIOS v2+: 2005-2008

Cache as RAM was introduced in 2005. Stefan Reinauer formed a company named coresystems GmbH to support LinuxBIOS. Stefan was one of the primary developers and co-leaders of LinuxBIOS with Ron Minnich. His significant contributions included the first AMD64 port, the original ACPI implementation, the original SMM implementation, the utility, and the FILO payload development and maintainer. In 2005, FSF started the Free BIOS campaign to support LinuxBIOS development. Ward Vandewege of FSF ported LinuxBIOS to the FSF servers and other mainboards.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 10 / 77 LinuxBIOS v3: 2006-2008

By 2006, LinuxBIOS had already supported hundreds of mainboards. With so many boards, there were problems with porting additional silicon and systems. Developers fixed and clarified many driver and bus support issues in the device tree. Kconfig firmware image archive called LAR (LinuxBIOS Archiver), which led to the more refined and flexible concept of CBFS It wasn’t the main development branch; it was essentially an R&D branch, where the best ideas were backported to v2.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 11 / 77 2008: LinuxBIOS renamed coreboot

https://www.coreboot.org/pipermail/coreboot/2008-January/ 029135.html LinuxBIOS = (core boot code) + (Linux kernel) Linux was no longer booted directly from flash

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 12 / 77 coreboot v4

In early 2010, coreboot moved from SVN to Git during the transition, the community took the opportunity to recognize the advancements of the past 10 years and updated to version 4.0. contributions from AMD: AMD Generic Encapsulated Software Architecture (AGESA) FSP for ThinkPad T60 coreboot v4.1

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 13 / 77 Why use coreboot

You can see the advantages of coreboot at: https://www.coreboot.org/users.html coreboot is (see FSF Free BIOS Campaign) fast boot times it’s flexible

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 14 / 77 libreboot and firmware freedom

Some firmware components are non-free: Intel ME firmware/AMD PSP Intel FSP/closed source AGESA Option ROMs (including VGA BIOS) CPU microcode EC firmware Libreboot is a coreboot distribution that removes proprietary components, including Intel ME, FSP, VGA BIOS, etc. On some laptops, the EC firmware is also free(Chromium EC in ).

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 15 / 77 me_cleaner

ME firmware can be neutralized: ME firmware partitions are individually signed, we can remove allthe partitions except FTPR. In each partition, the manifests of the modules are signed, but the modules are only checked before being executed, so the modules that don’t need to be executed can be removed. For more information, read the me_cleaner wiki at https: //github.com/corna/me_cleaner/wiki/How-does-it-work%3F.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 16 / 77 LinuxBoot

LinuxBoot (https://www.linuxboot.org) is a firmware for modern servers that replaces specific firmware functionality like the UEFI DXE phase with a Linux kernel and runtime.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 17 / 77 UEFI v.s. NERF

NERF is LinuxBoot with u-root as the initramfs. u-root contains boot policy tools in Go (e.g. PXE , booting via GRUB config) among standard busybox-like utilities rewritten in Go. UEFI = Unified Extensible Firmware Interface NERF = Non-Extensible Reduced Firmware

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 18 / 77 Fun stuff, and more

Fun stuff: https://www.coreboot.org/Fun_Stuff BIOS malware: https://news.ycombinator.com/item?id=10039870 rm -rf /sys/firmware/efi/efivars can brick a system SMM Vulnerabilities in firmware

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 19 / 77 1 What is coreboot? History Why use coreboot

2 How coreboot works

3 Building and using coreboot Building Flashing

4 Utilities and Debugging

5 Join the community

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 20 / 77 How coreboot works

We’ll take /x230 as example to see how a machine boots with coreboot. We can build coreboot with make V=1 > build.log to see which files are used to build coreboot for this mainboard. All the source code is in the src/ directory, we’ll omit it in the following slides.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 21 / 77 coreboot stages

The coreboot firmware runs in several stages. bootblock: the earliest code that the CPU runs romstage: before main memory is ready, only the code in the flash can be run, and no other memory can be used ramstage: after main memory can be used, the ramstage code is uncompressed in memory, and do the remaining initialization payload: OS or OS loader

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 22 / 77 bootblock

When the machine starts, PC poionts at reset vector (f000:fff0), the CPU runs the bootblock code. The bootblock code is in arch/x86/bootblock_romcc.S , which includes: cpu/x86/16bit/reset16.inc: the code at reset vector cpu/x86/16bit/entry16.inc: the 16-bit code that sets CPU to protected mode cpu/x86/32bit/entry32.inc: sets segment registers generated/bootblock.inc: generated by ROMCC from arch/x86/bootblock_simple.c , which then runs romstage

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 23 / 77 romstage

romstage starts at arch/x86/assembly_entry.S , which includes: cpu/x86/32bit/entry32.inc: loads GDT and sets segment registers generated/assembly.inc: generated from cpu/intel/model_206ax/cache_as_ram.inc, which: sets up CAR calls romstage_main() , which runs the init code in romstage disable CAR calls romstage_after_car() , which calls run_ramstage() to run ramstage romstage_main() is in cpu/intel/car/romstage.c, it calls mainboard_romstage_entry() in northbridge/intel/sandybridge/romstage.c, which does the DRAM initialization.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 24 / 77 ramstage

ramstage starts at src/arch/x86/c_start.S , it calls the main function in src/lib/hardwaremain.c. There are 12 boot states defined in source code. Functions for each state are run in ramstage. At last payload is loaded and run.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 25 / 77 Payloads

There are many coreboot payloads: SeaBIOS: a PC BIOS implementation GRUB2 Linux kernel Tianocore: a UEFI implementation by Intel depthcharge: a written by Google for Chromebooks u-boot Some useful tools can also be payloads: nvramcui: a tool to edit CMOS coreinfo: system information memtest86+

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 26 / 77 Full disk encryption with LUKS

When using coreboot, we can use GRUB or a Linux kernel based OS as payload. Therefore, we can do a full disk encryption with LUKS.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 27 / 77 Linux kernel as payload

We can first run a Linux kernel, then using kexec to run the kernel on disk. Petitboot: a bootloader designed to run in a Linux environment for OPAL on PowerPC/POWER machines and the Playstation 3 Heads: https://github.com/osresearch/heads

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 28 / 77 Supported OSes

coreboot supports many operating systems: Linux: boots via GRUB2,SeaBIOS, or using Linux kernel as payload OpenBSD: boots via SeaBIOS with VGA option ROM. Now it supports UEFI and don’t need VGA BIOS, so it now supports libreboot. See libreboot mailing list. Windows: boots via SeaBIOS and Tianocore

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 29 / 77 1 What is coreboot? History Why use coreboot

2 How coreboot works

3 Building and using coreboot Building Flashing

4 Utilities and Debugging

5 Join the community

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 30 / 77 Building coreboot and run on QEMU

https://www.coreboot.org/Lesson1 is a good place to start. Build a cross toolchain for building coreboot make crossgcc or make crossgcc-

Generate a configuration make nconfig

At last do a make to build it, the built firmware is at build/coreboot.rom. Run coreboot on QEMU qemu-system-i386 - build/coreboot.rom

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 31 / 77 Hardware flashing

To use coreboot on real machines, we need to know how to flash externally with a hardware flash programmer. Most of the mainboards can only be flashed externally with factory firmware running. We need to flash externally to unbrick a machine. We need a programmer and a connector to connect the flash.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 32 / 77 Tools to flash a chip

A lot of mainboards use SPI NOR flash, most of them are in SOIC-8 package. To program SPI NOR flash, we can use one of the following tools: Using Linux SPI: Raspberry Pi, Beaglebone Micro controllers: Arduino, Bus Pirate, STM32 Programmers: ch341a, dediprog To connect with SOIC-8 or SOIC-16 flash chips, we can use a clip.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 33 / 77 Flash with flashrom

We can use flashrom to flash the chips. command line flashrom -p [-r ] [-w ]

For Linux SPI flashrom -p linux_spi:dev=/dev/spidev1.0,spispeed=1024

For ch341a flashrom -p ch341a_spi

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 34 / 77 Internal flashing with flashrom

Many boards can be flashed internally with coreboot flashed. internal flashing flashrom -p internal:laptop=force_I_want_a_brick

We can also use a layout file to flash part of the ROM. flashing with layout flashrom -p --layout layout.txt \ --image bios -w

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 35 / 77 1 What is coreboot? History Why use coreboot

2 How coreboot works

3 Building and using coreboot Building Flashing

4 Utilities and Debugging

5 Join the community

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 36 / 77 Utilities and Debugging

To work with coreboot, we have many tools to use: nvramtool: dump CMOS contents, display and modify CMOS settings cbmem: display coreboot table and logs ectool: read and write EC memory, sometimes useful autoport: generate the code for a board you want to port, usually needs further changes To debug coreboot, we can read the cbmem console in a working system. We can also use a EHCI debug dongle. Net20DC is an expensive device, and its company is bankrupt. We can use a development board with OTG port, e.g. BeagleBone, Cubieboard For systems with serial output, we can also do the debugging with it.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 37 / 77 ACPI debug

Linux ACPI debugging: Documentation/acpi/debug.txt in Linux source code Linux ACPI table updating: https://wiki.archlinux.org/index. php/DSDT#Using_a_CPIO_archive

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 38 / 77 1 What is coreboot? History Why use coreboot

2 How coreboot works

3 Building and using coreboot Building Flashing

4 Utilities and Debugging

5 Join the community

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 39 / 77 The coreboot community

You can visit “Community and infrastructure“ section of https://www.coreboot.org/developers.html to get an overview of coreboot community. Some advice: Learn to use mailing list and IRC. Ask Questions The Smart Way

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 40 / 77 Community resources

Homepage and wiki: https://www.coreboot.org We can apply for a wiki account and write coreboot wiki. Mailing list: [email protected] IRC: #coreboot at irc.freenode.net Mattermost (bridged to IRC): https://chat.coreboot.org bug tracking system: https://ticket.coreboot.org/ twitter: @coreboot_org

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 41 / 77 I want to write some code

Gerrit code review is the project management system for coreboot. To push code to , you can manually set up the scripts, or just run make gitconfig . Using gerrit is easy: To push code: git push origin HEAD:refs/for/master We can add a topic: HEAD:refs/for/master%topic=some_topic To push a draft: HEAD:refs/drafts/master If you’ve modified your code, just amend it, and push again. I recommend working in a new git branch instead of master.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 42 / 77 Google Summer of Code

coreboot has been a GSoC mentoring organization for many years. We can read the project reports at https://blogs.coreboot.org. GSoC 2016 projects: better RISC-V support serialICE flashrom GSoC 2015 projects: H8S coreboot for AArch64 QEMU end user flash tool

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 43 / 77 The status of coreboot

The current development of coreboot focuses on: improvement on old platforms, and porting coreboot to boards with this platforms utilities and payloads Google Chromebooks and related chips new architectures: RISC-V, POWER8, etc.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 44 / 77 6 Porting coreboot with autoport ASRock B75 Pro3-M Sandy/Ivy Bridge HP Elitebooks Dell Latitude E6230

7 References

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 45 / 77 Porting coreboot with autoport

In this section, I’ll show how I ported coreboot to Sandy/Ivy Bridge laptops and mainboards with autoport.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 46 / 77 Chips on a mainboard

coreboot needs to initialize these chips. CPU northbridge: RAM init and graphics init southbridge: PCI, USB, SATA, LPC, GPIO super I/O embedded controller

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 47 / 77 Code for a mainboard

You can see what is needed for a mainboard in the directory for this mainboard. Kconfig: specifies what chips and drivers areused romstage.c: romstage code, including early southbridge init and reading DRAM SPD data .cb, mainboard.c: mainboard specific data gpio.c: GPIO config acpi/, dsdt.asl, acpi_tables.c, smihandler.c: ACPI and SMM code, some of the code is EC related cmos.layout, cmos.default

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 48 / 77 Using autoport

autoport is a tool to generate coreboot code for Sandy/Ivy Bridge boards. It uses inteltool to read the northbridge and southbridge registers. Manual fixes (see util/autoport/readme.md): where to read SPD data what is the EHCI debug port flash chip size EC and super I/O support!

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 49 / 77 Tools to work with the OEM firmware

Sometimes, we need to know how the OEM firmware works, and implement it in coreboot. These tools can help: UEFITool (https://github.com/LongSoft/UEFITool): a tool to view, extract and replace the modules in a UEFI firmware radare2 (https://github.com/radare/radare2): a framework, hex editor, and binary analysis tool

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 50 / 77 ASRock B75 Pro3-M

ASRock B75 Pro3-M is a desktop board. Porting coreboot to a desktop board is easier than to a laptop: Most desktop boards don’t have an EC. Most desktop boards have a at Super I/O, which is easier to use than an EHCI debug port. The flash chips on desktop boards are usually socketed.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 51 / 77 B75 Pro3-M: Super I/O

Just run autoport in GNU/Linux running on this board, and get the generated source code. B75 Pro3-M uses Nuvoton NCT6776 as Super I/O, which is also used by asrock/g41c-gs, so copy the Super I/O related things. If possible, see the superiotool output for details. Kconfig devicetree.cb mainboard_config_superio in romstage.c

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 52 / 77 B75 Pro3-M: Hanging on boot, how to solve it?

I got the debug output from the serial port, and saw the system hanging when configuring PCIe devices. I disabled the ASMedia SATA controller in devicetree.cb, and the system can boot. Patrick Rudolph saw from the boot log that the system stopped after enabling ASPM of the ASMedia SATA controller, thinking that the ASPM of that device should be disabled. Using ASPM override worked at the time I ported coreboot to this board. Now it uses the ASPM blacklist driver. The port of B75 Pro3-M was merged on Aug, 2017. (https://review.coreboot.org/20227/)

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 53 / 77 HP Elitebook 2760p

I ported coreboot to HP Elitebooks and succeeded last year. In this talk, I’ll talk about how I ported coreboot to HP Elitebook 2760p (https://review.coreboot.org/18241/): The flash chip is socketed, and is very easy to swap! Sandy Bridge platform, use autoport to generate the code

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 54 / 77 I could not power on the machine

At first, I built the ROM with the generated code and flashed it. However, the power LED of the laptop just blinked and I could not power on the laptop. Let’s look at what an embedded controller does: controlling the keyboard, touchpad, buttons and switches turning the on and off thermal management battery management … I guess the EC needs to read something from the flash chip to make it work, maybe it’s the EC firmware.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 55 / 77 First attempt: Using UEFITool

EC firmware is not UEFI modules, so I’ll look into the place whereno UEFI modules are stored, for example, paddings.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 56 / 77 EC firmware in the flash chip

Using strings , I can find some interesting things.

Now I can figure out the EC is based on 8051.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 57 / 77 Editing binary file using radare2

I use radare2 to edit binary file. Running r2 -n -w bios.rom to open a binary file for editing. Remember to make a copy of the file forbackup. s addr : seek to addr s $s-16 : seek to 16 bytes to the end of the file, $s means the file size wx deadbeef : write 4 bytes 0xde, 0xad, 0xbe, 0xef to the seek offset wx deadbeef @ addr : write 4 bytes 0xde, 0xad, 0xbe, 0xef to addr w0 10 : write 10 zero bytes to the seek offset wr 10 @ $s-0x100 : write 10 random bytes to 256 bytes to the end of the file

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 58 / 77 Testing where the EC reads in the flash chip

Now I use radare2 to write random bytes or zero bytes to the flash regions that I think may contain the things the EC needs to read. At last, I found two essential regions. a 64K region starting at 0x780000 a 0xa00 region starting at 0x7ff700

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 59 / 77 More observations

Looking at the blobs, it looks like that the first two bytes are the sizes of the blobs. After changing some bytes in the blobs, the laptop could not power on. However, I could enlarge the blob size and append zero bytes. At last, I found the next two bytes are checksum bytes, and the checksum is SYSV checksum. Another finding is that, the 8 bytes at $s-0x100 store the position of the two blobs.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 60 / 77 Keyboard

After adding the blobs, the laptop boots! However, thek eyboard doesn’t work, which means the keyboard controller is not initialized. It uses SMSC KBC1126 which provides EC, super I/O, and KBC I found an SMSC KBC1122 datasheet Also I found src/superio/smsc/kbc1100/, so the keyboard works finally How to use existing drivers: Add it to Kconfig Check other boards that use this driver and learn from it

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 61 / 77 Fan control

The laptop fan always runs on full speed, because EC is not initialized properly. I didn’t find anything about the fan control of this EC, so at last Ichose to reverse engineering it. Using UEFITool, I found a module called EcThermalInit.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 62 / 77 Analyzing on this module

I found there’s a protection in the factory firmware, which makes the laptop fail to boot if I remove or modify a UEFI module in the DXE core. But it’s easy to remove the protection. After that, I try to remove and modify the driver, to see what code is responsible for the fan control of the laptop.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 63 / 77 Reverse engineering with radare2

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 64 / 77 ACPI

I need to implement the ACPI support to support: battery status lid switch handling

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 65 / 77 How an OS initializes the ACPI support

In drivers/acpi/acpica/hwacpi.c of the kernel source code, a function called acpi_hw_set_mode sets ACPI on or off by writing a byte called acpi_enable or acpi_disable to the SMI command port to trigger an SMI. So we have to reverse the SMM modules in the firmware to see what it does to enable or disable ACPI.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 66 / 77 ACPI in HP Elitebooks

Fortunately, I found a bit called ACPI in EC RAM in the vendor DSDT, and this bit is set during a system wake up from sleep. Using ectool to set this bit, ACPI worked as expected. At last, I wrote the ACPI code according to the vendor DSDT, then the AC and battery status in HP Elitebooks running coreboot can be shown in the OS.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 67 / 77 Dell Latitude E6230

Dell Latitude is another series of business laptops, so I’m also interested in porting coreboot to it. A friend of mine gave me a E6230, then I used autoport to generate the coreboot code for it. EC and Super I/O: MEC5055+ECE5048, I can’t find anything about them Two flash chips: 8M+4M, the 4M one stores the high address part The 8M flash chip cannot be accessed via ISP

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 68 / 77 What to do when I can’t do an ISP

I desoldered the 8M flash chip with hot air, and I read its content. ThenI move all the BIOS region to the 8M chip: Use me_cleaner to shrink the ME firmware, and modify the IFD with ifdtool , so that all the things are in the lower 8M. Solder wires to a socket, so I can easily access and replace the chip.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 69 / 77 Soldering the wires

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 70 / 77 How to shut down with several instructions?

When I was modifying the firmware, I wanted to see if the code insome place was run. I wrote some instructions at that place, so that the system will shut down if those instructions are executed. For Intel systems, there are some PM ports handled by Intel PCH. I can shutdown the machine using 3 instructions:

mov eax, 0x3c00 mov dx, PMBASE+4 out dx, eax

PMBASE can be read from a running machine in PCI configuration space of 00:1f.0 offset 0x40. You can also disassemble the vendor firmware. It’s usually configured in bootblock or PEI phase.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 71 / 77 Making coreboot work on Dell Latitude E6230

Using the code generated by autoport, Dell Latitude E6230 can boot to OS. However, the system will shutdown in one minute after power on. Using UEFITool, I found a PEI module called PeiEcIoDriver, removing which will cause the laptop shutdown shortly after powering on the laptop.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 72 / 77 Reversing this module is easy, but after using the EC initialization code in coreboot, the laptop will still shutdown. The code uses port 0x910 and 0x911, but they’re not in the decode range when running the generated coreboot code. The OEM firmware sets the decode range in bootblock, and overrides it later, so I can’t find this in the running system. Solution: set the decode range in pch_enable_lpc in romstage.c

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 73 / 77 Still work in progress

You can see the code on gerrit: https://review.coreboot.org/22693/

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 74 / 77 References

coreboot history: Embedded Firmware Solutions, by Jiming Sun, Vincent Zimmer, Marc Jones, and Stefan Reinauer libreboot: https://libreboot.org/faq/

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 75 / 77 Hardware choosing(Machines)

Laptops laptops with libreboot supported, e.g. Lenovo X200 Intel platforms up to Ivy Bridge supports coreboot without FSP, and there’s no boot guard.

Development boards Raspberry Pi is very popular, but it’s not so open. Allwinner is not so friendly to free software community, but Allwinner chips has good community support. Beaglebone Black seems popular in coreboot and libreboot community.

...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 76 / 77 Hardware choosing(wifi cards and GPU)

wifi cards Atheros 802.11n chips have free driver and do not need . AR9382 is very cheap (down to 20 CNY on taobao), with excellent dual-band 300M performance. Broadcom sucks, so is Realtek. Chips from Intel,TI,etc. need proprietary firmware.

GPUs Many GPUs needs proprietary firmware blobs. There are some GPUs that Linux-libre can use: Intel Graphics before Skylake NVIDIA chips up to Kepler with nouveau driver embedded GPUs: freedreno, etnaviv, etc...... vimacs (LCPU) coreboot - the free firmware May 19th, 2018 77 / 77