Skip to content

Instantly share code, notes, and snippets.

@mh21
Created December 21, 2016 22:09
Show Gist options
  • Save mh21/c666b4dc6d35d86a02acc8754b676607 to your computer and use it in GitHub Desktop.
Save mh21/c666b4dc6d35d86a02acc8754b676607 to your computer and use it in GitHub Desktop.
Patch the biospba keymap (you can find the keymap files in the console-data debian package)
#!/bin/bash -e
wget https://github.com/Drive-Trust-Alliance/exec/blob/master/biospba.img.gz?raw=true -O biospba.img.gz
gunzip biospba.img.gz
sudo ./keytab-lilo.pl ./us.kmap.gz ./be-latin1.kmap.gz > be.ktl
cp biospba.img biospba_be.img
sudo kpartx -av biospba_be.img
sleep 1
sudo mount /dev/mapper/loop0p1 /mnt
sudo cp be.ktl /mnt/boot/syslinux
(echo kbdmap be.ktl; cat /mnt/boot/syslinux/syslinux.cfg) | sudo sponge /mnt/boot/syslinux/syslinux.cfg
sudo umount /mnt
sudo kpartx -d biospba_be.img
#!/usr/bin/perl
eval { use bytes; };
eval { binmode STDOUT; };
$DEFAULT_MAP = "us";
$DEFAULT_EXT = ".kmap";
sub usage
{
print STDERR
"usage: $0 [ -p old_code=new_code ] ...\n".
(" "x(8+length $0))."[path]default_layout[.kmap] ] ".
"[path]kbd_layout[.kmap]\n";
exit 1;
}
while ($ARGV[0] eq "-p") {
shift(@ARGV);
&usage unless $ARGV[0] =~ /=/;
$table[eval($`)] = eval($');
shift(@ARGV);
}
&usage unless defined $ARGV[0];
load_map("def",defined $ARGV[1] ? $ARGV[0] : undef);
load_map("kbd",defined $ARGV[1] ? $ARGV[1] : $ARGV[0]);
&build_table("plain","shift","ctrl","altgr","shift_ctrl",
"altgr_ctrl","alt","shift_alt","ctrl_alt");
for ($i = 0; $i < 256; $i++) {
printf("%c",$table[$i] ? $table[$i] : $i) || die "print: $!";
}
close STDOUT || die "close: $!";
sub load_map
{
local ($pfx,$map) = @_;
local ($empty,$current);
$map = $DEFAULT_MAP unless defined $map;
$map .= $DEFAULT_EXT unless $map =~ m|/[^/]+\.[^/]+$|;
if (!open(FILE,"loadkeys -m $map |")) {
print STDERR "loadkeys -m $map: $!\n";
exit 1;
}
undef $current;
$empty = 1;
while (<FILE>) {
chop;
if (/^(static\s+)?u_short\s+(\S+)_map\[\S*\]\s+=\s+{\s*$/) {
die "active at beginning of map" if defined $current;
$current = $pfx.":".$2;
next;
}
undef $current if /^};\s*$/;
next unless defined $current;
s/\s//g;
$map{$current} .= $_;
$empty = 0;
}
close FILE;
return unless $empty;
print STDERR "Keymap is empty\n";
exit 1;
}
sub build_table
{
local (@maps) = @_;
local (@tmp);
$set = 0;
for $map (@maps) {
$code = $set;
for (split(",",$map{"def:".$map})) {
die "bad map entry $_ (def, map $map)" unless /^0x\S\S(\S\S)$/;
$tmp[$code] = hex $1 unless $tmp[$code];
$code++;
}
$set += 256;
}
$set = 0;
for $map (@maps) {
$code = $set;
for (split(",",$map{"kbd:".$map})) {
die "bad map entry $_ (kbd, map $map)" unless /^0x\S\S(\S\S)$/;
$table[$tmp[$code]] = hex $1 unless $table[$tmp[$code]];
$code++;
}
$set += 256;
}
$table[0] = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment