Skip to content

Commit

Permalink
examples: update Xilinx example code.
Browse files Browse the repository at this point in the history
This provides bug fixes and enhancements to the Xilinx-specific example
code, and a couple of small fixes to the linux example code.

Signed-off-by: Ed Mooring <ed.mooring@linaro.org>
  • Loading branch information
Ben Levinsky authored and arnopo committed Jan 31, 2020
1 parent f98eb2a commit 007f2fe
Show file tree
Hide file tree
Showing 16 changed files with 721 additions and 141 deletions.
1 change: 1 addition & 0 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ collector_create (APP_LIB_DIRS "")
collector_create (APP_INC_DIRS "")
collector_create (APP_LIB_DEPS "")

collector_create (APP_EXTRA_C_FLAGS "")
set (APPS_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")

set (APPS_SHARE_DIR "${CMAKE_CURRENT_BINARY_DIR}/share")
Expand Down
13 changes: 8 additions & 5 deletions apps/examples/load_fw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

set (_cflags "${CMAKE_C_FLAGS} ${APP_EXTRA_C_FLAGS}")
collector_list (_app_extra_c_flags APP_EXTRA_C_FLAGS)
set (_cflags "${CMAKE_C_FLAGS} ${_app_extra_c_flags}")
set (_fw_dir "${APPS_SHARE_DIR}")

collector_list (_list PROJECT_INC_DIRS)
Expand All @@ -11,21 +11,24 @@ collector_list (_app_list APP_LIB_DIRS)
link_directories (${_list} ${_app_list})

get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_OPT)
collect (PROJECT_LIB_DEPS xilpm)
collector_list (_deps PROJECT_LIB_DEPS)

set (OPENAMP_LIB open_amp)

foreach (_app load_fw)
collector_list (_sources APP_COMMON_SOURCES)
list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/${_app}.c")
list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/mem_image_store.c")
list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/zynqmp_r5_lcm_rproc_example.c")
list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/zynqmp_apu_lcm_rproc_example.c")
list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/zynqmp_rpu_lcm_rproc_example.c")
list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/platform_info.c")
list (APPEND _sources "${CMAKE_CURRENT_SOURCE_DIR}/${_app}.c")

if (WITH_STATIC_LIB)
add_executable (${_app}.out ${_sources})
set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}")

target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections -T"${CMAKE_CURRENT_SOURCE_DIR}/lscript.ld" -Wl,--start-group ${OPENAMP_LIB}-static -lxilpm ${_deps} -Wl,--end-group)
target_link_libraries(${_app}.out -Wl,-Map=${_app}.map -Wl,--gc-sections -T"${CMAKE_CURRENT_SOURCE_DIR}/lscript.ld" -Wl,--start-group ${OPENAMP_LIB}-static ${_deps} -Wl,--end-group)

