Skip to content

Commit

Permalink
Use mobian packages for AYN Odin
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmaris committed Aug 27, 2024
1 parent f927994 commit d2c5069
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 8 deletions.
1 change: 1 addition & 0 deletions overlays/mobian-apt/etc/apt/sources.list.d/mobian.list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deb http://repo.mobian.org/ @@SUITE@@ main non-free-firmware
15 changes: 15 additions & 0 deletions overlays/networkd/etc/systemd/network/gadget.network
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Match]
Type=gadget

[Link]
RequiredForOnline=no

[Network]
DHCPServer=yes
Address=172.16.42.1/24

[DHCPServer]
EmitDNS=no
EmitNTP=no
EmitRouter=no
EmitTimezone=no
8 changes: 8 additions & 0 deletions overlays/networkd/etc/systemd/network/wlan0.network
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Match]
Name=wlan0

[Link]
RequiredForOnline=no

[Network]
DHCP=yes
45 changes: 44 additions & 1 deletion overlays/odin-debugging/etc/rc.local
Original file line number Diff line number Diff line change
@@ -1,6 +1,49 @@
#!/bin/bash
echo "*** rc.local ***"
setterm -blank 1
setterm -powerdown 1

echo "*** USB network gadget setup ***"
CONFIGFS=/sys/kernel/config/usb_gadget/g1
# Don't do anything if the USB gadget already exists
if ! [ -d $CONFIGFS ]
then
# Required to make a composite gadget
modprobe libcomposite

# Create all required directories
echo "Creating the USB gadget..."
mkdir -p $CONFIGFS
mkdir -p $CONFIGFS/strings/0x409
mkdir -p $CONFIGFS/configs/c.1
mkdir -p $CONFIGFS/configs/c.1/strings/0x409

# Setup IDs and strings
USB_VENDORID="0x1D6B" # Linux Foundation
USB_PRODUCTID="0x0104" # Multifunction composite gadget
USB_MANUF="AYN"
USB_PRODUCT="Odin USB Ethernet"
USB_SERIAL=$(sha256sum < /etc/machine-id | cut -d' ' -f1)

echo $USB_VENDORID > $CONFIGFS/idVendor
echo $USB_PRODUCTID > $CONFIGFS/idProduct
echo $USB_MANUF > $CONFIGFS/strings/0x409/manufacturer
echo $USB_PRODUCT > $CONFIGFS/strings/0x409/product
echo $USB_SERIAL > $CONFIGFS/strings/0x409/serialnumber

# Create ECM (ethernet) function
mkdir $CONFIGFS/functions/ecm.usb0

# Create configuration
echo "Ethernet" > $CONFIGFS/configs/c.1/strings/0x409/configuration
ln -s $CONFIGFS/functions/ecm.usb0 $CONFIGFS/configs/c.1

UDC="$(ls /sys/class/udc)"
echo "$UDC" > $CONFIGFS/UDC
fi

set -x
sleep 1
ip addr
networkctl
networkctl status
networkctl status
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Set wlan0 persistent MAC address
Wants=sysinit.target
After=-.mount tmp.mount
Before=systemd-networkd.service
ConditionPathExists=!/etc/udev/rules.d/10-wlan0-persistent-mac-address.rules

[Service]
Type=oneshot
ExecStart=/usr/local/libexec/set-wlan-mac.sh

[Install]
WantedBy=basic.target
24 changes: 24 additions & 0 deletions overlays/wlan-mac-from-android/usr/local/libexec/set-wlan-mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
set -euo pipefail

wlan_mac="empty"
if [[ -b /dev/disk/by-partlabel/persist ]]
then
mountpoint="$(mktemp -d)"
mount -o ro /dev/disk/by-partlabel/persist "$mountpoint"
set +e
wlan_mac="$(grep -Po '(?<=Intf0MacAddress=)[A-Fa-f0-9]{12}' ${mountpoint}/wlan_mac.bin)"
set -e
umount "$mountpoint"
rmdir "$mountpoint"
fi

if [[ "${#wlan_mac}" != "12" ]]
then
echo "Could not read wlan0 MAC address from Android partition, generating random one..."
wlan_mac="$(printf '02%02X%02X%02X%02X%02X' $[RANDOM%256] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256])"
fi

cat > /etc/udev/rules.d/10-wlan0-persistent-mac-address.rules <<EOT
ACTION=="add", SUBSYSTEM=="net", INTERFACE=="wlan0", PROGRAM="/sbin/ip link set %k address ${wlan_mac:0:2}:${wlan_mac:2:2}:${wlan_mac:4:2}:${wlan_mac:6:2}:${wlan_mac:8:2}:${wlan_mac:10:2}"
EOT
93 changes: 86 additions & 7 deletions recipes/ayn-odin.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{{- $suite := or .suite "bookworm" -}}
{{- $dist := or .dist "debian" -}}
{{- $contrib := or .contrib "true" -}}
{{- $nonfree := or .nonfree "true" -}}
{{- $default_image := printf "%s-%s-sdm845odin.img" $dist $suite -}}
{{- $image := or .image $default_image -}}
architecture: arm64
Expand Down Expand Up @@ -32,6 +34,22 @@ actions:
compression: gz
description: save basic root filesystem for later use
{{ end }}

- action: apt
recommends: false
packages:
- mobian-archive-keyring
description: Install mobian-archive-keyring

- action: overlay
description: Enable Mobian repository
source: ../overlays/mobian-apt

- action: run
description: Setup Mobian repository
chroot: true
script: ../scripts/setup-mobian-apt.sh {{ $suite }} {{ $suite }} {{ $contrib }} {{ $nonfree }}

