blob: 619aaa02dda1dc92d20e529488439d2fae01c528 [file] [log] [blame]
/*
* Copyright (c) 2018 The Fuchsia Authors
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _ZIRCON_ZIRCON_H_
#define _ZIRCON_ZIRCON_H_
#include <zircon/boot/image.h>
#include <zircon-estelle/driver-config.h>
#include <zircon-estelle/gpt.h>
#if defined(CONFIG_FIRMWARE_TESTING_DEV_BUILD)
#define BOOTLOADER_BUILD_VARIANT "test"
#elif defined(CONFIG_DEV_BUILD)
#define BOOTLOADER_BUILD_VARIANT "dev"
#elif defined(CONFIG_DOGFOOD_BUILD)
#define BOOTLOADER_BUILD_VARIANT "dogfood"
#elif defined(CONFIG_PROD_BUILD)
#define BOOTLOADER_BUILD_VARIANT "prod"
#else
#error Unknown bootloader build variant
#endif
/**
* Modifies the ZBI to add bootloader-generated items.
*
* This should be called exactly once after the prebuilt ZBI has been loaded
* into memory, before booting it.
*
* @zbi: ZBI container.
* @capacity: Total available space the container can expand to.
*
* Returns: 0 on success, nonzero on failure.
*/
int zircon_fixup_zbi(zbi_header_t *zbi, size_t capacity);
/**
* Adds a ZBI item to the given container.
*
* This is a thin wrapper around libzbi's zbi_create_entry_with_payload(),
* which adds:
* - additional length checks to prevent uint32_t overflow
* - automatic logging if appending the item fails
*
* @zbi: ZBI container.
* @capacity: ZBI container capacity.
* @type: ZBI item type to add.
* @extra: ZBI item extra value.
* @payload: ZBI item payload.
* @size: ZBI item payload size.
*
* Return: 0 on success, nonzero on error.
*/
int append_zbi_item_or_log(void *zbi, size_t capacity, uint32_t type,
uint32_t extra, const void *payload, size_t size);
/**
* Stages a ZBI_TYPE_BOOTLOADER_FILE item.
*
* This functionality is used by fastboot before the ZBI is loaded into
* memory, so we can't append it to the prebuilt ZBI directly. Instead we
* stage it in a buffer and it will be appended by zircon_preboot().
*
* @name: file name.
* @data: file contents.
* @data_len: contents length.
*
* Returns: 0 on success, nonzero on failure.
*/
int zircon_stage_zbi_file(const char *name, const uint8_t *data,
size_t data_len);
#endif