A’ cruthachadh ìomhaigh Ubuntu airson ARM “bhon fhìor thoiseach”

Nuair a thòisicheas leasachadh, gu tric chan eil e soilleir dè na pasganan a thèid gu na freumhan targaid.

Ann am faclan eile, tha e ro thràth grèim fhaighinn air LFS, buildroot no yocto (no rudeigin eile), ach feumaidh tu tòiseachadh mu thràth. Dha na daoine beairteach (tha 4GB eMMC agam air sampallan pìleat) tha slighe a-mach ann airson sgaoileadh a thoirt do luchd-leasachaidh a leigeas leotha rudeigin a tha a dhìth an-dràsta a lìbhrigeadh gu sgiobalta, agus an uairsin is urrainn dhuinn an-còmhnaidh liostaichean de phasgan a chruinneachadh agus liosta a chruthachadh airson na freumhan targaid.

Chan eil an artaigil seo ùr agus is e stiùireadh sìmplidh leth-bhreac a th’ ann.

Is e adhbhar an artaigil rootfs Ubuntu a thogail airson bùird ARM (nam chùis-sa, stèidhichte air Colibri imx7d).

A 'togail ìomhaigh

Bidh sinn a’ cruinneachadh na freumhan targaid airson ath-riochdachadh.

A’ dì-phapadh Ubuntu Base

Bidh sinn a’ taghadh an naidheachd sinn fhìn a rèir feum agus ar roghainnean fhèin. An seo tha mi air 20 a thoirt seachad.

$ mkdir ubuntu20
$ cd ubuntu20
$ mkdir rootfs
$ wget http://cdimage.ubuntu.com/ubuntu-base/releases/20.04/release/ubuntu-base-20.04-base-armhf.tar.gz
$ tar xf ubuntu-base-20.04-base-armhf.tar.gz -C rootfs

A’ sgrùdadh taic BINFMT anns an kernel

Ma tha cuairteachadh cumanta agad, tha taic ann airson BINFMT_MISC agus tha a h-uile càil air a rèiteachadh, mura h-eil, tha mi cinnteach gu bheil fios agad mar a bheir thu comas do thaic BINFMT anns an kernel.

Dèan cinnteach gu bheil BINFMT_MISC air a chomasachadh san kernel:

$ zcat /proc/config.gz | grep BINFMT
CONFIG_BINFMT_ELF=y
CONFIG_COMPAT_BINFMT_ELF=y
CONFIG_BINFMT_SCRIPT=y
CONFIG_BINFMT_MISC=y

A-nis feumaidh tu sgrùdadh a dhèanamh air na roghainnean:

$ ls /proc/sys/fs/binfmt_misc
qemu-arm  register  status
$ cat /proc/sys/fs/binfmt_misc/qemu-arm
enabled
interpreter /usr/bin/qemu-arm
flags: OC
offset 0
magic 7f454c4601010100000000000000000002002800
mask ffffffffffffff00fffffffffffffffffeffffff

Faodaidh tu clàradh le làimh a’ cleachdadh, mar eisimpleir, seo an stiùireadh seo.

A’ stèidheachadh gàirdean statach qemu

A-nis feumaidh sinn eisimpleir qemu air a chruinneachadh gu statach.

!!! AN aire !!!
Ma tha thu an dùil soitheach a chleachdadh airson rudeigin a thogail, thoir sùil air:
https://sourceware.org/bugzilla/show_bug.cgi?id=23960
https://bugs.launchpad.net/qemu/+bug/1805913
An uairsin airson aoigheachd x86_64 agus aoigh gàirdean feumaidh tu an tionndadh i386 de qemu a chleachdadh:
http://ftp.ru.debian.org/debian/pool/main/q/qemu/qemu-user-static_5.0-13_i386.deb

