diff options
Diffstat (limited to 'rpi2-debian-stdkernel')
-rw-r--r-- | rpi2-debian-stdkernel/.gitignore | 1 | ||||
-rwxr-xr-x | rpi2-debian-stdkernel/copy-to-sdcard.py | 71 | ||||
-rwxr-xr-x | rpi2-debian-stdkernel/format-sd-card-do-not-work-gpt.py | 61 | ||||
-rwxr-xr-x | rpi2-debian-stdkernel/format-sdcard.py | 33 | ||||
-rwxr-xr-x | rpi2-debian-stdkernel/make-rpi-debootstrap.py | 255 | ||||
-rw-r--r-- | rpi2-debian-stdkernel/other_boot_files/boot.scr | 25 | ||||
-rw-r--r-- | rpi2-debian-stdkernel/other_boot_files/config.txt | 6 | ||||
-rw-r--r-- | rpi2-debian-stdkernel/other_boot_files/ubuntu.pref | 3 | ||||
-rw-r--r-- | rpi2-debian-stdkernel/other_boot_files/ubuntu.sources | 4 | ||||
-rwxr-xr-x | rpi2-debian-stdkernel/other_boot_files/update-boot-uimage.sh | 3 | ||||
-rwxr-xr-x | rpi2-debian-stdkernel/other_boot_files/vg-copy-rpi | 13 |
11 files changed, 475 insertions, 0 deletions
diff --git a/rpi2-debian-stdkernel/.gitignore b/rpi2-debian-stdkernel/.gitignore new file mode 100644 index 0000000..5560aa3 --- /dev/null +++ b/rpi2-debian-stdkernel/.gitignore @@ -0,0 +1 @@ +debootstrapdir diff --git a/rpi2-debian-stdkernel/copy-to-sdcard.py b/rpi2-debian-stdkernel/copy-to-sdcard.py new file mode 100755 index 0000000..2717838 --- /dev/null +++ b/rpi2-debian-stdkernel/copy-to-sdcard.py @@ -0,0 +1,71 @@ +#!/usr/bin/python3 + +import glob +import os +import shutil +import subprocess +import sys +import tempfile +import time + +def reexec_root(): + # run as root + if os.geteuid() != 0: + os.execvp("sudo", ["sudo"] + sys.argv) + + +def run(*l, **d): + print('run:', *l, d) + return subprocess.run(*l, **d) + + +def out_of_date(path, timeout): + 'true if path mtime is greater than timeout in seconds' + return (time.time() - os.path.getmtime(path)) > timeout + + +def get_fresh_firmware(firmware_dir): + firmware_timeout = 24*3600 # 1d timeout + if (not os.path.exists(firmware_dir) + or out_of_date(firmware_dir, firmware_timeout)): + shutil.rmtree(firmware_dir, ignore_errors=True) + run(['git', 'clone', '--depth=1', + 'https://github.com/raspberrypi/firmware', + firmware_dir], check=True) + + +def copy_to_partitions(firmware_dir, boot_mountpoint, root_mountpoint): + for path in glob.glob(firmware_dir + '/boot/*'): + if os.path.isfile(path): + shutil.copy(path, boot_mountpoint) + for path in glob.glob('other_boot_files/*'): + shutil.copy(path, boot_mountpoint) + run(['rsync', '-aHX', 'debootstrapdir/.', root_mountpoint + '/.'], + check=True) + #shutil.copyfile('debootstrapdir/vmlinuz', boot_mountpoint + '/zImage', + # follow_symlinks=True) + + +def main(): + if len(sys.argv) < 2: + print('Usage: {} <device>'.format(sys.argv[0]), file=sys.stderr) + raise SystemExit(1) + device = sys.argv[1] + reexec_root() + firmware_dir = 'rpi-firmware' + boot_mountpoint = tempfile.TemporaryDirectory() + root_mountpoint = tempfile.TemporaryDirectory() + try: + run(['mount', device + '1', boot_mountpoint.name], check=True) + run(['mount', device + '2', root_mountpoint.name], check=True) + get_fresh_firmware(firmware_dir) + copy_to_partitions(firmware_dir, + boot_mountpoint.name, + root_mountpoint.name) + finally: + run(['umount', boot_mountpoint.name]) + run(['umount', root_mountpoint.name]) + + +if __name__ == '__main__': + main() diff --git a/rpi2-debian-stdkernel/format-sd-card-do-not-work-gpt.py b/rpi2-debian-stdkernel/format-sd-card-do-not-work-gpt.py new file mode 100755 index 0000000..3d1b295 --- /dev/null +++ b/rpi2-debian-stdkernel/format-sd-card-do-not-work-gpt.py @@ -0,0 +1,61 @@ +#!/usr/bin/python3 + +import sys +import subprocess + +def run(*l, **d): + print('run:', *l, d) + return subprocess.run(*l, **d) + +def main(): + if len(sys.argv) < 2: + print('Usage: {} <device>'.format(sys.argv[0]), file=sys.stderr) + raise SystemExit(1) + device = sys.argv[1] + # use this without check first, in some condition double invokation is + # needed... + run([ + 'sudo', + 'sgdisk', + '--zap-all', + device, + ]) + run([ + 'sudo', + 'sgdisk', + '--set-alignment=8192', + '--new=1:4M:+100M', + '--change-name=1:boot', + '--typecode=1:EF00', + '--largest-new=2', + '--change-name=2:root', + '--typecode=2:8300', + '--hybrid=1', + '--print', + '--print-mbr', + device, + ], check=True) + run([ + 'sudo', + 'mkfs.vfat', + '-F', '32', + '-n', 'boot', + device + '1', + ], check=True) + run([ + 'sudo', + 'mkfs.vfat', + '-n', 'boot', + device + '1', + ], check=True) + run([ + 'sudo', + 'mkfs.ext4', + '-q', + '-L', 'root', + device + '2' + ], check=True) + + +if __name__ == '__main__': + main() diff --git a/rpi2-debian-stdkernel/format-sdcard.py b/rpi2-debian-stdkernel/format-sdcard.py new file mode 100755 index 0000000..ea08728 --- /dev/null +++ b/rpi2-debian-stdkernel/format-sdcard.py @@ -0,0 +1,33 @@ +#!/usr/bin/python3 + +import json +import subprocess +import sys + +def run(*l, **d): + print('run:', *l, d) + return subprocess.run(*l, **d) + +def main(): + if len(sys.argv) < 2: + print('Usage: {} <device>'.format(sys.argv[0]), file=sys.stderr) + raise SystemExit(1) + device = sys.argv[1] + # first, clean possible gpt tables + run(['sudo', 'sgdisk', '--zap-all', device]) + part_commands = ''' + mklabel msdos + mkpart primary fat32 1M 99M + mkpart primary ext4 100M -1M + set 1 boot on + print + ''' + run(['sudo', 'parted', device], + check=True, input=part_commands.encode('utf8')) + run(['sudo', 'mkfs.vfat', '-n', 'boot', device + '1', ], check=True) + run(['sudo', 'mkfs.ext4', '-q', '-F', '-L', 'root', device + '2'], + check=True) + + +if __name__ == '__main__': + main() diff --git a/rpi2-debian-stdkernel/make-rpi-debootstrap.py b/rpi2-debian-stdkernel/make-rpi-debootstrap.py new file mode 100755 index 0000000..7925118 --- /dev/null +++ b/rpi2-debian-stdkernel/make-rpi-debootstrap.py @@ -0,0 +1,255 @@ +#!/usr/bin/python3 + +import os +import sys +import glob +import subprocess +import tempfile +import shutil +import re +import functools + +# http://elinux.org/RPi_U-Boot + +parameters = dict( + release='testing', + #mirror='http://fr.archive.ubuntu.com/ubuntu/', + mirror='http://httpredir.debian.org/debian', + arch='armhf', + packages=''' + aptitude + bash + bash-completion + bind9-host + bmon + busybox + bzip2 + curl + htop + iftop + ifupdown + iotop + iperf + iproute2 + iptables + iputils-ping + less + lftp + linux-image-armmp-lpae + locales + ncdu + ncurses-base + ncurses-term + net-tools + netbase + netcat + nload + openssh-client + openssh-server + psmisc + python3 + ranger + rsync + screen + sed + socat + strace + tar + tcpdump + telnet + tmux + tree + tzdata + vim + vim-nox + vim-runtime + w3m + wget + zsh + '''.split(), +) + + +open8 = functools.partial(open, encoding='utf8') +numerical_sort = lambda y: [int(x) if x.isdigit() else x + for x in re.split('(\d+)', y)] + + +def mlstrip(s): + return re.sub(r'^\s*', '', s, flags=re.MULTILINE) + + +def run(*l, **kw): + print('run:', *l) + return subprocess.run(*l, **kw) + + +def reexec_root(): + # run as root + if os.geteuid() != 0: + os.execvp("sudo", ["sudo"] + sys.argv) + + +def system_customization(rootdir): + os.unlink(rootdir + '/etc/localtime') + open8(rootdir + '/etc/zoneinfo', 'w').write('Europe/Paris\n') + shutil.copy(rootdir + '/usr/share/zoneinfo/Europe/Paris', + rootdir + '/etc/localtime') + + open8(rootdir + '/etc/network/interfaces', 'w').write(mlstrip( + '''\ + auto lo + iface lo inet loopback + + auto eth0 + iface eth0 inet dhcp + ''')) + open8(rootdir + '/etc/hosts', 'w').write(mlstrip( + '''\ + 127.0.0.1 localhost localhost.localdomain debian + + # the following lines are desirable for IPv6 capable hosts + ::1 localhost ip6-localhost ip6-loopback + ff02::1 ip6-allnodes + ff02::2 ip6-allrouters + ''')) + open8(rootdir + '/etc/hostname', 'w').write('debian\n') + os.makedirs(rootdir + '/boot/firmware', mode=0o755) + open8(rootdir + '/etc/fstab', 'w').write(mlstrip( + '''\ + # <device> <mount point> <type> <options> <dump> <pass> + /dev/mmcblk0p2 / ext4 errors=remount-ro,relatime 0 1 + /dev/mmcblk0p1 /boot/firmware vfat errors=remount-ro,relatime 0 2 + ''')) + + # activate serial console + run([ + 'ln', + '-s', + '/lib/systemd/system/serial-getty@.service', + rootdir + '/etc/systemd/system/getty.target.wants/serial-getty@ttyAMA0.service', + ], check=True) + os.makedirs(rootdir + '/etc/systemd/system/serial-getty@ttyAMA0.service.d', + mode=0o755) + open8(rootdir + + '/etc/systemd/system/serial-getty@ttyAMA0.service.d/autologin.conf', + 'w').write(mlstrip( + '''\ + [Service] + ExecStart= + ExecStart=-/sbin/agetty --autologin root --login-pause --noclear %I 115200,38400,9600 vt102 + ''')) + + open8(rootdir + '/etc/default/keyboard', 'w').write(mlstrip( + '''\ + XKBMODEL="pc105" + XKBLAYOUT="fr" + XKBVARIANT="bepo" + XKBOPTIONS="" + ''')) + + open8(rootdir + '/etc/default/locale', 'w').write(mlstrip( + '''\ + LANG="en_US.UTF-8" + LC_TIME="en_DK.UTF-8" + LC_PAPER="en_GB.UTF-8" + LC_MEASUREMENT="en_GB.UTF-8" + ''')) + + for locale in ['fr_FR', 'en_US', 'en_GB', 'en_DK', 'de_DE']: + run([ + 'localedef', + '--prefix={}'.format(rootdir), + '-f', 'UTF-8', + '-i', locale, + '{}.UTF-8'.format(locale) + ], check=True) + + open8(rootdir + '/etc/bash.bashrc', 'a').write(mlstrip( + '''\ + + # enable bash completion in interactive shells + if ! shopt -oq posix; then + if [ -f /usr/share/bash-completion/bash_completion ]; then + . /usr/share/bash-completion/bash_completion + elif [ -f /etc/bash_completion ]; then + . /etc/bash_completion + fi + fi + alias ls="ls --color=aut" + alias l="ls -CF" + alias ll="l -lh" + alias la="l -a" + alias e="vim" + alias rm='rm -i' + alias cp='cp -i' + alias mv='mv -i' + export PAGER=less + export EDITOR=vim + export VISUAL=vim + ''')) + + open8(rootdir + '/etc/vim/vimrc', 'w').write(mlstrip( + '''\ + set nocompatible + + au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif + filetype plugin indent on + set autoindent + set background=dark + set backspace=2 + set hidden + set hlsearch + set ignorecase + set incsearch + set laststatus=2 + set modelines=0 + set nobackup + set nowritebackup + set ruler + set scrolloff=3 + set shiftwidth=4 + set showcmd + set showmatch + set statusline=%<%f%h%m%r%=%l,%c\ %P + set ts=4 + set whichwrap=<,>,[,] + set wildmode=list:full + syntax on + ''')) + + + #kernel_params = 'ro text console=ttyAMA0,115200n8' + #kernel_params += ' console=tty0 net.ifnames=0' + #open8(rootdir + '/boot/grub/grub.cfg', 'w').write(mlstrip( + # '''\ + # terminal_output console + # serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1 + # set default=0 + # set timeout=3 + # menuentry 'default' {{ + # search --set=root --file /boot/grub/grub.cfg --hint hd0,gpt2 + # linux /vmlinuz root=PARTUUID={rid} {kp} + # initrd /initrd.img + # }} + # '''.format(rid=rootpartuuid, kp=kernel_params))) + + +def main(): + reexec_root() + rootdir = 'debootstrapdir' + os.makedirs(rootdir, mode=0o755) + run([ + 'qemu-debootstrap', + '--arch=' + parameters['arch'], + '--include=' + ','.join(parameters['packages']), + '--components=main,contrib', + parameters['release'], + rootdir, + parameters['mirror'], + ], check=True) + system_customization(rootdir) + + +if __name__ == '__main__': + main() diff --git a/rpi2-debian-stdkernel/other_boot_files/boot.scr b/rpi2-debian-stdkernel/other_boot_files/boot.scr new file mode 100644 index 0000000..f1ec9f8 --- /dev/null +++ b/rpi2-debian-stdkernel/other_boot_files/boot.scr @@ -0,0 +1,25 @@ +# u-boot commands, this file must be compiled with mk-image (or use +# update-boot-uimage.sh) + +#setenv machid 0x00000c42 + +# set the fdtfile according to your board model +#setenv fdtfile bcm2709-rpi-2-b.dtb +#setenv fdtfile bcm2835-rpi-b-rev2.dtb +setenv fdtfile bcm2836-rpi-2-b.dtb + +mmc dev 0 +#ext4load mmc 0:2 ${kernel_addr_r} vmlinuz +fatload mmc 0:1 ${kernel_addr_r} kernel.img +#ext4load mmc 0:2 ${ramdisk_addr_r} initrd.img +fatload mmc 0:1 ${fdt_addr_r} ${fdtfile} +setenv bootargs earlyprintk console=ttyAMA0,115200n8 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait noinitrd +#bootz ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r} +bootz ${kernel_addr_r} - ${fdt_addr_r} +#bootz ${kernel_addr_r} + +#mmc dev 0 +#ext4load mmc 0:2 0x01000000 vmlinuz +#fatload mmc 0:1 0x00000100 bcm2835-rpi-b-rev2.dtb +#setenv bootargs earlyprintk console=ttyAMA0,115200n8 +#bootz 0x01000000 - 0x00000100 diff --git a/rpi2-debian-stdkernel/other_boot_files/config.txt b/rpi2-debian-stdkernel/other_boot_files/config.txt new file mode 100644 index 0000000..62e6fd5 --- /dev/null +++ b/rpi2-debian-stdkernel/other_boot_files/config.txt @@ -0,0 +1,6 @@ +enable_uart=1 +device_tree_address=0x100 +device_tree_end=0x8000 +kernel=u-boot.bin +dtparam=i2c_arm=on +dtparam=spi=on diff --git a/rpi2-debian-stdkernel/other_boot_files/ubuntu.pref b/rpi2-debian-stdkernel/other_boot_files/ubuntu.pref new file mode 100644 index 0000000..844bf1c --- /dev/null +++ b/rpi2-debian-stdkernel/other_boot_files/ubuntu.pref @@ -0,0 +1,3 @@ +Package: * +Pin: origin "ports.ubuntu.com" +Pin-Priority: 100 diff --git a/rpi2-debian-stdkernel/other_boot_files/ubuntu.sources b/rpi2-debian-stdkernel/other_boot_files/ubuntu.sources new file mode 100644 index 0000000..a8a167d --- /dev/null +++ b/rpi2-debian-stdkernel/other_boot_files/ubuntu.sources @@ -0,0 +1,4 @@ +Types: deb +URIs: http://ports.ubuntu.com +Suites: yakkety yakkety-updates +Components: main universe diff --git a/rpi2-debian-stdkernel/other_boot_files/update-boot-uimage.sh b/rpi2-debian-stdkernel/other_boot_files/update-boot-uimage.sh new file mode 100755 index 0000000..838e411 --- /dev/null +++ b/rpi2-debian-stdkernel/other_boot_files/update-boot-uimage.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# Place the relevant set of boot commands into boot.scr +mkimage -A arm -O linux -T script -C none -n boot.scr -d boot.scr boot.scr.uimg diff --git a/rpi2-debian-stdkernel/other_boot_files/vg-copy-rpi b/rpi2-debian-stdkernel/other_boot_files/vg-copy-rpi new file mode 100755 index 0000000..a8eb53e --- /dev/null +++ b/rpi2-debian-stdkernel/other_boot_files/vg-copy-rpi @@ -0,0 +1,13 @@ +#!/bin/sh +set -eux +rootsource=$(findmnt -fno source -T /) +firmwaresource=$(findmnt -fno source -T /boot/firmware/) +if ! test x"$rootsource" = x"$firmwaresource"; then + cp --dereference /vmlinuz /boot/firmware/vmlinuz \ + || cp --dereference /vmlinuz.old /boot/firmware/vmlinuz + cp --dereference /initrd.img /boot/firmware/initrd.img \ + || cp --dereference /initrd.img.old /boot/firmware/initrd.img + ls -lah /vmlinuz /initrd.img > /boot/firmware/versions.txt \ + || ls -lah /vmlinuz.old /initrd.img.old > /boot/firmware/versions.txt +fi +exit 0 |