- action: apt
packages:
- bluez-firmware
Expand All @@ -44,22 +62,28 @@ actions:
- gdisk
- gnupg
- initramfs-tools
- libdrm-freedreno1
- libqmi-utils
- locales
- lsb-release
- make-dynpart-mappings
- man-db
- openssh-server
- parted
- protection-domain-mapper
- qcom-phone-utils
- qrtr-tools
- rmtfs
- sudo
- systemd-repart
- systemd-resolved
- systemd-timesyncd
- tqftpserv
- u-boot-tools
- u-boot-menu
# - u-boot-tools
# - u-boot-menu
- vim
- wget
- wireless-regdb
- wpasupplicant
- zstd
description: install some minimal packages
Expand All @@ -72,7 +96,14 @@ actions:
- action: overlay
source: ../overlays/ssh-keygen
description: >-
Set up script to run at first boot to regenerate SSH keys if missing
Set up script to run at first boot to
regenerate SSH host keys if missing.
- action: overlay
source: ../overlays/resize-rootfs
description: >-
Set up script to run at first boot to
resize root filesystem to fill disk/mmc/sd card
- action: run
chroot: true
Expand Down Expand Up @@ -103,6 +134,21 @@ actions:
- action: run
chroot: true
command: echo odin > /etc/hostname
description: Set hostname to 'odin'

- action: run
chroot: true
command: echo qcom/sdm845-ayn-odin-m2.dtb > /etc/kernel/devicetree
description: Use devicetree qcom/sdm845-ayn-odin-m2.dtb

- action: overlay
source: ../overlays/wlan-mac-from-android
description: Script to set wlan0 persistent MAC address from Android

- action: run
chroot: true
command: systemctl enable set-wlan-mac.service
description: Set wlan0 persistent MAC address from Android on 1st boot

- action: overlay
source: ../overlays/wpa-supplicant
Expand Down Expand Up @@ -155,9 +201,14 @@ actions:
description: Configure things for debugging bootup

- action: run
chroot: true
command: systemctl disable getty@tty1.service
description: Disable getty for debugging bootup
chroot: true
description: Disable getty clearing screen so we see console messages

- action: run
command: chmod +x /etc/rc.local
chroot: true
description: Make /etc/rc.local executable

- action: run
chroot: true
Expand All @@ -167,15 +218,28 @@ actions:
- action: image-partition
description: Partition SD card image
imagename: "{{ $image }}"
imagesize: 1500MB
imagesize: 2000MB
partitiontype: gpt
mountpoints:
- mountpoint: /
partition: root
options:
- "x-systemd.growfs"
- mountpoint: /boot/efi
partition: EFI
partitions:
- name: EFI
parttype: c12a7328-f81f-11d2-ba4b-00a0c93ec93b # EFI System Partition
fs: vfat
start: 0%
end: 256MB
flags:
- esp
- boot
- name: root
parttype: b921b045-1df0-41c3-af44-4c6f280d3fae # Root Partition (64-bit ARM/AArch64)
fs: ext4
start: 0%
start: 256MB
end: 100%

- action: filesystem-deploy
Expand All @@ -186,6 +250,21 @@ actions:
and switch the chroot to the mounted image's root filesystem
(further chroot commands affect the root filesystem inside the image)
- action: run
command: sed -i -e 's/$/ console=tty0/' /etc/kernel/cmdline
chroot: true
description: Add console=tty0 to kernel cmdline

- action: apt
packages:
- systemd-boot
- initramfs-tools

- action: run
chroot: true
command: apt-get clean
description: Save space by removing apt cache

- action: run
chroot: false
command: ln -sf /run/systemd/resolve/stub-resolv.conf "${ROOTDIR}/etc/resolv.conf"
Expand Down
41 changes: 41 additions & 0 deletions scripts/setup-mobian-apt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/sh

DEBIAN_SUITE=$1
SUITE=$2
CONTRIB=$3
NONFREE=$4

COMPONENTS="main"
[ "$CONTRIB" = "true" ] && COMPONENTS="$COMPONENTS contrib"
[ "$NONFREE" = "true" ] && COMPONENTS="$COMPONENTS non-free"

# Add debian-security for bullseye & bookworm; note that only the main component is supported
if [ "$DEBIAN_SUITE" = "bullseye" ] || [ "$DEBIAN_SUITE" = "bookworm" ]; then
echo "deb http://security.debian.org/ $DEBIAN_SUITE-security $COMPONENTS" >> /etc/apt/sources.list
# Temporary hack: add unstable as a lower priority source to install packages removed from testing
else
echo "deb http://deb.debian.org/debian unstable $COMPONENTS" >> /etc/apt/sources.list.d/unstable.list
echo "deb http://deb.debian.org/debian experimental $COMPONENTS" >> /etc/apt/sources.list.d/experimental.list

cat > /etc/apt/preferences.d/10-unstable-priority << EOF
Package: *
Pin: release a=unstable
Pin-Priority: 200
EOF

cat > /etc/apt/preferences.d/20-experimental-priority << EOF
Package: *
Pin: release a=experimental
Pin-Priority: 250
EOF
fi

# Set the proper suite in our sources.list
sed -i "s/@@SUITE@@/${SUITE}/" /etc/apt/sources.list.d/mobian.list

# Setup repo priorities so mobian comes first
cat > /etc/apt/preferences.d/00-mobian-priority << EOF
Package: *
Pin: release o=Mobian
Pin-Priority: 700
EOF

0 comments on commit d2c5069

Please sign in to comment.