Initial commit

This commit is contained in:
Philip Trauner 2018-04-07 23:26:16 +02:00
commit df5befa9d1
45 changed files with 2030 additions and 0 deletions

8
.gitattributes vendored Executable file
View file

@ -0,0 +1,8 @@
boot/MLO filter=lfs diff=lfs merge=lfs -text
*.img filter=lfs diff=lfs merge=lfs -text
*.wav filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
*.dtb filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
hacks/sfdisk filter=lfs diff=lfs merge=lfs -text

4
.gitignore vendored Executable file
View file

@ -0,0 +1,4 @@
build
mnt
root-fs/var/0s/source
scripts/linux.sh1

53
Makefile Normal file
View file

@ -0,0 +1,53 @@
.PHONY: all setup build
all: build combine
setup:
./scripts/setup-host.sh
.ONESHELL:
build:
set -e
cd scripts
./setup-root-fs.sh
sudo ./make-sd-card.sh
./linux-dtbs.sh
sudo ./debian.sh
.ONESHELL:
combine:
set -e
mkdir -p mnt
mkdir -p mnt/boot
mkdir -p mnt/rootfs
echo "Mounting 0s"
sudo kpartx -a build/0s.img
cd mnt
sudo mount /dev/mapper/loop0p1 boot
sudo mount /dev/mapper/loop0p2 rootfs
sleep 1
echo "Copying bootloader"
sudo cp ../boot/* boot
echo "Copying Debian"
sudo cp -rp ../build/debian/* rootfs
echo "Copying dtbs"
sudo cp -r ../build/linux/* rootfs
sleep 1
sudo umount boot
sudo umount rootfs
sleep 1
cd ..
echo "Unmounting 0s"
sudo kpartx -d build/0s.img

BIN
boot/MLO (Stored with Git LFS) Executable file

Binary file not shown.

BIN
boot/u-boot.img (Stored with Git LFS) Executable file

Binary file not shown.

3
boot/uEnv.txt Executable file
View file

@ -0,0 +1,3 @@
console="tty0 console=ttyO0,115200n8"
uenvcmd=set optargs "consoleblank=0 fbcon=rotate:2"

7
chroot/stage-1.sh Executable file
View file

@ -0,0 +1,7 @@
#!/bin/bash
set -e
set -x
cd debootstrap
./debootstrap --second-stage

50
chroot/stage-2.sh Executable file
View file

@ -0,0 +1,50 @@
#!/bin/bash
set -e
set -x
# Ensure temp files can be created (apt-key error)
chmod -R 777 /tmp
# Recreate /dev/null
rm -f /dev/null; mknod -m 666 /dev/null c 1 3
# Set password of user 'root' to 'wallaby'
echo "root:wallaby" | chpasswd
echo "Delete debian-fresh if the next step fails, package register is outdated."
# Fix apt-key and enable https transport for apt
apt-get install -y dirmngr apt-transport-https
# Add F-WuTS debian repo
apt-key adv --keyserver pgp.mit.edu --recv-keys 0xE9368D5F3DE2EA910F48AF0412F68D62509CD98B
echo "deb https://f-wuts.github.io/repo stretch main" >> /etc/apt/sources.list
apt-get update
# Don't setup keyboard layout interactively
DEBIAN_FRONTEND=noninteractive apt-get install -y \
python python3 python3-pip \
wpasupplicant wireless-tools udhcpd avahi-daemon openssh-server ntp net-tools \
alsa-utils fontconfig i2c-tools xorg \
build-essential \
busybox sudo curl wget nano screen git \
dbus \
linux-image-3.18.21-custom linux-headers-3.18.21-custom linux-libc-dev \
botui libwallaby libbotball
cd /
wget https://deb.nodesource.com/setup_6.x
chmod +x setup_6.x
./setup_6.x
rm setup_6.x
apt-get install nodejs -y
apt-get clean
npm config set unsafe-perm true
npm install -g gulp browserify
pip3 install pipenv

25
chroot/stage-3.sh Executable file
View file

@ -0,0 +1,25 @@
#!/bin/bash
set -e
cd /var/0s/source
cd harrogate
npm install
gulp compile
cd ..
cd c0re
# Fix Click encoding error
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
pipenv install --system
systemctl enable c0re
systemctl enable harrogate
systemctl enable hostname
systemctl enable reset_coproc
systemctl enable setup_sound
systemctl enable startup_sound
systemctl enable x11

BIN
hacks/sfdisk (Stored with Git LFS) Executable file

Binary file not shown.

BIN
root-fs/boot/am335x-botball-hdmi.dtb (Stored with Git LFS) Executable file

Binary file not shown.

BIN
root-fs/boot/am335x-botball-lcd.dtb (Stored with Git LFS) Executable file

Binary file not shown.

View file

@ -0,0 +1 @@
while true; do botui && break; done

9
root-fs/etc/default/udhcpd Executable file
View file

@ -0,0 +1,9 @@
# Comment the following line to enable
DHCPD_ENABLED="yes"
# Options to pass to busybox' udhcpd.
#
# -S Log to syslog
# -f run in foreground
DHCPD_OPTS="-S"

View file

@ -0,0 +1,45 @@
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- WenQuanYi Zen Hei Configure File -->
<fontconfig>
<!-- modified by Madsen@SMTH -->
<match target="font">
<test qual="any" name="family">
<string>WenQuanYi Zen Hei</string>
<string>文泉驿正黑</string>
<string>文泉驛正黑</string>
</test>
<edit name="globaladvance"><bool>false</bool></edit>
<edit name="spacing"><int>0</int></edit>
<edit name="antialias" mode="assign"><bool>true</bool></edit>
<edit name="hinting" mode="assign"><bool>true</bool></edit>
<edit name="hintstyle" mode="assign"><const>hintnone</const></edit>
<edit name="autohint" mode="assign"><bool>false</bool></edit>
<edit name="rh_prefer_bitmaps" mode="assign"><bool>false</bool></edit>
<edit name="rgba" mode="assign"><const>none</const></edit>
<edit name="embeddedbitmap"><bool>false</bool></edit>
</match>
<alias>
<family>serif</family>
<prefer>
<family>Bitstream Vera Serif</family>
<family>DejaVu Serif</family>
<family>WenQuanYi Zen Hei</family>
</prefer>
</alias>
<alias>
<family>sans-serif</family>
<prefer>
<family>Bitstream Vera Sans</family>
<family>DejaVu Sans</family>
<family>WenQuanYi Zen Hei</family>
</prefer>
</alias>
<alias>
<family>monospace</family>
<prefer>
<family>Bitstream Vera Sans Mono</family>
<family>DejaVu Sans Mono</family>
</prefer>
</alias>
</fontconfig>

View file

@ -0,0 +1,17 @@
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- WenQuanYi Zen Hei Configure File -->
<fontconfig>
<match target="font">
<test qual="any" name="family">
<string>WenQuanYi Zen Hei</string>
<string>文泉驿正黑</string>
<string>文泉驛正黑</string>
</test>
<test compare="more_eq" name="pixelsize"><double>11</double></test>
<test compare="less" name="pixelsize"><double>16</double></test>
<edit name="antialias" mode="assign"><bool>false</bool></edit>
<edit name="embeddedbitmap" mode="assign"><bool>true</bool></edit>
<edit name="hinting" mode="assign"><bool>false</bool></edit>
</match>
</fontconfig>

View file

@ -0,0 +1 @@
options 8192cu rtw_power_mgnt=0 rtw_enusbss=0

6
root-fs/etc/modules Executable file
View file

@ -0,0 +1,6 @@
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
g_ether

14
root-fs/etc/network/interfaces Executable file
View file

@ -0,0 +1,14 @@
# interfaces(5) file used by ifup(8) and ifdown(8) Include files from
# /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto usb0
iface usb0 inet static
address 192.168.124.1
netmask 255.255.255.0
broadcast 192.168.124.255
auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

122
root-fs/etc/ssh/sshd_config Normal file
View file

@ -0,0 +1,122 @@
# $OpenBSD: sshd_config,v 1.101 2017/03/14 07:19:07 djm Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key
# Ciphers and keying
#RekeyLimit default none
# Logging
#SyslogFacility AUTH
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#PubkeyAuthentication yes
# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2
#AuthorizedPrincipalsFile none
#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no
# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes
#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
# no default banner path
#Banner none
# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
# override default of no subsystems
Subsystem sftp /usr/lib/openssh/sftp-server
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server

View file

@ -0,0 +1,11 @@
[Unit]
After=systemd-user-sessions.service
[Service]
ExecStart=/usr/bin/python3 /var/0s/source/c0re/app.py
WorkingDirectory=/var/0s/source/c0re
Environment="PYTHONIOENCODING=UTF-8"
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,10 @@
[Unit]
After=multi-user.target
[Service]
ExecStart=/usr/bin/node /var/0s/source/harrogate/server.js
WorkingDirectory=/var/0s/source/harrogate
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,9 @@
[Unit]
Description=Automatically change hostname to Wallaby hardware ID
After=x11.service
[Service]
ExecStart=/usr/bin/wallaby_set_hostname.py
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,10 @@
[Unit]
Description=Reset Coprocessor
After=systemd-user-sessions.service
[Service]
RemainAfterExit=yes
ExecStart=/usr/bin/wallaby_reset_coproc
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,10 @@
[Unit]
Description=Setup sound
After=systemd-user-sessions.service
[Service]
ExecStartPre=/usr/sbin/alsactl --file /var/asound.state restore
ExecStart=/usr/bin/amixer set PCM 100%
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,9 @@
[Unit]
Description=Play the startup sound
After=setup_sound.service
[Service]
ExecStart=/usr/bin/aplay /var/startup.wav
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,9 @@
[Unit]
After=systemd-user-sessions.service
[Service]
ExecStart=/bin/su root -l -c /usr/bin/startx
Environment="DISPLAY=:0"
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,7 @@
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="wlan*", NAME="wlan0"

5
root-fs/etc/udhcpd.conf Executable file
View file

@ -0,0 +1,5 @@
start 192.168.124.2
end 192.168.124.254
interface usb0
remaining yes
option subnet 255.255.255.0

View file

@ -0,0 +1,8 @@
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="foo"
psk="bar-bar-bar"
}

View file

@ -0,0 +1,16 @@
#!/bin/bash
VCMD1='i2cget -y 0 0x50 0x40'
VCMD2='i2cget -y 0 0x50 0x41'
VCMD3='i2cget -y 0 0x50 0x42'
VCMD4='i2cget -y 0 0x50 0x43'
V1=$(eval $VCMD1)
V2=$(eval $VCMD2)
V3=$(eval $VCMD3)
V4=$(eval $VCMD4)
printf "\x$(printf %x ${V1})"
printf "\x$(printf %x ${V2})"
printf "\x$(printf %x ${V3})"
printf "\x$(printf %x ${V4})"

View file

@ -0,0 +1,7 @@
#!/bin/bash
echo 33 > /sys/class/gpio/export
echo 34 > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio33/direction
echo "out" > /sys/class/gpio/gpio34/direction

View file

@ -0,0 +1,13 @@
#!/bin/bash
if [ ! -d "/sys/class/gpio/gpio34" ]; then
echo "gpio34 missing - initializing gpio pins"
wallaby_init_gpio
fi
echo "resetting co processor..."
echo 1 > /sys/class/gpio/gpio34/value
echo 0 > /sys/class/gpio/gpio34/value
echo 1 > /sys/class/gpio/gpio34/value
echo "Done..."

View file

@ -0,0 +1,23 @@
#!/usr/bin/env python3
from subprocess import check_output, call
bot_id = "bot"
for i2c in range(4):
bot_id += check_output("i2cget -y 0 0x50 0x4%i" % i2c, shell=True).decode()[-2]
new_hosts_content = ""
for line in open("/etc/hosts", "r").read().split("\n"):
if line.startswith("127.0.1.1"):
new_hosts_content += "127.0.1.1\t%s\n" % bot_id
elif line != "":
new_hosts_content += "%s\n" % line
open("/etc/hosts", "w").write(new_hosts_content)
call("hostnamectl set-hostname %s" % bot_id, shell=True)
call("systemctl restart avahi-daemon", shell=True)
print("Hostname set: '%s'" % bot_id)

View file

@ -0,0 +1,12 @@
#ifndef _KIPR_BOTBALL_H_
#define _KIPR_BOTBALL_H_
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <wallaby/wallaby.h>
#include <string.h>
#include <time.h>
#endif

View file

@ -0,0 +1,5 @@
Section "Device"
Identifier "Builtin Default fbdev Device 0"
Driver "fbdev"
# Option "Rotate" "UD"
EndSection

View file

@ -0,0 +1,6 @@
Section "InputClass"
Identifier "calibration"
MatchProduct "ADS7846 Touchscreen"
Option "Calibration" "359 3711 3537 501"
Option "SwapAxes" "0"
EndSection

BIN
root-fs/usr/share/fonts/truetype/wqy-zenhei.ttf (Stored with Git LFS) Executable file

Binary file not shown.

1307
root-fs/var/asound.state Executable file

File diff suppressed because it is too large Load diff

BIN
root-fs/var/startup.wav (Stored with Git LFS) Executable file

Binary file not shown.

42
scripts/debian.sh Executable file
View file

@ -0,0 +1,42 @@
#!/bin/bash
set -e
mkdir -p ../build
cd ../build
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit
fi
echo "Delete debian-fresh if you interrupted the initial download."
if [ ! -d debian-fresh ]; then
echo "Initial download, this will take a while."
debootstrap --foreign --verbose --arch=armhf stretch ./debian-fresh
mkdir -p debian-fresh/usr/bin
cp /usr/bin/qemu-arm-static debian-fresh/usr/bin
# Stage 1
cp ../chroot/stage-1.sh debian-fresh
chroot debian-fresh/ ./stage-1.sh
rm debian-fresh/stage-1.sh
fi
rm -rf debian
cp -r debian-fresh debian
cp -r ../chroot debian
# Stage 2
echo "Installing dependencies."
chroot debian/ ./chroot/stage-2.sh
echo "Applying overlay fs"
cp -r ../root-fs/* debian
# Stage 3
echo "Running fs prepare"
chroot debian/ ./chroot/stage-3.sh
rm -rf debian/chroot

19
scripts/linux-dtbs.sh Executable file
View file

@ -0,0 +1,19 @@
#!/bin/bash
set -e
mkdir -p ../build
cd ../build
[[ -d wallaby-linux ]] || git clone https://github.com/F-WuTS/wallaby-linux.git --depth=1
mkdir -p linux/boot
cd wallaby-linux
# Remove .git folder to prevent dirty kernel names
[[ -d build ]] || rm -rf .git
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- dtbs -j8
cp -r arch/arm/boot/dts/am335x-pepper*.dt* ../linux/boot

64
scripts/make-sd-card.sh Executable file
View file

@ -0,0 +1,64 @@
#!/bin/bash
set -e
mkdir -p ../build
cd ../build
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
if lsblk | grep -q "loop0"; then
echo "loop0 found, trying to unmount automatically"
kpartx -d /dev/loop0
losetup -d /dev/loop0
fi
echo "Creating empty image"
dd if=/dev/zero of=0s.img bs=1M count=7500
sync
sleep 1
echo "Mouting empty image"
losetup /dev/loop0 0s.img
# echo "Zeroing empty image (no real reason to do so, still...)"
# dd if=/dev/zero of=/dev/loop0 bs=1024 count=1024
echo "Creating partitions"
# sfdisk was "upgraded" -> tons of flags removed
SIZE=`fdisk -l /dev/loop0 | grep Disk | awk '{print $5}'`
CYLINDERS=`echo $SIZE/255/63/512 | bc`
../hacks/sfdisk --force -D -uS -H 255 -S 63 -C $CYLINDERS /dev/loop0 << EOF
128,130944,0x0C,*
131072,,,-
EOF
# sfdisk --force -u S /dev/loop0 << EOF
# 128,130944,0x0C,*
# 131072,,,-
# EOF
losetup -d /dev/loop0
sync
kpartx -a 0s.img
# Resources don't become avaliable immediately
sleep 1
echo "Creating fs"
mkfs.vfat -F 32 -n "boot" /dev/mapper/loop0p1
mkfs.ext3 -F -L "rootfs" /dev/mapper/loop0p2
# Creating partitions is apperantly async
sleep 1
kpartx -d /dev/loop0
losetup -d /dev/loop0

19
scripts/setup-host.sh Executable file
View file

@ -0,0 +1,19 @@
#!/bin/bash
set -e
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
apt-get update
apt-get install curl -y
# git-lfs
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
dpkg --add-architecture armhf
apt-get update && apt-get upgrade -y
apt-get install crossbuild-essential-armhf bc git dosfstools kpartx \
debootstrap qemu-user-static git-lfs -y

23
scripts/setup-root-fs.sh Executable file
View file

@ -0,0 +1,23 @@
cd ..
mkdir -p root-fs/var/0s/source
cd root-fs/var/0s/source
if [ ! -d c0re ]; then
git clone https://github.com/F-WuTS/c0re.git --recursive --depth=1
else
git -C c0re fetch --all
git -C c0re reset --hard origin/master
fi
if [ ! -d harrogate ]; then
git clone https://github.com/F-WuTS/harrogate.git --depth=1
else
git -C harrogate fetch --all
git -C harrogate reset --hard origin/master
fi