Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·135 lines (114 loc) · 4.8 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·135 lines (114 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
###############################################################################
# setup.sh - Environment setup script for Qualcomm Linux kernel development
#
# Usage:
# ./setup.sh [--kernel <kernel_repo_url>] [--branch <branch_name>] [--ramdisk] [--help]
#
# Options:
# --kernel URL of the kernel repository to clone (default: https://github.com/qualcomm-linux/kernel.git)
# --branch Branch name to checkout from the kernel repository (default: qcom-next)
# --ramdisk If specified, downloads a default ramdisk image
# --help Show help message
#
# Description:
# This script sets up a development environment for building the Qualcomm
# Linux kernel using Docker. It installs Docker if not present, pulls a
# hosted Docker image by default, sets up useful aliases for kernel
# compilation, clones the kernel repository, and downloads systemd boot
# binaries and optionally a ramdisk image.
#
# Notes:
# - Run this script from your workspace directory.
# - After running, restart your terminal or run `source ~/.bashrc` to activate aliases.
###############################################################################
set -e
show_help() {
echo "Usage: ./setup.sh [options]"
echo ""
echo "Options:"
echo " --kernel <URL> Kernel repository URL (default: https://github.com/qualcomm-linux/kernel.git)"
echo " --branch <name> Branch name to checkout (default: qcom-next)"
echo " --ramdisk Downloads default ramdisk image"
echo " --help Show this help message"
echo ""
echo "Description:"
echo " Sets up a Qualcomm Linux kernel development environment using Docker."
echo " Installs Docker if missing, pulls a hosted Docker image by default,"
echo " configures aliases, clones the kernel repo, and downloads systemd boot"
echo " binaries and ramdisk."
}
# Default values
KERNEL_REPO=https://github.com/qualcomm-linux/kernel.git
KERNEL_BRANCH=qcom-next
KERNEL_PATH="../kernel"
RAMDISK_PATH="https://snapshots.linaro.org/member-builds/qcomlt/testimages/arm64/1379/initramfs-test-image-qemuarm64-20230321073831-1379.rootfs.cpio.gz"
HOSTED_KMAKE_IMAGE="artifacts.codelinaro.org/clo-420-qli-registry/kmake-image:ver.1.0"
# Parse long options
eval set -- "$(getopt -n "$0" -o "" \
--long kernel:,branch:,ramdisk:,help -- "$@")"
while [[ $# -gt 0 ]]; do
case "$1" in
--kernel) KERNEL_REPO="$2"; shift 2 ;;
--branch) KERNEL_BRANCH="$2"; shift 2 ;;
--ramdisk) RAMDISK_PATH="$2"; shift 2 ;;
--help) show_help; exit 0 ;;
--) shift; break ;;
*) echo "Unknown option: $1"; show_help ; exit 1 ;;
esac
done
if [ -n "$KERNEL_REPO" ] && [ -z "$KERNEL_BRANCH" ]; then
echo "Error: Provide branch name"
exit 1
fi
echo "Installing Docker (if not already installed)..."
if ! command -v docker &> /dev/null; then
echo "Docker not found. Installing..."
sudo apt-get update
sudo apt-get install -y docker.io
fi
echo "Adding current user to docker group..."
if getent group docker > /dev/null; then
echo "Group 'docker' already exists. Skipping group creation."
else
sudo groupadd docker
fi
if id -nG "$USER" | grep -qw docker; then
echo "User '$USER' is already in docker group."
else
sudo usermod -aG docker "$USER"
echo "Added '$USER' to docker group. Re-login may be required for group changes to take effect."
fi
echo "Pulling hosted kmake Docker image: $HOSTED_KMAKE_IMAGE"
docker pull "$HOSTED_KMAKE_IMAGE"
docker tag "$HOSTED_KMAKE_IMAGE" kmake-image
echo "Setting up Docker aliases..."
{
echo ""
echo "# kmake-image Docker aliases"
echo "alias kmake-image-run='docker run -it --rm --user \$(id -u):\$(id -g) --workdir=\"\$PWD\" -v \"\$(dirname \$PWD)\":\"\$(dirname \$PWD)\" kmake-image'"
echo "alias kmake='kmake-image-run make'"
} >> ~/.bashrc
export PATH=$PWD:$PATH
if [ -d "$KERNEL_PATH" ]; then
if [ "$(ls -A "$KERNEL_PATH")" ]; then
echo "Directory '$DIR' exists but is not-empty. Skip cloning kernel."
skip_kernel=true
fi
fi
if [[ $skip_kernel != true ]]; then
echo "Cloning Qualcomm Linux kernel tree..."
git clone --branch "$KERNEL_BRANCH" "$KERNEL_REPO" ../kernel
fi
echo "Downloading systemd boot binaries..."
mkdir -p ../artifacts
cd ../artifacts
wget -O ../artifacts/systemd-boot-efi.deb http://ports.ubuntu.com/pool/universe/s/systemd/systemd-boot-efi_255.4-1ubuntu8_arm64.deb
dpkg-deb -xv ../artifacts/systemd-boot-efi.deb ../artifacts/systemd
if [ -n "$RAMDISK_PATH" ]; then
echo "Downloading ramdisk..."
# wget -O ../artifacts/ramdisk.gz "$RAMDISK_PATH"
fi
echo "Downloading qcom-dtb-metadata..."
git clone https://github.com/qualcomm-linux/qcom-dtb-metadata.git ../artifacts/qcom-dtb-metadata
echo "Environment setup complete. Please restart your terminal or run 'source ~/.bashrc' to activate aliases."