nuttx/openamp/libmetal.defs
chao an ab51eae836 libmetal/atomic: enable 64-bit atomic by toolchain builtin flags
Fix compile error:
arm-none-eabi-ld: (remoteproc_virtio.o): in function `metal_io_read':
metal/io.h:252: undefined reference to `__atomic_load_8'
arm-none-eabi-ld: (remoteproc_virtio.o): in function `metal_io_write':
metal/io.h:290: undefined reference to `__atomic_store_8'

Not all 32-bit architectures support 64bit atomic, gcc/clang
toolchains have built-in properties to indicate whether support atomic64:

| $ arm-none-eabi-gcc -march=armv7e-m  -dM -E - < /dev/null | grep SYNC
| #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
| #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
| #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1

Signed-off-by: chao an <anchao@lixiang.com>
2024-06-29 22:38:48 +08:00

111 lines
3.9 KiB
Plaintext

############################################################################
# openamp/libmetal.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you 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.
#
############################################################################
ifeq ($(CONFIG_OPENAMP),y)
ifeq ($(CONFIG_ARCH), sim)
ifeq ($(CONFIG_HOST_ARM64), y)
LIBMETAL_ARCH = aarch64
else ifeq ($(CONFIG_HOST_ARM), y)
LIBMETAL_ARCH = arm
else ifeq ($(CONFIG_HOST_X86), y)
LIBMETAL_ARCH = x86
else
LIBMETAL_ARCH = x86_64
endif
else ifeq ($(CONFIG_ARCH), risc-v)
LIBMETAL_ARCH = riscv
else ifeq ($(CONFIG_ARCH), arm64)
LIBMETAL_ARCH = aarch64
else
LIBMETAL_ARCH = $(CONFIG_ARCH)
endif
CSRCS += libmetal/lib/system/nuttx/condition.c
CSRCS += libmetal/lib/system/nuttx/device.c
CSRCS += libmetal/lib/system/nuttx/init.c
CSRCS += libmetal/lib/system/nuttx/io.c
CSRCS += libmetal/lib/system/nuttx/irq.c
CSRCS += libmetal/lib/system/nuttx/shmem.c
CSRCS += libmetal/lib/system/nuttx/time.c
CSRCS += libmetal/lib/device.c
CSRCS += libmetal/lib/dma.c
CSRCS += libmetal/lib/init.c
CSRCS += libmetal/lib/io.c
CSRCS += libmetal/lib/irq.c
CSRCS += libmetal/lib/log.c
CSRCS += libmetal/lib/shmem.c
CSRCS += libmetal/lib/version.c
CFLAGS += -DMETAL_INTERNAL
LIBMETAL_HDRS_SEDEXP := \
"s/@PROJECT_VERSION_MAJOR@/0/g; \
s/@PROJECT_VERSION_MINOR@/1/g; \
s/@PROJECT_VERSION_PATCH@/0/g; \
s/@PROJECT_VERSION@/0.1.0/g; \
s/@PROJECT_SYSTEM@/nuttx/g; \
s/@PROJECT_PROCESSOR@/$(LIBMETAL_ARCH)/g; \
s/@PROJECT_MACHINE@/$(CONFIG_ARCH_CHIP)/g; \
s/@PROJECT_SYSTEM_UPPER@/nuttx/g; \
s/@PROJECT_PROCESSOR_UPPER@/$(LIBMETAL_ARCH)/g; \
s/@PROJECT_MACHINE_UPPER@/$(CONFIG_ARCH_CHIP)/g; \
s/cmakedefine HAVE_STDATOMIC_H/include <nuttx\/compiler.h>/g; \
s/defined(HAVE_STDATOMIC_H)/defined(CONFIG_HAVE_ATOMICS)/g; \
s/cmakedefine/undef/g"
ifeq ($(wildcard libmetal/.git),)
libmetal.zip:
# Download and unpack tarball if no git repo found
$(call DOWNLOAD,https://github.com/OpenAMP/libmetal/archive,v$(VERSION).zip,libmetal.zip)
$(Q) unzip -o libmetal.zip
$(Q) mv libmetal-$(VERSION) libmetal
$(Q) patch -p0 < 0001-libmetal-add-metal_list_for_each_safe-support.patch
$(Q) patch -p0 < 0002-libmetal-nuttx-io.c-align-access-when-read-write-siz.patch
$(Q) patch -p0 < 0003-libmetal-nuttx-io.c-Fix-void-pointer-arithmetic-in-a.patch
$(Q) patch -p0 < 0004-libmetal-atomic-enable-64-bit-atomic-by-toolchain-bu.patch
.libmetal_headers: libmetal.zip
else
.libmetal_headers:
endif
$(eval headers := $(wildcard libmetal/lib/compiler/gcc/*.h))
$(eval headers += $(wildcard libmetal/lib/processor/$(LIBMETAL_ARCH)/*.h))
$(eval headers += $(wildcard libmetal/lib/system/nuttx/*.h))
$(eval headers += $(wildcard libmetal/lib/*.h))
$(foreach header,$(headers), \
$(eval hobj := $(patsubst libmetal$(DELIM)lib$(DELIM)%,$(TOPDIR)$(DELIM)include$(DELIM)metal$(DELIM)%,$(header))) \
$(shell if [ ! -d $(dir $(hobj)) ];then mkdir -p $(dir $(hobj)); fi) \
$(shell sed $(LIBMETAL_HDRS_SEDEXP) $(header) > $(hobj)) \
)
touch $@
context:: .libmetal_headers
distclean::
$(call DELDIR, $(TOPDIR)$(DELIM)include$(DELIM)metal)
ifeq ($(wildcard libmetal/.git),)
$(call DELDIR, libmetal)
$(call DELFILE, libmetal.zip)
endif
$(call DELFILE, .libmetal_headers)
endif