blob: 7f05fb63eaff7d9f6ec7e30926e16e745f3b8bcb [file] [log] [blame]
/*
* Copyright (c) 2019 The Fuchsia Authors
*/
#include <common.h>
#include <zircon-estelle/fw-testing.h>
#include <zircon-estelle/zircon.h>
#include <stdlib.h>
static char *args = NULL;
static uint32_t args_len = 0;
int zircon_fw_testing_append_boot_items(const char *payload)
{
if (!payload) {
return -1;
}
uint32_t length = strlen(payload);
if (length == 0) {
return -1;
}
uint32_t new_args_len;
if (args) {
// a ' ' is inserted after previous args
new_args_len = args_len + length + 1;
} else {
new_args_len = length;
}
char *new_args = malloc(new_args_len + 1);
if (!new_args) {
return -1;
}
new_args[new_args_len] = '\0';
if (args) {
memcpy(new_args, args, args_len);
free(args);
new_args[args_len] = ' ';
memcpy(new_args + args_len + 1, payload, length);
} else {
memcpy(new_args, payload, length);
}
args_len = new_args_len;
args = new_args;
printf("args: %s, args_len: %u\n", args, args_len);
return 0;
}
int zircon_fw_testing_add_extra_zbi_items(zbi_header_t *zbi, size_t capacity)
{
int ret = 0;
if (args) {
ret = append_zbi_item_or_log(zbi, capacity, ZBI_TYPE_CMDLINE, 0,
args, args_len + 1);
free(args);
args = NULL;
args_len = 0;
}
return ret;
}