$ wget http://ftp.debian.org/debian/pool/main/q/qemu/qemu-user-static_5.0-13_amd64.deb
$ alient -t qemu-user-static_5.0-13_amd64.deb
# путь в rootfs и имя исполняемого файла должно совпадать с /proc/sys/fs/binfmt_misc/qemu-arm
$ mkdir qemu
$ tar xf qemu-user-static-5.0.tgz -C qemu
$ file qemu/usr/bin/qemu-arm-static
qemu/usr/bin/qemu-arm-static: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=be45f9a321cccc5c139cc1991a4042907f9673b6, for GNU/Linux 3.2.0, stripped
$ cp qemu/usr/bin/qemu-arm-static rootfs/usr/bin/qemu-arm
$ file rootfs/usr/bin/qemu-arm
rootfs/usr/bin/qemu-arm: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=be45f9a321cccc5c139cc1991a4042907f9673b6, for GNU/Linux 3.2.0, stripped

chroit

Sgriobt shìmplidh:

ch-mount.sh

#!/bin/bash

function mnt() {
    echo "MOUNTING"
    sudo mount -t proc /proc proc
    sudo mount --rbind /sys sys
    sudo mount --make-rslave sys
    sudo mount --rbind /dev dev
    sudo mount --make-rslave dev
    sudo mount -o bind /dev/pts dev/pts
    sudo chroot 
}

function umnt() {
    echo "UNMOUNTING"
    sudo umount proc
    sudo umount sys
    sudo umount dev/pts
    sudo umount dev

}

if [ "$1" == "-m" ] && [ -n "$2" ] ;
then
    mnt $1 $2
elif [ "$1" == "-u" ] && [ -n "$2" ];
then
    umnt $1 $2
else
    echo ""
    echo "Either 1'st, 2'nd or both parameters were missing"
    echo ""
    echo "1'st parameter can be one of these: -m(mount) OR -u(umount)"
    echo "2'nd parameter is the full path of rootfs directory(with trailing '/')"
    echo ""
    echo "For example: ch-mount -m /media/sdcard/"
    echo ""
    echo 1st parameter : 
    echo 2nd parameter : 
fi

Tha sinn a 'toirt meas air an toradh:

$ ./ch-mount.sh -m rootfs/
# cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
# uname -a
Linux NShubin 5.5.9-gentoo-x86_64 #1 SMP PREEMPT Mon Mar 16 14:34:52 MSK 2020 armv7l armv7l armv7l GNU/Linux

Dìreach airson spòrs, tomhais sinn am meud ro agus às deidh dhut an seata pacaidean as ìsle (dhòmhsa) a chuir a-steach:

# du -d 0 -h / 2>/dev/null
63M     /

Ùraich sinn:

# apt update
# apt upgrade --yes

Nach stàlaich sinn na pacaidean anns a bheil ùidh againn:

# SYSTEMD_IGNORE_CHROOT=yes apt install --yes autoconf kmod socat ifupdown ethtool iputils-ping net-tools ssh g++ iproute2 dhcpcd5 incron ser2net udev systemd gcc minicom vim cmake make mtd-utils util-linux git strace gdb libiio-dev iiod

Tha faidhlichean cinn kernel agus modalan na chùis air leth. Gu dearbh, cha stàlaich sinn an bootloader, kernel, modalan, craobh inneal tro Ubuntu. Thig iad thugainn bhon taobh a-muigh no cruinnichidh sinn iad fhèin no thèid an toirt dhuinn le neach-dèanamh a’ bhùird, co-dhiù tha seo taobh a-muigh raon an stiùiridh seo.

Gu ìre, tha e iomchaidh gabhail ri eadar-dhealachadh dreach, ach tha e nas fheàrr an toirt bhon togail kernel.

# apt install --yes linux-headers-generic

Chì sinn dè thachair agus thionndaidh e a-mach tòrr:

# apt clean
# du -d 0 -h / 2>/dev/null
770M    /

Na dìochuimhnich facal-faire a shuidheachadh.

