[gnome-build-meta/gnome-43] Initial buildable image



commit 5325e85fc310c6934a59bf2b33281ae78a0bf329
Author: Lawrence Hunter <lawrence hunter codethink co uk>
Date:   Tue Jul 26 21:20:41 2022 +0100

    Initial buildable image
    
    Add bootable PinePhone image with CI
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-build-meta/-/merge_requests/1731>

 .gitignore                                         |   6 +-
 .gitlab-ci.yml                                     |  58 ++++++
 elements/boards/pinephone/arm-trusted-firmware.bst |  27 +++
 elements/boards/pinephone/deps.bst                 |   9 +
 elements/boards/pinephone/filesystem.bst           |  10 +
 elements/boards/pinephone/image-deps.bst           |   7 +
 elements/boards/pinephone/image.bst                | 126 +++++++++++++
 elements/boards/pinephone/initial-scripts.bst      |   7 +
 elements/boards/pinephone/initramfs.bst            |  67 +++++++
 elements/boards/pinephone/initramfs/deps.bst       |  20 ++
 .../boards/pinephone/initramfs/initial-scripts.bst |   7 +
 elements/boards/pinephone/linux.bst                | 209 +++++++++++++++++++++
 elements/boards/pinephone/repo.bst                 |  29 +++
 elements/boards/pinephone/u-boot.bst               |  38 ++++
 utils/test_pinephone_image.py                      | 124 ++++++++++++
 15 files changed, 743 insertions(+), 1 deletion(-)
---
diff --git a/.gitignore b/.gitignore
index e136cb2b1..a7c2e0268 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,4 +9,8 @@ project.refs
 
 # Produced by the gnomeos build scripts
 ostree-gpg/
