Skip to content

Commit b177ca6

Browse files
deploy: 393f06a #210 (synchronize)
1 parent 0d9d17f commit b177ca6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+9247
-0
lines changed

.nojekyll

Whitespace-only changes.
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
.. _build-flow:
2+
3+
Build Flow
4+
==========
5+
6+
The Kuiper build process uses Docker to create a controlled environment for
7+
building Debian-based images for Analog Devices products. The build follows
8+
these high-level steps:
9+
10+
1. ``build-docker.sh`` creates a Docker container with all necessary build dependencies
11+
2. Inside the container, ``kuiper-stages.sh`` orchestrates a series of build stages
12+
3. Each stage performs specific tasks like system configuration, tool installation, and boot setup
13+
4. The final image is exported as a zip file to the ``kuiper-volume`` directory on your host machine
14+
15+
This approach ensures consistent builds across different host systems while
16+
allowing full customization through the ``config`` file.
17+
18+
The ``config`` file is first read by ``build-docker.sh`` on the host system
19+
to set up environment variables and Docker options. It is then copied into
20+
the container where ``kuiper-stages.sh`` reads it again to determine which
21+
stages to execute and how to configure them.
22+
23+
.. svg:: sources/build_flow.svg
24+
:align: center
25+
26+
----
27+
28+
Docker Build Environment
29+
------------------------
30+
31+
Docker is used to perform the build inside a container, which partially
32+
isolates the build from the host system. This allows the script to work on
33+
non-Debian based systems (e.g., Fedora Linux). The isolation is not total
34+
due to the need to use some kernel-level services for ARM emulation (binfmt)
35+
and loop devices (losetup).
36+
37+
The ``build-docker.sh`` script handles:
38+
39+
- Checking prerequisites and permissions
40+
- Building a Docker image with all necessary dependencies
41+
- Running a Docker container with appropriate options
42+
- Mounting volumes to share data between the host and container
43+
- Setting environment variables based on the ``config`` file
44+
- Starting the internal build process by calling ``kuiper-stages.sh``
45+
- Cleaning up the container after completion (if ``PRESERVE_CONTAINER=n``)
46+
47+
Running the Build
48+
~~~~~~~~~~~~~~~~~
49+
50+
To build:
51+
52+
.. code-block:: bash
53+
54+
sudo bash build-docker.sh
55+
56+
or
57+
58+
.. code-block:: bash
59+
60+
sudo ./build-docker.sh
61+
62+
Your Kuiper image will be in the ``kuiper-volume/`` folder inside the cloned
63+
repository on your machine as a zip file named
64+
``image_YYYY-MM-DD-ADI-Kuiper-Linux-[arch].zip``. After successful build,
65+
the Docker image and the build container are removed if ``PRESERVE_CONTAINER=n``.
66+
67+
If needed, you can remove the build container with:
68+
69+
.. code-block:: bash
70+
71+
docker rm -v debian_<DEBIAN_VERSION>_rootfs_container
72+
73+
If you choose to preserve the Docker container, you can access the Kuiper
74+
root filesystem by copying it from the container to your machine with this command:
75+
76+
.. code-block:: bash
77+
78+
CONTAINER_ID=$(docker inspect --format="{{.Id}}" debian_<DEBIAN_VERSION>_rootfs_container)
79+
sudo docker cp $CONTAINER_ID:<TARGET_ARCHITECTURE>_rootfs .
80+
81+
You need to replace ``<DEBIAN_VERSION>`` and ``<TARGET_ARCHITECTURE>`` with
82+
the ones in the configuration file.
83+
84+
Example:
85+
86+
.. code-block:: bash
87+
88+
CONTAINER_ID=$(docker inspect --format="{{.Id}}" debian_bookworm_rootfs_container)
89+
sudo docker cp $CONTAINER_ID:armhf_rootfs .
90+
91+
Docker Container Configuration
92+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93+
94+
When the Docker container is run, various required command line arguments are provided:
95+
96+
- ``-t``: Allocates a pseudo-TTY allowing interaction with container's shell
97+
- ``--privileged``: Provides elevated privileges required by the chroot command
98+
- ``-v /dev:/dev``: Mounts the host system's device directory
99+
- ``-v /lib/modules:/lib/modules``: Mounts kernel modules from the host
100+
- ``-v ./kuiper-volume:/kuiper-volume``: Creates a shared volume for the output
101+
- ``-e "DEBIAN_VERSION={value}"``: Sets environment variables from the config file
102+
103+
The ``--name`` and ``--privileged`` options are already set by the script and
104+
should not be redefined.
105+
106+
----
107+
108+
Stage-Based Build Process
109+
-------------------------
110+
111+
Inside the Docker container, ``kuiper-stages.sh`` orchestrates the entire
112+
build process. This script reads the ``config`` file, sets up environment
113+
variables, and executes a series of stages in a specific order.
114+
115+
How Stages Are Processed
116+
~~~~~~~~~~~~~~~~~~~~~~~~
117+
118+
The build process follows these steps inside the Docker container:
119+
120+
1. ``kuiper-stages.sh`` loops through the ``stages`` directory in alphanumeric order
121+
2. Within each stage, it processes subdirectories in alphanumeric order
122+
3. For each subdirectory, it runs the following files if they exist:
123+
124+
- ``run.sh`` - A shell script executed in the Docker container's context
125+
- ``run-chroot.sh`` - A shell script executed within the Kuiper image using chroot
126+
- Package installation files:
127+
128+
- ``packages-[*]`` - Lists packages to install with ``--no-install-recommends``
129+
- ``packages-[*]-with-recommends`` - Lists packages to install with their recommended dependencies
130+
131+
The package installation files (``packages-[*]``) are processed if the
132+
corresponding configuration option is enabled. For example, ``packages-desktop``
133+
is only processed if ``CONFIG_DESKTOP=y`` in the config file.
134+
135+
Key Stages Overview
136+
~~~~~~~~~~~~~~~~~~~
137+
138+
The build process is divided into several stages for logical clarity and modularity:
139+
140+
- **01.bootstrap** - Creates a usable filesystem using ``debootstrap``
141+
- **02.set-locale-and-timezone** - Configures system locale and timezone settings
142+
- **03.system-tweaks** - Sets up users, passwords, and system configuration
143+
- **04.configure-desktop-env** - Installs and configures desktop environment (if enabled)
144+
- **05.adi-tools** - Installs Analog Devices libraries and tools (based on config)
145+
- **06.boot-partition** - Adds boot files for different platforms
146+
- **07.extra-tweaks** - Applies custom scripts and additional configurations
147+
- **08.export-stage** - Creates and exports the final image
148+
149+
Each stage contains multiple substages that handle specific aspects of the
150+
build process. The stages are designed to be modular, allowing for easy
151+
customization and extension.
152+
153+
For a more detailed description of each stage and its purpose, see the
154+
:doc:`Stage Reference <stage-reference>` section.
155+
156+
Stage Execution Logic
157+
~~~~~~~~~~~~~~~~~~~~~
158+
159+
The ``kuiper-stages.sh`` script contains a helper function called
160+
``install_packages`` that handles package installation for each stage. This function:
161+
162+
1. Checks if package files exist for the current stage
163+
2. Verifies if the corresponding configuration option is enabled
164+
3. Installs the packages using the appropriate apt-get command
165+
166+
The script then executes each stage's ``run.sh`` script, which may perform
167+
additional configuration steps, compile software from source, or prepare files
168+
for the final image.
169+
170+
This modular approach allows users to easily customize the build process by
171+
modifying existing stages or adding new ones.

0 commit comments

Comments
 (0)