coreboot:scripts:putin

Putin puts stuff into coreboot ROM's.

#!/bin/bash
 
command=$1
rom=$2
interface="eno0"
macaddress=$(ip link show dev $interface | tail -n2 | xargs | cut -d" " -f2)
cbfstool="./cbfstool"
nvramtool="./nvramtool"
ich9gen="./ich9gen"
 
help="Use: $0 [--ivb | --ich9 | --ich7 | --realtek] <coreboot rom>"
 
if [ -z "$1" ]; then
  echo "$help"
  exit 1
fi
 
# Check if required tools are present
 
if [ ! -e $cbfstool ]; then
  echo "cbfstool not found!"
  exit 1
fi
 
if [ ! -e $nvramtool ]; then
  echo "nvramtool not found!"
  exit 1
fi
 
 
# Start scenarios
 
case "$command" in
 
 
  --ivb)
 
### CMOS ###
 
$nvramtool -C "$rom" -w power_management_beeps=Disable
 
echo "Enter VRAM size (e.g. 32 / 64 / 128 / 224) ..."
read -r vram_size
echo
 
$nvramtool -C "$rom" -w gfx_uma_size="$vram_size"M
 
if [ $? -ne 0 ]; then
  echo "Invalid VRAM size!"
  exit 1
fi
 
### GRUB CONFIGURATION ###
 
$cbfstool "$rom" remove -n etc/grub.cfg >/dev/null 2>&1
 
echo "Enter GRUB config path..."
read -r grub_config
echo
 
$cbfstool "$rom" add -n etc/grub.cfg -f "$grub_config" -t raw
 
if [ $? -ne 0 ]; then
  exit 1
fi
 
### DONE ###
 
echo "cbfstool output:"
echo
$cbfstool "$rom" print
 
;;
 
 
  --ich9)
 
### Check if ich9gen is present ###
if [ ! -e $ich9gen ]; then
  echo "ich9gen not found!"
  exit 1
fi
 
### DESCRIPTOR + GBE ###
 
echo "Detected MAC address is $macaddress"
echo "Do you want to use this? (Y/n)"
read -r response
 
case "$response" in
 
  [nN])
echo "Enter MAC address..."
read -r macaddress
echo
;;
 
  *)
echo "Using $macaddress"
echo
;;
 
esac
 
$ich9gen --macaddress "$macaddress" >/dev/null 2>&1
 
if [ $? -ne 0 ]; then
  echo "Invalid MAC address!"
  exit 1
fi
 
rom_size=$(stat -c%s "$rom")
echo "ROM size: $rom_size (autodetected)"
echo
 
if [ "$rom_size" -eq 8388608 ]; then
  dd if=ich9fdgbe_8m.bin of="$rom" bs=1 count=12k conv=notrunc >/dev/null 2>&1
elif [ "$rom_size" -eq 4194304 ]; then
  dd if=ich9fdgbe_4m.bin of="$rom" bs=1 count=12k conv=notrunc >/dev/null 2>&1
else
  echo "Invalid ROM!"
  exit 1
fi
 
rm ich9fdgbe_4m.bin ich9fdgbe_8m.bin mkgbe.c mkgbe.h
 
### CMOS ###
 
$nvramtool -C "$rom" -w power_management_beeps=Disable
$nvramtool -C "$rom" -w low_battery_beep=Disable
 
echo "Enter VRAM size (e.g. 32 / 64 / 128 / 256 / 352) ..."
read -r vram_size
echo
 
$nvramtool -C "$rom" -w gfx_uma_size="$vram_size"M
 
if [ $? -ne 0 ]; then
  echo "Invalid VRAM size!"
  exit 1
fi
 
### GRUB CONFIGURATION ###
 
$cbfstool "$rom" remove -n etc/grub.cfg >/dev/null 2>&1
 
echo "Enter GRUB config path..."
read -r grub_config
echo
 
$cbfstool "$rom" add -n etc/grub.cfg -f "$grub_config" -t raw
 
if [ $? -ne 0 ]; then
  exit 1
fi
 
### DONE ###
 
echo "cbfstool output:"
echo
$cbfstool "$rom" print
 
;;
 
 
  --ich7)
 
### CMOS ###
 
$nvramtool -C "$rom" -w power_on_after_fail=Disable
 
echo "Enter VRAM size (e.g. 16 / 32 / 64 / 128 / 256) ..."
read -r vram_size
echo
 
$nvramtool -C "$rom" -w gfx_uma_size="$vram_size"M
 
if [ $? -ne 0 ]; then
  echo "Invalid VRAM size!"
  exit 1
fi
 
### DONE ###
 
echo "cbfstool output:"
echo
$cbfstool "$rom" print
 
;;
 
 
  --realtek)
 
### MAC ADDRESS ###
 
$cbfstool "$rom" remove -n rt8168-macaddress >/dev/null 2>&1
 
echo "Enter MAC address..."
read -r macaddress
 
echo -n "$macaddress" > rt8168-macaddress
 
$cbfstool "$rom" add -n rt8168-macaddress -f rt8168-macaddress -t raw
 
rm rt8168-macaddress
 
### DONE ###
 
echo "cbfstool output:"
echo
$cbfstool "$rom" print
 
;;
 
 
  --help)
 
echo "$help"
 
;;
 
 
  *)
 
echo "Invalid options!"
exit 1
 
;;
 
esac
 
 
exit 0