WARNING!
Updating your firmware has a risk of bricking the machine.
You have been warned, and do so at your own risk.

also see: README

---

Serial output:

connect null modem cable to dock, then connect the USB adapter to the other end. 
Connect the USB end into another machine.

On that other machine, do this:
sudo screen /dev/ttyUSB0 115200

Then when you boot your X60, you can see serial output.

This is recommended for memtest86+
(if you do not have a serial port, memtest86+ is
also configured to beep when it detects an error)

---

software (and descriptions) (source code included):

 - bucts (BUC.TS) - sets to Top Swap (TS) but in the Backup Control (BUC) register.
 ----> when set to 0, the machine boots from the 64K at the end of the flash chip.
 ----> when set to 1, the machine boots from the 64K block below the 64K block at the end of the flash chip.
 -- Purpose: when flashing coreboot.rom (compiled coreboot image) the first time, the IBM BIOS sets
 --          the top 64K as read-only. the region below that is writeable (with changes made to flashchips.c in flashrom)
 --          so coreboot.rom is flashed after running "./bucts 1" as root. This sets the machine to boot from the lower 64K.
 --	before flashing coreboot.rom, these dd commands are used to copy what's at the end 64K of coreboot.rom, into the block
 --	below that, by using these "dd" commands on coreboot.rom:
 --	dd if=coreboot.rom of=top64k.bin bs=1 skip=$[$(stat -c %s coreboot.rom) - 0x10000] count=64k
 --	dd if=coreboot.rom bs=1 skip=$[$(stat -c %s coreboot.rom) - 0x20000] count=64k | hexdump
 --	dd if=top64k.bin of=coreboot.rom bs=1 seek=$[$(stat -c %s coreboot.rom) - 0x20000] count=64k conv=notrunc
 --
 -- Then, once coreboot is flashed the first time, the top 64K block is writeable.
 -- So coreboot.rom is flashed again (after reverting changes to flashrom's flashchips.c, and recompiling flashrom)
 -- This time, the top 64K of the flash chip is written properly, since coreboot does not restrict write access to that region.
 --
 -- It is important to always run bucts 1 before the first flash. If you flash the 1st time and boot the machine while TS is 0,
 -- it will boot the top 64K of code from the factory BIOS, but the rest of the flash chip is coreboot. Basically, it means the machine
 -- would be bricked. 
 --
 -- Also of note: the TS bit in BUC is remembered in CMOS memory. So, if there is no CMOS battery or the battery is dead,
 -- flashing coreboot (even if done with the correct steps) will likely brick the machine, since TS will not be maintained
 -- after shutting down (you cannot reboot after modifying the flash chip. you must cold boot) and will reset to 0 while
 -- the top 64K has not been written yet.
 --
--------
 - flashrom - used to write data to the flash chip (where coreboot lives).
 -- try this command to flash the coreboot.rom (after putting it in flashrom directory):
 -- sudo ./flashrom -p internal -w coreboot.rom
 --
 -- If that failed (on a system already with coreboot) and it mentions 3 flashchips detected, do this instead,
 -- since in this case you have the macronix flash chip (instead of SST):
 -- sudo ./flashrom -p internal -w coreboot.rom -c "MX25L1605D/MX25L1608D"
--------
 -- GRUB2 - a boot loader
 -- This is used to boot your kernel and initial ramdisk. There are also payloads (like memtest) that can be loaded from GRUB2
 -- GRUB2 in this case is actually a payload for coreboot.
 -- coreboot is not a BIOS. GNU/Linux does not require a BIOS, in fact.
 -- coreboot initializes the hardware, and then passes control over to the bootloader, in this case GRUB2.
 -- GRUB2 is a "payload" for coreboot. A coreboot payload is what coreboot executes after it is finished executing.
-------- 
 -- coreboot - hardware initialization. This is what runs when you first turn on your machine. 
 -- 



 -- 

----------------------

The things here should already be compiled (on trisquel 6) for yoru convenience
This should also work in gnewsense.


You need these dependencies to build/use

$ sudo apt-get -y install subversion git

    (these contain tools used for compiling source code) 

$ sudo apt-get -y install build-essential

    (these are required for building coreboot) 

$ sudo apt-get -y install libncurses5-dev doxygen iasl gdb flex bison

    (required for building flashrom) 

$ sudo apt-get -y install libpci-dev pciutils zlib1g-dev libftdi-dev

    (for building grub) 

$ sudo apt-get install bison libopts25 libselinux1-dev autogen m4 autoconf help2man libopts25-dev flex libfont-freetype-perl automake autotools-dev libfreetype6-dev texinfo

    (you also need to install unifont (for text in grub2) 

$ sudo apt-get -y install ttf-unifont 

---

Building GRUB2 from scratch

$ make clean

$ ./autogen.sh

$ ./configure --with-platform=coreboot

$ make 


put a grub.custom.cfg in grub/
this is your config


then put:
./grub-mkstandalone --grub-mkimage=./grub-mkimage -O i386-coreboot -o grub2-X60.elf --modules='ahci pata ehci uhci ohci usb_keyboard usbms part_msdos xfs ext2 fat at_keyboard part_gpt usbserial_usbdebug cbfs minix_be minix minix3_be minix3 minix2_be minix2 zfs ufs2 ufs1_be ufs1 udf squash4 romfs jfs reiserfs procfs odc ntfs nilfs2 newc iso9660 hfsplus cpio exfat cpio_be afs btrfs bfs hfs video_bochs password png keystatus sleep loopback gfxterm_background' --install-modules='ls echo linux search configfile normal cbtime cbls memrw iorw minicmd lsmmap lspci halt reboot hexdump pcidump regexp setpci lsacpi chain test' --fonts= --themes= --locales= -d grub-core/ /boot/grub/grub.cfg=grub.custom.cfg /memtest.elf=memdisk/memtest /background.png=memdisk/background.png

(make sure memtest executable and background.png (1024x768) exist in grub/memdisk)

put grub2-X60.elf in coreboot/

notes: I'd start by stripping down modules. I'm pretty sure you don't need sfs, affs or video_cirrus


go in coreboot (a .config is already there, you don't need to use make menuconfig)

make

# this is also advised:

cd build; dd if=coreboot.rom of=top64k.bin bs=1 skip=$[$(stat -c %s coreboot.rom) - 0x10000] count=64k; dd if=coreboot.rom bs=1 skip=$[$(stat -c %s coreboot.rom) - 0x20000] count=64k | hexdump; dd if=top64k.bin of=coreboot.rom bs=1 seek=$[$(stat -c %s coreboot.rom) - 0x20000] count=64k conv=notrunc

now you have a coreboot.rom

If you want to make changes to the coreboot config, you can edit .config in coreboot directory,
or use (in coreboot directory) the command "make menuconfig"

---
     sudo aptitude update 
flashrom and bucts are just "make clean" and "make", if you want to rebuild them.

flashchips.c should be modified according to your flash chip (if you have factory BIOS).
If coreboot is already flashed and running, then you do not need to touch flashchips.c (leave it in its default state).
You also (if coreboot is already flashed and running) do not need to use bucts at all.

(basically, if you bought an X60 from gluglug, you don't need to touch bucts or flashchips.c)








-------------


installing distributions:

NOTE: if installing gnewsense, MAKE SURE to enable SSH server (if you don't have a external monitor with a VGA cable).
There is an extra step that is needed after installing gnewsense, which makes either of these necessary.

Prepare installation media:
 - burn the ISO to a CD/DVD
or
 - dd if=distro.iso of=/dev/sdX bs=8M; sync
or
 - dd if=distro.iso of=/dev/sdXY bs=8M; sync

(sdX is a USB flash drive, eg /dev/sdb. sdXY is a partition on the HDD, eg /dev/sda4)

If you bought the machine recently (December 2013 onwards) there will be 4 partitions on the HDD:
 - /dev/sda1 is for /
 - /dev/sda2 is for /home
 - /dev/sda3 is for swap
 - /dev/sda4 is unassigned
use those dd commands on sda4:
 - dd if=distro.iso of=/dev/sda4 bs=8M; sync
Using the instructions below you can boot the ISO that you wrote to sda4.

If you bought the machine before December 2013 (note: you need the new coreboot version which I gave you.
I can help you update it if needed):
 - /dev/sda1 is for /
 - /dev/sha2 is for swap
In this case, do that (disable the swap partition, and use that):
 - swapoff -a
 - remove the swap entry in /etc/fstab (or comment it out)
 - dd the ISO to /dev/sda2

Parabola 2013.09.01 live ISO
press E in grub menu for the Parabola option.
Add this (without the quotes) to the linux line: " parabolaisobasedir=parabola parabolaisolabel=PARA_201309"
If booting from USB, leave it as-is. (note: GRUB2 USB support is buggy/temporamental at the time of writing)
If booting from CD drive, change (usb0) on both lines to (ata0)
If booting from a partition (eg /dev/sda4) change both (usb0) examples to say (ahci0,4).
Press F10 to boot with these options.

Trisquel 6 live desktop:
Press E on Trisquel 6 grub menu option.
If booting from USB, leave it as-is. (note: GRUB2 USB support is buggy/temporamental at the time of writing)
If booting from CD drive, change (usb0) on both lines to (ata0)
If booting from a partition (eg /dev/sda4) change both (usb0) examples to say (ahci0,4).
Press F10 to boot with these options.

gNewSense 3 netinstall (DVD image):
Press E on gnewsense 3 grub menu option.
If booting from USB, leave it as-is. (note: GRUB2 USB support is buggy/temporamental at the time of writing)
If booting from CD drive, change (usb0) on both lines to (ata0)
If booting from a partition (eg /dev/sda4) change both (usb0) examples to say (ahci0,4).
Press F10 to boot with these options.

gNewSense 3 netinstall (mini.iso):
Press E on gnewsense 3 grub menu option.
Change both lines so that they say this:
	linux (usb0)/linux
	initrd (usb0)/initrd.gz
If booting from USB, leave it as-is. (note: GRUB2 USB support is buggy/temporamental at the time of writing)
If booting from CD drive, change (usb0) on both lines to (ata0)
If booting from a partition (eg /dev/sda4) change both (usb0) examples to say (ahci0,4).
Press F10 to boot with these options.


NOTE:
If gnewsense installer complains about no CDROM detected and you aren't using a CD/DVD, then:

Load CD-ROM Drivers from remaveable media ?
Then it has these options:
Yes or No
I am choosing No

Manually select a CD-ROM module and device yes or no
I choose Yes
Then it has 2 menu items for "module neededfor accessing the cd-rom"
i select "none"

now i see a text box that has /dev/cdrom in it
i change that to /dev/sda2
(because i dd'd the gnewsense ISO to /dev/sda2. but you might have put it on a different partition).
and then i press enter
now the installation procedure continues successfully

NOTE:
gNewSense 3 comes with Linux-libre 2.6, which is old and does not have the thinkpad_acpi module.
So when you boot into it, there will be graphics on the screen but the backlight will turn on. 
There is a patch for Linux/Linux-libre 2.6 to add thinkpad_acpi support, but I didn't do that. 
Instead, I updated the kernel to one that has thinkpad_acpi already, using this page: http://jxself.org/linux-libre

You need to be able to see what you are doing at this time. 
There are 2 practical ways:
 - SSH into the machine from another machine
 - connect the machine to an external monitor using VGA

(note: install linux-libre32 package. you can also optionally install linux-libre32-headers and linux-libre32-source):
sudo apt-get install linux-libre32
OPTIONAL:
sudo apt-get install linux-libre32-headers linux-libre32-source

To make GRUB2 (coreboot payload) menu options work, you need to do this:
cd /
ls boot
in my case this showed me:
config-2.6.32-5gnewsense1-686  initrd.img-2.6.32-5gnewsense1-686  System.map-3.12.4-gnu
config-3.12.4-gnu	       initrd.img-3.12.4-gnu		  vmlinuz-2.6.32-5gnewsense1-686
grub			       System.map-2.6.32-5gnewsense1-686  vmlinuz-3.12.4-gnu

initrd.img-3.12.4-gnu and vmlinuz-3.12.4-gnu are for the kernel just installed. 
So, in / I do,
ls
this shows:
bin  boot  dev	etc  home  initrd.img  lib  lost+found	media  mnt  opt  proc  root  sbin  selinux  srv  sys  tmp  usr	var  vmlinuz

Delete vmlinuz and initrd (these are just symlinks/shortcuts to what's in /boot, currently they point to the old/useless kernel):
rm initrd.img vmlinuz

Add these symlinks:
ln -s boot/initrd.img-3.12.4-gnu initrd.img
ln -s boot/vmlinuz-3.12.4-gnu vmlinuz
ln -s initrd.img initrd.gz
ln -s initrd.img initrd
check that the symlinks are correct:
ls -lh .

Now, reboot. Now GRUB (with the default/generic options) will correctly boot the new kernel.

Now that the new kernel is installed, delete the old one (it's useless and taking up space):
sudo apt-get purge linux-image-2.6-686 linux-image-2.6.32-5gnewsense1-686

Reboot. Now there is only the new kernel.

NOTE: those commands above will differ if you have a different version.
It was 3.12-4 at the time of writing. For you it may be different. 

My plans are basically: provide a mini.iso (gnewsense netinstall) with an updated kernel from jxself already installed as default.

Then I deleted the kernel that gnewsense came with (as root)
apt-get purge linux-image-2.6-686 linux-image-2.6.32-5gnewsense1-686

(it may aswell be deleted since it's literally almost useless)
then reboot the machine (ctrl+alt+f2, then ctrl+alt+del)


--------------------

put your payload.elf in grub/memdisk
in that grub-mkstandalone command, add eg (without quotes): " /payload.elf=memdisk/payload.elf"

PAYLOADS (for GRUB2)
"make" is used to compile memtest86+ source code. then copy the "memtest" executable and put it in grub/memdisk
(rename it to memtest.elf)
then enable a grub config option like this:
menuentry 'Memtest86+' {
	chainloader (memdisk)/memtest.elf
}

When running memtest, it works, you will hear it beep, but you won't see output on the screen.
(you can view memtest86+ output on the serial output)
(if you do not have a serial port, memtest86+ is also configured to beep if errors are detected)

In config.h in memtest source code, these things are changed:

#define SERIAL_CONSOLE_DEFAULT 1
#define SERIAL_TTY 0
#define SERIAL_BAUD_RATE 115200

/* BEEP_MODE - Beep on error. Default off, Change to 1 to enable */
#define BEEP_MODE 1


