Initial commit: build env for the Ubtouch OS

Change-Id: I4bf8c32811d2785bd86a532f4cb435794f5c14d2
This commit is contained in:
akadmin 2025-10-08 16:49:47 +03:00
commit efb4feb07b
9 changed files with 740 additions and 0 deletions

3
.env Normal file
View file

@ -0,0 +1,3 @@
USE_CCACHE=1
CCACHE_DIR=/workspace/.ccache
CLEAN_BUILD="true"

7
.gitignore vendored Normal file
View file

@ -0,0 +1,7 @@
!.gitignore
.idea
brax3
.ccache
build.log
venv

124
Dockerfile Normal file
View file

@ -0,0 +1,124 @@
# Use specific Ubuntu version for reproducibility
FROM ubuntu:22.04
LABEL maintainer="Brax <support@braxtech.net>" \
description="Ubuntu Touch OS build environment" \
version="1.0"
# Set build arguments for flexibility
ARG CCACHE_SIZE=10G
ARG DEBIAN_FRONTEND=noninteractive
ARG TZ=UTC
# Environment variables
ENV DEBIAN_FRONTEND=${DEBIAN_FRONTEND} \
TZ=${TZ} \
USE_CCACHE=1 \
CCACHE_EXEC=/usr/bin/ccache \
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
# Set timezone to prevent tzdata interactive prompt
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
echo $TZ > /etc/timezone
# Update package lists and install essential packages
RUN dpkg --add-architecture i386 && \
apt-get update && \
apt-get install --no-install-recommends -y \
# Build essentials \
software-properties-common \
bc \
bison \
build-essential \
ccache \
curl \
git \
gnupg \
ca-certificates \
cpio \
curl \
fakeroot \
flex \
kmod \
libelf-dev \
libssl-dev \
libtinfo5 \
lz4 \
python3 \
sudo \
img2simg \
simg2img \
unzip \
zip \
wget \
zstd \
jq \
libncurses5 \
imagemagick \
liblz4-tool \
schedtool \
xsltproc \
rsync \
libxml2-utils \
python3-markdown \
tofrodos \
python2 \
gperf \
bzr \
libc6-dev \
libncurses5-dev:i386 \
x11proto-core-dev \
libx11-dev:i386 \
libreadline6-dev:i386 \
libgl1-mesa-glx:i386 \
libgl1-mesa-dev \
g++-multilib \
mingw-w64-i686-dev \
zlib1g-dev:i386 \
lzop \
xz-utils && \
# Clean up package cache
apt-get autoclean && \
rm -rf /var/lib/apt/lists/*
# python 2 is required for some android build tools
RUN update-alternatives --install /usr/bin/python python /usr/bin/python2 1
# Download and install Android platform-tools
RUN mkdir -p /opt/platform-tools && \
cd /opt/platform-tools && \
wget -q https://dl.google.com/android/repository/platform-tools-latest-linux.zip && \
unzip -q platform-tools-latest-linux.zip && \
rm platform-tools-latest-linux.zip && \
mv platform-tools/* . && \
rmdir platform-tools && \
chmod +x adb fastboot
# Add platform-tools to PATH
ENV PATH="/opt/platform-tools:${PATH}"
# Configure ccache
RUN ccache -M ${CCACHE_SIZE} && \
ccache -s
# Create workspace directory with proper ownership
RUN mkdir -p /workspace && \
chown -R ${BUILD_USER}:${BUILD_USER} /workspace
# Copy and set up entrypoint script
COPY --chown=root:root docker-entrypoint.sh /usr/local/bin/docker-entrypoint
COPY --chown=root:root docker-build.sh /usr/local/bin/docker-build
RUN chmod +x /usr/local/bin/docker-entrypoint && \
chmod +x /usr/local/bin/docker-build
# Switch to non-root user for security
USER root
WORKDIR /workspace
# Set up user-specific configurations
RUN echo 'export USE_CCACHE=1' >> ~/.bashrc && \
echo 'export CCACHE_EXEC=/usr/bin/ccache' >> ~/.bashrc
# Set entrypoint and default command
ENTRYPOINT ["docker-entrypoint"]
CMD ["/bin/bash"]

101
HOW_TO_FLASH.md Normal file
View file

@ -0,0 +1,101 @@
# Flashing Ubuntu Touch on BraX3
Follow these steps carefully to flash Ubuntu Touch images onto your BraX3 device.
---
## Prerequisites
- **ADB** and **Fastboot** tools must be installed on your computer.
- Device must have **LunarOS** installed.
- **USB Debugging** enabled (Settings → Developer Options → USB Debugging).
- **Unlock the Bootloader**.
> Follow the official guide
here: [How to Unlock the Bootloader of Your BraX3](https://community.braxtech.net/t/how-to-unlock-the-bootloader-of-your-brax3/45).
---
## Flashing Steps
1. Connect your device and verify it is detected:
```bash
adb devices
```
2. Reboot into fastboot mode:
```bash
adb reboot fastboot
```
3. Set Device Slot to **slot a**:
```bash
fastboot --set-active=a
```
4. Flash the **system image**:
```bash
fastboot flash system ubuntu.img
```
5. Reboot bootloader:
```bash
fastboot reboot bootloader
```
6. Flash the **boot partitions**:
```bash
fastboot flash boot_a boot.img
fastboot flash boot_b boot.img
```
7. Flash the **init_boot partitions**:
```bash
fastboot flash init_boot_a init_boot.img
fastboot flash init_boot_b init_boot.img
```
8. Wipe and format userdata for Ubuntu Touch:
```bash
fastboot -w
fastboot format:ext4 userdata
```
9. Reboot the device:
```bash
fastboot reboot
```
> Just make sure your fastboot/adb version is >= 35.0.2-12147458s.
> First Ubuntu Touch boot may take 58 minutes.
---
## Troubleshooting
* **Device not detected by `adb` or `fastboot`**:
* Check your USB cable and port.
* Install proper USB drivers if on Windows.
* Make sure USB Debugging is enabled in Developer Options.
* **Bootloop after flashing**:
* Recheck that you flashed all images in the correct order.
* Confirm that you used the **latest platform tools**.
* **Still stuck?**
Contact us or ask your question on the [BraxTech Community Forum](https://community.braxtech.net/).
---
## Completion
After the process is complete, reboot your device. Ubuntu Touch should now be installed on your BraX3. 🎉
```

201
LICENSE Normal file
View file

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

88
README.md Normal file
View file

@ -0,0 +1,88 @@
# How to Build UbtouchOS with Docker
## Why Docker?
Using Docker ensures all required dependencies are pre-installed and properly configured.
You dont need to install complex toolchains or modify your host system.
---
## Requirements
### Software
- **Docker**
Install Docker using the official script:
```bash
curl -fsSL https://get.docker.com | sh
```
- **Git**
[Install Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
- **Repo tool**
Install the Google `repo` tool:
```bash
mkdir -p ~/bin
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
export PATH=~/bin:$PATH
```
### Hardware
- **Disk:** \~30 GB (source code and build artifacts). SSD recommended
- **CPU:** 64-bit processor (Intel i5/i7 or AMD Ryzen 5/7 and above recommended, 8 cores or more preferred)
- **Memory:**
* Minimum: 16 GB RAM
* Bare minimum: 8 GB RAM (with swap; builds will be very slow and unstable)
---
## Usage
1. **Clone this repo** to your local machine and navigate into it:
```bash
git clone https://git.os-source.co/UbuntuTouchOs/build.git
cd build
```
2. **Clone the brax3 ubports** into the `UbuntuTouchOs/build` checkout directory:
```bash
git clone https://git.os-source.co/UbuntuTouchOs/brax3-ubports brax3
```
3. **Start the build with Docker**:
```bash
docker compose up -d
```
4. **Check the build logs and wait**:
```bash
docker logs -f repo_build_ubtouch
```
5. Once the "success message" appears in the logs (this typically takes 10-30 minutes, depending on your hardware,
navigate to the brax3/out folder to find your fastboot images:
```bash
ls -la brax3/out | grep ubuntu.img
-rw-r--r-- 1 root root 1433058439 Sep 23 16:50 ubuntu.img
```
6. After building, follow the flashing instructions in [HOW_TO_FLASH.md](HOW_TO_FLASH.md) to install the images onto your phone.
---
## Licensing
LunarOS/build is licensed under the **Apache License, Version 2.0**.
See [LICENSE](LICENSE) for the full license text.

102
docker-build.sh Executable file
View file

@ -0,0 +1,102 @@
#!/bin/bash
set -euo pipefail
# ===============================
# CONFIGURATION
# ===============================
CLEAN_BUILD="${CLEAN_BUILD:-false}"
HALIUM_REPO="${HALIUM_REPO:-https://gitlab.com/ubports/porting/community-ports/halium-generic-adaptation-build-tools.git}"
HALIUM_BRANCH="${HALIUM_BRANCH:-main}"
WORKDIR="$(pwd)"
OUTDIR="${WORKDIR}/out"
OTADIR="${WORKDIR}/ota"
BUILDDIR="${WORKDIR}/build"
# ===============================
# LOGGING FUNCTIONS
# ===============================
log() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $*" >&2
}
cleanup() {
local exit_code=$?
if [ $exit_code -ne 0 ]; then
log "Build failed with exit code $exit_code"
fi
}
trap cleanup EXIT
# ===============================
# PREPARE BUILD ENV
# ===============================
if [ "$CLEAN_BUILD" = "true" ]; then
log "Performing clean build: removing previous artifacts"
rm -rf "$OUTDIR" "$OTADIR" "$BUILDDIR"
else
log "Incremental build enabled (set CLEAN_BUILD=true to force wipe)"
fi
mkdir -p "$OUTDIR" "$OTADIR"
# ===============================
# CLONE HALIUM TOOLS
# ===============================
if [ ! -d "$BUILDDIR" ]; then
log "Cloning Halium build tools from $HALIUM_REPO (branch: $HALIUM_BRANCH)"
git clone -b "$HALIUM_BRANCH" "$HALIUM_REPO" "$BUILDDIR"
else
log "Halium build tools already present, pulling latest changes"
(cd "$BUILDDIR" && git fetch && git checkout "$HALIUM_BRANCH" && git pull --rebase) || true
fi
# ===============================
# BUILD KERNEL
# ===============================
log "Starting kernel build..."
"$BUILDDIR/build.sh"
log "Kernel build completed successfully"
# ===============================
# ROOTFS & OTA PREP
# ===============================
DATETIME=$(date +%Y%m%d-%H%M)
DEVICE="$(source deviceinfo && echo "$deviceinfo_codename")"
log "Preparing OTA for device: $DEVICE"
"$BUILDDIR/prepare-fake-ota.sh" "$OUTDIR/device_${DEVICE}.tar.xz" "$OTADIR"
log "Generating system image..."
"$BUILDDIR/system-image-from-ota.sh" "$OTADIR/ubuntu_command" "$OUTDIR"
mv "$OUTDIR/rootfs.img" "$OUTDIR/ubuntu.img"
# ===============================
# PACKAGE ARTIFACTS
# ===============================
cd "$OUTDIR"
log "Compressing ubuntu.img with zstd..."
rm -f ubuntu.img.zst
log "Cleaning generated {init}/boot artifacts inorder to use prebuilt ones"
rm -rf boot.img init_boot.img
log "Copying prebuilt artifacts"
cp -r ../boot.img .
cp -r ../init_boot.img .
zstd -q -f ubuntu.img
ZIPNAME="ubuntu-touch-${DEVICE}-${DATETIME}.zip"
log "Creating flashable zip: $ZIPNAME"
zip -r9 "$ZIPNAME" boot.img init_boot.img *.zst
cd "$WORKDIR"
# ===============================
# DONE
# ===============================
log "======================================="
log "Build completed successfully!"
log "Artifacts available in: $OUTDIR"
ls -lh "$OUTDIR"
log "======================================="

29
docker-compose.yml Normal file
View file

@ -0,0 +1,29 @@
services:
repo-build-ubtouch:
build:
context: .
dockerfile: Dockerfile
image: registry.os-source.co/os-build/ubtouch-os:0.9
container_name: repo_build_ubtouch
command: "docker-build"
restart: "no"
env_file:
- .env
volumes:
- ./:/workspace
- ccache_data:/workspace/.ccache
working_dir: /workspace/brax3
tty: true
stdin_open: true
init: true
networks:
- build_network
volumes:
ccache_data:
driver: local
name: ubtouchos_ccache
networks:
build_network:

85
docker-entrypoint.sh Executable file
View file

@ -0,0 +1,85 @@
#!/bin/bash
set -euo pipefail
# Function to log messages with timestamp
log() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $*" >&2
}
# Function to handle cleanup on exit
cleanup() {
local exit_code=$?
if [ $exit_code -ne 0 ]; then
log "Build process exited with code: $exit_code"
# Optional: Save ccache stats on failure
if command -v ccache >/dev/null 2>&1; then
log "Final ccache stats:"
ccache -s
fi
fi
}
# Set up signal handlers
trap cleanup EXIT
trap 'log "Received SIGTERM, shutting down gracefully..."; exit 143' TERM
trap 'log "Received SIGINT, shutting down gracefully..."; exit 130' INT
# Initialize environment
log "Initializing build environment for user: $(whoami)"
# Ensure proper ownership of workspace
if [ -d "/workspace" ] && [ -w "/workspace" ]; then
log "Workspace permissions verified"
else
log "Warning: Workspace permissions may be incorrect"
fi
# Display ccache status
if command -v ccache >/dev/null 2>&1; then
log "ccache status:"
ccache -s
fi
# Display Python versions
if command -v python3 >/dev/null 2>&1; then
log "Python 3 version: $(python3 --version 2>&1)"
fi
if command -v python2 >/dev/null 2>&1; then
log "Python 2 version: $(python2 --version 2>&1)"
fi
if command -v python >/dev/null 2>&1; then
log "Python version: $(python --version 2>&1)"
fi
# Display system info for debugging
log "System info - Cores: $(nproc), Memory: $(free -h | awk '/^Mem:/ {print $2}')"
# Set optimal make flags if not already set
if [ -z "${MAKEFLAGS:-}" ]; then
export MAKEFLAGS="-j$(nproc)"
log "Set MAKEFLAGS to: $MAKEFLAGS"
fi
# If no arguments provided, start interactive bash
if [ $# -eq 0 ]; then
log "Starting interactive bash session"
exec /bin/bash
fi
# Define log file path
BUILD_LOG="/workspace/build.log"
# Clean previous logs
: > "$BUILD_LOG" # This truncates the file without deleting it
# Or, alternatively: rm -f "$BUILD_LOG" && touch "$BUILD_LOG"
log "Executing command: $*"
# Run command, tee stdout/stderr to build.log and still display in docker logs
"$@" > >(tee -a "$BUILD_LOG") 2> >(tee -a "$BUILD_LOG" >&2)
exit_code=$?
log "Command exited with code $exit_code"
exit $exit_code