diff --git a/README_zh.md b/README_zh.md index 15e249dfada35465de70018dc3482353db18bea2..0ddd6d430fd08c44c28fd6fb00c9e8c0a413d0f1 100644 --- a/README_zh.md +++ b/README_zh.md @@ -1,101 +1,107 @@ # Patch组件 - [简介](#section11660541593) -- [特定芯片架构驱动补丁(比如Hi3516DV300)](#section1521510717399) - [目录](#section21571344112) -- [使用](#section1393789267) - - [使用说明](#section1352114469620) - -- [以hi3516dv300开源开发板+ubuntu x86主机开发环境为例](#section19369206113115) - - [场景1:版本级编译原生方式](#section1025111193220) - - [场景2:单独编译修改后的内核](#section17446652173211) - +- [使用说明](#section1393789267) +- [构建说明](#section19369206113115) - [相关仓](#section27639463106) ## 简介 -OpenHarmony的Linux内核基于开源Linux内核LTS 4.19.y分支演进,为满足不同的内核场景诉求,针对性地合入CVE补丁 + OpenHarmony特性 + vendor厂商具体的板级芯片驱动补丁从而构成完整的内核基线。 - -Linux社区LTS 4.19.y分支信息请查看[kernel官网](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/log/?h=linux-4.19.y)。 - -内核的Patch组成模块,在编译构建流程中,针对具体芯片平台,合入对应的架构驱动代码,进行编译对应的内核镜像。所有补丁来源均遵守GPL-2.0协议。 +OpenHarmony的Linux内核基于开源Linux内核LTS **4.19.y / 5.10.y** 分支演进,在此基线基础上,回合CVE补丁及OpenHarmony特性,作为OpenHarmony Common Kernel基线。针对不同的芯片,各厂商合入对应的板级驱动补丁,完成对OpenHarmony的基线适配。 -## 特定芯片架构驱动补丁(比如Hi3516DV300) +Linux社区LTS 4.19.y分支信息请查看[kernel官网](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/log/?h=linux-4.19.y); -vendor厂商提供的特定芯片架构驱动代码: +Linux社区LTS 5.10.y分支信息请查看[kernel官网](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/log/?h=linux-5.10.y)。 -hi3516dv300_small.patch: 在Hi3516DV300芯片上支持arm架构的内核启动(DTS等)及对应的drm/mmc等驱动的支持。 +内核的Patch组成模块,在编译构建流程中,针对具体芯片平台,合入对应的架构驱动代码,进行编译对应的内核镜像。所有补丁来源均遵守GPL-2.0协议。 ## 目录 ``` -├── kernel.mk # 支持Hi3516DV300等平台内核编译Makefile -├── kernel_module_build.sh # 支持Hi3516DV300等平台内核及KO模块编译脚本 -├── linux-4.19/hi3516dv300_small_patch # 4.19内核上Hi3516dv300开发板的补丁 - ├── hi3516dv300_small.patch # 厂商Hisilicon对应的开源开发板Hi3516dv300相关的芯片patch - ├── hdf.patch # Hi3516dv300开发板上支持HDF特性的patch +kernel/linux +├── build +│ ├── BUILD.gn # 编译框架GN文件 +│ ├── kernel.mk # 内核编译文件 +│ └── ohos.build # 内核编译组件文件 +├── patches +│ ├── linux-4.19 # linux-4.19 相关patch +│ │   └── hi3516dv300_patch +│ │   ├── hi3516dv300.patch # linux-4.19 hi3516dv300 SOC patch +│ │   └── hdf.patch # linux-4.19 hi3516dv300 hdf patch +│ └── linux-5.10 +│    └── hi3516dv300_patch +│    ├── hi3516dv300.patch # linux-5.10 hi3516dv300 SOC patch +│    └── hdf.patch # linux-5.10 hi3516dv300 hdf patch +└── config + ├── linux-4.19 + │   └── arch + │   └── arm + │   └── configs + │   ├── hi3516dv300_small_defconfig # 厂商Hisilicon对应的开源开发板Hi3516dv300小型系统的defconfig + │   ├── hi3516dv300_standard_defconfig # 厂商Hisilicon对应的开源开发板Hi3516dv300标准系统的defconfig + │   ├── small_common_defconfig # 小型系统的内核的common defconfig + │   └── standard_common_defconfig # 标准系统的内核的common defconfig + └── linux-5.10 + └── arch + └── arm + └── configs +    ├── hi3516dv300_small_defconfig # 厂商Hisilicon对应的开源开发板Hi3516dv300小型系统的defconfig +    ├── hi3516dv300_standard_defconfig # 厂商Hisilicon对应的开源开发板Hi3516dv300标准系统的defconfig +    ├── small_common_defconfig # 小型系统的内核的common defconfig +    └── standard_common_defconfig # 标准系统的内核的common defconfig ``` -## 使用 +## 使用说明 -### 使用说明 +1. 合入HDF补丁 -如需使用上述patch,需要在内核代码完成对应芯片平台驱动补丁进行合入。 + 在kernel/linux/build仓中,按照kernel.mk中HDF的补丁合入方法,合入不同内核版本对应的HDF内核补丁: + + ``` + $(OHOS_BUILD_HOME)/drivers/adapter/khdf/linux/patch_hdf.sh $(OHOS_BUILD_HOME) $(KERNEL_SRC_TMP_PATH) $(HDF_PATCH_FILE) + ``` -1. 合入芯片平台驱动补丁(参考kernel.mk) +2. 合入芯片平台驱动补丁 - 针对不同芯片平台合入对应的patch,以上述Hi3516DV300为例: + 以Hi3516DV300为例: + + 在kernel/linux/build仓中,按照kernel.mk中的芯片组件所对应的patch路径规则及命名规则,将对应的芯片组件patch放到对应路径下: + + ``` + DEVICE_PATCH_DIR := $(OHOS_BUILD_HOME)/kernel/linux/patches/${KERNEL_VERSION}/$(DEVICE_NAME)_patch + DEVICE_PATCH_FILE := $(DEVICE_PATCH_DIR)/$(DEVICE_NAME).patch + ``` - ``` - patch -p1 < hdf.patch && patch -p1 < hi3516dv300_small.patch - ``` +3. 修改自己所需要编译的config - >![](public_sys-resources/icon-notice.gif) **须知:** - >* 由于OpenHarmony工程的编译构建流程中会拷贝kernel/linux-4.19的代码环境后进行打补丁动作,在使用如下场景1的OpenHarmony的版本级编译命令前,需要kernel/linux-4.19保持原代码环境。 - >* 对应拷贝后的目录位于: out/KERNEL_OBJ/kernel/src_tmp/linux-4.19,需要在该目录下进行如下场景2的单独编译等开发操作。 + 在kernel/linux/build仓中,按照kernel.mk中的芯片组件所对应的patch路径规则及命名规则,将对应的芯片组件config放到对应路径下: + + ``` + KERNEL_CONFIG_PATH := $(OHOS_BUILD_HOME)/kernel/linux/config/${KERNEL_VERSION} + DEFCONFIG_FILE := $(DEVICE_NAME)_$(BUILD_TYPE)_defconfig + ``` + + > **须知:** + > + >由于OpenHarmony工程的编译构建流程中会拷贝kernel/linux/linux-\*\.\*的代码环境后进行打补丁动作,在使用OpenHarmony的版本级编译命令前,需要kernel/linux/linux-\*\.\*原代码环境。 + > + >根据不同系统工程,编译完成后会在out目录下的kernel目录中生成对应实际编译的内核,基于此目录的内核,进行对应的config修改,将最后生成的\.config文件cp到config仓对应的路径文件里,即可生效。 -## 以hi3516dv300开源开发板+ubuntu x86主机开发环境为例 +## 构建说明 -### 场景1:版本级编译原生方式 +以hi3516dv300开源开发板+ubuntu x86主机开发环境为例 使用工程的全量编译命令,编译生成uImage内核镜像 ``` -./build.sh --product-name Hi3516DV300 # 编译hi3516dv300的uImage内核镜像 +./build.sh --product-name Hi3516DV300 # 编译hi3516dv300镜像 + --build-target build_kernel # 编译hi3516dv300的uImage内核镜像 + --gn-args linux_kernel_version=\"linux-5.10\" # 编译指定内核版本 ``` -### 场景2:单独编译修改后的内核 - -1. 准备工作 - - 准备编译环境,可以使用开源arm clang/gcc编译器,或者使用工程自带编译器。 - - 进入工程主目录配置环境变量: - - ``` - export TARGET_PRODUCT=Hi3516DV300 # HDF驱动需要 - export PATH=`pwd`/prebuilts/clang/ohos/linux-x86_64/llvm/bin:`pwd`/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi/bin/:$PATH # 配置编译环境 - MAKE_OPTIONES="ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- CC=clang HOSTCC=clang" # 使用工程项目自带的clang环境 - ``` - -2. 直接进入整编过的内核目录out/KERNEL_OBJ/kernel/src_tmp/linux-4.19下修改内核代码或config (OpenHarmony提供对应平台的defconfig供参考)。 -3. 生成内核.config。 - - ``` - make ${MAKE_OPTIONES} hi3516dv300_standard_defconfig # 使用自带的默认config 构建内核 - ``` - -4. 编译生成对应的内核Image。 - - ``` - make ${MAKE_OPTIONES} -j32 uImage # 编译uImage内核镜像 - ``` - - ## 相关仓 kernel\_linux\_patches -device\_hisilicon\_hi3516dv300 - diff --git a/linux-4.19/prebuilts/linux_header_install.sh b/linux-4.19/prebuilts/linux_header_install.sh deleted file mode 100755 index bcbb701e71bd2d935efa57501f910a352776973c..0000000000000000000000000000000000000000 --- a/linux-4.19/prebuilts/linux_header_install.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/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/kernel/linux/patches/linux-4.19/prebuilts/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} -cp -r ${KERNEL_ROOT}/drivers/staging/android/uapi/* ${OUT_HDR}/uapi/linux -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 diff --git a/linux-4.19/prebuilts/thirdparty_headers.sh b/linux-4.19/prebuilts/thirdparty_headers.sh deleted file mode 100755 index 1a0a7810d8236c5302fdd944767675a9f91de861..0000000000000000000000000000000000000000 --- a/linux-4.19/prebuilts/thirdparty_headers.sh +++ /dev/null @@ -1,49 +0,0 @@ -#/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}/kernel/linux/patches/linux-4.19/prebuilts/linux_headers_install" -TMP_DIR_ORI="${PRJ_ROOT}/kernel/linux/patches/linux-4.19/prebuilts/ohos_tmp_ori" -TMP_DIR="${PRJ_ROOT}/kernel/linux/patches/linux-4.19/prebuilts/ohos_tmp" -MUSL_DIR="${PWD}/usr/include" -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!!!" - 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 kernel/linux/patches/linux-4.19/prebuilts/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} diff --git a/linux-4.19/prebuilts/update_headers.py b/linux-4.19/prebuilts/update_headers.py deleted file mode 100755 index 18f162172bbf4e765bbaa838fc526a203eb544c5..0000000000000000000000000000000000000000 --- a/linux-4.19/prebuilts/update_headers.py +++ /dev/null @@ -1,229 +0,0 @@ -#!/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 = "kernel/linux/patches/linux-4.19/prebuilts/ohos_tmp" - external_dir = '/kernel/linux/patches/linux-4.19/prebuilts/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) - diff --git a/linux-5.10/prebuilts/linux_header_install.sh b/linux-5.10/prebuilts/linux_header_install.sh deleted file mode 100755 index 6ddbabb164a184eec94ada0904e6afa9d46be984..0000000000000000000000000000000000000000 --- a/linux-5.10/prebuilts/linux_header_install.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/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/linux-5.10" -ARM_HDR="$KERNEL_ROOT/hdr_install/${ARM_TYPE}_header" -OUT_HDR="$PRJ_ROOT/kernel/linux/patches/linux-5.10/prebuilts/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} -cp -r ${KERNEL_ROOT}/drivers/staging/android/uapi/* ${OUT_HDR}/uapi/linux -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 diff --git a/linux-5.10/prebuilts/thirdparty_headers.sh b/linux-5.10/prebuilts/thirdparty_headers.sh deleted file mode 100755 index efd9846061dd13c7048c47ca8f336508edb1026f..0000000000000000000000000000000000000000 --- a/linux-5.10/prebuilts/thirdparty_headers.sh +++ /dev/null @@ -1,49 +0,0 @@ -#/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}/kernel/linux/patches/linux-5.10/prebuilts/linux_headers_install" -TMP_DIR_ORI="${PRJ_ROOT}/kernel/linux/patches/linux-5.10/prebuilts/ohos_tmp_ori" -TMP_DIR="${PRJ_ROOT}/kernel/linux/patches/linux-5.10/prebuilts/ohos_tmp" -MUSL_DIR="${PWD}/usr/include" -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!!!" - 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 kernel/linux/patches/linux-5.10/prebuilts/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} diff --git a/linux-5.10/prebuilts/update_headers.py b/linux-5.10/prebuilts/update_headers.py deleted file mode 100755 index 3fc0145e3e8bcf6314b0cf1eca6cd5333d2f4f79..0000000000000000000000000000000000000000 --- a/linux-5.10/prebuilts/update_headers.py +++ /dev/null @@ -1,229 +0,0 @@ -#!/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 = "kernel/linux/patches/linux-5.10/prebuilts/ohos_tmp" - external_dir = '/kernel/linux/patches/linux-5.10/prebuilts/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) -