Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OpenAMP building with newlib #14203

Merged
merged 2 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
/dts/bindings/*/nxp* @MaureenHelm
/ext/fs/ @nashif @ramakrishnapallala
/ext/hal/cmsis/ @MaureenHelm @galak
/ext/hal/libmetal/ @galak
/ext/hal/nordic/ @carlescufi @anangl
/ext/hal/nxp/ @MaureenHelm
/ext/hal/qmsi/ @nashif
Expand Down
17 changes: 14 additions & 3 deletions ext/hal/libmetal/libmetal/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ env:
- ZEPHYR_TOOLCHAIN_VARIANT=zephyr
- ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk
- ZEPHYR_BASE=$TRAVIS_BUILD_DIR/deps/zephyr
- ZEPHYR_SDK_VERSION=0.9.3
- ZEPHYR_SDK_VERSION=0.9.5
- ZEPHYR_SDK_DOWNLOAD_FOLDER=https://github.com/zephyrproject-rtos/meta-zephyr-sdk/releases/download/$ZEPHYR_SDK_VERSION
- ZEPHYR_SDK_SETUP_BINARY=zephyr-sdk-$ZEPHYR_SDK_VERSION-setup.run
- ZEPHYR_SDK_DOWNLOAD_URL=$ZEPHYR_SDK_DOWNLOAD_FOLDER/$ZEPHYR_SDK_SETUP_BINARY
- FREERTOS_ZIP_URL=https://cfhcable.dl.sourceforge.net/project/freertos/FreeRTOS/V10.0.1/FreeRTOSv10.0.1.zip
- GCC_ARM_COMPILER_PACKAGE=gcc-arm-embedded_7-2018q2-1~trusty1_amd64.deb
- CC=gcc-4.9
- CXX=g++-4.9

matrix:
fast_finish: true
Expand All @@ -34,17 +36,26 @@ cache:
directories:
- $ZEPHYR_SDK_INSTALL_DIR
- /usr/local/bin
- $HOME/bin/cmake

before_install:
- if [ ! -f $HOME/bin/cmake/cmake-3.13.1-Linux-x86_64/bin/cmake ]; then
mkdir -p $HOME/bin/cmake && cd $HOME/bin/cmake &&
wget https://github.com/Kitware/CMake/releases/download/v3.13.1/cmake-3.13.1-Linux-x86_64.sh &&
yes | sh cmake-3.13.1-Linux-x86_64.sh | cat &&
cd -;
fi &&
export PATH=$HOME/bin/cmake/cmake-3.13.1-Linux-x86_64/bin:$PATH
- if [[ "$TARGET" == "zephyr" ]]; then
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test &&
sudo apt-get update -qq &&
sudo apt-get install libc6-dev-i386 make gperf gcc g++ python3-ply python3-yaml python3-pip device-tree-compiler ncurses-dev uglifyjs -qq &&
sudo pip3 install pyelftools;
fi
- if [[ "$TARGET" == "linux" ]]; then
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test &&
sudo apt-get update -qq &&
sudo apt-get install libsysfs-dev libhugetlbfs-dev make gcc;
sudo apt-get install libsysfs-dev libhugetlbfs-dev make gcc-4.9;
fi
# This is to kick start CI on generic platform. Will need to have a proper way to get the required packages
- if [[ "$TARGET" == "generic" || "$TARGET" == "freertos" ]]; then
Expand Down Expand Up @@ -77,7 +88,7 @@ script:
- if [[ "$TARGET" == "zephyr" ]]; then
mkdir -p ../libmetal/build-zephyr &&
cd ../libmetal/build-zephyr &&
cmake .. -DWITH_ZEPHYR=on -DBOARD=qemu_cortex_m3 -DWITH_TESTS=on &&
cmake .. -DWITH_ZEPHYR=on -DBOARD=qemu_cortex_m3 &&
make VERBOSE=1;
fi
- if [[ "$TARGET" == "linux" ]]; then
Expand Down
6 changes: 5 additions & 1 deletion ext/hal/libmetal/libmetal/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ collect (PROJECT_LIB_HEADERS device.h)
collect (PROJECT_LIB_HEADERS dma.h)
collect (PROJECT_LIB_HEADERS io.h)
collect (PROJECT_LIB_HEADERS irq.h)
collect (PROJECT_LIB_HEADERS irq_controller.h)
collect (PROJECT_LIB_HEADERS list.h)
collect (PROJECT_LIB_HEADERS log.h)
collect (PROJECT_LIB_HEADERS mutex.h)
collect (PROJECT_LIB_HEADERS shmem.h)
collect (PROJECT_LIB_HEADERS sleep.h)
collect (PROJECT_LIB_HEADERS softirq.h)
collect (PROJECT_LIB_HEADERS spinlock.h)
collect (PROJECT_LIB_HEADERS sys.h)
collect (PROJECT_LIB_HEADERS time.h)
Expand All @@ -31,8 +33,10 @@ collect (PROJECT_LIB_SOURCES dma.c)
collect (PROJECT_LIB_SOURCES device.c)
collect (PROJECT_LIB_SOURCES init.c)
collect (PROJECT_LIB_SOURCES io.c)
collect (PROJECT_LIB_SOURCES irq.c)
collect (PROJECT_LIB_SOURCES log.c)
collect (PROJECT_LIB_SOURCES shmem.c)
collect (PROJECT_LIB_SOURCES softirq.c)
collect (PROJECT_LIB_SOURCES version.c)

add_subdirectory (compiler)
Expand Down Expand Up @@ -62,7 +66,7 @@ endif (WITH_DEFAULT_LOGGER)

if (WITH_ZEPHYR)
zephyr_library_named(metal)
add_dependencies(metal ${OFFSETS_H_TARGET})
add_dependencies(metal offsets_h)
zephyr_library_sources(${_sources})
zephyr_include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
else (WITH_ZEPHYR)
Expand Down
3 changes: 3 additions & 0 deletions ext/hal/libmetal/libmetal/lib/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

#if defined(HAVE_STDATOMIC_H) && !defined(__STDC_NO_ATOMICS__) && \
!defined(__cplusplus)
# include <stdint.h>
# include <stdatomic.h>
#elif defined(__cplusplus)
# include <atomic>
#elif defined(__GNUC__)
# include <metal/compiler/gcc/atomic.h>
#else
Expand Down
3 changes: 3 additions & 0 deletions ext/hal/libmetal/libmetal/lib/compiler/gcc/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ extern "C" {
#define metal_align(n) __attribute__((aligned(n)))
#define metal_weak __attribute__((weak))

#define METAL_PACKED_BEGIN
#define METAL_PACKED_END __attribute__((__packed__))

#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions ext/hal/libmetal/libmetal/lib/compiler/iar/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ extern "C" {
#define metal_align(n) __attribute__((aligned(n)))
#define metal_weak __attribute__((weak))

#define METAL_PACKED_BEGIN __packed
#define METAL_PACKED_END

#ifdef __cplusplus
}
#endif
Expand Down
12 changes: 7 additions & 5 deletions ext/hal/libmetal/libmetal/lib/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ void metal_io_init(struct metal_io_region *io, void *virt,
unsigned page_shift, unsigned int mem_flags,
const struct metal_io_ops *ops)
{
const struct metal_io_ops nops = {NULL, NULL, NULL, NULL, NULL, NULL};
const struct metal_io_ops nops = {
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
};

io->virt = virt;
io->physmap = physmap;
Expand All @@ -37,7 +39,7 @@ int metal_io_block_read(struct metal_io_region *io, unsigned long offset,
unsigned char *dest = dst;
int retlen;

if (offset > io->size)
if (offset >= io->size)
return -ERANGE;
if ((offset + len) > io->size)
len = io->size - offset;
Expand Down Expand Up @@ -74,7 +76,7 @@ int metal_io_block_write(struct metal_io_region *io, unsigned long offset,
const unsigned char *source = src;
int retlen;

if (offset > io->size)
if (offset >= io->size)
return -ERANGE;
if ((offset + len) > io->size)
len = io->size - offset;
Expand Down Expand Up @@ -110,7 +112,7 @@ int metal_io_block_set(struct metal_io_region *io, unsigned long offset,
unsigned char *ptr = metal_io_virt(io, offset);
int retlen = len;

if (offset > io->size)
if (offset >= io->size)
return -ERANGE;
if ((offset + len) > io->size)
len = io->size - offset;
Expand All @@ -123,7 +125,7 @@ int metal_io_block_set(struct metal_io_region *io, unsigned long offset,
unsigned int i;

for (i = 1; i < sizeof(int); i++)
cint |= ((unsigned int)value << (8 * i));
cint |= ((unsigned int)value << (CHAR_BIT * i));

for (; len && ((uintptr_t)ptr % sizeof(int)); ptr++, len--)
*(unsigned char *)ptr = (unsigned char) value;
Expand Down
45 changes: 29 additions & 16 deletions ext/hal/libmetal/libmetal/lib/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ struct metal_io_ops {
memory_order order,
int len);
void (*close)(struct metal_io_region *io);
metal_phys_addr_t
(*offset_to_phys)(struct metal_io_region *io,
unsigned long offset);
unsigned long (*phys_to_offset)(struct metal_io_region *io,
metal_phys_addr_t phys);
};

/** Libmetal I/O region structure. */
Expand Down Expand Up @@ -126,7 +131,7 @@ static inline size_t metal_io_region_size(struct metal_io_region *io)
static inline void *
metal_io_virt(struct metal_io_region *io, unsigned long offset)
{
return (io->virt != METAL_BAD_VA && offset <= io->size
return (io->virt != METAL_BAD_VA && offset < io->size
? (uint8_t *)io->virt + offset
: NULL);
}
Expand Down Expand Up @@ -154,12 +159,16 @@ metal_io_virt_to_offset(struct metal_io_region *io, void *virt)
static inline metal_phys_addr_t
metal_io_phys(struct metal_io_region *io, unsigned long offset)
{
unsigned long page = (io->page_shift >=
sizeof(offset) * CHAR_BIT ?
0 : offset >> io->page_shift);
return (io->physmap != NULL && offset <= io->size
? io->physmap[page] + (offset & io->page_mask)
: METAL_BAD_PHYS);
if (!io->ops.offset_to_phys) {
unsigned long page = (io->page_shift >=
sizeof(offset) * CHAR_BIT ?
0 : offset >> io->page_shift);
return (io->physmap != NULL && offset < io->size
? io->physmap[page] + (offset & io->page_mask)
: METAL_BAD_PHYS);
}

return io->ops.offset_to_phys(io, offset);
}

/**
Expand All @@ -171,15 +180,19 @@ metal_io_phys(struct metal_io_region *io, unsigned long offset)
static inline unsigned long
metal_io_phys_to_offset(struct metal_io_region *io, metal_phys_addr_t phys)
{
unsigned long offset =
(io->page_mask == (metal_phys_addr_t)(-1) ?
phys - io->physmap[0] : phys & io->page_mask);
do {
if (metal_io_phys(io, offset) == phys)
return offset;
offset += io->page_mask + 1;
} while (offset < io->size);
return METAL_BAD_OFFSET;
if (!io->ops.phys_to_offset) {
unsigned long offset =
(io->page_mask == (metal_phys_addr_t)(-1) ?
phys - io->physmap[0] : phys & io->page_mask);
do {
if (metal_io_phys(io, offset) == phys)
return offset;
offset += io->page_mask + 1;
} while (offset < io->size);
return METAL_BAD_OFFSET;
}

return (*io->ops.phys_to_offset)(io, phys);
}

/**
Expand Down
138 changes: 138 additions & 0 deletions ext/hal/libmetal/libmetal/lib/irq.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* Copyright (c) 2019, Xilinx Inc. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <errno.h>
#include <metal/irq.h>
#include <metal/irq_controller.h>
#include <metal/list.h>
#include <metal/utilities.h>

/** List of registered IRQ controller */
static METAL_DECLARE_LIST(irq_cntrs);

static int metal_irq_allocate(int irq_base, int irq_num)
{
struct metal_list *node;
struct metal_irq_controller *cntr;
int irq_tocheck = irq_base, irq_end_tocheck;

if (irq_num == 0) {
return METAL_IRQ_ANY;
}
if (irq_tocheck == METAL_IRQ_ANY) {
irq_tocheck = 0;
}
irq_end_tocheck = irq_tocheck + irq_num;

metal_list_for_each(&irq_cntrs, node) {
int cntr_irq_base, cntr_irq_end;

cntr = metal_container_of(node,
struct metal_irq_controller, node);
cntr_irq_base = cntr->irq_base;
cntr_irq_end = cntr_irq_base + cntr->irq_num;
if (irq_tocheck < cntr_irq_end &&
irq_end_tocheck > cntr_irq_base) {
if (irq_base != METAL_IRQ_ANY) {
/* IRQ has been allocated */
return METAL_IRQ_ANY;
}
irq_tocheck = cntr_irq_end;
irq_end_tocheck = irq_tocheck + irq_num;
}
}
return irq_tocheck;
}

int metal_irq_register_controller(struct metal_irq_controller *cntr)
{
int irq_base;
struct metal_list *node;

if (cntr == NULL) {
return -EINVAL;
}
metal_list_for_each(&irq_cntrs, node) {
if (node == &cntr->node) {
return 0;
}
}

/* Allocate IRQ numbers which are not yet used by any IRQ
* controllers.*/
irq_base = metal_irq_allocate(cntr->irq_base , cntr->irq_num);
if (irq_base == METAL_IRQ_ANY) {
return -EINVAL;
}
cntr->irq_base = irq_base;

metal_list_add_tail(&irq_cntrs, &cntr->node);
return 0;
}

static struct metal_irq_controller *metal_irq_get_controller(int irq)
{
struct metal_list *node;
struct metal_irq_controller *cntr;

metal_list_for_each(&irq_cntrs, node) {
int irq_base, irq_end;

cntr = (struct metal_irq_controller *)
metal_container_of(node, struct metal_irq_controller,
node);
irq_base = cntr->irq_base;
irq_end = irq_base + cntr->irq_num;
if (irq >= irq_base && irq < irq_end) {
return cntr;
}
}
return NULL;
}

static void _metal_irq_set_enable(int irq, unsigned int state)
{
struct metal_irq_controller *cntr;

cntr = metal_irq_get_controller(irq);
if (cntr == NULL) {
return;
}
cntr->irq_set_enable(cntr, irq, state);
}

int metal_irq_register(int irq,
metal_irq_handler irq_handler,
void *arg)
{
struct metal_irq_controller *cntr;
struct metal_irq *irq_data;

cntr = metal_irq_get_controller(irq);
if (cntr == NULL) {
return -EINVAL;
}
if (cntr->irq_register != NULL) {
return cntr->irq_register(cntr, irq, irq_handler, arg);
}
if (cntr->irqs == NULL) {
return -EINVAL;
}
irq_data = &cntr->irqs[irq - cntr->irq_base];
irq_data->hd = irq_handler;
irq_data->arg = arg;
return 0;
}

void metal_irq_enable(unsigned int vector)
{
_metal_irq_set_enable((int)vector, METAL_IRQ_ENABLE);
}

void metal_irq_disable(unsigned int vector)
{
_metal_irq_set_enable((int)vector, METAL_IRQ_DISABLE);
}
Loading