提交 e8ce3d7e 编写于 作者: C Caoruihong

chore: simplify the prebuilt build steps

Now, we do just a make command to generate prebuilt files

Change-Id: I3b72b5a817ec46ae6a3c3c24fcc8c91c05f5a700
Signed-off-by: NCaoruihong <crh.cao@huawei.com>
上级 0987d98f
apidoc
usr
lib
build/linux_header_install_for_*
build/musl_copy_for_*
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
config("sysroot_flags") {
cflags = [ "--sysroot="+rebase_path(".") ]
}
group("sysroot") {
deps = [ "build" ]
public_configs = [ ":sysroot_flags" ]
}
SYSROOT
DESCRIPTION
-----------
Sysroot is a directory which is considered to be the root directory for
the purpose of locating headers and libraries.
Most of the headers in usr path were generated from MUSL by compilation, you can see
the license information of MUSL in COPYRIGHT file.
The build path contains compilation scripts, you can see the license information
in LICENSE file.
usr/include/arm-liteos/fb.h was generated from NUTTX headers, to provide
necessary information from kernel to userspace.
usr/include/arm-liteos/linux, usr/include/arm-liteos/asm,
usr/include/arm-liteos/asm-generic, ohos/uapi were generated from the Linux kernel
headers by update_headers.py, to provide necessary information from
kernel to userspace.
......@@ -16,7 +16,6 @@
```
/prebuilts/lite/sysroot
├── build # Toolchain building (including build scripts)
├── thirdparty # Temporary third-party header files required for toolchain building
├── usr # C library and header files exposed externally
│ ├── include # Header files exposed externally
│ │ └── arm-liteos # Chip architecture for the toolchain
......@@ -30,7 +29,7 @@
## Compilation and Building<a name="section137768191623"></a>
When bugs in the musl library are fixed or the version is updated, you need to compile and build a new libc library by executing **thirdparty\_headers.sh** and **build\_musl\_clang.sh** scripts in the **build** directory, respectively. The new libc library will be stored in the **/prebuilts/lite/sysroot/build/usr** directory. Then, you need to replace the header files and libc library in the **/prebuilts/lite/sysroot/usr** directory.
When bugs in the musl library are fixed or the version is updated, you need to compile and build a new libc library by executing `make` in the **build** directory, respectively. The new libc library will be stored in the **/prebuilts/lite/sysroot/usr** directory.
## Usage<a name="section68313135353"></a>
......@@ -38,7 +37,7 @@ When bugs in the musl library are fixed or the version is updated, you need to c
- The following is a sample script for compiling the **helloworld.c** program:
```
clang -o helloworld helloworld.c -target arm-liteos -L ~/llvm/lib/clang/9.0.0/lib/arm-liteos/a7_softfp_neon-vfpv4 --sysroot=/usr/xxx/OS/prebuilts/lite/sysroot/
clang -o helloworld helloworld.c -target arm-liteos --sysroot=/my_ohos_root_path/prebuilts/lite/sysroot/
```
The compiler directory is **\~/llvm**.
......
......@@ -16,7 +16,6 @@ sysroot是一个用作clang编译器查找标准库和头文件的根目录,
```
/prebuilts/lite/sysroot
├── build # 工具链构建目录,包括构建脚本
├── thirdparty # 临时生成的工具链构建所需的三方头文件
├── usr # 对外C库及头文件
│ ├── include # 对外头文件存放目录
│ │ └── arm-liteos # 工具链对应的芯片架构
......@@ -30,7 +29,7 @@ sysroot是一个用作clang编译器查找标准库和头文件的根目录,
## 编译构建<a name="section137768191623"></a>
musl库bug修复或者新版本更新时,需要重新编译构建新的libc库。分别执行build目录下的thirdparty\_headers.sh和build\_musl\_clang.sh脚本即可编译构建出新的libc库,存放于/prebuilts/lite/sysroot/build/usr目录下,然后替换/prebuilts/lite/sysroot/usr目录下对应的头文件及libc库即可
musl库bug修复或者新版本更新时,需要重新编译构建新的libc库。在build目录下执行`make`即可编译构建出新的libc库,存放于/prebuilts/lite/sysroot/usr目录下
## 使用说明<a name="section68313135353"></a>
......@@ -38,7 +37,7 @@ musl库bug修复或者新版本更新时,需要重新编译构建新的libc库
- 编译用户程序helloworld.c示例如下:
```
clang -o helloworld helloworld.c -target arm-liteos -L ~/llvm/lib/clang/9.0.0/lib/arm-liteos/a7_softfp_neon-vfpv4 --sysroot=/usr/xxx/OS/prebuilts/lite/sysroot/
clang -o helloworld helloworld.c -target arm-liteos --sysroot=/my_ohos_root_path/prebuilts/lite/sysroot/
```
其中,编译器目录为\~/llvm。
......
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//build/lite/config/component/lite_component.gni")
build_ext_component("build") {
exec_path = rebase_path(target_out_dir)
root_path = rebase_path("//.", exec_path)
makefile_path = rebase_path("Makefile", exec_path)
command = "make TOPDIR=$root_path -f $makefile_path"
}
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ARCH = arm
TARGET = $(ARCH)-liteos
CROSS_COMPILE = llvm-
CC = clang --target=$(TARGET) $(ARCH_CFLAGS)
MULTILIB = $(patsubst $(shell $(CC) -print-file-name=)%/,%,$(dir $(shell $(CC) -print-libgcc-file-name)))
MUSLBUILDDIR = build_$(ARCH)$(subst $(eval) ,,$(patsubst -%,_%,$(sort $(ARCH_CFLAGS))))
HIDE = @
TOPDIR = $(shell pwd)/../../../..
MUSLDIR = $(TOPDIR)/third_party/musl
LINUXKERNELDIR = $(TOPDIR)/third_party/Linux_Kernel
OPTRTDIR = $(TOPDIR)/third_party/optimized-routines
NUTTXDIR = $(TOPDIR)/third_party/NuttX
SYSROOTDIR = $(TOPDIR)/prebuilts/lite/sysroot
LINUXDIR = $(TOPDIR)/kernel/linux-4.19
TARGETS = liteos_a_user
TARGETS += $(if $(wildcard $(LINUXDIR)),linux_user,)
define LINUX_TYPES_H
/* Auto generated file at $(shell date), do NOT edit! */
#ifndef _LINUX_TYPES_H
#define _LINUX_TYPES_H
#include <stdint.h>
typedef uint32_t __u32, __le32;
#endif
endef
export LINUX_TYPES_H
ifeq ($(ARCH),arm)
ARCH_CFLAGS = -mfloat-abi=softfp -mcpu=cortex-a7 -mfpu=neon-vfpv4
else
$(warning *** warning: ARCH $(ARCH) has not been tested yet, use with cautions!)
ARCH_CFLAGS =
endif
CFLAGS = -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack -Wl,--build-id=sha1
.PHONY: $(TARGETS:%=musl_copy_for_%)
.PHONY: $(TARGETS:%=musl_patch_for_%)
.PHONY: $(TARGETS:%=musl_install_for_%)
.PHONY: $(TARGETS:%=linux_header_install_for_%)
.PHONY: $(TARGETS:%=nuttx_header_install_for_%)
.PHONY: $(TARGETS:%=optimized_routines_install_for_%)
.PHONY: all clean distclean
all: $(TARGETS:%=musl_install_for_%) $(if $(filter liteos_a_user,$(TARGETS)),musl_install_for_liteos_a_user_debug,)
$(TARGETS:%=musl_copy_for_%):
$(HIDE) mkdir -p $@
$(HIDE) cp -rfu $(MUSLDIR)/[^p]* $@
optimized_routines_install_for_liteos_a_user: musl_copy_for_liteos_a_user
ifneq ($(ARCH),)
$(HIDE) cp -rfp $(OPTRTDIR)/string/$(ARCH)/* $</src/string/$(ARCH)/
$(HIDE) cp -rfp $(OPTRTDIR)/string/asmdefs.h $</src/string/asmdefs.h
ifeq ($(ARCH),arm)
$(HIDE) rm -f $</src/string/arm/memcpy.c
$(HIDE) rm -f $</src/string/arm/memcpy_le.S
$(HIDE) rm -f $</src/string/arm/memset.S
$(HIDE) touch $</src/string/arm/strlen.S
endif
endif
nuttx_header_install_for_liteos_a_user: musl_copy_for_liteos_a_user
$(HIDE) sed '/^#include/d' $(NUTTXDIR)/include/nuttx/video/fb.h | sed 's,FAR ,,g' | sed 's,LosVmMapRegion,void,g' > $</include/fb.h
linux_header_install_for_liteos_a_user: musl_copy_for_liteos_a_user
$(HIDE) mkdir -p $@
$(HIDE) make -sj headers_install ARCH=$(ARCH) INSTALL_HDR_PATH=$(shell pwd)/$@ -C $(LINUXKERNELDIR)
$(HIDE) install -p -m 644 -D $@/include/linux/capability.h $</include/linux/capability.h
$(HIDE) echo "$$LINUX_TYPES_H" > $</include/linux/types.h
linux_header_install_for_linux_user: musl_copy_for_linux_user
$(HIDE) make -sj headers_install ARCH=$(ARCH) INSTALL_HDR_PATH=$(shell pwd)/$< -C $(LINUXDIR)
$(HIDE) find $< \( -name .install -o -name ..install.cmd \) -delete
$(HIDE) find $< -type d -empty -delete
musl_patch_for_liteos_a_user: nuttx_header_install_for_liteos_a_user
musl_patch_for_liteos_a_user: linux_header_install_for_liteos_a_user
musl_patch_for_liteos_a_user: optimized_routines_install_for_liteos_a_user
musl_patch_for_liteos_a_user: musl_copy_for_liteos_a_user
$(HIDE) cp -rfp $(MUSLDIR)/porting/liteos_a/user/* $</
musl_patch_for_linux_user: linux_header_install_for_linux_user
musl_patch_for_linux_user: musl_copy_for_linux_user
$(HIDE) cp -rfp $(MUSLDIR)/porting/linux/user/* $</
musl_install_for_liteos_a_user: musl_patch_for_liteos_a_user
$(HIDE) cd musl_copy_for_liteos_a_user && mkdir -p $(MUSLBUILDDIR) && cd $(MUSLBUILDDIR) && \
../configure --prefix=/usr --target=$(TARGET) --includedir=/usr/include/$(TARGET) --libdir=/usr/$(MULTILIB) \
CC="$(CC)" CROSS_COMPILE=$(CROSS_COMPILE) CFLAGS="$(CFLAGS)" >/dev/null && \
sed 's, -m 644 , -m 444 ,g' Makefile | make -f- -sj install-headers install-libs DESTDIR=$(SYSROOTDIR)
musl_install_for_linux_user: TARGET = $(ARCH)-linux-ohosmusl
musl_install_for_linux_user: MULTILIB = lib/$(TARGET)
musl_install_for_linux_user: CC += -fuse-ld=lld --rtlib=compiler-rt
musl_install_for_linux_user: musl_patch_for_linux_user
$(HIDE) cd musl_copy_for_linux_user && mkdir -p $(MUSLBUILDDIR) && cd $(MUSLBUILDDIR) && \
../configure --prefix=/usr --target=$(TARGET) --includedir=/usr/include/$(TARGET) --libdir=/usr/$(MULTILIB) \
CC="$(CC)" CROSS_COMPILE=$(CROSS_COMPILE) CFLAGS="$(CFLAGS)" >/dev/null && \
sed 's, -m 644 , -m 444 ,g' Makefile | make -f- -sj install-headers install-libs DESTDIR=$(SYSROOTDIR)
musl_install_for_liteos_a_user_debug: CFLAGS += -funwind-tables -fasynchronous-unwind-tables -rdynamic -I $(shell $(CC) -print-file-name=)include
musl_install_for_liteos_a_user_debug: musl_install_for_liteos_a_user
$(HIDE) mkdir -p musl_copy_for_liteos_a_user_debug && \
cp -rfp musl_copy_for_liteos_a_user/* musl_copy_for_liteos_a_user_debug && \
cp -rfp $(MUSLDIR)/porting/liteos_a/user_debug/* musl_copy_for_liteos_a_user_debug
$(HIDE) cd musl_copy_for_liteos_a_user_debug && mkdir -p $(MUSLBUILDDIR) && cd $(MUSLBUILDDIR) && \
../configure --prefix=/usr --target=$(TARGET) --includedir=/usr/include/$(TARGET) --libdir=/usr/$(MULTILIB)/debug \
LDFLAGS="-L $(dir $(shell $(CC) -print-libgcc-file-name)) -lunwind -L lib -ldl" \
CC="$(CC)" CROSS_COMPILE=$(CROSS_COMPILE) CFLAGS="$(CFLAGS)" >/dev/null && \
sed 's, -m 644 , -m 444 ,g' Makefile | make -f- -sj install-headers install-libs DESTDIR=$(SYSROOTDIR) ALL_INCLUDES=include/debug.h
ifeq ($(ARCH),arm)
ARCH_CFLAGS1 = -mfloat-abi=soft -march=armv7-a
ARCH_CFLAGS2 = -mfloat-abi=soft -mcpu=cortex-a7
ARCH_CFLAGS3 = -mfloat-abi=hard -mcpu=cortex-a7 -mfpu=neon-vfpv4
ARCH_CFLAGS4 = -mfloat-abi=softfp -mcpu=cortex-a7 -mfpu=neon-vfpv4
define multilib_template =
.PHONY: musl_install_for_liteos_a_user$(1) musl_install_for_liteos_a_user_debug$(1)
all: $$(if $$(filter liteos_a_user,$$(TARGETS)),musl_install_for_liteos_a_user$(1) musl_install_for_liteos_a_user_debug$(1),)
musl_install_for_liteos_a_user$(1): ARCH_CFLAGS = $$($(2))
musl_install_for_liteos_a_user$(1): musl_install_for_liteos_a_user
$$(HIDE) cd musl_copy_for_liteos_a_user && mkdir -p $$(MUSLBUILDDIR) && cd $$(MUSLBUILDDIR) && \
../configure --prefix=/usr --target=$$(TARGET) --libdir=/usr/$$(MULTILIB) \
CC="$$(CC)" CROSS_COMPILE=$$(CROSS_COMPILE) CFLAGS="$$(CFLAGS)" >/dev/null && \
sed 's, -m 644 , -m 444 ,g' Makefile | make -f- -sj install-libs DESTDIR=$$(SYSROOTDIR)
musl_install_for_liteos_a_user_debug$(1): ARCH_CFLAGS = $$($(2))
musl_install_for_liteos_a_user_debug$(1): CFLAGS += -funwind-tables -fasynchronous-unwind-tables -rdynamic -I $$(shell $$(CC) -print-file-name=)include
musl_install_for_liteos_a_user_debug$(1): musl_install_for_liteos_a_user_debug
$$(HIDE) cd musl_copy_for_liteos_a_user_debug && mkdir -p $$(MUSLBUILDDIR) && cd $$(MUSLBUILDDIR) && \
../configure --prefix=/usr --target=$$(TARGET) --libdir=/usr/$$(MULTILIB)/debug \
LDFLAGS="-L $$(dir $$(shell $$(CC) -print-libgcc-file-name)) -lunwind -L lib -ldl" \
CC="$$(CC)" CROSS_COMPILE=$$(CROSS_COMPILE) CFLAGS="$$(CFLAGS)" >/dev/null && \
sed 's, -m 644 , -m 444 ,g' Makefile | make -f- -sj install-libs DESTDIR=$$(SYSROOTDIR)
endef
$(foreach flags,1 2 3 4,$(eval $(call multilib_template,$(flags),ARCH_CFLAGS$(flags))))
endif
clean:
$(HIDE) rm -rf musl_copy_for_* linux_header_install_for_*
distclean: clean
$(HIDE) rm -rf $(SYSROOTDIR)/lib $(SYSROOTDIR)/usr
#!/bin/bash
#Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
# This script is used to prepare header files for musl's libc.so.
set -e
ARM_TYPE=arm
PRJ_ROOT="$PWD/../../../../../"
KERNEL_ROOT="$PRJ_ROOT/kernel/linux-4.19"
ARM_HDR="$KERNEL_ROOT/hdr_install/${ARM_TYPE}_header"
OUT_HDR="$PRJ_ROOT/prebuilts/lite/sysroot/thirdparty/linux_headers_install"
export Z_BUILD_TOP="$PRJ_ROOT"
if [ -d "$ARM_HDR" ];then
rm -r $ARM_HDR
fi
if [ -d "$OUT_HDR" ];then
rm -r $OUT_HDR
fi
mkdir -p $ARM_HDR
mkdir -p $OUT_HDR
pushd $KERNEL_ROOT
make headers_install ARCH=${ARM_TYPE} INSTALL_HDR_PATH=$ARM_HDR
popd
function copy_if_exists () {
local check_dir=$1
local src_dir=$2
local tgt_dir=$3
mkdir -p ${tgt_dir}
for file in $(ls -d ${src_dir}/* 2> /dev/null); do
if [[ -f "${file}" ]] && [[ "${file}" =~ .h$ ]]; then
header=$(basename ${file})
if [[ -f "${check_dir}/${header}" ]]; then
cp ${file} ${tgt_dir}
fi
fi
done
}
cp -r ${KERNEL_ROOT}/include/uapi ${OUT_HDR}
cp -r ${KERNEL_ROOT}/include/generated/uapi ${OUT_HDR}
cp -r ${ARM_HDR}/include/asm ${OUT_HDR}/uapi
cp -r ${KERNEL_ROOT}/arch/${ARM_TYPE}/include/uapi ${OUT_HDR}/uapi/asm-${ARM_TYPE}
cp -r ${KERNEL_ROOT}/arch/${ARM_TYPE}/include/generated/uapi ${OUT_HDR}/uapi/asm-${ARM_TYPE}
copy_if_exists "${KERNEL_ROOT}/include/uapi/asm-generic" \
"${KERNEL_ROOT}/arch/${ARM_TYPE}/include/generated/asm" \
"${OUT_HDR}/uapi/asm-${ARM_TYPE}/asm"
cp ${KERNEL_ROOT}/include/linux/compiler_types.h ${OUT_HDR}/uapi/linux
#!/bin/bash
#Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
# This script is used to prepare header files for musl's libc.so.
set -e
ARM_TYPE=arm
PRJ_ROOT="${PWD}/../../../../"
LINUX_HDR="${PRJ_ROOT}/prebuilts/lite/sysroot/thirdparty/linux_headers_install"
TMP_DIR_ORI="${PRJ_ROOT}/prebuilts/lite/sysroot/ohos_tmp_ori"
TMP_DIR="${PRJ_ROOT}/prebuilts/lite/sysroot/ohos_tmp"
if [ $# -eq 1 ]; then
MUSL_DIR="$1/include"
else
MUSL_DIR="${PWD}/musl/include"
fi
export Z_BUILD_TOP="${PRJ_ROOT}"
if [ ! -d "${LINUX_HDR}/uapi/asm-${ARM_TYPE}" ] || [ ! -d "${LINUX_HDR}/uapi/asm-generic" ] || [ ! -d "${LINUX_HDR}/uapi/linux" ];then
echo "please install headers first!!!"
echo "see guide at ${SYSROOT}/../../thirdparty/README"
exit 1
fi
mkdir -p ${TMP_DIR_ORI}
mkdir -p ${TMP_DIR}
cp -rf ${LINUX_HDR}/* ${TMP_DIR_ORI}
echo "#ifndef _UAPI_LINUX_COMPILER_H" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h
echo "#define _UAPI_LINUX_COMPILER_H" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h
echo "#define __user" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h
echo "#endif" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h
pushd ${PRJ_ROOT}
python prebuilts/lite/sysroot/build/update_headers.py 2>/dev/null
popd
if [ ! -d ${MUSL_DIR} ]; then
mkdir -p ${MUSL_DIR}
fi
cp -rf ${TMP_DIR}/uapi/* ${MUSL_DIR}/
rm -rf ${TMP_DIR_ORI}
rm -rf ${TMP_DIR}
include $(musldir)/config.mak
HIDE := @
optdir = ./optimized-routines
MUSL_ALL_OBJS = $(sort $(wildcard $(musldir)/obj/src/*/*.lo) $(wildcard $(musldir)/obj/src/*/$(ARCH)/*.lo) $(wildcard $(musldir)/obj/ldso/*.lo) $(wildcard $(musldir)/obj/compat/time32/*.lo))
MUSL_LIBC_OBJS = $(filter $(musldir)/obj/src/%,$(MUSL_ALL_OBJS)) $(filter $(musldir)/obj/compat/%,$(MUSL_ALL_OBJS))
REPLACED_FUNC = memchr memcpy memcpy_le strcmp strcpy strlen
REPLACED_OBJS = $(addprefix $(musldir)/obj/src/string/,$(addsuffix .lo,$(REPLACED_FUNC)))
REPLACED_OBJS += $(addprefix $(musldir)/obj/src/string/$(ARCH)/,$(addsuffix .lo,$(REPLACED_FUNC)))
MUSL_LIBC_OBJS := $(filter-out $(REPLACED_OBJS),$(MUSL_LIBC_OBJS))
MUSL_LDSO_OBJS = $(filter $(musldir)/obj/ldso/%,$(MUSL_ALL_OBJS:%.o=%.lo))
OPT_ALL_OBJS = $(sort $(wildcard $(optdir)/build/string/arm/*.o))
OPT_AOBJS = $(OPT_ALL_OBJS)
OPT_OBJS = $(filter $(optdir)/build/string/arm/%,$(OPT_ALL_OBJS:%.o=%.os))
LDFLAGS_ALL = -Wl,--sort-section,alignment -Wl,--sort-common -Wl,--gc-sections -Wl,--hash-style=both -Wl,--no-undefined -Wl,--exclude-libs=ALL -Wl,--dynamic-list=$(musldir)/dynamic.list
LDFLAGS_ALL += $(LDFLAGS)
ifeq ("$(CROSS_COMPILE)", "llvm-")
TARGET_LIBC_A = libc_opt_clang.a
TARGET_LIBC_SO = libc_opt_clang.so
else
TARGET_LIBC_A = libc_opt.a
TARGET_LIBC_SO = libc_opt.so
endif
ifeq ("$(ARCH)","")
all:
@echo "Please run linux_header_install.sh thirdparty_headers.sh build_musl(_clang).sh before running make."
@exit 1
else
ifeq ("$(ARCH)","arm")
# making a new libc.a libc.so
all: $(TARGET_LIBC_A) $(TARGET_LIBC_SO)
@echo "success!"
$(TARGET_LIBC_A):
$(HIDE) $(AR) rc $@ $(MUSL_LIBC_OBJS) $(OPT_AOBJS)
$(HIDE) $(RANLIB) $@
$(TARGET_LIBC_SO):
$(HIDE) $(CC) $(LDFLAGS_ALL) -L ${musldir}/lib/ -ldl -lpthread -nostdlib -shared -Wl,-e,_dlstart -o $@ $(MUSL_LIBC_OBJS) $(OPT_OBJS) $(MUSL_LDSO_OBJS) $(LIBCC)
clean:
ifeq ($(TARGET_LIBC_A), $(wildcard $(TARGET_LIBC_A)))
rm $(TARGET_LIBC_A)
endif
ifeq ($(TARGET_LIBC_SO), $(wildcard $(TARGET_LIBC_SO)))
rm $(TARGET_LIBC_SO)
endif
endif
endif
To build toolchains, we follow the steps.
1.linux headers install
```
./linux_header_install.sh
```
2.build musl
```
./build_musl_clang.sh
```
3.copy usr directory
```
cp -rf usr/lib usr/include ../../usr/
```
#!/bin/bash
#Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
set -e
readonly PRJ_ROOT="$PWD/../../../../../"
readonly MUSL_DIR="${PWD}/musl"
readonly MUSL_CUR_DIR="./musl"
readonly MUSL_DEBUG_DIR="${PWD}/musl_debug"
readonly MUSL_DEBUG_CUR_DIR="./musl_debug"
readonly MUSL_PATCH="${PWD}/musl-debug.patch"
readonly SYSROOT_DEBUG="${PWD}/usr_debug"
readonly MUSL_SOURCE="${PRJ_ROOT}/third_party/musl/*"
readonly OPTIMIZE_DIR="${PWD}/optimized-routines"
readonly OPTIMIZE_SOURCE="${PRJ_ROOT}/third_party/optimized-routines/*"
readonly LITEOSTOPDIR="${PRJ_ROOT}/kernel/liteos_a"
readonly SYSROOT="${PWD}/usr"
BUILD=`gcc -dumpmachine`
HOST=`gcc -dumpmachine`
TARGET=arm-liteos
CROSS_COMPILE=llvm-
CFLAGS_FOR_TARGET="--target=${TARGET} -mfloat-abi=soft -march=armv7-a -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack"
CFLAGS_FOR_TARGET1="--target=${TARGET} -mfloat-abi=soft -mcpu=cortex-a7 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack"
CFLAGS_FOR_TARGET2="--target=${TARGET} -mfloat-abi=softfp -mcpu=cortex-a7 -mfpu=neon-vfpv4 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack"
CFLAGS_FOR_TARGET3="--target=${TARGET} -mfloat-abi=hard -mcpu=cortex-a7 -mfpu=neon-vfpv4 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack"
TARGET_LIBC_A="${PWD}/libc_opt_clang.a"
TARGET_LIBC_SO="${PWD}/libc_opt_clang.so"
PARALLEL=`grep ^processor /proc/cpuinfo|wc -l`
LITEOS_COMPILER_PATH=`${LITEOSTOPDIR}/tools/build/mk/get_llvm_compiler_path.sh ${CROSS_COMPILE} ${LITEOSTOPDIR}`
LDFLAG="-L${LITEOS_COMPILER_PATH}/lib/clang/9.0.0/lib/${TARGET} -L${LITEOS_COMPILER_PATH}/lib/${TARGET}/c++ --rtlib=compiler-rt -lclang_rt.builtins -lunwind -fuse-ld=lld -Wl,--build-id=sha1"
export PATH="${LITEOS_COMPILER_PATH}/bin:${PATH}"
# prepare to build musl
if [ -d "${MUSL_DIR}" ]; then
rm -r ${MUSL_DIR}
fi
mkdir -p ${MUSL_DIR}
if [ -d "${SYSROOT}" ]; then
rm -r ${SYSROOT}
fi
mkdir -p ${SYSROOT}
cp -r ${MUSL_SOURCE} ${MUSL_DIR}
# prepare to build optimized-routines for improve musl performance
if [ -d "${OPTIMIZE_DIR}" ]; then
rm -r ${OPTIMIZE_DIR}
fi
mkdir -p ${OPTIMIZE_DIR}
cp -r ${OPTIMIZE_SOURCE} ${OPTIMIZE_DIR}
# build optimized-routines
function build_opt()
{
pushd ${OPTIMIZE_DIR}
# generate the config.mk file required for compiling the optimized-routines lib.
exec 3>&1 1>config.mk
cat << EOF
# This version of config.mk was generated by:
# build_musl.sh
# The default configuration(CFLAGS) is from optimized-routines.
# Any changes made here will be lost if build_musl.sh re-run
# Target architecture: aarch64, arm or x86_64
ARCH = arm
# Subprojects to build
SUBS = string
# Use for cross compilation with gcc/clang.
CROSS_COMPILE = ${CROSS_COMPILE}
# Compiler for the target
CC = ${LITEOS_COMPILER_PATH}/bin/clang
CFLAGS = -std=c99 -pipe -O3 --target=arm-liteos -march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=softfp -nostdinc
CFLAGS += -I/${SYSROOT}/../../../usr/include/${TARGET}
CFLAGS += -Wall -Wno-missing-braces
# Enable debug info.
#HOST_CFLAGS += -g
#CFLAGS += -g
# Use with clang.
CFLAGS += -ffp-contract=fast
LDFLAGS = -L${LITEOS_COMPILER_PATH}/lib/clang/9.0.0/lib/${TARGET}/a7_softfp_neon-vfpv4 -L${SYSROOT}/../../../usr/lib/${TARGET}/a7_softfp_neon-vfpv4 -lclang_rt.builtins -fuse-ld=lld -nostartfiles
EOF
exec 1>&3 3>&-
make -j
popd
}
# generate the final libc.so file.
function install_opt_libc()
{
if [ -e "${TARGET_LIBC_A}" ]; then
rm ${TARGET_LIBC_A}
fi
if [ -e "${TARGET_LIBC_SO}" ]; then
rm ${TARGET_LIBC_SO}
fi
# make libc_opt.a libc_opt.so by makefile
make musldir=$2 -j
# copy libc_opt.so libc_opt.a to a specified directory to replace the original libc.so libc.a file.
if [ -e "${TARGET_LIBC_A}" ] && [ -e "${TARGET_LIBC_SO}" ] ; then
rm $1/lib/libc.a $1/lib/libc.so
cp ${TARGET_LIBC_A} $1/lib/libc.a
cp ${TARGET_LIBC_SO} $1/lib/libc.so
else
printf "build libc_opt error!"
exit 1;
fi
}
function install_debug_musl()
{
mkdir -p ${SYSROOT}/include/${TARGET}/debug
mkdir -p ${SYSROOT}/lib/${TARGET}/debug
mkdir -p ${SYSROOT}/lib/${TARGET}/a7_soft/debug
mkdir -p ${SYSROOT}/lib/${TARGET}/a7_softfp_neon-vfpv4/debug
mkdir -p ${SYSROOT}/lib/${TARGET}/a7_hard_neon-vfpv4/debug
cp -f ${SYSROOT_DEBUG}/include/${TARGET}/debug.h ${SYSROOT}/include/${TARGET}/debug
cp -f ${SYSROOT_DEBUG}/lib/${TARGET}/libc.* ${SYSROOT}/lib/${TARGET}/debug
cp -f ${SYSROOT_DEBUG}/lib/${TARGET}/a7_soft/libc.* ${SYSROOT}/lib/${TARGET}/a7_soft/debug
cp -f ${SYSROOT_DEBUG}/lib/${TARGET}/a7_softfp_neon-vfpv4/libc.* ${SYSROOT}/lib/${TARGET}/a7_softfp_neon-vfpv4/debug
cp -f ${SYSROOT_DEBUG}/lib/${TARGET}/a7_hard_neon-vfpv4/libc.* ${SYSROOT}/lib/${TARGET}/a7_hard_neon-vfpv4/debug
}
# build musl
function build_musl()
{
pushd $5
if [ "$5" = "${MUSL_DEBUG_DIR}" ]; then
patch -p1 < ${MUSL_PATCH}
fi
HEADERDIR="$6/include/${TARGET}"
LIBDIR="$6/lib/${TARGET}"
BINDIR="$6/bin/${TARGET}"
SYSDIR="$6/sys/${TARGET}"
mkdir -p ${LIBDIR} ${BINDIR} ${SYSDIR} ${HEADERDIR}
CC="${LITEOS_COMPILER_PATH}/bin/clang $1" CROSS_COMPILE="${CROSS_COMPILE}" LDFLAGS="${LDFLAG}" ./configure --prefix=$6 --libdir=${LIBDIR} --bindir=${BINDIR} --syslibdir=${SYSDIR} --includedir=$HEADERDIR --build=$BUILD --host=$TARGET
make -j ${PARALLEL}
popd
build_opt
install_opt_libc "$5" "$7"
pushd $5
make install
make clean
HEADERDIR="$6/include/${TARGET}"
LIBDIR="$6/lib/${TARGET}/a7_soft"
BINDIR="$6/bin/${TARGET}/a7_soft"
SYSDIR="$6/sys/a7_soft"
mkdir -p ${LIBDIR} ${BINDIR} ${SYSDIR} ${HEADERDIR}
CC="${LITEOS_COMPILER_PATH}/bin/clang $2" CROSS_COMPILE="${CROSS_COMPILE}" LDFLAGS="${LDFLAG}" ./configure --prefix=$6 --libdir=${LIBDIR} --bindir=${BINDIR} --syslibdir=${SYSDIR} --includedir=${HEADERDIR} --build=${BUILD} --host=${TARGET}
make -j ${PARALLEL}
popd
build_opt
install_opt_libc "$5" "$7"
pushd $5
make install
make clean
HEADERDIR="$6/include/${TARGET}"
LIBDIR="$6/lib/${TARGET}/a7_softfp_neon-vfpv4"
BINDIR="$6/bin/${TARGET}/a7_softfp_neon-vfpv4"
SYSDIR="$6/sys/${TARGET}/a7_softfp_neon-vfpv4"
mkdir -p ${LIBDIR} ${BINDIR} ${SYSDIR} ${HEADERDIR}
CC="${LITEOS_COMPILER_PATH}/bin/clang $3" CROSS_COMPILE="${CROSS_COMPILE}" LDFLAGS="${LDFLAG}" ./configure --prefix=$6 --libdir=${LIBDIR} --bindir=${BINDIR} --syslibdir=${SYSDIR} --includedir=${HEADERDIR} --build=${BUILD} --host=${TARGET}
make -j ${PARALLEL}
popd
build_opt
install_opt_libc "$5" "$7"
pushd $5
make install
make clean
HEADERDIR="$6/include/${TARGET}"
LIBDIR="$6/lib/${TARGET}/a7_hard_neon-vfpv4"
BINDIR="$6/bin/${TARGET}/a7_hard_neon-vfpv4"
SYSDIR="$6/sys/${TARGET}/a7_hard_neon-vfpv4"
mkdir -p ${LIBDIR} ${BINDIR} ${SYSDIR} ${HEADERDIR}
CC="${LITEOS_COMPILER_PATH}/bin/clang $4" CROSS_COMPILE="${CROSS_COMPILE}" LDFLAGS="${LDFLAG}" ./configure --prefix=$6 --libdir=${LIBDIR} --bindir=${BINDIR} --syslibdir=${SYSDIR} --includedir=${HEADERDIR} --build=${BUILD} --host=${TARGET}
make -j ${PARALLEL}
popd
build_opt
install_opt_libc "$5" "$7"
pushd $5
make install
popd
}
# prepare linux compat headers for musl
sh thirdparty_headers.sh ${MUSL_DIR}
# build musl
build_musl "${CFLAGS_FOR_TARGET}" "${CFLAGS_FOR_TARGET1}" "${CFLAGS_FOR_TARGET2}" "${CFLAGS_FOR_TARGET3}" "${MUSL_DIR}" "${SYSROOT}" "${MUSL_CUR_DIR}"
# prepare for musl debug
CFLAGS_DEBUG_FOR_TARGET=${CFLAGS_FOR_TARGET}" -funwind-tables -rdynamic"
CFLAGS_DEBUG_FOR_TARGET1=${CFLAGS_FOR_TARGET1}" -funwind-tables -rdynamic"
CFLAGS_DEBUG_FOR_TARGET2=${CFLAGS_FOR_TARGET2}" -funwind-tables -rdynamic"
CFLAGS_DEBUG_FOR_TARGET3=${CFLAGS_FOR_TARGET3}" -funwind-tables -rdynamic"
UNWIND_H="${LITEOS_COMPILER_PATH}/lib/clang/9.0.0/include/unwind*"
if [ -d "${MUSL_DEBUG_DIR}" ]; then
rm -r ${MUSL_DEBUG_DIR}
fi
if [ -d "${SYSROOT_DEBUG}" ]; then
rm -r ${SYSROOT_DEBUG}
fi
mkdir -p ${MUSL_DEBUG_DIR}
mkdir -p ${SYSROOT_DEBUG}
cp -r ${MUSL_SOURCE} ${MUSL_DEBUG_DIR}
cp -f ${UNWIND_H} ${MUSL_DEBUG_DIR}/include
# prepare linux compat headers for musl debug
sh thirdparty_headers.sh ${MUSL_DEBUG_DIR}
# build musl debug
build_musl "${CFLAGS_DEBUG_FOR_TARGET}" "${CFLAGS_DEBUG_FOR_TARGET1}" "${CFLAGS_DEBUG_FOR_TARGET2}" "${CFLAGS_DEBUG_FOR_TARGET3}" "${MUSL_DEBUG_DIR}" "${SYSROOT_DEBUG}" "${MUSL_DEBUG_CUR_DIR}"
# generate final musl debug shared library
install_debug_musl
#!/bin/bash
#Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
# This script is used to prepare header files for musl's libc.so.
set -e
PRJ_ROOT="$PWD/../../../../../"
KERNEL_ROOT="$PRJ_ROOT/third_party/Linux_Kernel"
ARM_HDR="$PRJ_ROOT/third_party/Linux_Kernel/hdr_install/arm_header"
OUT_HDR="$PRJ_ROOT/prebuilts/lite/sysroot/thirdparty/linux_headers_install"
export Z_BUILD_TOP="$PRJ_ROOT"
if [ -d "$ARM_HDR" ];then
rm -r $ARM_HDR
fi
if [ -d "$OUT_HDR" ];then
rm -r $OUT_HDR
fi
mkdir -p $ARM_HDR
mkdir -p $OUT_HDR
pushd $KERNEL_ROOT
make headers_install ARCH=arm INSTALL_HDR_PATH=$ARM_HDR
popd
cp -r $KERNEL_ROOT/include/uapi/* $OUT_HDR
cp -r $ARM_HDR/include/asm $OUT_HDR
#!/bin/bash
#Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
LOAD_BASE="0x2000000"
LLVM_ADDR2LINE=llvm-addr2line
GCC_ADDR2LINE=addr2line
get_line()
{
SYM_ADDR=$(echo $1 | awk '{print $2}')
ELF_OFFSET=`echo ${SYM_ADDR} | cut -d '[' -f2 | cut -d ']' -f1`
FILE_LINE=`${ADDR2LINE} -f -e $2 ${ELF_OFFSET} | awk 'NR==2'`
if [[ "${FILE_LINE}" == *"?"* ]]; then
typeset ELF_OFFSET=$((ELF_OFFSET+LOAD_BASE))
ELF_OFFSET=$(echo "obase=16;${ELF_OFFSET}" | bc)
FILE_LINE=`${ADDR2LINE} -f -e $2 ${ELF_OFFSET} | awk 'NR==2'`
fi
echo ${FILE_LINE}
}
parse_line()
{
FILE_PATH=$(echo $1 | awk '{print $4}')
ELF_FILE=${FILE_PATH##*/}
ELF_FILE=${ELF_FILE//[$'\t\r\n']}
FLAG=false
for i in $2; do
if [ "${ELF_FILE}" = "$i" ]; then
if [ ! -f "$i" ]; then
echo "Error: no such file: $i"
exit 1
fi
FILE_LINE=`get_line "$1" $i`
if [[ "${FILE_LINE}" == *"?"* ]] || [ -z "${FILE_LINE}" ]; then
echo " * Error: you need ensure whether file: "$i" was compiled with -g or not! *"
exit 1
fi
LINE=`echo $1 | tr -d '\r'`
LINE=$(echo ${LINE} | awk '{print $1,$2}')
echo " "${LINE}" at "${FILE_LINE}
FLAG=true
break
fi
done
if [[ "${FLAG}" == "false" ]]; then
echo " "$1
fi
}
if [ $# -le 1 ]; then
echo "Usage: ./out2line.sh text.txt elf1 elf2 ..."
exit 1
fi
read -n5 -p "Compiler is [gcc/llvm]: " ANSWER
case ${ANSWER} in
(gcc | GCC)
which ${GCC_ADDR2LINE} >/dev/null 2>&1
if [ $? -eq 0 ]; then
ADDR2LINE=${GCC_ADDR2LINE}
else
echo "${GCC_ADDR2LINE} command not found!"
exit 1
fi;;
(llvm | LLVM)
which ${LLVM_ADDR2LINE} >/dev/null 2>&1
if [ $? -eq 0 ]; then
ADDR2LINE=${LLVM_ADDR2LINE}
else
echo "${LLVM_ADDR2LINE} command not found! Trying to use ${GCC_ADDR2LINE}!"
which ${GCC_ADDR2LINE} >/dev/null 2>&1
if [ $? -eq 0 ]; then
ADDR2LINE=${GCC_ADDR2LINE}
else
echo "${GCC_ADDR2LINE} command not found!"
exit 1
fi
fi;;
(*)
echo "Error choise!"
exit 1
esac
echo -e "Now using ${ADDR2LINE} ...\n"
PARAM_LIST="${*:2}"
cat $1 | while read line; do
HEAD_STRING=$(echo ${line} | awk '{print $1}')
if [[ "${HEAD_STRING}" == *"#"* ]]; then
parse_line "${line}" "${PARAM_LIST}"
else
if [[ "${HEAD_STRING}" == *"["* ]]; then
echo " "${line}
else
echo ${line}
fi
fi
done
此差异已折叠。
#!/bin/bash
#Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
# This script is used to prepare header files for musl's libc.so.
set -e
PRJ_ROOT="${PWD}/../../../../../"
LINUX_HDR="${PRJ_ROOT}/prebuilts/lite/sysroot/thirdparty/linux_headers_install"
TMP_DIR_ORI="${PRJ_ROOT}/prebuilts/lite/sysroot/ohos_tmp_ori"
TMP_DIR="${PRJ_ROOT}/prebuilts/lite/sysroot/ohos_tmp"
if [ $# -eq 1 ]; then
MUSL_DIR="$1/include"
else
MUSL_DIR="${PWD}/musl/include"
fi
export Z_BUILD_TOP="${PRJ_ROOT}"
if [ ! -d "${LINUX_HDR}/asm" ] || [ ! -d "${LINUX_HDR}/asm-generic" ] || [ ! -d "${LINUX_HDR}/linux" ];then
echo "please install headers first!!!"
echo "see guide at ${SYSROOT}/../../thirdparty/README"
exit 1
fi
mkdir -p ${TMP_DIR_ORI}
mkdir -p ${TMP_DIR}
mkdir -p ${TMP_DIR_ORI}/uapi/asm-generic
mkdir -p ${TMP_DIR_ORI}/uapi/asm
mkdir -p ${TMP_DIR_ORI}/uapi/linux
cp ${LINUX_HDR}/asm-generic/bitsperlong.h ${TMP_DIR_ORI}/uapi/asm-generic
cp ${LINUX_HDR}/asm-generic/int-ll64.h ${TMP_DIR_ORI}/uapi/asm-generic
cp ${LINUX_HDR}/asm-generic/posix_types.h ${TMP_DIR_ORI}/uapi/asm-generic
cp ${LINUX_HDR}/asm/bitsperlong.h ${TMP_DIR_ORI}/uapi/asm
cp ${LINUX_HDR}/asm/posix_types.h ${TMP_DIR_ORI}/uapi/asm
cp ${LINUX_HDR}/asm/types.h ${TMP_DIR_ORI}/uapi/asm
cp ${LINUX_HDR}/linux/capability.h ${TMP_DIR_ORI}/uapi/linux
cp ${LINUX_HDR}/linux/posix_types.h ${TMP_DIR_ORI}/uapi/linux
cp ${LINUX_HDR}/linux/stddef.h ${TMP_DIR_ORI}/uapi/linux
cp ${LINUX_HDR}/linux/types.h ${TMP_DIR_ORI}/uapi/linux
echo "#ifndef _UAPI_LINUX_COMPILER_H" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h
echo "#define _UAPI_LINUX_COMPILER_H" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h
echo "#define __user" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h
echo "#endif" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h
pushd ${PRJ_ROOT}
python prebuilts/lite/sysroot/build/liteos/update_headers.py 2>/dev/null
popd
cp -rf ${TMP_DIR}/uapi/* ${MUSL_DIR}/
rm -rf ${TMP_DIR_ORI}
rm -rf ${TMP_DIR}
#!/usr/bin/env python
#-*-coding:utf-8-*-
#Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
# Perform for Z kernel headers
import sys
import os
import getopt
import subprocess
import time
import string
import re
import glob
# /*..*/ //...
Rule1 = "(\/\*(\s|.)*?\*\/)|(\/\/.*)"
c1=re.compile(Rule1)
#use list for order
key_list = [
# grep key, gerp dir, sed key, sed replace
["CONFIG_64BIT", ".", "CONFIG_64BIT", "__LP64__"],
["__unused;", ".", "__unused;", "__linux_unused;"],
["__unused\[", ".", "__unused\[", "__linux_unused["],
[" private;", ".", " private;", " __linux_private;"],
["\*virtual;", ".", "\*virtual;", "\* __linux_virtual;"],
["struct msqid_ds", ".", "struct msqid_ds", "struct __kernel_legacy_msqid_ds"],
["struct semid_ds", ".", "struct semid_ds", "struct __kernel_legacy_semid_ds"],
["struct shmid_ds", ".", "struct shmid_ds", "struct __kernel_legacy_shmid_ds"],
["struct ipc_perm", ".", "struct ipc_perm", "struct __kernel_legacy_ipc_perm"],
["union semun", ".", "union semun", "union __kernel_legacy_semun"],
["_NSIG", ".", "_NSIG", "_KERNEL__NSIG"],
["_KERNEL__NSIG_", ".", "_KERNEL__NSIG_", "_NSIG_"],
["#define NSIG\s", ".", "#define NSIG", "#define _KERNEL_NSIG"],
["SIGRTMIN", ".", "SIGRTMIN", "__SIGRTMIN"],
["SIGRTMAX", ".", "SIGRTMAX", "__SIGRTMAX"],
["struct udphdr", ".", "struct udphdr", "struct __kernel_udphdr"],
["struct __kernel_sockaddr_storage", ".", "struct __kernel_sockaddr_storage", "struct sockaddr_storage"],
["off_t", "asm-mips/asm/stat.h", "off_t", "__kernel_off_t"],
["#ifndef __EXPORTED_HEADERS__", ".", "#ifndef __EXPORTED_HEADERS__", "#if 0 \/*__EXPORTED_HEADERS__*\/"],
["#ifndef __KERNEL_STRICT_NAMES", ".", "#ifndef __KERNEL_STRICT_NAMES", "#if 0 \/*__KERNEL_STRICT_NAMES*\/"],
["#ifdef __CHECKER__", ".", "#ifdef __CHECKER__", "#if 0 \/*__CHECKER__*\/"],
["#ifdef __HAVE_BUILTIN_BSWAP16__", ".", "#ifdef __HAVE_BUILTIN_BSWAP16__", "#if 1 \/*__HAVE_BUILTIN_BSWAP16__*\/"],
["#ifdef __HAVE_BUILTIN_BSWAP32__", ".", "#ifdef __HAVE_BUILTIN_BSWAP32__", "#if 1 \/*__HAVE_BUILTIN_BSWAP32__*\/"],
["#ifdef __HAVE_BUILTIN_BSWAP64__", ".", "#ifdef __HAVE_BUILTIN_BSWAP64__", "#if 1 \/*__HAVE_BUILTIN_BSWAP64__*\/"],
["#if defined(__ARMEB__)", "asm-arm", "#if defined(__ARMEB__)", "#if 0 \/*__ARMEB__*\/"],
["#ifdef __ARMEB__", "asm-arm", "#ifdef __ARMEB__", "#if 0 \/*__ARMEB__*\/"],
["defined(__ARM_EABI__)", "asm-arm", "defined(__ARM_EABI__)", "1 \/*defined(__ARM_EABI__)*\/"],
["#ifdef __MIPSEB__", "asm-mips", "#ifdef __MIPSEB__", "#if 0 \/*__MIPSEB__*\/"],
["#elif defined (__MIPSEB__)", "asm-mips", "#elif defined (__MIPSEB__)", "#elif 0 \/*__MIPSEB__*\/"],
["#if defined(__MIPSEB__)", "asm-mips", "#if defined(__MIPSEB__)", "#if 0 \/*__MIPSEB__*\/"],
["#elif defined(__MIPSEL__)", "asm-mips", "#elif defined(__MIPSEL__)", "#elif 1 \/*__MIPSEL__*\/"],
["#elif defined (__MIPSEL__)", "asm-mips", "#elif defined (__MIPSEL__)", "#elif 1 \/*__MIPSEL__*\/"],
["\!defined(__SANE_USERSPACE_TYPES__)", "asm-mips", "\!defined(__SANE_USERSPACE_TYPES__)", "0 \/*__SANE_USERSPACE_TYPES__*\/"],
["\/\*.*\*\/", ".", "\/\*.*\*\/", ""],
]
def deal_file(src):
# file exist or not
if not os.path.exists(src):
print('Error: file - %s doesn\'t exist.'% src)
return False
if os.path.islink(src):
print('Error: file - %s is a link.'% src)
return False
filetype = (os.path.splitext(src))[1]
if not filetype in ['.c','.h','.cpp','.hh','.cc']:
return False
try:
if not os.access(src, os.W_OK):
os.chmod(src, 0o664)
except:
print('Error: you can not chang %s\'s mode.'% src)
# del all comments
inputf = open(src, 'r')
outputfilename = (os.path.splitext(src))[0] + '_no_comment'+filetype
outputf = open(outputfilename, 'w')
lines=inputf.read()
inputf.close()
lines=re.sub(Rule1,"",lines)
outputf.write(lines)
outputf.close()
#del right space & blank line
os.remove(src)
inputf = open(outputfilename, 'r')
outputf = open(src, 'w')
#write head info
outputf.write("/*\n")
outputf.write(" * This header was generated from the Linux kernel headers by update_headers.py,\n")
outputf.write(" * to provide necessary information from kernel to userspace, such as constants,\n")
outputf.write(" * structures, and macros, and thus, contains no copyrightable information.\n")
outputf.write(" */\n")
line = inputf.readline()
while line:
if line == '\n':
line = line.strip("\n")
else:
line = line.rstrip() + '\n'
outputf.write(line)
line = inputf.readline()
inputf.close()
outputf.close()
os.remove(outputfilename)
return True
def deal_dir(src):
# dir exist or not
if not os.path.exists(src):
print('Error: dir - %s is not exist.'% src)
return False
filelists = os.listdir(src)
for eachfile in filelists:
eachfile = src + '/' +eachfile
if os.path.isdir(eachfile):
deal_dir(eachfile)
elif os.path.isfile(eachfile):
deal_file(eachfile)
return True
def copy_kernel_headers(build_top, original_dir, target_dir):
headers_dir = build_top + '/' + target_dir
external_dir = build_top + original_dir
headers_rm_cmd = "rm " + headers_dir + "/uapi -rf"
headers_cp_cmd = "cp " + external_dir + " " + headers_dir + " -r"
try:
status = subprocess.call(headers_rm_cmd, shell=True)
except:
printf("[Error] rm error!!!")
try:
status = subprocess.call(headers_cp_cmd, shell=True)
except:
printf("[Error] cp error!!!")
return 1
def replace_key_words_ext(keys):
replace_key_words(keys[0], keys[1], keys[2], keys[3])
return 1
def replace_key_words(original_key, target_dir, replace_key, replace_str):
replace_cmd = "grep \""+ original_key + "\" -rl " + target_dir + " | xargs sed -i \"s/" + replace_key + "/" + replace_str + "/g\""
try:
status = subprocess.call(replace_cmd, shell=True)
except:
printf("[Error] replace CONFIG_64BIT error!!!")
return 1
def usage():
print(" Usage: run the script at the root of project.\n For example:\n\
python ./foundation/ccruntime/libc/kernel/tools/update_Z_header.py")
return 0
def main():
if len(sys.argv) > 1:
usage()
return -1
kernel_dir = "prebuilts/lite/sysroot/ohos_tmp"
external_dir = '/prebuilts/lite/sysroot/ohos_tmp_ori/uapi'
status = -1
try:
build_top = os.environ["Z_BUILD_TOP"]
except KeyError as e:
print("[Warning] no env : %s, use current work dir." %(str(e)))
build_top = subprocess.check_output("pwd", shell=True)
status = copy_kernel_headers(build_top.strip(), external_dir, kernel_dir)
if status != 1:
print("[Error] copy files fail!!!")
sys.exti(1)
try:
os.chdir(kernel_dir + "/uapi")
except:
print("[Error] no uapi dir1!!!")
sys.exit(1)
current_dir = os.getcwd()
if "uapi" not in current_dir:
print("[Error] not uapi dir!!!")
sys.exit(1)
for val in key_list:
replace_key_words_ext(val)
try:
os.chdir("../")
except:
print("[Error] no uapi dir2!!!")
sys.exit(1)
deal_dir("uapi")
return 1
if __name__ == "__main__":
starttime=time.time()
main()
endtime=time.time()
print(endtime-starttime)
To build toolchains, we need some thirdparty headers.
1.linux headers
use following commands to install.
KERNEL_DIR project root directory for linux kernel.
kernel source version should be 4.4
...
cp -r $KERNEL_DIR/include/uapi/* ./linux_headers_install
...
pushd $KERNEL_DIR
make headers_install ARCH=arm INSTALL_HDR_PATH=./tmp_dir
popd
...
cp -r $KERNEL_DIR/tmp_dir/asm ./linux_headers_install
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册