blob: a94f94aa760c1e56ab3575785d6e88e4dc19d1c8 [file] [log] [blame]
Jackie Huangb5105bb2019-10-16 14:53:59 +08001#!/bin/bash
Jackie Huang54049b42019-11-13 14:43:04 +08002#
3# Copyright (C) 2019 Wind River Systems, Inc.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
Jackie Huang90b87ff2019-09-30 13:36:48 +080016
Jackie Huangab45ef32019-11-07 11:49:57 +080017# Ensure we fail the job if any steps fail.
Jackie Huangba8ab242019-11-07 16:31:10 +080018set -e -o pipefail
Jackie Huangab45ef32019-11-07 11:49:57 +080019
Jackie Huangaa94cc12020-03-02 19:29:01 +080020SUPPORTED_BSP="intel-x86-64 nxp-lx2xxx"
21WRTEMPLATE_COMMON="feature/oran-host-rt-tune feature/kubernetes feature/self-hosted"
22WRTEMPLATE_X86="feature/hosts-ia feature/kvm feature/dpdk"
23
24SRC_ORAN_BRANCH="master"
25SRC_WRL_BRANCH="WRLINUX_10_18_BASE"
26SRC_WRL_URL="git://github.com/WindRiver-Labs/wrlinux-x.git"
27
28SCRIPTS_DIR=$(dirname $(readlink -f $0))
29
Jackie Huang90b87ff2019-09-30 13:36:48 +080030help_info () {
31cat << ENDHELP
32Usage:
Jackie Huangaa94cc12020-03-02 19:29:01 +080033$(basename $0) <-w WORKSPACE_DIR> [-b BSP] [-n] [-h] [-r]
Jackie Huang90b87ff2019-09-30 13:36:48 +080034where:
Jackie Huangbe9f4e22019-10-16 10:02:00 +080035 -w WORKSPACE_DIR is the path for the project
Jackie Huangaa94cc12020-03-02 19:29:01 +080036 -b BPS is one of supported BSP: "${SUPPORTED_BSP}"
37 (default is intel-x86-64 if not specified.)
Jackie Huangbe9f4e22019-10-16 10:02:00 +080038 -n dry-run only for bitbake
39 -h this help info
Jackie Huang6d582c52019-11-01 15:28:47 +080040 -e EXTRA_CONF is the pat for extra config file
Jackie Huang45c76112019-12-09 17:39:02 +080041 -r whether to inherit rm_work (default is Yes)
Jackie Huang90b87ff2019-09-30 13:36:48 +080042ENDHELP
43}
44
45echo_info () {
46 echo "INFO: $1"
47}
48
49echo_error () {
50 echo "ERROR: $1"
51}
52
53echo_cmd () {
54 echo
Jackie Huang6d582c52019-11-01 15:28:47 +080055 echo_info "$1"
Jackie Huang90b87ff2019-09-30 13:36:48 +080056 echo "CMD: ${RUN_CMD}"
57}
58
59if [ $# -eq 0 ]; then
Jackie Huangbe9f4e22019-10-16 10:02:00 +080060 echo "Missing options!"
Jackie Huang90b87ff2019-09-30 13:36:48 +080061 help_info
62 exit
63fi
64
Jackie Huang45c76112019-12-09 17:39:02 +080065check_yn_rm_work () {
66 yn="$1"
67 case ${yn} in
68 [Yy]|[Yy]es)
69 RM_WORK="Yes"
70 ;;
71 [Nn]|[Nn]o)
72 RM_WORK="No"
73 ;;
74 *)
75 echo "Invalid arg for -r option."
76 help_info
77 exit 1
78 ;;
79 esac
80}
81
Jackie Huangaa94cc12020-03-02 19:29:01 +080082check_valid_bsp () {
83 bsp="$1"
84 for b in ${SUPPORTED_BSP}; do
85 if [ "${bsp}" == "${b}" ]; then
86 BSP_VALID="${bsp}"
87 break
88 fi
89 done
90 if [ -z "${BSP_VALID}" ]; then
91 echo_error "${bsp} is not a supported BSP, the supported BSPs are: ${SUPPORTED_BSP}"
92 exit 1
93 fi
94}
95
Jackie Huangbe9f4e22019-10-16 10:02:00 +080096DRYRUN=""
Jackie Huang6d582c52019-11-01 15:28:47 +080097EXTRA_CONF=""
Jackie Huang45c76112019-12-09 17:39:02 +080098RM_WORK="Yes"
Jackie Huangaa94cc12020-03-02 19:29:01 +080099BSP="intel-x86-64"
Jackie Huangbe9f4e22019-10-16 10:02:00 +0800100
Jackie Huangaa94cc12020-03-02 19:29:01 +0800101while getopts "w:b:e:r:nh" OPTION; do
Jackie Huangbe9f4e22019-10-16 10:02:00 +0800102 case ${OPTION} in
103 w)
104 WORKSPACE=`readlink -f ${OPTARG}`
105 ;;
Jackie Huangaa94cc12020-03-02 19:29:01 +0800106 b)
107 check_valid_bsp ${OPTARG}
108 ;;
Jackie Huang6d582c52019-11-01 15:28:47 +0800109 e)
110 EXTRA_CONF=`readlink -f ${OPTARG}`
Jackie Huang45c76112019-12-09 17:39:02 +0800111 ;;
Jackie Huangbe9f4e22019-10-16 10:02:00 +0800112 n)
113 DRYRUN="-n"
114 ;;
Jackie Huang45c76112019-12-09 17:39:02 +0800115 r)
116 check_yn_rm_work ${OPTARG}
117 ;;
Jackie Huangbe9f4e22019-10-16 10:02:00 +0800118 h)
119 help_info
120 exit
121 ;;
122 esac
123done
124
Jackie Huangaa94cc12020-03-02 19:29:01 +0800125if [ -z "${WORKSPACE}" ]; then
Jackie Huangbe9f4e22019-10-16 10:02:00 +0800126 echo_info "No workspace specified, a directory 'workspace' will be created in current directory as the workspace"
127 WORKSPACE=`readlink -f workspace`
128fi
Jackie Huang90b87ff2019-09-30 13:36:48 +0800129
Jackie Huangaa94cc12020-03-02 19:29:01 +0800130if [ -n "${BSP_VALID}" ]; then
131 BSP="${BSP_VALID}"
132fi
133
134SRC_WRL_DIR=${WORKSPACE}/src_wrlinux
Jackie Huang90b87ff2019-09-30 13:36:48 +0800135SRC_ORAN_DIR=${WORKSPACE}/src_oran
136PRJ_BUILD_DIR=${WORKSPACE}/prj_oran-inf
137
138mkdir -p ${SRC_WRL_DIR} ${PRJ_BUILD_DIR} ${SRC_ORAN_DIR}
139
140echo_info "The following directories are created in your workspace(${WORKSPACE}):"
Jackie Huangaa94cc12020-03-02 19:29:01 +0800141echo_info "For wrlinux source: ${SRC_WRL_DIR}"
Jackie Huang90b87ff2019-09-30 13:36:48 +0800142echo_info "For oran layer source: ${SRC_ORAN_DIR}"
143echo_info "For build project: ${PRJ_BUILD_DIR}"
144
Jackie Huangaa94cc12020-03-02 19:29:01 +0800145# Clone the source of WRLinux from github and setup
146RUN_CMD="git clone --branch ${SRC_WRL_BRANCH} ${SRC_WRL_URL}"
147echo_cmd "Cloning wrlinux-x source from github:"
Jackie Huang90b87ff2019-09-30 13:36:48 +0800148cd ${SRC_WRL_DIR}
149${RUN_CMD}
150
Jackie Huangaa94cc12020-03-02 19:29:01 +0800151RUN_CMD="./wrlinux-x/setup.sh --machines ${BSP} --layers meta-cloud-services"
Jackie Huang90b87ff2019-09-30 13:36:48 +0800152echo_cmd "Setup wrlinux build project:"
153${RUN_CMD}
154
Jackie Huang6d582c52019-11-01 15:28:47 +0800155# Clone the oran layer if it's not already cloned
Jackie Huang6d582c52019-11-01 15:28:47 +0800156# Check if the script is inside the repo
Jackie Huang1135be22019-11-05 15:39:00 +0800157if cd ${SCRIPTS_DIR} && git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
Jackie Huang6d582c52019-11-01 15:28:47 +0800158 CLONED_ORAN_REPO=`dirname ${SCRIPTS_DIR}`
159 echo_info "Use the cloned oran repo: ${CLONED_ORAN_REPO}"
Jackie Huangb6503892019-12-07 23:39:51 +0800160 mkdir ${SRC_ORAN_DIR}/rtp
161 cd ${SRC_ORAN_DIR}/rtp
162 ln -sf ${CLONED_ORAN_REPO}/meta-oran meta-oran
163 ln -sf ${CLONED_ORAN_REPO}/scripts scripts
Jackie Huang6d582c52019-11-01 15:28:47 +0800164else
165 echo_info "Cloning oran layer:"
Jackie Huang1135be22019-11-05 15:39:00 +0800166 cd ${SRC_ORAN_DIR}
Jackie Huangaa94cc12020-03-02 19:29:01 +0800167 RUN_CMD="git clone --branch ${SRC_ORAN_BRANCH} https://gerrit.o-ran-sc.org/r/pti/rtp"
Jackie Huang6d582c52019-11-01 15:28:47 +0800168 echo_cmd "Cloing with:"
169 ${RUN_CMD}
170fi
Jackie Huang90b87ff2019-09-30 13:36:48 +0800171
Jackie Huangaa94cc12020-03-02 19:29:01 +0800172# Apply meta patches for nxp-lx2xxx
173if [ "${BSP}" == "nxp-lx2xxx" ]; then
174 cd ${SRC_WRL_DIR}/layers/nxp-lx2xxx/
175 git am ${SRC_ORAN_DIR}/rtp/scripts/meta-patches/nxp-lx2xxx/0001-Revert-nxp-lx2xxx-remove-preempt-rt-related-file.patch
176fi
177
Jackie Huang90b87ff2019-09-30 13:36:48 +0800178# Source the build env
179cd ${SRC_WRL_DIR}
180. ./environment-setup-x86_64-wrlinuxsdk-linux
181set ${PRJ_BUILD_DIR}
182. ./oe-init-build-env ${PRJ_BUILD_DIR}
183
Jackie Huang6d582c52019-11-01 15:28:47 +0800184# Add the meta-oran layer
Jackie Huang90b87ff2019-09-30 13:36:48 +0800185cd ${PRJ_BUILD_DIR}
Jackie Huang6d582c52019-11-01 15:28:47 +0800186RUN_CMD="bitbake-layers add-layer ${SRC_ORAN_DIR}/rtp/meta-oran"
187echo_cmd "Add the meta-oran layer into the build project"
188${RUN_CMD}
Jackie Huang90b87ff2019-09-30 13:36:48 +0800189
190# Add extra configs into local.conf
191cat << EOF >> conf/local.conf
192########################
193# Configs for oran-inf #
194########################
195DISTRO = "oran-inf"
196BB_NO_NETWORK = '0'
Jackie Huangb06a9772019-12-03 17:13:24 +0800197
198# Work around for CI build
199IMAGE_INSTALL_remove = "ceph"
Jackie Huangaa94cc12020-03-02 19:29:01 +0800200
201# For container image
202WR_APP_CONTAINER_APP = "rt-tests"
203
204# Disable multilib fo nxp-lx2xxx
205MULTILIBS_nxp-lx2xxx = ""
206DEFAULTTUNE_virtclass-multilib-lib32_nxp-lx2xxx = ""
207
208# Add templates
209WRTEMPLATE += "${WRTEMPLATE_COMMON}"
210WRTEMPLATE_prepend_x86-64 += "${WRTEMPLATE_X86}"
Jackie Huang90b87ff2019-09-30 13:36:48 +0800211EOF
212
Jackie Huang45c76112019-12-09 17:39:02 +0800213if [ "${RM_WORK}" == "Yes" ]; then
214 echo "INHERIT += 'rm_work'" >> conf/local.conf
215fi
216
Jackie Huang6d582c52019-11-01 15:28:47 +0800217if [ "${EXTRA_CONF}" != "" ] && [ -f "${EXTRA_CONF}" ]; then
218 cat ${EXTRA_CONF} >> conf/local.conf
219fi
220
Jackie Huang90b87ff2019-09-30 13:36:48 +0800221# Build the oran-inf-host image
222mkdir -p logs
223TIMESTAMP=`date +"%Y%m%d_%H%M%S"`
Jackie Huang6d582c52019-11-01 15:28:47 +0800224RUN_CMD="bitbake ${DRYRUN} oran-image-inf-host"
225echo_cmd "Build the oran-image-inf-host image"
Jackie Huangbe9f4e22019-10-16 10:02:00 +0800226bitbake ${DRYRUN} oran-image-inf-host 2>&1|tee logs/bitbake_oran-image-inf-host_${TIMESTAMP}.log
Jackie Huang6d582c52019-11-01 15:28:47 +0800227
Jackie Huangaa94cc12020-03-02 19:29:01 +0800228RUN_CMD="bitbake ${DRYRUN} wr-app-container"
229echo_cmd "Build the wr-app-container image"
230bitbake ${DRYRUN} wr-app-container 2>&1|tee logs/bitbake_wr-app-container_${TIMESTAMP}.log
231
Jackie Huang6d582c52019-11-01 15:28:47 +0800232echo_info "Build succeeded, you can get the image in ${PRJ_BUILD_DIR}/tmp-glibc/deploy/images/intel-x86-64/oran-image-inf-host-intel-x86-64.iso"