Skip to content

Commit d2829b5

Browse files
committed
configure-setup: Update script that prepares boot partition
Update 'configure-setup' script to be run as a command inside the Kuiper image. Update script to read multiple .json files Add needed packages in the image. Add 'help' option for script. Signed-off-by: mlradu <[email protected]>
1 parent 3503ab3 commit d2829b5

File tree

4 files changed

+137
-68
lines changed

4 files changed

+137
-68
lines changed

stages/02.set-locale-and-timezone/03.mandatory-packages/00.install-packages/packages

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ device-tree-compiler
2424
psmisc
2525
tree
2626
bash-completion
27+
jq
28+
bsdextrautils

stages/08.export-stage/04.export-image/configure-setup.sh

Lines changed: 0 additions & 67 deletions
This file was deleted.
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
#
4+
# kuiper2.0 - Embedded Linux for Analog Devices Products
5+
#
6+
# Copyright (c) 2024 Analog Devices, Inc.
7+
# Author: Larisa Radu <[email protected]>
8+
9+
show_help() {
10+
11+
cat << EOF
12+
Usage:
13+
sudo $(basename "$0") [OPTIONS] [ARGUMENTS]
14+
15+
Description:
16+
Script that prepares Kuiper image to boot on a carrier board.
17+
18+
Arguments:
19+
eval-board Name of the project
20+
carrier Carrier board name
21+
22+
Options:
23+
-h, --help Show this help message
24+
25+
Example:
26+
sudo $(basename "$0") ad4003 zed
27+
EOF
28+
29+
echo -e "\n\nAvailable projects in your Kuiper image:\n"
30+
31+
{
32+
# Print header
33+
echo -e "ADI Eval Board\tCarrier"
34+
35+
# Print projects and boards
36+
find /boot -type f -name "*.json" | while read -r file; do
37+
jq -r '
38+
.projects[]?
39+
| select(has("name") and has("board"))
40+
| [.name, .board]
41+
| @tsv
42+
' "$file"
43+
done
44+
} | column -t -s $'\t'
45+
}
46+
47+
# Check if the script is run as root
48+
if [ "$(id -u)" != "0" ] ; then
49+
echo "This script must be run as root"
50+
exit 1
51+
fi
52+
53+
# Handle -h / --help first
54+
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
55+
show_help
56+
exit 0
57+
fi
58+
59+
# Validate positional arguments
60+
if [[ $# -lt 2 ]]; then
61+
echo -e "Error: Missing arguments.\n" >&2
62+
show_help
63+
exit 2
64+
fi
65+
66+
ADI_EVAL_BOARD=${1}
67+
CARRIER=${2}
68+
BOOTLOADER_DEV=${3:-"/dev/mmcblk0p3"}
69+
70+
if [[ ! -z "${ADI_EVAL_BOARD}" && ! -z "${CARRIER}" ]]; then
71+
72+
# Extract project description from .json by selecting the project set in the configuration file
73+
PROJECT_DESCRIPTION=$(find /boot -type f -name "*.json" \
74+
-exec jq -c '.projects[]? | select(.name=="'${ADI_EVAL_BOARD}'" and .board=="'${CARRIER}'")' {} + \
75+
| head -n 1)
76+
77+
# Check if project exists
78+
if [[ -z "${PROJECT_DESCRIPTION}" ]]; then
79+
echo "Cannot find project ${ADI_EVAL_BOARD} for board ${CARRIER}. Setup not configured."
80+
else
81+
# Extract kernel path from the project description
82+
kernel=$(echo "$PROJECT_DESCRIPTION" | jq -r '.kernel')
83+
84+
# Copy kernel to Kuiper boot directory
85+
cp -v ${kernel} /boot
86+
if [ $? -ne 0 ]; then
87+
echo "Something went wrong while copying the kernel. Boot partition can't be configured."
88+
exit
89+
fi
90+
91+
# Extract paths with boot files from the project description
92+
paths=$(echo "$PROJECT_DESCRIPTION" | jq -r '.files[].path')
93+
94+
# Add the correct prefix for all paths and copy them to Kuiper boot directory
95+
cp -v $paths /boot
96+
if [ $? -ne 0 ]; then
97+
echo "Something went wrong while copying boot files. Boot partition can't be configured."
98+
exit
99+
fi
100+
101+
# Check if project platform is Intel
102+
if [[ ! -z $(echo "$PROJECT_DESCRIPTION" | jq 'select(.platform == "intel")') ]]; then
103+
104+
# Create folder if it doesn't exist and move copied extlinux.conf to extlinux folder
105+
mkdir -p /boot/extlinux/ && mv -v /boot/extlinux.conf /boot/extlinux/
106+
107+
# Extract preloader file from the project description
108+
preloader=$(echo "$PROJECT_DESCRIPTION" | jq -r '.preloader')
109+
110+
# Write preloader file to corresponding image partition
111+
dd if=${preloader} of=${BOOTLOADER_DEV} status=progress
112+
if [ $? -ne 0 ]; then
113+
echo "Something went wrong while copying the preloader. Boot partition can't be configured."
114+
exit
115+
fi
116+
fi
117+
echo "Successfully prepared boot partition for running project ${ADI_EVAL_BOARD} on ${CARRIER}."
118+
fi
119+
else
120+
echo "Setup won't be configured because setup variables are null."
121+
fi
122+

stages/08.export-stage/04.export-image/run.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,19 @@ fi
124124
# - get the path of the current script: BASH_SOURCE
125125
# - remove the name of the current script: %%/run.sh
126126
# - concatenate with the configuration script (because it is at the same level as the current one): /configure-setup.sh
127-
bash "${BASH_SOURCE%%/run.sh}"/configure-setup.sh ${BOOTLOADER_DEV}
127+
# Run script inside chroot is variables are set
128+
129+
install -m 755 "${BASH_SOURCE%%/run.sh}"/files/configure-setup.sh "${BUILD_DIR}/usr/bin"
130+
131+
if [[ ! -z "${ADI_EVAL_BOARD}" && ! -z "${CARRIER}" ]]; then
132+
133+
chroot "${BUILD_DIR}" << EOF
134+
bash configure-setup.sh ${ADI_EVAL_BOARD} ${CARRIER} ${BOOTLOADER_DEV}
135+
EOF
136+
137+
else
138+
echo "Setup won't be configured because setup variables are null."
139+
fi
128140

129141
rsync -aHAXx --exclude /var/cache/apt/archives --inplace --exclude /boot "${BUILD_DIR}/" "${EXPORT_ROOTFS_DIR}/"
130142
rsync -rtx --inplace "${BUILD_DIR}/boot/" "${EXPORT_ROOTFS_DIR}/boot/"

0 commit comments

Comments
 (0)