• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2################################################################################
3#
4# Copyright (C) 2022 Huawei Device Co., Ltd.
5# SPDX-License-Identifier: GPL-2.0
6#
7# Legacy blkg rwstat helpers enabled by CONFIG_BLK_CGROUP_RWSTAT.
8# Do not use in new code.
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16################################################################################
17# File: tracepoint.sh
18#
19# Description: test tracepoint
20#
21# Authors:     yang ming di
22#
23# History:     August 4 2022 - test tracepoint
24#
25################################################################################
26
27set -e
28
29CURRENT_DIR=$(pwd)
30ROOT_DIR=$(cd ${CURRENT_DIR}/../../ && pwd)
31ROOT_FILE_DIR=${ROOT_DIR}/kernel/linux/build/test/tracepointtest
32COMPILE_DIR=${ROOT_DIR}/out/kernel/src_tmp/linux-5.10
33OBJ_DIR=${ROOT_DIR}/out/kernel/OBJ
34DRIVERS_DIR=${ROOT_DIR}/out/kernel/src_tmp/linux-5.10/drivers
35TRACEPOINT_INCLUDE_DIR=${ROOT_DIR}/out/kernel/src_tmp/linux-5.10/include/trace/hooks
36DRIVERS_TRACEPOINT_DIR=${ROOT_DIR}/out/kernel/src_tmp/linux-5.10/drivers/tracepointtest
37CONFIG_DIR=${ROOT_DIR}/out/kernel/src_tmp/linux-5.10/arch/arm64/configs
38
39copy() {
40  local SOURCE_PATH=$1
41  local TARGET_PATH=$2
42  echo "copy ${SOURCE_PATH} to ${TARGET_PATH}"
43  cp -rf ${SOURCE_PATH} ${TARGET_PATH}
44}
45
46modify_config() {
47  local SOURCE_FILE=$1
48  local TARGET_FILE=$2
49  if [ -e "${CONFIG_DIR}/tmp" ]; then
50    rm -f ${CONFIG_DIR}/tmp
51  fi
52
53  cp -f ${CONFIG_DIR}/${TARGET_FILE} ${CONFIG_DIR}/${TARGET_FILE}_tmpfile
54
55  while read line; do
56    echo "$line" >>${CONFIG_DIR}/tmp
57  done <${CONFIG_DIR}/${TARGET_FILE}
58
59  while read line; do
60    if [[ "$line" != "#"* ]]; then
61      echo "$line" >>${CONFIG_DIR}/tmp
62    fi
63  done <${SOURCE_FILE}
64
65  mv ${CONFIG_DIR}/tmp ${CONFIG_DIR}/${TARGET_FILE}
66}
67
68modify_files() {
69  local KCONFIG=${DRIVERS_DIR}/Kconfig
70  local MAKEFILE=${DRIVERS_DIR}/Makefile
71  local VENDOR_HOOKS=${DRIVERS_DIR}/hooks/vendor_hooks.c
72  local TMPFILE=${DRIVERS_DIR}/tmp
73
74  cp -f ${KCONFIG} ${KCONFIG}_tmpfile
75  cp -f ${MAKEFILE} ${MAKEFILE}_tmpfile
76  cp -f ${VENDOR_HOOKS} ${VENDOR_HOOKS}_tmpfile
77
78  if [ -e "${TMPFILE}" ]; then
79    rm -f ${TMPFILE}
80  fi
81
82  while read line; do
83    if [[ "$line" != "endmenu" ]]; then
84      echo "$line" >>${TMPFILE}
85    fi
86  done <${KCONFIG}
87  echo "source \"drivers/tracepointtest/Kconfig\"" >>${TMPFILE}
88  echo "endmenu" >>${TMPFILE}
89  mv ${TMPFILE} ${KCONFIG}
90
91  while read line; do
92    echo "$line" >>${TMPFILE}
93  done <${MAKEFILE}
94  echo "obj-y   += tracepointtest/" >>${TMPFILE}
95  mv ${TMPFILE} ${MAKEFILE}
96
97  while read line; do
98    echo "$line" >>${TMPFILE}
99  done <${VENDOR_HOOKS}
100  echo "#include <trace/hooks/emmc.h>" >>${TMPFILE}
101  echo "EXPORT_TRACEPOINT_SYMBOL_GPL(vendor_aml_emmc_partition);" >>${TMPFILE}
102  echo "EXPORT_TRACEPOINT_SYMBOL_GPL(vendor_fake_boot_partition);" >>${TMPFILE}
103  mv ${TMPFILE} ${VENDOR_HOOKS}
104}
105
106compile() {
107  cd ${COMPILE_DIR} || exit
108  export PRODUCT_COMPANY=hihope
109  export DEVICE_NAME=rk3568
110  export DEVICE_COMPANY=rockchip
111  export PRODUCT_PATH=${ROOT_DIR}/out/kernel/vendor/hihope/rk3568
112  ./make-ohos.sh TB-RK3568X0 >null
113  if [ $? -ne 0 ]; then
114    echo "compile failed"
115    exit 1
116  else
117    echo "compile success"
118  fi
119}
120
121collect_ko() {
122  if [ -e "${OBJ_DIR}/kofiles" ]; then
123    rm -f ${OBJ_DIR}/kofiles
124    mkdir -p ${OBJ_DIR}/kofiles
125  else
126    mkdir -p ${OBJ_DIR}/kofiles
127  fi
128
129  find ${DRIVERS_TRACEPOINT_DIR} -name '*.ko' | xargs cp -t ${OBJ_DIR}/kofiles
130}
131
132restore() {
133  local CONFIGNAME=rockchip_linux_defconfig
134  local KCONFIG=${DRIVERS_DIR}/Kconfig
135  local MAKEFILE=${DRIVERS_DIR}/Makefile
136  local HEADERFILE=${TRACEPOINT_INCLUDE_DIR}/emmc.h
137  local VENDOR_HOOKS=${DRIVERS_DIR}/hooks/vendor_hooks.c
138
139  if [ -d "${DRIVERS_TRACEPOINT_DIR}" ]; then
140    rm -rf ${DRIVERS_TRACEPOINT_DIR}
141  fi
142
143  if [ -e "${HEADERFILE}" ]; then
144    rm -rf ${HEADERFILE}
145  fi
146  mv -f ${CONFIG_DIR}/${CONFIGNAME}_tmpfile ${CONFIG_DIR}/${CONFIGNAME}
147  mv -f ${KCONFIG}_tmpfile ${KCONFIG}
148  mv -f ${MAKEFILE}_tmpfile ${MAKEFILE}
149  mv -f ${VENDOR_HOOKS}_tmpfile ${VENDOR_HOOKS}
150  if [ -e "${COMPILE_DIR}/.lock" ]; then
151    rm -rf ${COMPILE_DIR}/.lock
152  fi
153}
154
155main() {
156  if [ -e "${COMPILE_DIR}/.lock" ]; then
157    restore
158  fi
159
160  echo "" >${COMPILE_DIR}/.lock
161
162  if [ -d "${DRIVERS_DIR}/tracepointtest" ]; then
163    rm -rf ${DRIVERS_DIR}/tracepointtest
164    mkdir -p ${DRIVERS_DIR}/tracepointtest
165  else
166    mkdir -p ${DRIVERS_DIR}/tracepointtest
167  fi
168
169  for dir in $(ls "${ROOT_FILE_DIR}"); do
170    if [ -d "${ROOT_FILE_DIR}/${dir}" ]; then
171      copy ${ROOT_FILE_DIR}/${dir} ${DRIVERS_TRACEPOINT_DIR}/${dir}
172    elif [[ "${dir}" == "Makefile" ]]; then
173      copy ${ROOT_FILE_DIR}/${dir} ${DRIVERS_TRACEPOINT_DIR}/${dir}
174    elif [[ "${dir}" == "Kconfig" ]]; then
175      copy ${ROOT_FILE_DIR}/${dir} ${DRIVERS_TRACEPOINT_DIR}/${dir}
176    elif [[ "${dir}" == *.h ]]; then
177      copy ${ROOT_FILE_DIR}/${dir} ${TRACEPOINT_INCLUDE_DIR}/${dir}
178    elif [[ "${dir}" == "rockchip_linux_defconfig" ]]; then
179      modify_config ${ROOT_FILE_DIR}/${dir} ${dir}
180    fi
181  done
182
183  modify_files
184  compile
185  collect_ko
186  restore
187}
188
189main
190