negative zero

Librebooting a T400

2021 October 4

[libreboot] [tech]


The backlight script was corrected on 2021 November 21.

I posted an update to this post on 2021 November 29.


DISCLAIMER: This is not meant to be followed as a tutorial on its own. You can damage your computer doing this, and this post on its own does not provide enough information to safely do it yourself. Look at an actual tutorial for proper instructions.

I got a hand-me-down Thinkpad T400 recently, and I flashed Libreboot onto it.

I had no idea what I was doing at first, but I primarily used the following guides to figure it out:


Supplies

The T400 model apparently can have a BIOS chip with either 8 or 16 connectors. This chip is located on the underside of the mainboard. The process of taking apart the T400 starts at the top, by removing the trackpad panel, then the keyboard. In order to get to the BIOS chip, you have to pretty much take apart the laptop completely, extract the mainboard, and flip it over. This is a very involved process; I counted 56 screws I had to remove. (Not all of those screws made their way back into the right place afterwards...)

Alternatively, you could do this.

You need to know which type of chip you have so you can get the right type of SOIC clip for connecting to it. When I took apart my T400, I found that mine had 16 connectors, so I needed a clip with 16 pins.

At this point, I could figure out what parts I needed:

The SOIC clip I got was a bad choice. The pins were too close together, so the jumper wires didn't have room to fit properly on them. I ended up bending the pins on the clip out at odd angles to make the wires fit on them. It did work, but it wasn't a great solution, and I didn't feel at all confident in it when I was doing it. If you need a 16-pin clip, try to get one with properly spaced-out pins.

I already owned a Raspberry Pi, so I used that.


Flashing Libreboot

Once I had the supplies I needed (and a T400 which was already disassembled at this point), it was time to flash the BIOS.

There were several steps to this:

  1. setting up the Pi (flashrom, spidev, ssh so I could control the Pi without connecting a keyboard and monitor to it)
  2. connecting the pins on the Pi to the pins on the SOIC clip and connecting the SOIC clip to the BIOS chip
  3. backing up the existing firmware (in case something went wrong)
  4. downloading Libreboot
  5. modifying Libreboot to include the laptop's original MAC address
  6. flashing Libreboot to the board

I went with the most recent stable version of Libreboot: 20160907, with the GRUB payload. (I went with the vesafb version, which provides a graphical bootloader.) There are newer testing versions, but I felt very unconfident in what I was doing and wanted to minimize the number of things that could go wrong. I may try a newer version in the future.

Fortunately, nothing went wrong with the actual flashing process. Libreboot installed successfully on the first try!


Reassembly

I had to learn to use thermal paste. Hopefully I did it correctly.

There are a lot of screws in this thing, and not all of them made it back into the right place, but I got enough of it right that I'm not too worried.

While I was messing with the hardware, I opened up the monitor half (where the built-in microphone is housed) and cut out the microphone (for privacy reasons).


Installing an OS

I tried installing Fedora (LUKS-encrypted). The install appeared to work, but Libreboot GRUB couldn't boot it.

I tried installing Debian (also LUKS-encrypted). Libreboot GRUB can boot it... but for some reason, it can only boot if the optical disk drive is unplugged.

I ended up doing 5 or so installs before I figured out how to get it working how I wanted, and in the end I settled on Debian (LUKS-encrypted, but with an unencrypted /boot partition). I might try again to get Fedora working sometime in the future. I might try SeaBIOS in the future to see if that works better.

My T400 only has 4GB of RAM currently, so I'm not going to try to run Qubes on it. It should be upgradable, but it sounds like it's capped at 8GB, and I'd really want more than 8 for Qubes.


Quirks

Backlight issues

See Libreboot - Miscellaneous - Finetune backlight control on intel gpu's.

Adjusting the backlight manually requires the intel-gpu-tools package.

I figured out that on my T400, it works fairly well (consistent brightness across the screen, no high-pitched whine, no noticeable flickering) when the first value is 0x6000 and the second value is a multiple of 0x0800. I wrote this Bash script (which I put at /usr/local/bin/backlight) to incrementally adjust the backlight:

#!/bin/bash

REGISTRY=0x00061254
PWM_DIVIDER=6000
current=0x$(sudo intel_reg read $REGISTRY 2>&1 | grep -Po '(?<=BLC_PWM_CTL \(0x00061254\): 0x)(.*)(?=)' | cut -c 5-8)
plusminus="$1"
new=""

if [[ ! -n $plusminus ]];then
	sudo intel_reg read $REGISTRY
	exit
fi

if [ $plusminus = "+" ];then
	if [ $(($current)) -lt $((0x5200)) ];then
		new=$(($current + 0x0800))
	fi
elif [ $plusminus = "-" ];then
	if [ $(($current)) -gt $((0x0800)) ];then
		new=$(($current - 0x0800))
	fi
fi

if [[ -n $new ]];then
	if [ $(($new)) -lt $((0x1000)) ];then
		new="0800"
	else
		new=$(printf '%x\n' $new)
	fi
	sudo intel_reg write $REGISTRY 0x$PWM_DIVIDER$new
fi

Here's what it does:

Note that we have to do the intel_reg commands as root. I wanted this to be automatable, so I made these specific commands possible to do without a password by adding /etc/sudoers.d/backlight:

myusername	ALL=(ALL) NOPASSWD:/usr/bin/intel_reg write 0x00061254 0x[0-f][0-f][0-f][0-f][0-f][0-f][0-f][0-f]
myusername	ALL=(ALL) NOPASSWD:/usr/bin/intel_reg read 0x00061254

This makes it possible without a password to read the backlight value or write a new backlight value specifically in the form of an 8-character hexadecimal value.

In my Xfce settings, I added application shortcuts to run backlight + and backlight - in response to certain keys being pressed.

Now I can adjust my brightness in a reasonable way!


Suspend

If I just close the lid of the laptop, it doesn't seem to suspend properly. If instead I lock the laptop first, then close it, it suspends.

This was a userspace problem, not a BIOS problem, and I later fixed it.


Optical disk drive

Like I mentioned earlier, I have to remove the CD/DVD drive when I turn on the laptop, or it won't boot from the hard drive. I can put the drive back in before the OS actually boots and use it if I need.

This was fixed by updating to a newer version of Libreboot.


Conclusion

I think that's all I have to say. I externally flashed Libreboot, which was a major accomplishment for me! It's got some quirks and issues, and I've generally been able to deal with them one way or another.