-ostree-repo/
\ No newline at end of file
+ostree-repo/
+
+**/*.DS_STORE
+logs/
+*.img
\ No newline at end of file
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 911ace902..054cb0623 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -91,6 +91,22 @@ default:
     - image
     expire_in: '2 days'
 
+.image-template:
+  stage: deploy
+  needs:
+    - job: "track"
+      optional: true
+  when: always
+  allow_failure: false
+  script:
+    - ${BST_NO_PUSH} --max-jobs $(( $(nproc) / 4 )) -o arch "${ARCH}" build "${IMAGE}"
+    - ${BST} -o arch "${ARCH}" checkout --hardlinks "${IMAGE}" image
+  artifacts:
+    when: always
+    paths:
+      - image
+    expire_in: "2 days"
+
 .deploy-rules:
   rules:
   - if: $EMERGENCY || $BST_TRACK_TAGS != "false"
@@ -276,6 +292,18 @@ pinebook-pro-image:
   variables:
     IMAGE: boards/pinebook-pro/image.bst
 
+pinephone-image:
+  extends:
+  - .manual-image-template
+  - .aarch64
+  needs:
+  - job: "track"
+    optional: true
+  - job: "build-aarch64"
+    artifacts: false
+  variables:
+    IMAGE: boards/pinephone/image.bst
+
 rock64-image:
   extends:
   - .manual-image-template
@@ -484,6 +512,36 @@ test-iso-installer-x86_64:
   - x86_64
   - gnome-build-meta
 
+test-pinephone-aarch64:
+  image: ubuntu:latest
+  stage: test
+  when: always
+  variables:
+    IMAGE: boards/pinephone/image.bst
+  needs:
+  - job: "pinephone-image"
+    artifacts: true
+  before_script:
+  - export DEBIAN_FRONTEND=noninteractive
+  - apt update -y
+  - apt install software-properties-common -y
+  - add-apt-repository ppa:deadsnakes/ppa
+  - apt update
+  - apt install python3.8 -yqq
+  - python3 --version
+  - apt-get install qemu-system-arm expect wget -y
+  - wget 
http://snapshots.linaro.org/components/kernel/leg-virt-tianocore-edk2-upstream/latest/QEMU-AARCH64/RELEASE_GCC5/QEMU_EFI.img.gz
+  - gunzip QEMU_EFI.img.gz
+  - qemu-img create -f qcow2 debian.img 32G
+  - qemu-img create -f qcow2 varstore.img 64M
+  - mv $(pwd)/image/disk.img.xz ./disk.img.xz
+  - unxz -T$(nproc) disk.img.xz
+  - chmod +x utils/test_pinephone_image.py
+  script:
+  - python3 utils/test_pinephone_image.py
+  tags:
+  - aarch64
+  - gnome-build-meta
 
 pages:
   stage: 'reports'
diff --git a/elements/boards/pinephone/arm-trusted-firmware.bst 
b/elements/boards/pinephone/arm-trusted-firmware.bst
new file mode 100644
index 000000000..bf01413b9
--- /dev/null
+++ b/elements/boards/pinephone/arm-trusted-firmware.bst
@@ -0,0 +1,27 @@
+kind: manual
+
+sources:
+- kind: git_tag
+  url: github:ARM-software/arm-trusted-firmware.git
+  track: v2.7
+
+build-depends:
+- freedesktop-sdk.bst:bootstrap-import.bst
+# This is required because at part of the firmware has to be built for
+# armv7. freedesktop-sdk.bst:cross-compilers/gcc-arm.bst does not
+# seem to be able to compile like needed.
+- boards/common/arm-none-eabi-gcc.bst
+
+variables:
+  board: sun50i_a64
+
+environment:
+  CFLAGS: '-fno-stack-protector'
+  LDFLAGS: ''
+
+config:
+  build-commands:
+  - make -j$(nproc) PLAT=%{board} DEBUG=1 all
+
+  install-commands:
+  - install -Dm644 -t "%{install-root}%{indep-libdir}/u-boot/pinephone" build/%{board}/debug/bl31/bl31.elf
diff --git a/elements/boards/pinephone/deps.bst b/elements/boards/pinephone/deps.bst
new file mode 100644
index 000000000..b65aca92d
--- /dev/null
+++ b/elements/boards/pinephone/deps.bst
@@ -0,0 +1,9 @@
+kind: stack
+
+depends:
+- core/meta-gnome-core-mobile.bst
+
+- vm/common-deps.bst
+- vm/os-release-user.bst
+
+- boards/pinephone/initramfs.bst
diff --git a/elements/boards/pinephone/filesystem.bst b/elements/boards/pinephone/filesystem.bst
new file mode 100644
index 000000000..40f33bf4f
--- /dev/null
+++ b/elements/boards/pinephone/filesystem.bst
@@ -0,0 +1,10 @@
+kind: compose
+
+build-depends:
+- boards/pinephone/deps.bst
+- boards/pinephone/initramfs.bst
+
+config:
+  exclude:
+  - devel
+  - debug
diff --git a/elements/boards/pinephone/image-deps.bst b/elements/boards/pinephone/image-deps.bst
new file mode 100644
index 000000000..b95c0713a
--- /dev/null
+++ b/elements/boards/pinephone/image-deps.bst
@@ -0,0 +1,7 @@
+kind: stack
+
+depends:
+- boards/pinephone/u-boot.bst
+- core-deps/libostree.bst
+- freedesktop-sdk.bst:components/genimage.bst
+- freedesktop-sdk.bst:integration/mtab.bst
diff --git a/elements/boards/pinephone/image.bst b/elements/boards/pinephone/image.bst
new file mode 100644
index 000000000..f30368a4b
--- /dev/null
+++ b/elements/boards/pinephone/image.bst
@@ -0,0 +1,126 @@
+kind: script
+
+build-depends:
+- boards/pinephone/image-deps.bst
+- boards/pinephone/repo.bst
+- boards/pinephone/linux.bst
+
+variables:
+  linux-root: b921b045-1df0-41c3-af44-4c6f280d3fae
+  ostree-branch: gnome-os/aarch64/pinephone
+  board: pinephone
+
+  sysroot: "/sysroot"
+
+environment:
+  OSTREE_REPO: "%{sysroot}/ostree/repo"
+  XZFLAGS: -T%{max-jobs}
+
+environment-nocache:
+- XZFLAGS
+
+
+config:
+  layout:
+  - element: ''
+    destination: '/sysroot'
+  - element: components/genimage.bst
+    destination: '/'
+  - element: boards/pinephone/repo.bst
+    destination: '/source-repo'
+  - element: boards/pinephone/image-deps.bst
+    destination: '/'
+  - element: core-deps/libostree.bst
+    destination: '/'
+  - element: boards/pinephone/linux.bst
+    destination: '/kernel'
+
+  commands:
+  - mkdir -p "${OSTREE_REPO}"
+  - ostree init --repo="${OSTREE_REPO}" --mode=bare
+
+  - ostree config --group sysroot set bootloader auto
+  - ostree pull-local "/source-repo" %{ostree-branch}
+
+  - mkdir -p "%{sysroot}/boot"
+
+  - ostree admin init-fs "%{sysroot}"
+  - ostree admin os-init --sysroot="%{sysroot}" gnome-os
+
+  # U-Boot does not provide EFI variables at runtime. So /dev/gpt-auto-root
+  # is not available.
+  - |
+    ostree admin deploy --os="gnome-os" \
+         --sysroot="%{sysroot}" %{ostree-branch} \
+         --karg="rw" --karg="splash" \
+         --karg="root=LABEL=root" \
+         --karg="console=ttyS0,115200n8" \
+         --karg="earlycon=ttyS0,115200n8" 
+
+  - |
+    mkdir -p "%{sysroot}/etc/ostree"
+    cp -r "%{sysroot}"/ostree/boot.1/gnome-os/*/*/etc/ostree/remotes.d "%{sysroot}/etc/ostree/remotes.d"
+
+  - |
+    ostree admin set-origin --sysroot="%{sysroot}" \
+           --index=0 \
+           gnome-os dummy \
+           %{ostree-branch}
+
+  - cp -r "%{sysroot}"/ostree/boot.1/gnome-os/*/*/boot/EFI/ "%{sysroot}/boot/"
+
+  - cp -r "/kernel/boot/dtbs" "%{sysroot}/boot/dtb"
+
+  - |
+    size=$(($(du -s -B 4K "%{sysroot}" | cut -f1)*4+200*1024))
+    cat >%{install-root}/genimage.cfg <<EOF
+    image efi.img {
+        vfat {
+            extraargs = "-F32 -n EFI"
+        }
+        mountpoint = "/boot"
+        size = 500M
+    }
+    image root.img {
+        ext4  {
+            label = "root"
+            use-mke2fs = true
+        }
+        size = ${size}K
+    }
+    image disk.img {
+        hdimage {
+            gpt = true
+            align = 1M
+        }
+        partition idbloader {
+            image = "idbloader.img"
+            offset = 32K
+            in-partition-table = false
+        }
+        partition uboot {
+            image = "u-boot.itb"
+            offset = 8M
+            in-partition-table = false
+        }
+        partition efi {
+            image = "efi.img"
+            partition-type-uuid = "U"
+        }
+        partition root {
+            image = "root.img"
+            partition-type-uuid = "%{linux-root}"
+        }
+    }
+    EOF
+
+  - | 
+    cd %{install-root}
+    genimage --rootpath "%{sysroot}" --inputpath "%{indep-libdir}/u-boot/pinephone/"
+    mv images/disk.img .
+    rm -rf genimage.cfg images/ tmp/
+
+
+  - sfdisk --part-attrs %{install-root}/disk.img 2 55
+  
+  - xz ${XZFLAGS} %{install-root}/disk.img
diff --git a/elements/boards/pinephone/initial-scripts.bst b/elements/boards/pinephone/initial-scripts.bst
new file mode 100644
index 000000000..a185f71c2
--- /dev/null
+++ b/elements/boards/pinephone/initial-scripts.bst
@@ -0,0 +1,7 @@
+kind: collect_initial_scripts
+
+build-depends:
+- boards/pinephone/deps.bst
+
+config:
+  path: /etc/fdsdk/initial_scripts
diff --git a/elements/boards/pinephone/initramfs.bst b/elements/boards/pinephone/initramfs.bst
new file mode 100644
index 000000000..e29599a47
--- /dev/null
+++ b/elements/boards/pinephone/initramfs.bst
@@ -0,0 +1,67 @@
+kind: script
+
+build-depends:
+- freedesktop-sdk.bst:vm/prepare-image.bst
+- boards/pinephone/initramfs/deps.bst
+- boards/pinephone/initramfs/initial-scripts.bst
+
+variables:
+  uuidnamespace: aea54278-2587-4075-ae67-8688ace4ce3d
+
+config:
+  layout:
+  - element: ''
+    destination: '/tmp'
+  - element: ''
+    destination: '/var/tmp'
+  - element: ''
+    destination: '/efi'
+  - element: boards/pinephone/initramfs/initial-scripts.bst
+    destination: '/'
+  - element: boards/pinephone/initramfs/deps.bst
+    destination: '/'
+  - element: vm/prepare-image.bst
+    destination: '/'
+
+  commands:
+  - |
+    prepare-image.sh \
+       --seed "%{uuidnamespace}" \
+       --rootsource LABEL=root \
+       --efisource LABEL=EFI \
+       --efipath /boot >/dev/null
+
+  - |
+    mkdir -p "%{install-root}/usr/lib/"
+    cp -r /usr/lib/modules "%{install-root}/usr/lib/"
+
+  - |
+    version="$(ls -1 /lib/modules | head -n1)"
+    mkdir -p "%{install-root}/usr/lib/modules/${version}"
+    dracut -v --fstab \
+           --no-machineid \
+           --kver "${version}" \
+           --add ostree \
+           --add plymouth \
+           --add eos-repartition \
+           --add-drivers "rockchipdrm panfrost panel_simple analogix_dp pwm_bl drm_kms_helper" \
+           --install 'fsck.ext4' \
+           "%{install-root}/usr/lib/modules/${version}/initramfs"
+
+  - |
+    version="$(ls -1 /lib/modules | head -n1)"
+    cp /boot/vmlinuz "%{install-root}/usr/lib/modules/${version}/vmlinuz"
+
+  - dbus-uuidgen >/etc/machine-id
+  - SYSTEMD_RELAX_ESP_CHECKS=1 bootctl --path='/efi' --no-variables install
+  - rm /etc/machine-id
+
+  - cp -r /efi "%{install-root}/boot"
+
+  - |
+    cat <<EOF >"%{install-root}/boot/loader/loader.conf"
+    timeout 3
+    editor no
+    console-mode max
+    default *
+    EOF
diff --git a/elements/boards/pinephone/initramfs/deps.bst b/elements/boards/pinephone/initramfs/deps.bst
new file mode 100644
index 000000000..87cd9b33a
--- /dev/null
+++ b/elements/boards/pinephone/initramfs/deps.bst
@@ -0,0 +1,20 @@
+kind: stack
+
+depends:
+- freedesktop-sdk.bst:bootstrap-import.bst
+- freedesktop-sdk.bst:components/util-linux.bst
+- freedesktop-sdk.bst:components/systemd.bst
+- freedesktop-sdk.bst:components/dbus.bst
+- freedesktop-sdk.bst:components/dracut.bst
+- freedesktop-sdk.bst:components/os-release.bst
+- freedesktop-sdk.bst:components/shadow.bst
+- freedesktop-sdk.bst:components/tzdata.bst
+- freedesktop-sdk.bst:components/pkg-config.bst
+- vm/plymouth-gnome-theme.bst
+
+- boards/pinephone/linux.bst
+- freedesktop-sdk.bst:components/linux-firmware.bst
+- freedesktop-sdk.bst:components/wireless-regdb-bin.bst
+
+- core-deps/libostree.bst
+- vm/eos-repartition.bst
diff --git a/elements/boards/pinephone/initramfs/initial-scripts.bst 
b/elements/boards/pinephone/initramfs/initial-scripts.bst
new file mode 100644
index 000000000..ea5223955
--- /dev/null
+++ b/elements/boards/pinephone/initramfs/initial-scripts.bst
@@ -0,0 +1,7 @@
+kind: collect_initial_scripts
+
+build-depends:
+- boards/pinephone/initramfs/deps.bst
+
+config:
+  path: /etc/fdsdk/initial_scripts
diff --git a/elements/boards/pinephone/linux.bst b/elements/boards/pinephone/linux.bst
new file mode 100644
index 000000000..7b304fe71
--- /dev/null
+++ b/elements/boards/pinephone/linux.bst
@@ -0,0 +1,209 @@
+kind: manual
+
+sources:
+- kind: git_tag
+  url: github:megous/linux.git
+  track: orange-pi-5.10
+  ref: orange-pi-5.10-20210226-1254-0-g5aa571dfc47b2fa92615ea5774475fa3650e8eb3
+
+depends:
+- freedesktop-sdk.bst:components/kmod.bst
+
+build-depends:
+- freedesktop-sdk.bst:bootstrap-import.bst
+- freedesktop-sdk.bst:components/bison.bst
+- freedesktop-sdk.bst:components/flex.bst
+- freedesktop-sdk.bst:components/bc.bst
+- freedesktop-sdk.bst:components/gzip.bst
+- freedesktop-sdk.bst:components/openssl.bst
+
+variables:
+  bootdir: /boot
+  kernel_arch: arm64
+  image-name: arch/arm64/boot/Image
+
+environment:
+  ARCH: '%{kernel_arch}'
+
+config:
+  configure-commands:
+  - make clean defconfig
+  
+  - |
+    # Modify the kernel config for additional features
+
+    # Kernel Config Options
+    scripts/config -e DEVTMPFS
+    scripts/config -e CGROUPS
+    scripts/config -e INOTIFY_USER
+    scripts/config -e SIGNALFD
+    scripts/config -e TIMERFD
+    scripts/config -e EPOLL
+    scripts/config -e NET
+    scripts/config -e SYSFS
+    scripts/config -e PROC_FS
+    scripts/config -e FHANDLE
+
+    # Kernel crypto/hash API
+    scripts/config -e CRYPTO_USER_API_HASH
+    scripts/config -e CRYPTO_HMAC
+    scripts/config -e CRYPTO_SHA256
+
+    # udev will fail to work with legacy sysfs
+    scripts/config -d SYSFS_DEPRECATED
+
+    # Boot is very slow with systemd when legacy PTYs are present
+    scripts/config -d LEGACY_PTYS
+    scripts/config -d LEGACY_PTY_COUNT
+
+    # Legacy hotplug confuses udev
+    scripts/config --set-str UEVENT_HELPER_PATH ""
+
+    # Userspace firmware loading not supported
+    scripts/config -d FW_LOADER_USER_HELPER
+
+    # Some udev/virtualization requires
+    scripts/config -e DMIID
+
+    # Support for some SCSI devices serial number retrieval
+    scripts/config -e BLK_DEV_BSG
+
+    # Required for PrivateNetwork= in service units
+    scripts/config -e NET_NS
+    scripts/config -e USER_NS
+
+    # Required for 9p support
+    scripts/config -e NET_9P
+    scripts/config -e NET_9P_VIRTIO
+    scripts/config -e 9P_FS
+    scripts/config -e 9P_FS_POSIX_ACL
+    scripts/config -e 9P_FS_SECURITY
+    scripts/config -e VIRTIO_PCI
+
+    # Strongly Recommended
+    scripts/config -e IPV6
+    scripts/config -e AUTOFS4_FS
+    scripts/config -e TMPFS_XATTR
+    scripts/config -e TMPFS_POSIX_ACL
+    scripts/config -e EXT4_FS_POSIX_ACL
+    scripts/config -e EXT4_FS_SECURITY
+    scripts/config -e XFS_POSIX_ACL
+    scripts/config -e BTRFS_FS_POSIX_ACL
+    scripts/config -e SECCOMP
+    scripts/config -e SECCOMP_FILTER
+    scripts/config -e CHECKPOINT_RESTORE
+
+    # Required for CPUShares= in resource control unit settings
+    scripts/config -e CGROUP_SCHED
+    scripts/config -e FAIR_GROUP_SCHED
+
+    # Required for CPUQuota= in resource control unit settings
+    scripts/config -e CFS_BANDWIDTH
+
+    # Required for IPAddressDeny=, IPAddressAllow= in resource control unit settings
+    scripts/config -e CGROUP_BPF
+
+    # For UEFI systems
+    scripts/config -e EFIVAR_FS
+    scripts/config -e EFI_PARTITION
+
+    # RT group scheduling (effectively) makes RT scheduling unavailable for userspace
+    scripts/config -d RT_GROUP_SCHED
+
+    # Required for 3D acceleration in qemu
+    scripts/config -e CONFIG_DRM_VIRTIO_GPU
+
+    # Required for systemd-nspawn
+    scripts/config -e DEVPTS_MULTIPLE_INSTANCES
+
+    # Sound with QEMU
+    scripts/config -e SND_HDA_GENERIC
+
+    scripts/config -e MMC
+    scripts/config -m PWRSEQ_SD8787
+    scripts/config -e MMC_BLOCK_MINORS=32
+    scripts/config -m SDIO_UART
+    scripts/config -e MMC_SDHCI
+    scripts/config -e MMC_SDHCI_PCI
+    scripts/config -e MMC_SDHCI_ACPI
+    scripts/config -e MMC_SDHCI_PLTFM
+    scripts/config -e MMC_SDHCI_OF_ARASAN
+    scripts/config -e MMC_SPI
+    scripts/config -e MMC_DW
+    scripts/config -e MMC_DW_PCI
+    scripts/config -e MMC_DW_ROCKCHIP
+
+    scripts/config -d DRM_LIMA
+
+    scripts/config -e DRM_PANFROST
+    scripts/config -m DRM_MALI_DISPLAY
+    scripts/config -m DRM_ANALOGIX_ANX78XX
+    scripts/config -m DRM_DW_HDMI_CEC
+    scripts/config -e DRM_LOAD_EDID_FIRMWARE
+
+    scripts/config -m BATTERY_CW2015
+
+    scripts/config -e FIRMWARE_EDID
+
+    scripts/config -m CRYPTO_DEV_ROCKCHIP
+    scripts/config -e PCIE_ROCKCHIP_HOST
+    scripts/config -e PHY_ROCKCHIP_DP
+    scripts/config -e PHY_ROCKCHIP_INNO_HDMI
+    scripts/config -e PHY_ROCKCHIP_PCIE
+    scripts/config -e ROCKCHIP_LVDS
+    scripts/config -e ROCKCHIP_MBOX
+    scripts/config -e ROCKCHIP_RGB
+    scripts/config -m SND_SOC_ROCKCHIP_MAX98090
+    scripts/config -m SND_SOC_ROCKCHIP_PDM
+    scripts/config -m VIDEO_ROCKCHIP_RGA
+    scripts/config -e ROCKCHIP_SUSPEND_MODE
+    scripts/config -e ROCKCHIP_SIP
+
+    scripts/config -e DRM_PANEL
+    scripts/config -m DRM_PANEL_LVDS
+    scripts/config -m DRM_PANEL_SIMPLE
+
+    scripts/config -m HID_MULTITOUCH
+
+    scripts/config -m SND_SOC_ES8316
+    scripts/config -m SND_SOC_SIMPLE_AMPLIFIER
+    scripts/config -m SND_SIMPLE_CARD
+
+    scripts/config -e CHARGER_GPIO
+    scripts/config -m PWRSEQ_SD8787
+    scripts/config -m PWRSEQ_SIMPLE
+    scripts/config -e GPIO_SYSCON
+
+    scripts/config -e RTC_DRV_RK808
+
+    scripts/config -e WIRELESS
+    scripts/config -m CFG80211
+    scripts/config -e CFG80211_WEXT
+    scripts/config -e MAC80211
+    scripts/config -e NETDEVICES
+    scripts/config -e WLAN
+
+
+  build-commands:
+  - make -j$(nproc)
+
+  install-commands:
+  - install -Dm644 "%{image-name}" '%{install-root}%{bootdir}/vmlinuz'
+  - install -Dm644 System.map '%{install-root}%{bootdir}/System.map'
+  - make INSTALL_MOD_PATH='%{install-root}%{prefix}' modules_install
+  - rm %{install-root}%{indep-libdir}/modules/*/{source,build}
+  - make INSTALL_DTBS_PATH='%{install-root}%{bootdir}/dtbs' dtbs_install
+
+public:
+  bst:
+    integration-commands:
+    - |
+      cd '%{indep-libdir}/modules'
+      for version in *; do
+        depmod -b '%{prefix}' -a "$version";
+      done
+
+    split-rules:
+      devel:
+        (>):
+        - '%{bootdir}/System.map'
diff --git a/elements/boards/pinephone/repo.bst b/elements/boards/pinephone/repo.bst
new file mode 100644
index 000000000..9d2409098
--- /dev/null
+++ b/elements/boards/pinephone/repo.bst
@@ -0,0 +1,29 @@
+kind: ostree
+
+build-depends:
+- freedesktop-sdk.bst:vm/prepare-image.bst
+- core-deps/libostree.bst
+- boards/pinephone/filesystem.bst
+- boards/pinephone/initial-scripts.bst
+
+variables:
+  uuidnamespace: aea54278-2587-4075-ae67-8688ace4ce3d
+  ostree-branch: gnome-os/aarch64/pinephone
+
+config:
+  environment:
+  - core-deps/libostree.bst
+  - vm/prepare-image.bst
+  - boards/pinephone/initial-scripts.bst
+  ostree-branch: '%{ostree-branch}'
+  initial-commands:
+  - |
+    prepare-image.sh \
+       --sysroot %{sysroot} \
+       --seed "%{uuidnamespace}" \
+       --rootpasswd root \
+       --rootsource LABEL=root \
+       --efisource LABEL=EFI \
+       --efipath /boot >/dev/null
+
+  - mv %{sysroot}/etc %{sysroot}/usr/etc
diff --git a/elements/boards/pinephone/u-boot.bst b/elements/boards/pinephone/u-boot.bst
new file mode 100644
index 000000000..ccb3d4fbf
--- /dev/null
+++ b/elements/boards/pinephone/u-boot.bst
@@ -0,0 +1,38 @@
+kind: manual
+
+sources:
+- kind: git
+  url: gitlab:pine64-org/u-boot.git
+  track: pinephone-2021-06-22
+  ref: 378121422954a58bc0072b0c8965fdc7b2332e55
+
+build-depends:
+- freedesktop-sdk.bst:components/bison.bst
+- freedesktop-sdk.bst:components/dtc.bst
+- freedesktop-sdk.bst:components/flex.bst
+- freedesktop-sdk.bst:components/gzip.bst
+- freedesktop-sdk.bst:components/bc.bst
+- freedesktop-sdk.bst:components/swig.bst
+- freedesktop-sdk.bst:components/python3-setuptools.bst
+- boards/common/python3-as-python2.bst
+- boards/pinephone/arm-trusted-firmware.bst
+
+environment:
+  BL31: "%{indep-libdir}/u-boot/pinephone/bl31.elf"
+
+variables:
+  board: pinephone
+
+config:
+  configure-commands:
+  - make distclean
+  - make "%{board}_defconfig"
+
+  build-commands:
+  - make -j$(nproc) V=1 all
+
+  install-commands:
+  - mv u-boot.img idbloader.img
+  - install -Dm644 -t "%{install-root}%{indep-libdir}/u-boot/%{board}" idbloader.img
+  - mv u-boot-sunxi-with-spl.fit.itb u-boot.itb      
+  - install -Dm644 -t "%{install-root}%{indep-libdir}/u-boot/%{board}" u-boot.itb
diff --git a/utils/test_pinephone_image.py b/utils/test_pinephone_image.py
new file mode 100644
index 000000000..96f6185d8
--- /dev/null
+++ b/utils/test_pinephone_image.py
@@ -0,0 +1,124 @@
+"""test_pinephone_image.py: Boots a disk image and tests that it works."""
+
+import argparse
+import asyncio
+import asyncio.subprocess
+import logging
+import sys
+import os
+import signal
+
+FAILURE_TIMEOUT = 1800  # seconds
+BUFFER_SIZE = 80  # how many characters to read at once
+
+DIALOGS = {
+    'root-login':
+    [
+        'login:',
+        'root',
+        'Password:',
+        'root',
+        '#',
+        'uname -a',
+        '#',
+        'sudo shutdown now',
+        'Power down'
+
+    ]
+}
+
+
+def argument_parser():
+    parser = argparse.ArgumentParser(
+        description="Test that PinePhone image works as expected")
+    parser.add_argument('--dialog', dest='dialog', default='root-login',
+                        help='dialog to follow\
+                            (valid values {}, default: root-login)'
+                        .format(DIALOGS.keys()))
+
+    return parser
+
+
+async def await_line(stream, marker):
+    """Read from 'stream' until a line appears contains 'marker'."""
+    marker = marker.encode("utf-8")
+    buf = b""
+
+    while not stream.at_eof():
+        chunk = await stream.read(BUFFER_SIZE)
+        sys.stdout.buffer.write(chunk)
+        buf += chunk
+        lines = buf.split(b'\n')
+        for line in lines:
+            if marker in line:
+                try:
+                    return line.decode("utf-8")
+                except UnicodeDecodeError:
+                    break
+        buf = lines[-1]
+
+
+async def run_test(command, dialog):
+    dialog = DIALOGS[dialog]
+
+    logging.debug("Starting process: {}", command)
+    process = await asyncio.create_subprocess_exec(
+        *command,
+        stdin=asyncio.subprocess.PIPE,
+        stdout=asyncio.subprocess.PIPE,
+        start_new_session=True)
+
+    success = False
+    try:
+        while dialog:
+            prompt = await await_line(process.stdout, dialog.pop(0))
+
+            assert prompt is not None
+            if dialog:
+                process.stdin.write(dialog.pop(0).encode('ascii') + b'\n')
+
+        print("Test successful")
+        success = True
+    except asyncio.CancelledError:
+        # Move straight to killing the process group
+        pass
+    finally:
+        try:
+            os.killpg(os.getpgid(process.pid), signal.SIGKILL)
+        except ProcessLookupError:
+            pass
+
+    await process.communicate()
+    await process.wait()
+    return success
+
+
+def fail_timeout(qemu_task):
+    sys.stderr.write("Test failed as timeout of %i seconds was reached.\n" %
+                     FAILURE_TIMEOUT)
+    qemu_task.cancel()
+
+
+def main():
+    args = argument_parser().parse_args()
+
+    command = ['qemu-system-aarch64', '-cpu', 'cortex-a57', '-M', 'virt', '-m',
+               '4096', '--nographic', '-drive',
+               'if=pflash,format=raw,file=QEMU_EFI.img',
+               '-drive', 'if=pflash,file=varstore.img',
+               '-drive', 'if=virtio,file=debian.img',
+               '-drive', 'if=virtio,format=raw,file=disk.img']
+
+    loop = asyncio.get_event_loop()
+    qemu_task = loop.create_task(run_test(command, args.dialog))
+    loop.call_later(FAILURE_TIMEOUT, fail_timeout, qemu_task)
+    loop.run_until_complete(qemu_task)
+    loop.close()
+
+    if qemu_task.result():
+        return 0
+    return 1
+
+
+result = main()
+sys.exit(result)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]