install (TARGETS ${_app}.out RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif (WITH_STATIC_LIB)
Expand Down
109 changes: 109 additions & 0 deletions apps/examples/load_fw/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright(c) 2019 Xilinx Ltd.
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#ifndef COMMON_H_
#define COMMON_H_

#include <metal/alloc.h>
#include <metal/io.h>
#include <metal/sys.h>
#include <metal/utilities.h>
#include <openamp/remoteproc.h>
#include <openamp/remoteproc_loader.h>
#include <stdarg.h>
#include <stdio.h>
/* Xilinx headers */
#include <pm_api_sys.h>
#include <xil_mpu.h>
#include <xil_printf.h>
#include <xreg_cortexr5.h>

#ifdef versal
#include <xpm_nodeid.h>
#include <xpm_defs.h>

#ifndef NODE_APU_0
#define NODE_APU_0 PM_DEV_ACPU_0
#endif
#ifndef NODE_APU_1
#define NODE_APU_1 PM_DEV_ACPU_1
#endif
#ifndef NODE_RPU_0
#define NODE_RPU_0 PM_DEV_RPU0_0
#endif
#ifndef NODE_RPU
#define NODE_RPU PM_DEV_RPU0_0
#endif

#ifndef NODE_RPU_1
#define NODE_RPU_1 PM_DEV_RPU0_1
#endif

#ifndef NODE_TCM_0_A
#define NODE_TCM_0_A PM_DEV_TCM_0_A
#endif
#ifndef NODE_TCM_0_B
#define NODE_TCM_0_B PM_DEV_TCM_0_B
#endif
#ifndef NODE_TCM_1_A
#define NODE_TCM_1_A PM_DEV_TCM_1_A
#endif
#ifndef NODE_TCM_1_B
#define NODE_TCM_1_B PM_DEV_TCM_1_B
#endif

#ifndef NODE_DDR
#define NODE_DDR PM_DEV_DDR_0
#endif

#ifndef NODE_OCM_BANK_0
#define NODE_OCM_BANK_0 PM_DEV_OCM_0
#endif
#ifndef NODE_OCM_BANK_1
#define NODE_OCM_BANK_1 PM_DEV_OCM_1
#endif
#ifndef NODE_OCM_BANK_2
#define NODE_OCM_BANK_2 PM_DEV_OCM_2
#endif
#ifndef NODE_OCM_BANK_3
#define NODE_OCM_BANK_3 PM_DEV_OCM_3
#endif

/* Requirement limits */
#define XPM_MAX_CAPABILITY (PM_CAP_ACCESS | PM_CAP_CONTEXT | PM_CAP_WAKEUP)
#define XPM_MAX_LATENCY (0xFFFFU)
#define XPM_MAX_QOS (100)
#define XPM_MIN_CAPABILITY (0)
#define XPM_MIN_LATENCY (0)
#define XPM_MIN_QOS (0)
#define XPM_DEF_CAPABILITY XPM_MAX_CAPABILITY
#define XPM_DEF_LATENCY XPM_MAX_LATENCY
#define XPM_DEF_QOS XPM_MAX_QOS

enum XPmRequestAck {
REQUEST_ACK_NO = 1,
REQUEST_ACK_BLOCKING,
REQUEST_ACK_NON_BLOCKING,
REQUEST_ACK_CB_CERROR,
};

#else /* zynqmp */
#include <pm_defs.h>
#define XPM_MAX_QOS MAX_QOS
#define XPM_MIN_QOS (0)
#endif /* versal */

#define LPRINTF(format, ...) xil_printf(format, ##__VA_ARGS__)
//#define LPRINTF(format, ...)
#define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__)

struct rproc_priv {
struct remoteproc *rproc;
int cpu_id;
};

#endif /* COMMON_H_ */
117 changes: 20 additions & 97 deletions apps/examples/load_fw/load_fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,9 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <metal/io.h>
#include <metal/sys.h>
#include <openamp/remoteproc.h>
#include <openamp/remoteproc_loader.h>
#include <stdarg.h>
#include <stdio.h>
/* Xilinx headers */
#include <pm_api_sys.h>
#include <pm_defs.h>
#include <xil_printf.h>
#include <platform_info.h>
#include <common.h>

#define LPRINTF(format, ...) xil_printf(format, ##__VA_ARGS__)
//#define LPRINTF(format, ...)
#define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__)

extern struct remoteproc_ops r5_rproc_ops;
extern struct image_store_ops mem_image_store_ops;

struct mem_file {
Expand All @@ -33,57 +20,6 @@ static struct mem_file image = {
.base = (void *)0x3ED00000,
};

static XIpiPsu IpiInst;

static XStatus IpiConfigure(XIpiPsu *const IpiInstPtr)
{
XStatus Status;
XIpiPsu_Config *IpiCfgPtr;

/* Look Up the config data */
IpiCfgPtr = XIpiPsu_LookupConfig(XPAR_XIPIPSU_0_DEVICE_ID);
if (NULL == IpiCfgPtr) {
Status = XST_FAILURE;
LPERROR("%s ERROR in getting CfgPtr\r\n", __func__);
return Status;
}

/* Init with the Cfg Data */
Status = XIpiPsu_CfgInitialize(IpiInstPtr, IpiCfgPtr,
IpiCfgPtr->BaseAddress);
if (XST_SUCCESS != Status) {
LPERROR("%s ERROR #%d in configuring IPI\r\n", __func__, Status);
return Status;
}
return Status;
}

static void app_log_handler(enum metal_log_level level,
const char *format, ...)
{
char msg[1024];
va_list args;
static const char *level_strs[] = {
"metal: emergency: ",
"metal: alert: ",
"metal: critical: ",
"metal: error: ",
"metal: warning: ",
"metal: notice: ",
"metal: info: ",
"metal: debug: ",
};

va_start(args, format);
vsnprintf(msg, sizeof(msg), format, args);
va_end(args);

if (level <= METAL_LOG_EMERGENCY || level > METAL_LOG_DEBUG)
level = METAL_LOG_EMERGENCY;

xil_printf("%s%s", level_strs[level], msg);
}

int load_exectuable_block(struct remoteproc *rproc,
struct image_store_ops *store_ops, void *store,
const char *img_path)
Expand All @@ -95,6 +31,7 @@ int load_exectuable_block(struct remoteproc *rproc,
return -EINVAL;
/* Configure remoteproc to get ready to load executable */
remoteproc_config(rproc, NULL);

/* Load remoteproc executable */
LPRINTF("Start to load executable with remoteproc_load() \r\n");
ret = remoteproc_load(rproc, NULL, store, store_ops, NULL);
Expand All @@ -109,16 +46,19 @@ int load_exectuable_block(struct remoteproc *rproc,
return ret;
}
LPRINTF("successfully started the processor\r\n");
#ifndef RPU_BOOT_LINUX
/* ... */
asm volatile("wfi");
LPRINTF("going to stop the processor\r\n");
remoteproc_stop(rproc);
/* application may want to do some cleanup before shutdown */
LPRINTF("going to shutdown the processor\r\n");
remoteproc_shutdown(rproc);
#endif /* RPU_BOOT_LINUX */
return 0;
}

#ifndef RPU_BOOT_LINUX
int load_exectuable_noblock(struct remoteproc *rproc,
struct image_store_ops *store_ops, void *store,
const char *img_path)
Expand Down Expand Up @@ -196,55 +136,38 @@ int load_exectuable_noblock(struct remoteproc *rproc,
remoteproc_shutdown(rproc);
return 0;
}

#endif /* RPU_BOOT_LINUX */

int main(void)
{
struct remoteproc rproc;
struct remoteproc *ret_rproc;
struct remoteproc *rproc = NULL;
void *store = &image;
unsigned int cpu_id = NODE_RPU_1;
unsigned int cpu_id = LOAD_FW_TARGET;
int ret;
struct metal_init_params metal_param = {
.log_handler = app_log_handler,
.log_level = METAL_LOG_DEBUG,
};

if (XST_SUCCESS != IpiConfigure(&IpiInst)) {
LPERROR("Failed to config IPI instance\r\n");
return -1;
}
if (XST_SUCCESS != XPm_InitXilpm(&IpiInst)) {
LPERROR("Failed to initialize PM\r\n");
return -1;
}

LPRINTF("Loading Exectuable Demo\r\n");
/* Initialize libmetal evironment */
metal_init(&metal_param);
/* Initialize remoteproc instance */
ret_rproc = remoteproc_init(&rproc, &r5_rproc_ops, &cpu_id);
if (!ret_rproc) {
LPRINTF("failed to initialize coprocessor\r\n");
LPRINTF("Loading Exectuable Demo\n");
rproc = app_init(cpu_id);
if (!rproc) {
LPERROR("app_init failed\r\n");
return -1;
}

ret = load_exectuable_block(&rproc, &mem_image_store_ops, store, NULL);
ret = load_exectuable_block(rproc, &mem_image_store_ops, store, NULL);
if (ret < 0) {
LPERROR("load_exectuable_block failed\r\n");
/* Make sure the remote is shut down */
remoteproc_shutdown(&rproc);
remoteproc_shutdown(rproc);
return -1;
}

ret = load_exectuable_noblock(&rproc, &mem_image_store_ops, store,
#ifndef RPU_BOOT_LINUX
ret = load_exectuable_noblock(rproc, &mem_image_store_ops, store,
NULL);
if (ret < 0) {
LPERROR("load_exectuable_noblock failed\r\n");
/* Make sure the remote is shut down */
remoteproc_shutdown(&rproc);
remoteproc_shutdown(rproc);
return -1;
}
remoteproc_remove(&rproc);
#endif /* RPU_BOOT_LINUX */
remoteproc_remove(rproc);
return ret;
}
16 changes: 2 additions & 14 deletions apps/examples/load_fw/mem_image_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,7 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <metal/io.h>
#include <metal/sys.h>
#include <openamp/remoteproc_loader.h>
#include <stdarg.h>
#include <stdio.h>
/* Xilinx headers */
#include <pm_api_sys.h>
#include <pm_defs.h>
#include <xil_printf.h>

#define LPRINTF(format, ...) xil_printf(format, ##__VA_ARGS__)
//#define LPRINTF(format, ...)
#define LPERROR(format, ...) LPRINTF("ERROR: " format, ##__VA_ARGS__)
#include <common.h>

struct mem_file {
const void *base;
Expand Down Expand Up @@ -56,7 +44,7 @@ int mem_image_load(void *store, size_t offset, size_t size,

(void)is_blocking;

LPRINTF("%s: offset=0x%x, size=0x%x\r\n",
LPRINTF("%s: offset=0x%x, size=0x%x\n\r",
__func__, offset, size);
if (pa == METAL_BAD_PHYS) {
if (data == NULL) {
Expand Down
Loading

0 comments on commit 007f2fe

Please sign in to comment.