17 #define DEFAULT_ALGORITHM_TIMEOUT_MS 40000
33 uint8_t *log_buff = calloc(1, len);
35 LOG_ERROR(
"Failed to allocate memory for the stub log!");
61 mem_handles = calloc(run->
mem_args.
count,
sizeof(*mem_handles));
63 LOG_ERROR(
"Failed to alloc target mem handles!");
76 LOG_ERROR(
"Failed to alloc target buffer!");
80 mem_handles[i] = area;
82 if (usr_param_num != UINT_MAX)
90 LOG_ERROR(
"Failed to prepare algorithm host side args stub (%d)!", retval);
103 LOG_ERROR(
"Failed to start algorithm (%d)!", retval);
112 LOG_ERROR(
"Failed to exec algorithm user func (%d)!", retval);
114 uint32_t timeout_ms = 0;
124 LOG_ERROR(
"Failed to wait algorithm (%d)!", retval);
133 LOG_ERROR(
"Algorithm run failed (%d)!", retval);
158 if (!run || !run->
hw)
173 LOG_ERROR(
"Failed to start algorithm (%d)!", retval);
177 uint32_t timeout_ms = 0;
187 LOG_ERROR(
"Failed to wait algorithm (%d)!", retval);
192 LOG_ERROR(
"Algorithm run failed (%d)!", retval);
206 size_t remaining =
length % 4;
212 memset(dest + remaining, 0xFF, 4 - remaining);
213 for (
size_t i = 0; i < remaining; i++)
214 dest[i] = src[
length - remaining + i];
219 for (
size_t i =
offset; i < aligned_len; i += 4) {
239 assert(
sizeof(buf) % 4 == 0);
241 while (sec_wr < section->
size) {
242 uint32_t nb = section->
size - sec_wr >
sizeof(buf) ?
sizeof(buf) : section->
size - sec_wr;
243 size_t size_read = 0;
246 LOG_ERROR(
"Failed to read stub section (%d)!", retval);
251 size_t aligned_len =
ALIGN_UP(size_read, 4);
252 uint8_t reversed_buf[aligned_len];
274 LOG_ERROR(
"Failed to write stub section!");
280 LOG_ERROR(
"Failed to write stub section!");
303 const uint8_t *tramp =
NULL;
305 bool alloc_code_working_area =
true;
307 if (!run || !run->
hw)
311 LOG_ERROR(
"Failed to start algo time measurement!");
321 LOG_DEBUG(
"stub: base 0x%x, start 0x%" PRIx32
", %d sections",
335 LOG_ERROR(
"no working area available, can't alloc space for stub code!");
339 alloc_code_working_area =
false;
342 uint32_t code_size = 0;
348 if (section->
size == 0)
355 if (alloc_code_working_area) {
358 LOG_ERROR(
"no working area available, can't alloc space for stub code!");
369 " address mismatch!",
388 if (alloc_code_working_area) {
391 LOG_ERROR(
"no working area available, can't alloc space for stub jumper!");
399 size_t al_tramp_size =
ALIGN_UP(tramp_sz, 4);
403 uint8_t reversed_tramp[al_tramp_size];
416 LOG_ERROR(
"Failed to write stub jumper!");
421 code_size += al_tramp_size;
426 if (alloc_code_working_area) {
431 LOG_ERROR(
"no working area available, can't alloc space for stub code!");
442 if (section->
size == 0)
451 LOG_DEBUG(
"DATA sec size %" PRIu32
" -> %" PRIu32, section->
size, data_sec_sz);
455 LOG_ERROR(
"no working area available, can't alloc space for stub data!");
465 " address mismatch!",
482 LOG_ERROR(
"no working area available, can't alloc stub stack!");
490 LOG_ERROR(
"Failed to stop algo run measurement!");
532 const uint8_t *tramp =
NULL;
536 if (!run || !run->
hw)
540 LOG_ERROR(
"Failed to start algo time measurement!");
550 if (tramp_sz > run->
on_board.code_buf_size) {
551 LOG_ERROR(
"Stub tramp size %zu bytes exceeds target buf size %d bytes!",
552 tramp_sz, run->
on_board.code_buf_size);
557 LOG_ERROR(
"Algorithm stack size not fit into the allocated target stack!");
569 LOG_ERROR(
"Failed to write stub jumper!");
576 LOG_ERROR(
"Failed to stop algo run measurement!");
static void reverse_binary(const uint8_t *src, uint8_t *dest, size_t length)
int esp_algorithm_exec_onboard_func_va(struct target *target, struct esp_algorithm_run_data *run, uint32_t num_args, va_list ap)
static int esp_algorithm_run_debug_stub(struct target *target, struct esp_algorithm_run_data *run, uint32_t num_args, va_list ap)
static int esp_algorithm_run_image(struct target *target, struct esp_algorithm_run_data *run, uint32_t num_args, va_list ap)
#define DEFAULT_ALGORITHM_TIMEOUT_MS
int esp_algorithm_load_func_image(struct target *target, struct esp_algorithm_run_data *run)
static int esp_algorithm_read_stub_logs(struct target *target, struct esp_algorithm_stub *stub)
int esp_algorithm_unload_onboard_func(struct target *target, struct esp_algorithm_run_data *run)
int esp_algorithm_unload_func_image(struct target *target, struct esp_algorithm_run_data *run)
static int load_section_from_image(struct target *target, struct esp_algorithm_run_data *run, int section_num, bool reverse)
int esp_algorithm_exec_func_image_va(struct target *target, struct esp_algorithm_run_data *run, uint32_t num_args, va_list ap)
int esp_algorithm_load_onboard_func(struct target *target, target_addr_t func_addr, struct esp_algorithm_run_data *run)
static uint64_t esp_algorithm_user_arg_get_uint(struct esp_algorithm_run_data *run, int arg_num)
Get the value of an argument passed via registers from the stub main function.
static void esp_algorithm_user_arg_set_uint(struct esp_algorithm_run_data *run, int arg_num, uint64_t val)
Set the value of an argument passed via registers to the stub main function.
#define ESP_IMAGE_ELF_PHF_EXEC
int image_read_section(struct image *image, int section, target_addr_t offset, uint32_t size, uint8_t *buffer, size_t *size_read)
void alive_sleep(uint64_t ms)
#define LOG_OUTPUT(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_DEBUG(expr ...)
size_t size
Size of the control block search area.
int(* algo_init)(struct target *target, struct esp_algorithm_run_data *run, uint32_t num_args, va_list ap)
int(* algo_cleanup)(struct target *target, struct esp_algorithm_run_data *run)
const uint8_t *(* stub_tramp_get)(struct target *target, size_t *size)
uint32_t iram_len
Total reserved IRAM size.
bool reverse
IRAM DRAM address range reversed or not.
uint32_t bss_size
BSS section size.
uint32_t dram_org
DRAM start address in the linker script.
uint32_t iram_org
IRAM start address in the linker script.
uint32_t count
Number of memory params.
struct mem_param * params
Memory params.
struct reg_param * params
Algorithm register params.
uint32_t count
Number of register params.
struct esp_algorithm_run_data::@96::@98 on_board
struct esp_algorithm_reg_args reg_args
Algorithm register arguments.
struct esp_algorithm_mem_args mem_args
Algorithm memory arguments.
esp_algorithm_usr_func_init_t usr_func_init
Host side algorithm function setup routine.
esp_algorithm_usr_func_t usr_func
Host side algorithm function.
void * usr_func_arg
Host side algorithm function argument.
uint32_t timeout_ms
Algorithm completion timeout in ms.
const struct esp_algorithm_hw * hw
HW specific API.
struct esp_algorithm_image image
esp_algorithm_usr_func_done_t usr_func_done
Host side algorithm function cleanup routine.
struct esp_algorithm_stub stub
Stub.
uint32_t stack_size
Algorithm stack size.
int32_t ret_code
Algorithm return code.
target_addr_t stack_addr
Address of the target buffer for stack.
target_addr_t tramp_addr
Address of the target buffer for stub trampoline.
void * ainfo
Algorithm's arch-specific info.
uint32_t log_buff_size
Size of the log buffer.
struct working_area * padding
Working area for padding between code and data area.
target_addr_t tramp_mapped_addr
Tramp code area will be filled from dbus.
struct working_area * data
Working area for data segment.
struct working_area * tramp
Working area for trampoline.
target_addr_t log_buff_addr
Address of the log buffer.
struct working_area * stack
Working area for stack.
target_addr_t entry
Entry addr.
struct working_area * code
Working area for code segment.
unsigned int num_sections
struct imagesection * sections
target_addr_t base_address
void target_free_all_working_areas(struct target *target)
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
int target_alloc_working_area(struct target *target, uint32_t size, struct working_area **area)
int target_free_working_area(struct target *target, struct working_area *area)
Free a working area.
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
int target_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Read count items of size bytes from the memory of target at the address given.
int target_wait_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
Waits for an algorithm started with target_start_algorithm() to complete.
int target_start_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, target_addr_t entry_point, target_addr_t exit_point, void *arch_info)
Executes a target-specific native code algorithm and leaves it running.
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
float duration_elapsed(const struct duration *duration)
int duration_measure(struct duration *duration)
Update the duration->elapsed field to finish the duration measurement.
int duration_start(struct duration *duration)
Update the duration->start field to start the duration measurement.