A 'pacadh an ìomhaigh

$ sudo tar -C rootfs --transform "s|^./||" --numeric-owner --owner=0 --group=0 -c ./ | tar --delete ./ | gzip > rootfs.tar.gz

A bharrachd air an sin, is urrainn dhuinn msaakeeper a chuir a-steach leis an t-suidheachadh autopush

Uill, canaidh sinn gun do sgaoil sinn ar co-chruinneachadh, thòisich an obair air an dòigh as fheàrr air dreachan eadar-dhealaichte den t-siostam againn a chruinneachadh nas fhaide air adhart.

faodaidh neach-gleidhidh tighinn gu ar cuideachadh.

Tha sàbhailteachd na chùis phearsanta:

  • faodaidh tu meuran sònraichte a dhìon
  • cruthaich iuchair shònraichte airson gach inneal
  • cuir à comas putadh feachd
  • etc. ...
# ssh-keygen
# apt install etckeeper
# etckeeper init
# cd /etc
# git remote add origin ...

Feuch an cuir sinn autopush air dòigh

Faodaidh sinn, gu dearbh, meuran a chruthachadh air an inneal ro-làimh (canamaid gun dèan sinn sgriobt no seirbheis a ruitheas a’ chiad uair a thèid a chuir air bhog).

# cat /etc/etckeeper/etckeeper.conf
PUSH_REMOTE="origin"

No is urrainn dhuinn rudeigin nas glice a dhèanamh ...

Dòigh leisg

Leig leinn seòrsa de dh ’aithnichear sònraichte a bhith againn, can àireamh sreathach a’ phròiseasar (no MAC - ceannaich companaidhean trom an raon):

cat / proc / cpuinfo

# cat /proc/cpuinfo
processor       : 0
model name      : ARMv7 Processor rev 5 (v7l)
BogoMIPS        : 60.36
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xc07
CPU revision    : 5

processor       : 1
model name      : ARMv7 Processor rev 5 (v7l)
BogoMIPS        : 60.36
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xc07
CPU revision    : 5

Hardware        : Freescale i.MX7 Dual (Device Tree)
Revision        : 0000
Serial          : 06372509

An uairsin is urrainn dhuinn a chleachdadh airson ainm a’ mheur air am bi sinn a’ putadh:

# cat /proc/cpuinfo | grep Serial | cut -d':' -f 2 | tr -d [:blank:]
06372509

Cruthaichidh sinn sgriobt sìmplidh:

# cat /etc/etckeeper/commit.d/40myown-push
#!/bin/sh
set -e

if [ "$VCS" = git ] && [ -d .git ]; then
  branch=$(cat /proc/cpuinfo | grep Serial | cut -d':' -f 2 | tr -d [:blank:])
  cd /etc/
  git push origin master:${branch}
fi

Agus tha sin uile - às deidh greis is urrainn dhuinn sùil a thoirt air na h-atharrachaidhean agus liosta de phasganan a chruthachadh airson an firmware targaid.

Stuthan air am moladh

BINFMT_MISC
Taic Kernel airson cruthan binary measgaichte (binfmt_misc)
A 'cur ri chèile le qemu cleachdaiche chroot
A’ togail rootfs Ubuntu airson ARM
Mar a chruthaicheas tu Ubuntu àbhaisteach beò bhon fhìor thoiseach
Crossdev qemu-static-user-chroot
etc fear-gleidhidh

duilgheadas getdents64

Bidh readdir() a’ tilleadh NULL (errno = EOVERFLOW) airson qemu statach cleachdaiche 32-bit air aoigheachd 64-bit
Bidh ext4 64 bit hash a’ briseadh 32 bit glibc 2.28+
compiler_id_detection a’ fàiligeadh airson armhf nuair a bhios tu a’ cleachdadh atharrais modh cleachdaiche QEMU
Chan eil CMake ag obair ceart fo qemu-arm

Source: www.habr.com