diff --git a/build/Makefile b/build/Makefile index 35c45743..d17c4a8a 100644 --- a/build/Makefile +++ b/build/Makefile @@ -103,16 +103,15 @@ tees: setup_links libs $(drivers) $(frameworks) $(service) $(drivers): setup_links libs link_libs $(frameworks): setup_links libs link_libs $(service): setup_links libs link_libs -package: $(STAGE_DIR)/bootfs.img - rm -rf $(BUILD_TOOLS)/ramfsmkimg_host/ramfsmkimg +package: $(product_apps) cp -a $(PLAT_AUTOCONF_FILE) $(TOPDIR)/../tee_os_kernel/include/generated/. - cp -a $(PLAT_CFG_DIR)/plat_cfg.c $(TOPDIR)/../tee_os_kernel/build/tools/generate_img - cp -a $(PLAT_CFG_DIR)/plat_cfg.h $(TOPDIR)/../tee_os_kernel/build/tools/generate_img @mkdir $(FILEMGR_BOOT_ELF) - cp -a $(STAGE_DIR)/bootfs.img $(FILEMGR_BOOT_ELF)/. + @mkdir $(FILEMGR_BOOT_ELF)/check_syms_y + @mkdir $(FILEMGR_BOOT_ELF)/apps + cp -a $(check-syms-y) $(FILEMGR_BOOT_ELF)/check_syms_y + cp -a $(product_apps) $(FILEMGR_BOOT_ELF)/apps -PHONY += $(STAGE_DIR)/bootfs.img -PHONY += link_libs link_arm_libs link_aarch64_libs +PHONY += link_libs link_arm_libs link_aarch64_libs $(product_apps) link_libs: link_arm_libs link_aarch64_libs link_arm_libs: libs diff --git a/build/mk/common/operation/project.mk b/build/mk/common/operation/project.mk index 0654f9a4..63412fd9 100644 --- a/build/mk/common/operation/project.mk +++ b/build/mk/common/operation/project.mk @@ -28,17 +28,9 @@ teelib := libcrypto_hal libtimer libagent libagent_base libhmdrv libteeos libper syslib := libelf_verify libspawn_common libelf_verify_key libdynconfmgr libdynconfbuilder drvlib := libdrv_frame -libs: libtee_shared libdrv_shared ramfsmkimg_host $(syslib) +libs: libtee_shared libdrv_shared $(syslib) @echo "libsok" -libhwsecurec_host: - @echo "building libhwsecurec_host" - $(VER) $(MAKE) -C $(THIRDPARTY_LIBS)/$@ -f $(PREBUILD_HEADER)/.config -f Makefile all - -ramfsmkimg_host: libhwsecurec_host - @echo "building ramfsmkimg_host" - $(VER) $(MAKE) -C $(BUILD_TOOLS)/$@ -f $(PREBUILD_HEADER)/.config -f Makefile all - $(teelib): @echo "building teelibs=$@ target" $(if $(findstring false, $(CONFIG_SUPPORT_64BIT)), ,$(VER) $(MAKE) -C $(TEELIB)/$@ ARCH=aarch64 -f $(PREBUILD_HEADER)/.config -f Makefile all) @@ -113,6 +105,3 @@ endif GENERAL_OPTIONS := -Wdate-time -Wfloat-equal -Wshadow -fsigned-char -fno-strict-aliasing \ -pipe -fno-common uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))) - -# bootfs image -include $(BUILD_PACK)/bootfs.mk diff --git a/build/mk/pack/bootfs.mk b/build/mk/pack/bootfs.mk deleted file mode 100644 index fce1e045..00000000 --- a/build/mk/pack/bootfs.mk +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright (C) 2022 Huawei Technologies Co., Ltd. -# Licensed under the Mulan PSL v2. -# You can use this software according to the terms and conditions of the Mulan PSL v2. -# You may obtain a copy of Mulan PSL v2 at: -# http://license.coscl.org.cn/MulanPSL2 -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR -# PURPOSE. -# See the Mulan PSL v2 for more details. - -RAMFSMKIMG := $(BUILD_TOOLS)/ramfsmkimg_host/ramfsmkimg - -boot-fs-files-y += $(OUTPUTDIR)/arm/apps/teesmcmgr.elf - -# tee framework, select by tee framework config.mk -# all products should define product_apps for themselves -boot-fs-files-y += $(product_apps) - -ifneq ($(CONFIG_NOT_CHECK_SYM_A32), y) -check-syms-y += $(filter-out $(OUTPUTDIR)/arm/drivers/%.elf $(OUTPUTDIR)/aarch64/drivers/%.elf, $(product_apps)) -endif - -ifeq ($(CONFIG_TA_64BIT), true) -boot-fs-files-y += $(PREBUILD_LIBS)/aarch64/libc_shared.so -endif -ifeq ($(CONFIG_TA_32BIT), true) -boot-fs-files-y += $(PREBUILD_LIBS)/arm/libc_shared_a32.so -endif - -boot-fs := $(boot-fs-files-y) -boot-fs := $(filter-out $(PREBUILD_LIBS)/aarch64/libc_shared.so $(PREBUILD_LIBS)/arm/libc_shared_a32.so, $(boot-fs)) - -$(STAGE_DIR)/bootfs.img: $(boot-fs-files-y) FORCE - @if [ "xy" = "xy" ] ; then \ - set -e ;\ - for i in $(check-syms-y) ; do \ - echo " [ CHECK SYMS ]: $$i" ;\ - $(BUILD_TOOLS)/generate_img/check-syms.sh $$i \ - $(PREBUILD_LIBS)/arm/libc_shared_a32.so \ - $(OUTPUTDIR)/arm/obj/arm/libtee_shared/libtee_shared_a32.so \ - $(OUTPUTDIR)/arm/obj/arm/libdrv_shared/libdrv_shared_a32.so; \ - done ;\ - for i in $(check-a64-syms-y) ; do \ - echo " [ CHECK a64 SYMS ]: $$i" ;\ - $(BUILD_TOOLS)/generate_img/check-syms.sh $$i \ - $(PREBUILD_LIBS)/aarch64/libc_shared.so \ - $(OUTPUTDIR)/aarch64/obj/aarch64/libtee_shared/libtee_shared.so \ - $(OUTPUTDIR)/aarch64/obj/aarch64/libdrv_shared/libdrv_shared.so; \ - done ; fi - @test -d $(dir $@) || mkdir -p $(dir $@) - @echo " [ MAKING BOOT RAMFS ]: $@" - $(BUILD_TOOLS)/generate_img/smart-strip.sh $(boot-fs) - $(VER) $(RAMFSMKIMG) -n $(HM_BOOTFS_SIZE) $@ $(boot-fs-files-y) - -FORCE: ; diff --git a/build/mk/pack/plat_config.mk b/build/mk/pack/plat_config.mk index 52f6f90c..2b4c00fd 100644 --- a/build/mk/pack/plat_config.mk +++ b/build/mk/pack/plat_config.mk @@ -109,3 +109,9 @@ product_apps += $(OUTPUTDIR)/arm/drivers/crypto_mgr.elf check-syms-y += $(OUTPUTDIR)/arm/drivers/crypto_mgr.elf endif +product_apps += $(OUTPUTDIR)/arm/apps/teesmcmgr.elf + +ifneq ($(CONFIG_NOT_CHECK_SYM_A32), y) +check-syms-y += $(filter-out $(OUTPUTDIR)/arm/drivers/%.elf $(OUTPUTDIR)/aarch64/drivers/%.elf, $(product_apps)) +endif + diff --git a/build/tools/generate_img/check-syms.sh b/build/tools/generate_img/check-syms.sh deleted file mode 100755 index c4b5ab81..00000000 --- a/build/tools/generate_img/check-syms.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -# Usage: check-syms.sh TA.elf libc.so libtee.so -# Copyright (C) 2022 Huawei Technologies Co., Ltd. -# Licensed under the Mulan PSL v2. -# You can use this software according to the terms and conditions of the Mulan PSL v2. -# You may obtain a copy of Mulan PSL v2 at: -# http://license.coscl.org.cn/MulanPSL2 -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR -# PURPOSE. -# See the Mulan PSL v2 for more details. - -# add ignored syms to IGNORED -IGNORED=$(echo cfi_disabled; echo llvm_gcov_init; echo llvm_gcov_reset; echo llvm_gcov_dump;) -# add undefined syms to UNDEF -UNDEF=$(objdump -T "$1" | grep '\*UND\*' | egrep -o '[^ ]+$') - -# add defined syms to ALLDEF -# ALLDEF for check: -# libc_shared_a32.so libc_shared_a32.so -# libtee_shared_a32.so libtee_shared.so -# libdrv_shared_a32.so libdrv_shared.so -ALLDEF="$IGNORED\n" -DEF_NUM=1 -for i in $* ; do -if [ $DEF_NUM -gt 1 ] ; then -DEF[$DEF_NUM]=$(objdump -T "$i" | grep -v '\*UND\*' | egrep -o '[^ ]+$') -ALLDEF=${ALLDEF}"${DEF[$DEF_NUM]}\n" -fi -let DEF_NUM++ -done - -# check undefined syms -for sym in $UNDEF ; do -if ! (echo -e "$ALLDEF" | grep -qs "^$sym$") ; then -echo "$(basename $1) contains undefined symbol $sym" -exit 1 -fi -done -exit 0 diff --git a/build/tools/generate_img/smart-strip.sh b/build/tools/generate_img/smart-strip.sh deleted file mode 100755 index 64abf28b..00000000 --- a/build/tools/generate_img/smart-strip.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash -# Get the elf file, judge 32 or 64, and strip off some symbol information and debugging information to make the file smaller -# Copyright (C) 2022 Huawei Technologies Co., Ltd. -# Licensed under the Mulan PSL v2. -# You can use this software according to the terms and conditions of the Mulan PSL v2. -# You may obtain a copy of Mulan PSL v2 at: -# http://license.coscl.org.cn/MulanPSL2 -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR -# PURPOSE. -# See the Mulan PSL v2 for more details. -set -e - -strip_file() { - STRIP_OPTION="-d -x -p" - is_elf=$(file "$1" | grep ELF) - if [ "x${is_elf}" = x ]; then - # not a ELF file - return - fi - if (echo "$1" | grep '\.so$') ; then - STRIP_OPTION="-s -p" - fi - set +o errexit - is_arm=$(readelf -h "$1" 2>/dev/null | grep -E "Machine:.*(ARM|AArch64)") - is_a32=$(readelf -h "$1" 2>/dev/null | grep "Class:.*ELF32") - is_a64=$(readelf -h "$1" 2>/dev/null | grep "Class:.*ELF64") - is_obj=$(readelf -h "$1" 2>/dev/null | grep "Type:.*REL") - if [ "x${is_obj}" != x ]; then - STRIP_OPTION="-d -p" - fi - set -o errexit - if [ "x${is_arm}" != x ]; then - IS_A32=0 - IS_A64=0 - if [ "x${is_a32}" != x ]; then - IS_A32=1 - fi - if [ "x${is_a64}" != x ]; then - IS_A64=1 - fi - - ls -l "$1" - if [ "$IS_A32" = 1 ]; then - "${STRIP}" ${STRIP_OPTION} "$1" - fi - - if [ "$IS_A64" = 1 ]; then - "${STRIP}" ${STRIP_OPTION} "$1" - fi - ls -l "$1" - fi -} - -for fn in $*; do - strip_file "$fn" -done diff --git a/build/tools/ramfsmkimg_host/Makefile b/build/tools/ramfsmkimg_host/Makefile deleted file mode 100755 index 763f6c7c..00000000 --- a/build/tools/ramfsmkimg_host/Makefile +++ /dev/null @@ -1,87 +0,0 @@ -# Copyright (C) 2022 Huawei Technologies Co., Ltd. -# Licensed under the Mulan PSL v2. -# You can use this software according to the terms and conditions of the Mulan PSL v2. -# You may obtain a copy of Mulan PSL v2 at: -# http://license.coscl.org.cn/MulanPSL2 -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR -# PURPOSE. -# See the Mulan PSL v2 for more details. - -CC = cc -CPPFLAGS := -LDFLAGS := - -ifeq ($(USE_LIBC_32), y) - ARCH = arm -endif -ifeq ($(USE_LIBC_64), y) - ARCH = aarch64 -endif - -ifeq ($(TARGET_IS_ARM32),y) - ARCH = arm -endif - -include $(BUILD_CONFIG)/var.mk -CPPFLAGS += -I$(BUILD_TOOLS)/ramfsmkimg_host/include -CPPFLAGS += -I$(PREBUILD_HEADER)/host -CPPFLAGS += -I$(PREBUILD_HEADER)/ddk/hmapi -CPPFLAGS += -I$(PREBUILD_HEADER)/inner_sdk/hmapi -CPPFLAGS += -I$(TEE_SECUREC_DIR)/include -CPPFLAGS += -I$(PREBUILD_HEADER)/libc/hm -CPPFLAGS += -I$(PREBUILD_HEADER)/kernel/uapi -CPPFLAGS += -I$(PREBUILD_HEADER)/kernel/arch/arm/uapi -CPPFLAGS += -I$(PREBUILD_HEADER) -CPPFLAGS += -I$(PREBUILD_HEADER)/libc/arch/aarch64 -CPPFLAGS += -I$(PREBUILD_HEADER)/libc -CPPFLAGS += -I$(PREBUILD_HEADER)/libc/arch/generic - -CFLAGS := - -CPPFLAGS += -DDEBUG_USE_STDIO=1 -CPPFLAGS += -DHM_HOST_BUILD=1 - -CFLAGS += -Wall -Wextra -Werror -Wl,-z,relro -Wl,-z,noexecstack -Wl,-z,now -fstack-protector-all -CFLAGS += -D__IN_KERNEL__ - -ifeq ($(CONFIG_HW_SECUREC_MIN_MEM),y) -CFLAGS += -DSECUREC_WARP_OUTPUT=1 -DSECUREC_WITH_PERFORMANCE_ADDONS=0 -endif - -LDFLAGS += -L$(OUTPUTDIR)/$(ARCH)/obj/$(ARCH)/libhwsecurec_host -LDFLAGS += -L/usr/lib/x86_64-linux-gnu -LDFLAGS += -lhwsecurec_host - -C_SRCS := $(wildcard $(BUILD_TOOLS)/ramfsmkimg_host/src/*.c) -C_OBJS := $(addprefix $(BUILD_TOOLS)/ramfsmkimg_host/src/,$(notdir $(patsubst %.c,%.o,$(C_SRCS)))) - -# $(1) Relative or absolute pathname to C file -define c_to_o -$(BUILD_TOOLS)/ramfsmkimg_host/src/$(patsubst %.c,%.o,$(notdir $(1))): $(1) - $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $$@ $$^ -endef - -install_headers: - -all: stage - rm $(BUILD_TOOLS)/ramfsmkimg_host/src/main.o - rm $(BUILD_TOOLS)/ramfsmkimg_host/.done-fetch -stage: build -fetch: $(BUILD_TOOLS)/ramfsmkimg_host/.done-fetch - -$(BUILD_TOOLS)/ramfsmkimg_host/.done-fetch: - mkdir -p $(BUILD_TOOLS)/ramfsmkimg_host - touch $@ - -build: $(BUILD_TOOLS)/ramfsmkimg_host/.done-fetch $(BUILD_TOOLS)/ramfsmkimg_host/ramfsmkimg - -$(BUILD_TOOLS)/ramfsmkimg_host/ramfsmkimg: $(C_OBJS) - pwd - $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $^ $(LDFLAGS) - -$(foreach c_file,$(C_SRCS),$(eval $(call c_to_o,$(c_file)))) - -clean: - -.PHONY: fetch build diff --git a/build/tools/ramfsmkimg_host/src/main.c b/build/tools/ramfsmkimg_host/src/main.c deleted file mode 100644 index 06f72ab7..00000000 --- a/build/tools/ramfsmkimg_host/src/main.c +++ /dev/null @@ -1,423 +0,0 @@ -/* - * Copyright (C) 2022 Huawei Technologies Co., Ltd. - * Licensed under the Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR - * PURPOSE. - * See the Mulan PSL v2 for more details. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "ramfs.h" - -struct file_stat_entry { - const char *filename; - uint32_t uid; - uint32_t gid; - uint32_t mode; -} g_file_stat_entries[] = { - { "/picosh.elf", 0, 1001, 07005 }, - { "/picosh", 0, 1001, 07005 }, - { "/teesmcmgr.elf", 1, 1001, 07005 }, - { "/taloader.elf", 2, 1001, 07005 }, - { "/tarunner_a32.elf", 2, 1001, 07005 }, - { "/tarunner.elf", 2, 1001, 07005 }, - { "/gtask.elf", 3, 1000, 07005 }, - { "/ssa.elf", 8, 1001, 00040 }, - { "/keymaster.elf", 6, 1001, 00040 }, - { "/gatekeeper.elf", 7, 1001, 00040 }, - { "/storage.elf", 9, 1001, 00040 }, - { "/antiroot.elf", 10, 1001, 00040 }, - { "/secboot.elf", 11, 1001, 00040 }, - { "/sem.elf", 13, 1001, 00040 }, - { "/README", 14, 14, 00000 }, - { "/hm_qemu_test_a32", 0, 1001, 07005 }, - { "/hm_qemu_test", 0, 1001, 07005 }, - { "/kernel_debugger", 0, 1001, 07005 }, - { "/perf.elf", 15, 1001, 07005 }, - { "/perf", 15, 1001, 07005 }, - { "/vdec.elf", 16, 1001, 00040 }, - { "/secmem.elf", 17, 1001, 00040 }, - { "/hivcodec.elf", 18, 1001, 00040 }, - { "/file_encry.elf", 19, 19, 00040 }, - /* - * gtask spawn drvmgr - * drvmgr spawn tarunner - * gtask gid is 1000, tarunner and other ta gid is 1001 - * so set drvmgr gid to 1002 - * otherwise it will be failed in check_file_permission when spawn tarunner - * if the parent process gid equal with the child process gid - */ - { "/drvmgr.elf", 20, 1002, 07005 }, - { "/libc_shared.so", 0, 1001, 00040 }, - { "/libc_shared_a32.so", 0, 1001, 00040 }, - { "/libtee_shared.so", 0, 1001, 00040 }, - { "/libtee_shared_a32.so", 0, 1001, 00040 }, - { "/libc++_shared.so", 0, 1001, 00040 }, - { "/libc++_shared_a32.so", 0, 1001, 00040 }, - { "/libtest_shared.so", 0, 1001, 00040 }, - { "/libtest_shared_a32.so", 0, 1001, 00040 }, - { "/attestation_ta.elf", 24, 1001, 00040 }, - { "/se_service.elf", 26, 1001, 00040 }, - { "/huk_service.elf", 32, 1001, 00040 }, - { "/crypto_mgr.elf", 33, 1002, 07005 }, -}; - -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) -#endif - -#ifndef RAM_STATIC_ASSERT -#define RAM_STATIC_ASSERT(condition, name) extern int g_STATIC_ASSERT_##name[1 - 2 * (int)((condition) == false)] -#endif - -#define RAMFS_ERROR (-1) -#define SIZE_K 1024U -#define SIZE_M (1024 * 1024) -#define ARGC_0 0U -#define ARGC_1 1U -#define SHIFT_OFFSET 30U -#define ARGC_MAX 1024U -#define INODE_GID 1001U -#define INODE_MODE 00040U - -RAM_STATIC_ASSERT(sizeof(struct ramfs_super) == RAMFS_SUPER_SIZE, ramfs_super_size_correct); -RAM_STATIC_ASSERT(sizeof(struct ramfs_inode) == RAMFS_INODE_SIZE, ramfs_inode_size_correct); - -static void usage(const char *name) -{ - (void)fprintf(stderr, - "usage: %s -n size imgfile infile...\n" - "where:\tsize Size of the resulting image, optionally\n" - "\t\tfollowed by:\n" - "\t\tK\tSize is in kibibytes\n" - "\t\tM\tSize is mebibytes\n", - name); - exit(EXIT_FAILURE); -} - -static int ramfs_set_stat(struct ramfs_inode *inode) -{ - uint32_t i; - static uint32_t other_uid; - other_uid = (uint32_t)ARRAY_SIZE(g_file_stat_entries); - - for (i = 0; i < ARRAY_SIZE(g_file_stat_entries); i++) { - struct file_stat_entry *e = &g_file_stat_entries[i]; - if (strncmp(inode->filename, e->filename, sizeof(inode->filename)) == 0) { - inode->uid = e->uid; - inode->gid = e->gid; - inode->mode = e->mode; - return 0; - } - } - inode->uid = other_uid; - inode->gid = INODE_GID; - inode->mode = INODE_MODE; - other_uid++; - (void)perror("ramfs_set_stat: filename not found, new internal ta\n"); - return 0; -} - -static struct ramfs_metadata *ramfs_metadata_alloc_init(int32_t nr_files) -{ - int32_t metadata_size; - metadata_size = (int32_t)ramfs_calc_metadata_size((uint32_t)nr_files); - struct ramfs_metadata *metadata = NULL; - int32_t ret_s; - - metadata = calloc(metadata_size, ARGC_1); - if (metadata == NULL) { - perror("alloc super block failed\n"); - return NULL; - } - - ret_s = memcpy_s(metadata->super.magic, sizeof(metadata->super.magic), RAMFS_MAGIC, sizeof(metadata->super.magic)); - if (ret_s != EOK) { - perror("memcpy_s failed\n"); - free(metadata); - return NULL; - } - - metadata->super.version = RAMFS_VERSION; - metadata->super.nr_files = (uint32_t)nr_files; - return metadata; -} - -static void ramfs_metadata_destroy(struct ramfs_metadata *metadata) -{ - free(metadata); -} - -static int32_t set_inode_info(struct ramfs_inode *inode, const char *filename, - int32_t *bytes, struct stat *stat_buf, uint32_t offset) -{ - int32_t err; - const char *basename = NULL; - - if (inode == NULL) - return RAMFS_ERROR; - - basename = ramfs_extract_basename(filename); - if (basename == NULL || basename[0] == '\0') { - (void)printf("wrong file name: '%s'\n", filename); - return RAMFS_ERROR; - } - - *bytes = snprintf_s(inode->filename, sizeof(inode->filename), sizeof(inode->filename) - ARGC_1, "/%s", basename); - if (*bytes == -1) { - (void)printf("wrong file name: '%s'\n", filename); - return RAMFS_ERROR; - } - - err = stat(filename, stat_buf); - if (err < 0) { - perror("stat failed"); - return RAMFS_ERROR; - } - - if (stat_buf->st_size > RAMFS_MAX_FILE_SIZE) { - (void)printf("file '%s' too large\n", filename); - return RAMFS_ERROR; - } - - inode->offset = offset; - inode->size = (uint32_t)stat_buf->st_size; - - if (ramfs_set_stat(inode) < 0) { - perror("ramfs_set_stat error\n"); - return RAMFS_ERROR; - } - - return 0; -} - -/* return negative when failure */ -static long process_file(struct ramfs_metadata *metadata, FILE *img_fp, uint32_t num, uint32_t offset, - const char *filename) -{ - struct ramfs_inode *inode = NULL; - uint8_t buffer[PAGE_SIZE]; - struct stat stat_buf; - int32_t bytes; - long written; - FILE *fp = NULL; - int32_t err; - - inode = ramfs_metadata_inode(metadata, num); - err = set_inode_info(inode, filename, &bytes, &stat_buf, offset); - if (err < 0) { - perror("set inode info failed\n"); - return RAMFS_ERROR; - } - - fp = fopen(filename, "rb"); - if (fp == NULL) { - perror("open file error\n"); - return RAMFS_ERROR; - } - - written = 0; - do { - bzero(buffer, PAGE_SIZE); - bytes = (int32_t)fread(buffer, ARGC_1, PAGE_SIZE, fp); - if (bytes == 0) - break; - - bytes = (int32_t)fwrite(buffer, ARGC_1, PAGE_SIZE, img_fp); - if (bytes != PAGE_SIZE) { - perror("write file error"); - (void)fclose(fp); - return RAMFS_ERROR; - } - written += PAGE_SIZE; - } while (bytes != 0); - - (void)fclose(fp); - return written; -} - -static int32_t process_files_check_params(unsigned long size, int32_t argc) -{ - unsigned long size_max; - size_max = (ARGC_1 << SHIFT_OFFSET); - if (size > size_max) { - perror("size too large\n"); - return RAMFS_ERROR; - } - - if ((argc > (int32_t)ARGC_MAX) || (argc < (int32_t)ARGC_1)) { - perror("too many or too less files"); - return RAMFS_ERROR; - } - - return 0; -} - -static int32_t fill_files(FILE *img_fp, struct ramfs_metadata *metadata, - unsigned long size, int32_t argc, char * const argv[]) -{ - int32_t err; - uint32_t i; - uint32_t offset; - - err = fseeko(img_fp, (off_t)ramfs_metadata_size(metadata), SEEK_SET); - if (err != 0) { - perror("fseeko error\n"); - return RAMFS_ERROR; - } - - /* start filling files */ - if (size <= ramfs_metadata_size(metadata)) { - perror("size is less than size of metadata\n"); - return RAMFS_ERROR; - } - size -= ramfs_metadata_size(metadata); - - for (i = 0, offset = 0; i < (uint32_t)argc; i++) { - long filled_size = process_file(metadata, img_fp, i, offset, argv[i]); - if (filled_size < 0) { - perror("process_file failed\n"); - return RAMFS_ERROR; - } - - if (size < (unsigned long)filled_size) { - perror("size is too small\n"); - return RAMFS_ERROR; - } - - offset += (uint32_t)filled_size; - } - - err = fseeko(img_fp, 0, SEEK_SET); - if (err != 0) { - perror("fseeko error"); - return RAMFS_ERROR; - } - - if (fwrite(metadata, ramfs_metadata_size(metadata), ARGC_1, img_fp) != ARGC_1) { - perror("Write metadata failed\n"); - return RAMFS_ERROR; - } - - return 0; -} - -static void process_files(unsigned long size, const char *imgfile, int32_t argc, char * const argv[]) -{ - int32_t err; - FILE *img_fp = NULL; - struct ramfs_metadata *metadata = NULL; - - if (process_files_check_params(size, argc) != 0) - exit(EXIT_FAILURE); - - metadata = ramfs_metadata_alloc_init(argc); - if (metadata == NULL) { - perror("ramfs metadata alloc failed\n"); - exit(EXIT_FAILURE); - } - - img_fp = fopen(imgfile, "w"); - if (img_fp == NULL) { - perror(imgfile); - ramfs_metadata_destroy(metadata); - exit(EXIT_FAILURE); - } - - err = fill_files(img_fp, metadata, size, argc, argv); - if (err != 0) { - (void)fclose(img_fp); - ramfs_metadata_destroy(metadata); - exit(EXIT_FAILURE); - } - - (void)fclose(img_fp); - ramfs_metadata_destroy(metadata); -} - -static void handle_opt(int32_t argc, char *argv[], unsigned long *size) -{ - int32_t opt; - char *endptr = NULL; - char modifier; - opt = getopt(argc, argv, "n:f:"); - while (opt != RAMFS_ERROR) { - switch (opt) { - case 'n': - if (*optarg == '\0') { - (void)fprintf(stderr, "Zero-length size not allowed\n"); - usage(argv[0]); - } - - *size = strtoul(optarg, &endptr, 0); - modifier = *endptr; - if (modifier == '\0') - break; - unsigned long msize = 0; - if (modifier == 'K') - msize = SIZE_K; - if (modifier == 'M') - msize = SIZE_M; - if (msize != 0 && *size > UINT64_MAX / msize) { - (void)fprintf(stderr, "size is too large\n"); - usage(argv[0]); - } - if (msize != 0) - *size *= msize; - endptr++; - if (*endptr != '\0') - usage(argv[0]); - break; - - case 'f': - if (*optarg == '\0') { - (void)fprintf(stderr, "Not a correct file name\n"); - usage(argv[0]); - } - (void)printf("doesn't support .ini file\n"); - break; - - default: - usage(argv[0]); - break; - } - opt = getopt(argc, argv, "n:f:"); - } -} - -int32_t main(int32_t argc, char *argv[]) -{ - unsigned long size; - int32_t n_args; - size = 0; - - handle_opt(argc, argv, &size); - - n_args = argc - optind; - - switch (n_args) { - case ARGC_0: - case ARGC_1: - usage(argv[0]); - break; - default: - if (size == 0) { - usage(argv[0]); - break; - } - process_files(size, argv[optind], n_args - (int32_t)ARGC_1, &argv[optind + ARGC_1]); - break; - } - return 0; -} diff --git a/config/platform/oh/oh/oh_32/plat_cfg/plat_cfg.c b/config/platform/oh/oh/oh_32/plat_cfg/plat_cfg.c deleted file mode 100644 index 2e1306cb..00000000 --- a/config/platform/oh/oh/oh_32/plat_cfg/plat_cfg.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2022 Huawei Technologies Co., Ltd. - * Licensed under the Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR - * PURPOSE. - * See the Mulan PSL v2 for more details. - */ - -#include "plat_cfg.h" -#include "plat_cfg_public.h" -#include -#include "uart_register.h" - -struct platform_info g_plat_cfg = { - /* - * To config, set TRUSTEDCORE_PHY_TEXT_BASE in common/var.mk - * value is assigned in boot_kernel_on_current_cpu function - */ - .phys_region_start = 0, - .uart_addr = UART_ADDR, - .uart_type = UART_ENABLE_FLAG | PL011_TYPE, - .shmem_offset = SHMEM_OFFSET, - .shmem_size = SHMEM_SIZE, - /* 6 MB */ - .phys_region_size = TEEOS_MEM_SIZE, - - .gic_config = { - .version = GIC_V2_VERSION, - .v2 = { - .dist = { GIC_V2_DIST_BASE, GIC_V2_DIST_BASE + PAGE_SIZE }, - .contr = { GIC_V2_CPU_BASE, GIC_V2_CPU_BASE + PAGE_SIZE }, - } - }, - - .spi_num_for_notify = HI3516_SPI_NUM, - - .plat_features = PLAT_DEF_ENG, - - /* at most PLAT_MAX_DEVIO_REGIONS (128) regions */ - .extend_datas_io = { - .extend_magic = 0, - .extend_length = 0, - .extend_paras = {0}, - .plat_io_regions = { - /* .start, .end */ - /* the first region should be UART6 */ - { CPU_CTLR_ADDR, CPU_CTLR_ADDR + CPU_CTLR_SIZE }, - /* this is terminator */ - { 0, 0 } - } - } -}; diff --git a/config/platform/oh/oh/oh_32/plat_cfg/plat_cfg.h b/config/platform/oh/oh/oh_32/plat_cfg/plat_cfg.h deleted file mode 100644 index 0c50aaff..00000000 --- a/config/platform/oh/oh/oh_32/plat_cfg/plat_cfg.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2022 Huawei Technologies Co., Ltd. - * Licensed under the Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR - * PURPOSE. - * See the Mulan PSL v2 for more details. - */ -#ifndef PLAT_CFG_H -#define PLAT_CFG_H - -#define TEEOS_MEM_SIZE 0x1000000 -#define UART_ADDR 0x120a0000 -#define TIMER1_BASE 0x12000000 -#define TIMER1_BASE_SIZE 0x1000 -#define CPU_CTLR_ADDR 0x12010000 -#define CPU_CTLR_SIZE 0x1000 -#define SEC_TRNG0_BASE 0x10090000 -#define SEC_TRNG0_SIZE 0x1000 -#define SEC_CLK_BASE 0x12010000 -#define SEC_CLK_SIZE 0x1000 -#define SEC_KLAD_BASE 0x10070000 -#define SEC_KLAD_SIZE 0x1000 -#define SEC_OTP_BASE 0x100B0000 -#define SEC_OTP_SIZE 0x1000 -#define OFFSET_PADDR_TO_VADDR 0 -#define HI3516_SPI_NUM 105 -#define GIC_V2_DIST_BASE 0x10301000 -#define GIC_V2_CPU_BASE 0x10302000 -#define SHMEM_SIZE 0x1000 -#define SHMEM_OFFSET (TEEOS_MEM_SIZE - SHMEM_SIZE) -#endif diff --git a/config/platform/oh/oh/oh_64/plat_cfg/plat_cfg.c b/config/platform/oh/oh/oh_64/plat_cfg/plat_cfg.c deleted file mode 100644 index f8f74639..00000000 --- a/config/platform/oh/oh/oh_64/plat_cfg/plat_cfg.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2022 Huawei Technologies Co., Ltd. - * Licensed under the Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR - * PURPOSE. - * See the Mulan PSL v2 for more details. - */ -#include "plat_cfg.h" -#include "plat_cfg_public.h" -#include -#include "uart_register.h" - -#ifndef __aarch64__ -#error "Only aarch64 is supported!" -#endif - -struct platform_info g_plat_cfg = { - - /* - * To config, set TRUSTEDCORE_PHY_TEXT_BASE in common/var.mk - * value is assigned in boot_kernel_on_current_cpu function - */ - .phys_region_start = 0, - .phys_region_size = TEEOS_MEM_SIZE, - .uart_addr = UART_ADDR, - .uart_type = PL011_TYPE | UART_ENABLE_FLAG, - .shmem_offset = SHMEM_OFFSET, - .shmem_size = SHMEM_SIZE, - .protected_regions = {{ BL31_PADDR_START, BL31_PADDR_END }}, - - .plat_features = -#ifdef CONFIG_ARM64_PAN - PLAT_DEF_ENG | PLAT_ENABLE_PAN, -#else - PLAT_DEF_ENG, -#endif - - .gic_config = { - .version = GIC_V3_VERSION, - .v3 = { - .dist = { GIC_V3_DIST_PADDR, GIC_V3_DIST_PADDR + GIC_DIST_PAGENUM * PAGE_SIZE }, - .redist_num = GIC_REDIST_NUM, - .redist_stride = GIC_REDIST_MEMSIZE, - .redist = { - { GIC_V3_REDIST_PADDR, GIC_V3_REDIST_PADDR + GIC_REDIST_PAGENUM * PAGE_SIZE } - } - } - }, - - .spi_num_for_notify = SPI_NUM, - /* at most PLAT_MAX_DEVIO_REGIONS (128) regions */ - .extend_datas_io = { - .extend_magic = 0, - .extend_length = 0, - .extend_paras = {0}, - .plat_io_regions = { - { OS_TIMER0_REG, OS_TIMER0_REG + OS_TIMER0_REG_SIZE }, - { OS_TIMER1_REG, OS_TIMER1_REG + OS_TIMER1_REG_SIZE }, - { UART_ADDR, UART_ADDR + UART_ADDR_SIZE }, - { 0, 0 } /* this is terminator */ - } - } -}; \ No newline at end of file diff --git a/config/platform/oh/oh/oh_64/plat_cfg/plat_cfg.h b/config/platform/oh/oh/oh_64/plat_cfg/plat_cfg.h deleted file mode 100644 index b176c663..00000000 --- a/config/platform/oh/oh/oh_64/plat_cfg/plat_cfg.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2022 Huawei Technologies Co., Ltd. - * Licensed under the Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR - * PURPOSE. - * See the Mulan PSL v2 for more details. - */ -#ifndef PLAT_CFG_H -#define PLAT_CFG_H - -/* gic */ -#define GIC_V3_DIST_PADDR 0x08000000 -#define GIC_V3_REDIST_PADDR 0x080A0000 -#define GIC_DIST_PAGENUM 16 -#define GIC_REDIST_PAGENUM 256 -#define GIC_REDIST_NUM 1 -#define GIC_REDIST_MEMSIZE 0x20000 -#define SPI_NUM 111 - -#define TEEOS_MEM_SIZE 0x8000000 -#define SHMEM_OFFSET 0x5FF000 -#define SHMEM_SIZE 0x1000 - -/* uart addr */ -#define UART_ADDR 0x09040000 -#define UART_ADDR_SIZE 0x1000 - -/* timer reg */ -#define OS_TIMER0_REG 0x20001000 -#define OS_TIMER0_REG_SIZE 0x1000 -#define OS_TIMER1_REG 0x20002000 -#define OS_TIMER1_REG_SIZE 0x1000 -#define OFFSET_PADDR_TO_VADDR 0 - -/* protect region */ -#define BL31_PADDR_START 0xe040000 -#define BL31_PADDR_END 0xe060000 -#endif \ No newline at end of file diff --git a/lib/teelib/libteeos/include/tee/tee_uuid.h b/lib/teelib/libteeos/include/tee/tee_uuid.h new file mode 100644 index 00000000..3cdff525 --- /dev/null +++ b/lib/teelib/libteeos/include/tee/tee_uuid.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2023 Huawei Technologies Co., Ltd. + * Licensed under the Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR + * PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +#ifndef TEE_UUID_H +#define TEE_UUID_H + +#include + +#define NODE_LEN 8 +typedef struct tee_uuid { + uint32_t timeLow; + uint16_t timeMid; + uint16_t timeHiAndVersion; + uint8_t clockSeqAndNode[NODE_LEN]; +} TEE_UUID; + +#endif