[zircon] Update to latest changes for booting zircon

Change-Id: I72732076f3d40acd773f47079504b921e042dd7e
diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 2258cd9..e08def9 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -30,17 +30,8 @@
 #include <asm/armv7.h>
 #endif
 
-#if defined(CONFIG_FUCHSIA_BOOT_IMAGE)
-#include <fuchsia/bootdata.h>
-#include <fuchsia/driver-config.h>
-
-static void append_bootdata(bootdata_t* container, uint32_t type, uint32_t extra,
-							const void* payload, uint32_t length);
-
-#if defined(CONFIG_IMX8MEVK)
-#include <fuchsia/board/imx8mevk/board-config.h>
-#endif
-
+#if defined(CONFIG_ZIRCON_BOOT_IMAGE)
+#include <zircon/zircon.h>
 #endif
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -448,57 +439,41 @@
 #endif
 
 
-#if defined(CONFIG_FUCHSIA_BOOT_IMAGE)
+#if defined(CONFIG_ZIRCON_BOOT_IMAGE)
 
-#define FUCHSIA_KERNEL_ALIGN	65536
+#define ZIRCON_KERNEL_ALIGN	65536
 
-static void append_bootdata(bootdata_t* container, uint32_t type, uint32_t extra,
-							const void* payload, uint32_t length) {
-	bootdata_t* dest = (bootdata_t*)((uintptr_t)container + container->length + sizeof(bootdata_t));
-
-	dest->type = type;
-	dest->length = length;
-	dest->extra = extra;
-	dest->flags = 0;
-	dest->reserved0 = 0;
-	dest->reserved1 = 0;
-	dest->magic = BOOTITEM_MAGIC;
-	dest->crc32 = BOOTITEM_NO_CRC32;
-
-	if (length) {
-		memcpy(dest + 1, payload, length);
-	}
-	length = BOOTDATA_ALIGN(length + sizeof(bootdata_t));
-	container->length += length;
-}
-
-int do_bootm_fuchsia(int flag, int argc, char * const argv[],
+int do_bootm_zircon(int flag, int argc, char * const argv[],
 		   bootm_headers_t *images)
 {
-	bootdata_t* bootdata = (bootdata_t *)images->ep;
-	const bootdata_t* kernel_hdr = &bootdata[1];
-	const bootdata_kernel_t* kernel = (bootdata_kernel_t *)&bootdata[2];
+	zbi_header_t* zbi = (zbi_header_t *)images->ep;
+	const zbi_header_t* kernel_hdr = &zbi[1];
+	const zbi_kernel_t* kernel = (zbi_kernel_t *)&zbi[2];
 
-	append_board_bootdata(bootdata);
-
-	uint32_t bootdata_len = bootdata->length + sizeof(bootdata_t);
-	uint32_t kernel_len = kernel_hdr->length + 2 * sizeof(bootdata_t);
-
-	// If bootdata_len is greater than kernel_len,
-	// then we have bootdata records after the kernel.
-	// In that case we must relocate the kernel after the bootdata
-	if (bootdata_len > kernel_len) {
-		uintptr_t dest = (ulong)bootdata + bootdata_len;
-		// align to 64K boundary
-		dest = (dest + FUCHSIA_KERNEL_ALIGN - 1) & ~(FUCHSIA_KERNEL_ALIGN - 1);
-		memcpy((void *)dest, bootdata, kernel_len);
-		images->ep = dest + kernel->entry64;
-	} else {
-		images->ep = (ulong)bootdata + kernel->entry64;
+	int ret = zircon_preboot(zbi);
+	if (ret < 0) {
+	    printf("zircon_preboot failed\n");
+	    return ret;
 	}
 
-	// this will pass the bootdata pointer to the kernel via x0
-	images->ft_addr = (char *)bootdata;
+	uint32_t zbi_len = zbi->length + sizeof(zbi_header_t);
+	uint32_t kernel_len = kernel_hdr->length + 2 * sizeof(zbi_header_t);
+
+	// If zbi_len is greater than kernel_len,
+	// then we have boot items after the kernel.
+	// In that case we must relocate the kernel after the zbi
+	if (zbi_len > kernel_len) {
+		uintptr_t dest = (ulong)zbi + zbi_len;
+		// align to 64K boundary
+		dest = (dest + ZIRCON_KERNEL_ALIGN - 1) & ~(ZIRCON_KERNEL_ALIGN - 1);
+		memcpy((void *)dest, zbi, kernel_len);
+		images->ep = dest + kernel->entry;
+	} else {
+		images->ep = (ulong)zbi + kernel->entry;
+	}
+
+	// this will pass the zbi pointer to the kernel via x0
+	images->ft_addr = (char *)zbi;
 
 	boot_jump_linux(images, flag);
 	return 0;
diff --git a/board/freescale/imx8mq_evk/Makefile b/board/freescale/imx8mq_evk/Makefile
index a7a4e9a..e9c9e21 100644
--- a/board/freescale/imx8mq_evk/Makefile
+++ b/board/freescale/imx8mq_evk/Makefile
@@ -5,6 +5,7 @@
 #
 
 obj-y += imx8m_evk.o
+obj-y += zircon.o
 
 ifdef CONFIG_SPL_BUILD
 obj-y += spl.o
diff --git a/board/freescale/imx8mq_evk/zircon.c b/board/freescale/imx8mq_evk/zircon.c
new file mode 100644
index 0000000..525944a
--- /dev/null
+++ b/board/freescale/imx8mq_evk/zircon.c
@@ -0,0 +1,90 @@
+// Copyright 2018 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <zircon/zircon.h>
+
+#define PDEV_VID_NXP                9
+#define PDEV_PID_IMX8MEVK           1
+
+const char* BOOTLOADER_VERSION = "zircon-bootloader=0.04";
+
+static const zbi_cpu_config_t cpu_config = {
+    .cluster_count = 1,
+    .clusters = {
+        {
+            .cpu_count = 4,
+        },
+    },
+};
+
+static const zbi_mem_range_t mem_config[] = {
+    {
+        .type = ZBI_MEM_RANGE_RAM,
+        .paddr = 0x40000000,
+        .length = 0xc0000000, // 3GB
+    },
+    {
+        .type = ZBI_MEM_RANGE_PERIPHERAL,
+        .paddr = 0,
+        .length = 0x40000000,
+    },
+};
+
+static const dcfg_simple_t uart_driver = {
+    .mmio_phys = 0x30860000,
+    .irq = 58,
+};
+
+static const dcfg_arm_gicv3_driver_t gicv3_driver = {
+    .mmio_phys = 0x38800000,
+    .gicd_offset = 0x00000,
+    .gicr_offset = 0x80000,
+    .gicr_stride = 0x20000,
+    .ipi_base = 9,
+    // Used for Errata e11171
+    .mx8_gpr_phys = 0x30340000,
+};
+
+static const dcfg_arm_psci_driver_t psci_driver = {
+    .use_hvc = false,
+};
+
+static const dcfg_arm_generic_timer_driver_t timer_driver = {
+    .irq_phys = 30,
+    .irq_virt = 27,
+    .freq_override = 8333333,
+};
+
+static const zbi_platform_id_t platform_id = {
+    .vid = PDEV_VID_NXP,
+    .pid = PDEV_PID_IMX8MEVK,
+    .board_name = "imx8mevk",
+};
+
+int zircon_preboot(zbi_header_t* zbi) {
+    // add CPU configuration
+    zircon_append_boot_item(zbi, ZBI_TYPE_CPU_CONFIG, 0, &cpu_config,
+                    sizeof(zbi_cpu_config_t) +
+                    sizeof(zbi_cpu_cluster_t) * cpu_config.cluster_count);
+
+    // add memory configuration
+    zircon_append_boot_item(zbi, ZBI_TYPE_MEM_CONFIG, 0, &mem_config,
+                    sizeof(zbi_mem_range_t) * (sizeof(mem_config)/sizeof(mem_config[0])));
+
+    // add kernel drivers
+    zircon_append_boot_item(zbi, ZBI_TYPE_KERNEL_DRIVER, KDRV_NXP_IMX_UART, &uart_driver,
+                    sizeof(uart_driver));
+    zircon_append_boot_item(zbi, ZBI_TYPE_KERNEL_DRIVER, KDRV_ARM_GIC_V3, &gicv3_driver,
+                    sizeof(gicv3_driver));
+    zircon_append_boot_item(zbi, ZBI_TYPE_KERNEL_DRIVER, KDRV_ARM_PSCI, &psci_driver,
+                    sizeof(psci_driver));
+    zircon_append_boot_item(zbi, ZBI_TYPE_KERNEL_DRIVER, KDRV_ARM_GENERIC_TIMER, &timer_driver,
+                    sizeof(timer_driver));
+
+    zircon_append_boot_item(zbi, ZBI_TYPE_CMDLINE, 0, BOOTLOADER_VERSION, strlen(BOOTLOADER_VERSION) + 1);
+
+    // add platform ID
+    zircon_append_boot_item(zbi, ZBI_TYPE_PLATFORM_ID, 0, &platform_id, sizeof(platform_id));
+    return 0;
+}
diff --git a/common/Makefile b/common/Makefile
index d0866f2..b1acbe1 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -149,7 +149,7 @@
 obj-$(CONFIG_CMD_IDE) += ide.o
 obj-y += image.o
 obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o
-obj-$(CONFIG_FUCHSIA_BOOT_IMAGE) += image-fuchsia.o
+obj-$(CONFIG_ZIRCON_BOOT_IMAGE) += image-zircon.o
 obj-$(CONFIG_$(SPL_)OF_LIBFDT) += image-fdt.o
 obj-$(CONFIG_$(SPL_)FIT) += image-fit.o
 obj-$(CONFIG_$(SPL_)FIT_SIGNATURE) += image-sig.o
diff --git a/common/bootm.c b/common/bootm.c
index 38f2e6e..487e086 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -164,14 +164,14 @@
 		ep_found = true;
 		break;
 #endif
-#ifdef CONFIG_FUCHSIA_BOOT_IMAGE
-	case IMAGE_FORMAT_FUCHSIA:
+#ifdef CONFIG_ZIRCON_BOOT_IMAGE
+	case IMAGE_FORMAT_ZIRCON:
 		images.os.type = IH_TYPE_KERNEL;
-		images.os.comp =  fuchsia_image_get_comp(os_hdr);
-		images.os.os = IH_OS_FUCHSIA;
+		images.os.comp =  zircon_image_get_comp(os_hdr);
+		images.os.os = IH_OS_ZIRCON;
 
-		images.os.end = fuchsia_image_get_end(os_hdr);
-		images.os.load = fuchsia_image_get_kload(os_hdr);
+		images.os.end = zircon_image_get_end(os_hdr);
+		images.os.load = zircon_image_get_kload(os_hdr);
 		if (images.os.load == 0x10008000)
 			images.os.load = 0x1080000;
 		images.ep = images.os.load;
@@ -891,11 +891,11 @@
 		images->fit_noffset_os = os_noffset;
 		break;
 #endif
-#ifdef CONFIG_FUCHSIA_BOOT_IMAGE
-	case IMAGE_FORMAT_FUCHSIA:
-		printf("## Booting Fuchsia Image at 0x%08lx ...\n", img_addr);
+#ifdef CONFIG_ZIRCON_BOOT_IMAGE
+	case IMAGE_FORMAT_ZIRCON:
+		printf("## Booting Zircon Image at 0x%08lx ...\n", img_addr);
 		buf = map_sysmem(img_addr, 0);
-		if (fuchsia_image_get_kernel(buf, images->verify,
+		if (zircon_image_get_kernel(buf, images->verify,
 					     os_data, os_len))
 			return NULL;
 		break;
diff --git a/common/bootm_os.c b/common/bootm_os.c
index 4cc9421..163c685 100644
--- a/common/bootm_os.c
+++ b/common/bootm_os.c
@@ -477,8 +477,8 @@
 #ifdef CONFIG_BOOTM_OPENRTOS
 	[IH_OS_OPENRTOS] = do_bootm_openrtos,
 #endif
-#ifdef CONFIG_FUCHSIA_BOOT_IMAGE
-	[IH_OS_FUCHSIA] = do_bootm_fuchsia,
+#ifdef CONFIG_ZIRCON_BOOT_IMAGE
+	[IH_OS_ZIRCON] = do_bootm_zircon,
 #endif
 };
 
diff --git a/common/image-fuchsia.c b/common/image-fuchsia.c
deleted file mode 100644
index e5b143f..0000000
--- a/common/image-fuchsia.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2018 The Fuchsia Authors
- *
- * SPDX-License-Identifier: GPL-2.0+
- */
-
-#include <common.h>
-#include <image.h>
-#include <fuchsia/bootdata.h>
-
-int fuchsia_image_check_header(const void *hdr)
-{
-    const bootdata_t* bootdata = hdr;
-
-    return (bootdata[0].type == BOOTDATA_CONTAINER &&
-            bootdata[0].extra == BOOTDATA_MAGIC &&
-            bootdata[0].magic == BOOTITEM_MAGIC &&
-            bootdata[1].type == BOOTDATA_KERNEL &&
-            bootdata[1].magic == BOOTITEM_MAGIC) ? 0 : -1;
-}
-
-/**
- * fuchsia_image_get_kernel() - processes kernel part of Fuchsia bootdata
- * @bootdata:   Pointer to bootdata.
- * @verify:     Checksum verification flag. Currently unimplemented.
- * @os_data:    Pointer to a ulong variable, will hold os data start
- *          address.
- * @os_len: Pointer to a ulong variable, will hold os data length.
- *
- * This function returns the os image's start address and length. Also,
- * it appends the kernel command line to the bootargs env variable.
- *
- * Return: Zero, os start address and length on success,
- *      otherwise on failure.
- */
-int fuchsia_image_get_kernel(const void* hdr, int verify,
-                 ulong *os_data, ulong *os_len)
-{
-    if (fuchsia_image_check_header(hdr))
-        return -1;
-
-    const bootdata_t* bootdata = hdr;
-
-    *os_data = (ulong)bootdata;
-    *os_len = (ulong) bootdata->length + sizeof(bootdata_t);
-
-    return 0;
-}
-
-ulong fuchsia_image_get_end(const void *hdr)
-{
-    const bootdata_t* container_hdr = hdr;
-    return (ulong)hdr + container_hdr->length + sizeof(bootdata_t);
-}
-
-ulong fuchsia_image_get_kload(const void *hdr)
-{
-    return 0x40480000;
-}
-
-ulong fuchsia_image_get_comp(const void *hdr)
-{
-    return IH_COMP_NONE;
-}
\ No newline at end of file
diff --git a/common/image-zircon.c b/common/image-zircon.c
new file mode 100644
index 0000000..e3562aa
--- /dev/null
+++ b/common/image-zircon.c
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2018 The Fuchsia Authors
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <image.h>
+#include <zircon/image.h>
+
+void zircon_append_boot_item(zbi_header_t* container, uint32_t type, uint32_t extra,
+                             const void* payload, uint32_t length) {
+	zbi_header_t* dest = (zbi_header_t*)((uintptr_t)container + container->length + sizeof(zbi_header_t));
+
+	dest->type = type;
+	dest->length = length;
+	dest->extra = extra;
+	dest->flags = 0;
+	dest->reserved0 = 0;
+	dest->reserved1 = 0;
+	dest->magic = ZBI_ITEM_MAGIC;
+	dest->crc32 = ZBI_ITEM_NO_CRC32;
+
+	if (length) {
+		memcpy(dest + 1, payload, length);
+	}
+	length = ZBI_ALIGN(length + sizeof(zbi_header_t));
+	container->length += length;
+}
+
+int zircon_image_check_header(const void *hdr)
+{
+	const zbi_header_t* zbi = hdr;
+printf("zircon_image_check_header zbi[0].type %08x zbi[0].extra %08x zbi[0].magic %08x zbi[1].type %08x\n",
+        zbi[0].type, zbi[0].extra, zbi[0].magic, zbi[1].type);
+
+	return (zbi[0].type == ZBI_TYPE_CONTAINER &&
+			zbi[0].extra == ZBI_CONTAINER_MAGIC &&
+			zbi[0].magic == ZBI_ITEM_MAGIC &&
+			ZBI_IS_KERNEL_BOOTITEM(zbi[1].type) &&  // TODO: change this to comparison with
+			                                        // ZBI_TYPE_KERNEL_ARM64 after zircon kernel
+			                                        // is switched over
+			zbi[1].magic == ZBI_ITEM_MAGIC) ? 0 : -1;
+}
+
+/**
+ * zircon_image_get_kernel() - processes kernel part of Zircon bootdata
+ * @bootdata:	Pointer to bootdata.
+ * @verify:		Checksum verification flag. Currently unimplemented.
+ * @os_data:	Pointer to a ulong variable, will hold os data start
+ *			address.
+ * @os_len:	Pointer to a ulong variable, will hold os data length.
+ *
+ * This function returns the os image's start address and length. Also,
+ * it appends the kernel command line to the bootargs env variable.
+ *
+ * Return: Zero, os start address and length on success,
+ *		otherwise on failure.
+ */
+int zircon_image_get_kernel(const void* hdr, int verify,
+			     ulong *os_data, ulong *os_len)
+{
+	if (zircon_image_check_header(hdr))
+		return -1;
+
+	const zbi_header_t* zbi = hdr;
+
+	*os_data = (ulong)zbi;
+	*os_len = zbi->length + sizeof(*zbi);
+	return 0;
+}
+
+ulong zircon_image_get_end(const void *hdr)
+{
+	const zbi_header_t* zbi = hdr;
+	return (ulong)hdr + zbi->length + sizeof(*zbi);
+}
+
+ulong zircon_image_get_kload(const void *hdr)
+{
+	return 0x40480000;
+}
+
+ulong zircon_image_get_comp(const void *hdr)
+{
+	return IH_COMP_NONE;
+}
diff --git a/common/image.c b/common/image.c
index 1de9017..ed55ef3 100644
--- a/common/image.c
+++ b/common/image.c
@@ -880,9 +880,10 @@
 	if (fdt_check_header(img_addr) == 0)
 		return IMAGE_FORMAT_FIT;
 #endif
-#ifdef CONFIG_FUCHSIA_BOOT_IMAGE
-	if (fuchsia_image_check_header(img_addr) == 0)
-		return IMAGE_FORMAT_FUCHSIA;
+#ifdef CONFIG_ZIRCON_BOOT_IMAGE
+	if (zircon_image_check_header(img_addr) == 0) {
+		return IMAGE_FORMAT_ZIRCON;
+	}
 #endif
 #ifdef CONFIG_ANDROID_BOOT_IMAGE
 	if (android_image_check_header(img_addr) == 0)
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 2b1bb9c..635e868 100755
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -23,8 +23,8 @@
 #include <linux/usb/gadget.h>
 #include <linux/usb/composite.h>
 #include <linux/compiler.h>
-#ifdef CONFIG_FUCHSIA_BOOT_IMAGE
-#include <fuchsia/bootdata.h>
+#ifdef CONFIG_ZIRCON_BOOT_IMAGE
+#include <zircon/image.h>
 #endif
 #include <version.h>
 #include <g_dnl.h>
@@ -1586,27 +1586,26 @@
 		/* we should use avb_part_data->data as boot image */
 		/* boot image is already read by avb */
 		hdr = (struct andr_img_hdr *)avb_loadpart->data;
+#ifdef CONFIG_ZIRCON_BOOT_IMAGE
+		if (zircon_image_check_header(hdr) == 0) {
+			printf("Found Zircon Image!!!!!\n");
+			const zbi_header_t* zbi = (zbi_header_t*) hdr;
+			printf("Load image at 0x%lx\n",zircon_image_get_kload(hdr));
+			memcpy((void *)(ulong)(zircon_image_get_kload(hdr)),
+				(void *)hdr,
+				sizeof(*zbi) + ALIGN(zbi->length, hdr->page_size));
+			char fboot_addr_start[12];
+			char *boot_args[] = { NULL, fboot_addr_start, NULL, NULL};
+			boot_args[0] = "bootm";
+			sprintf(fboot_addr_start, "0x%lx", zircon_image_get_kload(hdr));
+			do_bootm(NULL, 0, 2, boot_args);
+			/* This only happens if image is somehow faulty so we start over */
+			do_reset(NULL, 0, 0, NULL);
+		}
+#endif
 		if (android_image_check_header(hdr)) {
 			printf("boota: bad boot image magic\n");
-#ifdef CONFIG_FUCHSIA_BOOT_IMAGE
-			if (fuchsia_image_check_header(hdr) == 0) {
-				printf("Found Fuchsia Image!!!!!\n");
-				const bootdata_t* bootdata = (bootdata_t*) hdr;
-				printf("Load bootdata at 0x%lx\n",fuchsia_image_get_kload(hdr));
-				memcpy((void *)(ulong)(fuchsia_image_get_kload(hdr)),
-					(void *)hdr,
-					sizeof(*bootdata) + ALIGN(bootdata->length, hdr->page_size));
-				char fboot_addr_start[12];
-				char *boot_args[] = { NULL,fboot_addr_start, NULL, NULL};
-				boot_args[0] = "bootm";
-				sprintf(fboot_addr_start, "0x%lx", fuchsia_image_get_kload(hdr));
-				do_bootm(NULL, 0, 2, boot_args);
-				/* This only happens if image is somehow faulty so we start over */
-				do_reset(NULL, 0, 0, NULL);
-			}
-#else
 			goto fail;
-#endif
 		}
 		if (avb_result == AVB_AB_FLOW_RESULT_OK)
 			printf(" verify OK, boot '%s%s'\n",
diff --git a/include/bootm.h b/include/bootm.h
index b7fba6f..0bf0829 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -36,7 +36,7 @@
 			bootm_headers_t *images);
 
 extern boot_os_fn do_bootm_linux;
-extern boot_os_fn do_bootm_fuchsia;
+extern boot_os_fn do_bootm_zircon;
 
 int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 void lynxkdi_boot(image_header_t *hdr);
diff --git a/include/configs/imx8mq_evk_android.h b/include/configs/imx8mq_evk_android.h
index 41da7ec..84f3c7c 100644
--- a/include/configs/imx8mq_evk_android.h
+++ b/include/configs/imx8mq_evk_android.h
@@ -7,7 +7,7 @@
 #ifndef IMX8MQ_EVK_ANDROID_H
 #define IMX8MQ_EVK_ANDROID_H
 
-#define CONFIG_FUCHSIA_BOOT_IMAGE
+#define CONFIG_ZIRCON_BOOT_IMAGE
 #define CONFIG_IMX8MEVK
 
 #define CONFIG_BOOTLOADER_OFFSET_33K
diff --git a/include/fuchsia/board/imx8mevk/board-config.h b/include/fuchsia/board/imx8mevk/board-config.h
deleted file mode 100644
index 5c21ebf..0000000
--- a/include/fuchsia/board/imx8mevk/board-config.h
+++ /dev/null
@@ -1,87 +0,0 @@
-// Copyright 2018 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#define PDEV_VID_NXP                9
-#define PDEV_PID_IMX8MEVK           1
-
-const char* BOOTLOADER_VERSION = "fuchsia-bootloader=0.03";
-
-static const bootdata_cpu_config_t cpu_config = {
-    .cluster_count = 1,
-    .clusters = {
-        {
-            .cpu_count = 4,
-        },
-    },
-};
-
-static const bootdata_mem_range_t mem_config[] = {
-    {
-        .type = BOOTDATA_MEM_RANGE_RAM,
-        .paddr = 0x40000000,
-        .length = 0xc0000000, // 3GB
-    },
-    {
-        .type = BOOTDATA_MEM_RANGE_PERIPHERAL,
-        .paddr = 0,
-        .length = 0x40000000,
-    },
-};
-
-static const dcfg_simple_t uart_driver = {
-    .mmio_phys = 0x30860000,
-    .irq = 58,
-};
-
-static const dcfg_arm_gicv3_driver_t gicv3_driver = {
-    .mmio_phys = 0x38800000,
-    .gicd_offset = 0x00000,
-    .gicr_offset = 0x80000,
-    .gicr_stride = 0x20000,
-    .ipi_base = 9,
-    // Used for Errata e11171
-    .mx8_gpr_phys = 0x30340000,
-};
-
-static const dcfg_arm_psci_driver_t psci_driver = {
-    .use_hvc = false,
-};
-
-static const dcfg_arm_generic_timer_driver_t timer_driver = {
-    .irq_phys = 30,
-    .irq_virt = 27,
-    .freq_override = 8333333,
-};
-
-static const bootdata_platform_id_t platform_id = {
-    .vid = PDEV_VID_NXP,
-    .pid = PDEV_PID_IMX8MEVK,
-    .board_name = "imx8mevk",
-};
-
-static void append_board_bootdata(bootdata_t* bootdata) {
-    // add CPU configuration
-    append_bootdata(bootdata, BOOTDATA_CPU_CONFIG, 0, &cpu_config,
-                    sizeof(bootdata_cpu_config_t) +
-                    sizeof(bootdata_cpu_cluster_t) * cpu_config.cluster_count);
-
-    // add memory configuration
-    append_bootdata(bootdata, BOOTDATA_MEM_CONFIG, 0, &mem_config,
-                    sizeof(bootdata_mem_range_t) * (sizeof(mem_config)/sizeof(mem_config[0])));
-
-    // add kernel drivers
-    append_bootdata(bootdata, BOOTDATA_KERNEL_DRIVER, KDRV_NXP_IMX_UART, &uart_driver,
-                    sizeof(uart_driver));
-    append_bootdata(bootdata, BOOTDATA_KERNEL_DRIVER, KDRV_ARM_GIC_V3, &gicv3_driver,
-                    sizeof(gicv3_driver));
-    append_bootdata(bootdata, BOOTDATA_KERNEL_DRIVER, KDRV_ARM_PSCI, &psci_driver,
-                    sizeof(psci_driver));
-    append_bootdata(bootdata, BOOTDATA_KERNEL_DRIVER, KDRV_ARM_GENERIC_TIMER, &timer_driver,
-                    sizeof(timer_driver));
-
-    append_bootdata(bootdata, BOOTDATA_CMDLINE, 0, BOOTLOADER_VERSION, strlen(BOOTLOADER_VERSION) + 1);
-
-    // add platform ID
-    append_bootdata(bootdata, BOOTDATA_PLATFORM_ID, 0, &platform_id, sizeof(platform_id));
-}
diff --git a/include/fuchsia/bootdata.h b/include/fuchsia/bootdata.h
deleted file mode 100644
index 7aa791a..0000000
--- a/include/fuchsia/bootdata.h
+++ /dev/null
@@ -1,298 +0,0 @@
-/*
- * Copyright (c) 2018 The Fuchsia Authors
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef _FUCHSIA_BOOTDATA_H_
-#define _FUCHSIA_BOOTDATA_H_
-
-// lsw of sha256("bootdata")
-#define BOOTDATA_MAGIC (0x868cf7e6)
-
-// lsw of sha256("bootitem")
-#define BOOTITEM_MAGIC (0xb5781729)
-
-// Round n up to the next 8 byte boundary
-#define BOOTDATA_ALIGN(n) (((n) + 7) & (~7))
-
-#define BOOTITEM_NO_CRC32 (0x4a87e8d6)
-
-// This flag is required.
-#define BOOTDATA_FLAG_V2         (0x00010000)
-
-// Bootdata items with the CRC32 flag must have a valid crc32.
-// Otherwise their crc32 field must contain BOOTITEM_NO_CRC32
-#define BOOTDATA_FLAG_CRC32      (0x00020000)
-
-// Containers are used to wrap a set of bootdata items
-// written to a file or partition.  The "length" is the
-// length of the set of following bootdata items.  The
-// "extra" is the value BOOTDATA_MAGIC and "flags" is
-// set to 0.
-#define BOOTDATA_CONTAINER        (0x544f4f42) // BOOT
-
-// BOOTFS images.  The "extra" field is the decompressed
-// size of the image, if compressed, otherwise the same
-// as the "length" field.
-#define BOOTDATA_BOOTFS_BOOT      (0x42534642) // BFSB
-#define BOOTDATA_BOOTFS_SYSTEM    (0x53534642) // BFSS
-#define BOOTDATA_BOOTFS_DISCARD   (0x58534642) // BFSX
-
-#define BOOTDATA_BOOTFS_MASK      (0x00FFFFFF)
-#define BOOTDATA_BOOTFS_TYPE      (0x00534642) // BFS\0
-
-// Virtual disk images.  The header fields and compression protocol
-// are the same as for the BOOTFS types, but the payload before
-// compression is a raw disk image rather than BOOTFS format.
-#define BOOTDATA_RAMDISK          (0x4b534452) // RDSK
-
-// A Zircon Kernel Image
-// Content: bootdata_kernel_t
-#define BOOTDATA_KERNEL           (0x4c4e524b) // KRNL
-
-// A Zircon Partition Map
-// Content: bootdata_partition_map_t
-#define BOOTDATA_PARTITION_MAP    (0x54524150) // PART
-
-// Flag indicating that the bootfs is compressed.
-#define BOOTDATA_BOOTFS_FLAG_COMPRESSED  (1 << 0)
-
-
-// These items are for passing from bootloader to kernel
-
-// Kernel Command Line String
-// Content: uint8_t[]
-#define BOOTDATA_CMDLINE          (0x4c444d43) // CMDL
-
-// ACPI Root Table Pointer
-// Content: uint64_t phys addr
-#define BOOTDATA_ACPI_RSDP        (0x50445352) // RSDP
-
-// SMBIOS entry point pointer
-// Content: uint64_t phys addr
-#define BOOTDATA_SMBIOS           (0x49424d53) // SMBI
-
-// Framebuffer Parameters
-// Content: bootdata_swfb_t
-#define BOOTDATA_FRAMEBUFFER      (0x42465753) // SWFB
-
-// Debug Serial Port
-// Content: bootdata_uart_t
-#define BOOTDATA_DEBUG_UART       (0x54524155) // UART
-
-// Platform ID Information
-// Content: bootdata_platform_id_t
-#define BOOTDATA_PLATFORM_ID      (0x44494C50) // PLID
-
-// Memory which will persist across warm boots
-// Content bootdata_lastlog_nvram_t
-#define BOOTDATA_LASTLOG_NVRAM    (0x4c4c564e) // NVLL
-
-// This reflects a typo we need to support for a while
-#define BOOTDATA_LASTLOG_NVRAM2   (0x4c4c5643) // CVLL
-
-// E820 Memory Table
-// Content: e820entry[]
-#define BOOTDATA_E820_TABLE       (0x30323845) // E820
-
-// EFI Memory Map
-// Content: a uint64_t entrysz followed by a set of
-// efi_memory_descriptor aligned on entrysz
-#define BOOTDATA_EFI_MEMORY_MAP   (0x4d494645) // EFIM
-
-// EFI System Table
-// Content: a uint64_t physical address of the table
-#define BOOTDATA_EFI_SYSTEM_TABLE (0x53494645) // EFIS
-
-// Last crashlog
-// Content: ascii/utf8 log data from previous boot
-#define BOOTDATA_LAST_CRASHLOG    (0x4d4f4f42) // BOOM
-
-// CPU configuration
-// Content: bootdata_cpu_config_t
-#define BOOTDATA_CPU_CONFIG       (0x43555043) // CPUC
-
-// Memory configuration
-// Content: one or more of bootdata_mem_range_t (count determined by bootdata_t length)
-#define BOOTDATA_MEM_CONFIG       (0x434D454D) // MEMC
-
-// Kernel driver configuration
-// Content: driver specific struct, with type determined by bootdata "extra" field
-#define BOOTDATA_KERNEL_DRIVER    (0x5652444B) // KDRV
-
-#define BOOTDATA_IGNORE           (0x50494b53) // SKIP
-
-// BootData header, describing the type and size of data
-// used to initialize the system. All fields are little-endian.
-//
-// BootData headers in a stream must be 8-byte-aligned.
-//
-// The length field specifies the actual payload length
-// and does not include the size of padding.
-typedef struct {
-    // Boot data type
-    uint32_t type;
-
-    // Size of the payload following this header
-    uint32_t length;
-
-    // type-specific extra data
-    // For CONTAINER this is MAGIC.
-    // For BOOTFS this is the decompressed size.
-    uint32_t extra;
-
-    // Flags for the boot data. See flag descriptions for each type.
-    uint32_t flags;
-
-    // For future expansion.  Set to 0.
-    uint32_t reserved0;
-    uint32_t reserved1;
-
-    // Must be BOOTITEM_MAGIC
-    uint32_t magic;
-
-    // Must be the CRC32 of payload if FLAG_CRC32 is set,
-    // otherwise must be BOOTITEM_NO_CRC32
-    uint32_t crc32;
-} bootdata_t;
-
-typedef struct {
-    uint64_t base; // physical base addr
-    uint32_t width;
-    uint32_t height;
-    uint32_t stride;
-    uint32_t format;
-} bootdata_swfb_t;
-
-typedef struct {
-    uint64_t entry64;
-    uint64_t reserved;
-} bootdata_kernel_t;
-
-typedef struct {
-    bootdata_t hdr_file;
-    bootdata_t hdr_kernel;
-    bootdata_kernel_t data_kernel;
-} zircon_kernel_t;
-
-#define BOOTDATA_PART_NAME_LEN 32
-#define BOOTDATA_PART_GUID_LEN 16
-
-typedef struct {
-    uint8_t type_guid[BOOTDATA_PART_GUID_LEN];
-    uint8_t uniq_guid[BOOTDATA_PART_GUID_LEN];
-    uint64_t first_block;
-    uint64_t last_block;
-    uint64_t flags;
-    char name[BOOTDATA_PART_NAME_LEN];
-} bootdata_partition_t;
-
-typedef struct {
-    uint64_t block_count;
-    uint64_t block_size;
-    // pdev_vid/pid/did are used to match partition map to
-    // appropriate block device on the platform bus
-    uint32_t pdev_vid;
-    uint32_t pdev_pid;
-    uint32_t pdev_did;
-    uint32_t partition_count;
-    char guid[BOOTDATA_PART_GUID_LEN];
-    bootdata_partition_t partitions[];
-} bootdata_partition_map_t;
-
-typedef struct {
-    uint64_t base;
-    uint64_t length;
-} bootdata_nvram_t;
-
-#define BOOTDATA_UART_NONE 0
-#define BOOTDATA_UART_PC_PORT 1
-#define BOOTDATA_UART_PC_MMIO 2
-typedef struct {
-    uint64_t base;
-    uint32_t type;
-    uint32_t irq;
-} bootdata_uart_t;
-
-typedef struct {
-    uint32_t vid;
-    uint32_t pid;
-    char board_name[32];
-} bootdata_platform_id_t;
-
-typedef struct {
-    uint32_t cpu_count;     // number of CPU cores in the cluster
-    uint32_t type;          // for future use
-    uint32_t flags;         // for future use
-    uint32_t reserved;
-} bootdata_cpu_cluster_t;
-
-typedef struct {
-    uint32_t cluster_count;
-    uint32_t reserved[3];
-    bootdata_cpu_cluster_t clusters[];
-} bootdata_cpu_config_t;
-
-#define BOOTDATA_MEM_RANGE_RAM          1
-#define BOOTDATA_MEM_RANGE_PERIPHERAL   2
-#define BOOTDATA_MEM_RANGE_RESERVED     3
-typedef struct {
-    uint64_t    paddr;
-    uint64_t    length;
-    uint32_t    type;
-    uint32_t    reserved;
-} bootdata_mem_range_t;
-
-/* EFI Variable for Crash Log */
-#define ZIRCON_VENDOR_GUID \
-    {0x82305eb2, 0xd39e, 0x4575, {0xa0, 0xc8, 0x6c, 0x20, 0x72, 0xd0, 0x84, 0x4c}}
-#define ZIRCON_CRASHLOG_EFIVAR \
-    { 'c', 'r', 'a', 's', 'h', 'l', 'o', 'g', 0 };
-#define ZIRCON_CRASHLOG_EFIATTR \
-    (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS)
-
-
-// BOOTFS is a trivial "filesystem" format
-//
-// It consists of a bootfs_header_t
-//
-// Followed by a series of bootfs_entry_t's of:
-//   name length (32bit le)
-//   data size   (32bit le)
-//   data offset (32bit le)
-//   namedata   (namelength bytes, includes \0)
-//
-// - data offsets must be page aligned (multiple of 4096)
-// - entries start on uint32 boundaries
-
-//lsw of sha256("bootfs")
-#define BOOTFS_MAGIC (0xa56d3ff9)
-
-#define BOOTFS_MAX_NAME_LEN 256
-
-typedef struct bootfs_header {
-    // magic value BOOTFS_MAGIC
-    uint32_t magic;
-
-    // total size of all bootfs_entry_t's
-    // does not include the size of the bootfs_header_t
-    uint32_t dirsize;
-
-    // 0, 0
-    uint32_t reserved0;
-    uint32_t reserved1;
-} bootfs_header_t;
-
-typedef struct bootfs_entry {
-    uint32_t name_len;
-    uint32_t data_len;
-    uint32_t data_off;
-    char name[];
-} bootfs_entry_t;
-
-#define BOOTFS_ALIGN(nlen) (((nlen) + 3) & (~3))
-#define BOOTFS_RECSIZE(entry) \
-    (sizeof(bootfs_entry_t) + BOOTFS_ALIGN(entry->name_len))
-
-#endif
\ No newline at end of file
diff --git a/include/image.h b/include/image.h
index d5d12e1..9b24527 100644
--- a/include/image.h
+++ b/include/image.h
@@ -160,7 +160,7 @@
 	IH_OS_OSE,			/* OSE		*/
 	IH_OS_PLAN9,			/* Plan 9	*/
 	IH_OS_OPENRTOS,		/* OpenRTOS	*/
-	IH_OS_FUCHSIA,		/* Fuchsia	*/
+	IH_OS_ZIRCON,		/* Zircon	*/
 
 	IH_OS_COUNT,
 };
@@ -559,7 +559,7 @@
 #endif
 #define IMAGE_FORMAT_FIT	0x02	/* new, libfdt based format */
 #define IMAGE_FORMAT_ANDROID	0x03	/* Android boot image */
-#define IMAGE_FORMAT_FUCHSIA	0x04	/* Fuchsia boot image */
+#define IMAGE_FORMAT_ZIRCON	0x04	/* Zircon boot image */
 
 ulong genimg_get_kernel_addr_fit(char * const img_addr,
 			         const char **fit_uname_config,
@@ -1331,14 +1331,14 @@
 		.handler = _handler, \
 	}
 
-#if defined(CONFIG_FUCHSIA_BOOT_IMAGE)
+#if defined(CONFIG_ZIRCON_BOOT_IMAGE)
 struct andr_img_hdr;
-int fuchsia_image_check_header(const void *hdr);
-int fuchsia_image_get_kernel(const void* hdr, int verify,
+int zircon_image_check_header(const void *hdr);
+int zircon_image_get_kernel(const void* hdr, int verify,
 			     ulong *os_data, ulong *os_len);
-ulong fuchsia_image_get_end(const void *hdr);
-ulong fuchsia_image_get_kload(const void *hdr);
-ulong fuchsia_image_get_comp(const void *hdr);
-#endif /* CONFIG_FUCHSIA_BOOT_IMAGE */
+ulong zircon_image_get_end(const void *hdr);
+ulong zircon_image_get_kload(const void *hdr);
+ulong zircon_image_get_comp(const void *hdr);
+#endif /* CONFIG_ZIRCON_BOOT_IMAGE */
 
 #endif	/* __IMAGE_H__ */
diff --git a/include/fuchsia/driver-config.h b/include/zircon/driver-config.h
similarity index 97%
rename from include/fuchsia/driver-config.h
rename to include/zircon/driver-config.h
index 1a79267..b3bf01c 100644
--- a/include/fuchsia/driver-config.h
+++ b/include/zircon/driver-config.h
@@ -28,6 +28,7 @@
     uint64_t shutdown_args[3];
     uint64_t reboot_args[3];
     uint64_t reboot_bootloader_args[3];
+    uint64_t reboot_recovery_args[3];
 } dcfg_arm_psci_driver_t;
 
 // for KDRV_ARM_GIC_V2
@@ -73,4 +74,4 @@
     uint64_t preset_phys;
     uint64_t hiu_phys;
     uint64_t hdmitx_phys;
-} dcfg_amlogic_hdcp_driver_t;
\ No newline at end of file
+} dcfg_amlogic_hdcp_driver_t;
diff --git a/include/zircon/gpt.h b/include/zircon/gpt.h
new file mode 100644
index 0000000..4d0a1aa
--- /dev/null
+++ b/include/zircon/gpt.h
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2018 The Fuchsia Authors
+ *
+ * SPDX-License-Identifier:	BSD-3-Clause
+ */
+
+#ifndef _ZIRCON_GPT_H_
+#define _ZIRCON_GPT_H_
+
+// GUID for a system partition
+#define GUID_SYSTEM_STRING "606B000B-B7C7-4653-A7D5-B737332C899D"
+#define GUID_SYSTEM_VALUE {                        \
+    0x0b, 0x00, 0x6b, 0x60,                        \
+    0xc7, 0xb7,                                    \
+    0x53, 0x46,                                    \
+    0xa7, 0xd5, 0xb7, 0x37, 0x33, 0x2c, 0x89, 0x9d \
+}
+
+// GUID for a data partition
+#define GUID_DATA_STRING "08185F0C-892D-428A-A789-DBEEC8F55E6A"
+#define GUID_DATA_VALUE {                          \
+    0x0c, 0x5f, 0x18, 0x08,                        \
+    0x2d, 0x89,                                    \
+    0x8a, 0x42,                                    \
+    0xa7, 0x89, 0xdb, 0xee, 0xc8, 0xf5, 0x5e, 0x6a \
+}
+
+// GUID for a installer partition
+#define GUID_INSTALL_STRING "48435546-4953-2041-494E-5354414C4C52"
+#define GUID_INSTALL_VALUE {                       \
+    0x46, 0x55, 0x43, 0x48,                        \
+    0x53, 0x49,                                    \
+    0x41, 0x20,                                    \
+    0x49, 0x4E, 0x53, 0x54, 0x41, 0x4C, 0x4C, 0x52 \
+}
+
+#define GUID_BLOB_STRING "2967380E-134C-4CBB-B6DA-17E7CE1CA45D"
+#define GUID_BLOB_VALUE {                          \
+    0x0e, 0x38, 0x67, 0x29,                        \
+    0x4c, 0x13,                                    \
+    0xbb, 0x4c,                                    \
+    0xb6, 0xda, 0x17, 0xe7, 0xce, 0x1c, 0xa4, 0x5d \
+}
+
+#define GUID_FVM_STRING "41D0E340-57E3-954E-8C1E-17ECAC44CFF5"
+#define GUID_FVM_VALUE {                           \
+    0x40, 0xe3, 0xd0, 0x41,                        \
+    0xe3, 0x57,                                    \
+    0x4e, 0x95,                                    \
+    0x8c, 0x1e, 0x17, 0xec, 0xac, 0x44, 0xcf, 0xf5 \
+}
+
+#define GUID_ZIRCON_A_STRING "DE30CC86-1F4A-4A31-93C4-66F147D33E05"
+#define GUID_ZIRCON_A_VALUE { \
+    0x86, 0xcc, 0x30, 0xde, \
+    0x4a, 0x1f, \
+    0x31, 0x4a, \
+    0x93, 0xc4, 0x66, 0xf1, 0x47, 0xd3, 0x3e, 0x05, \
+}
+
+#define GUID_ZIRCON_B_STRING "23CC04DF-C278-4CE7-8471-897D1A4BCDF7"
+#define GUID_ZIRCON_B_VALUE { \
+    0xdf, 0x04, 0xcc, 0x23, \
+    0x78, 0xc2, \
+    0xe7, 0x4c, \
+    0x84, 0x71, 0x89, 0x7d, 0x1a, 0x4b, 0xcd, 0xf7 \
+}
+
+#define GUID_ZIRCON_R_STRING "A0E5CF57-2DEF-46BE-A80C-A2067C37CD49"
+#define GUID_ZIRCON_R_VALUE { \
+    0x57, 0xcf, 0xe5, 0xa0, \
+    0xef, 0x2d, \
+    0xbe, 0x46, \
+    0xa8, 0x0c, 0xa2, 0x06, 0x7c, 0x37, 0xcd, 0x49 \
+}
+
+#define GUID_SYS_CONFIG_STRING "4E5E989E-4C86-11E8-A15B-480FCF35F8E6"
+#define GUID_SYS_CONFIG_VALUE { \
+    0x9e, 0x98, 0x5e, 0x4e,                        \
+    0x86, 0x4c,                                    \
+    0xe8, 0x11,                                    \
+    0xa1, 0x5b, 0x48, 0x0f, 0xcf, 0x35, 0xf8, 0xe6 \
+}
+
+#define GUID_FACTORY_CONFIG_STRING "5A3A90BE-4C86-11E8-A15B-480FCF35F8E6"
+#define GUID_FACTORY_CONFIG_VALUE { \
+    0xbe, 0x90, 0x3a, 0x5a,                        \
+    0x86, 0x4c,                                    \
+    0xe8, 0x11,                                    \
+    0xa1, 0x5b, 0x48, 0x0f, 0xcf, 0x35, 0xf8, 0xe6 \
+}
+
+#define GUID_BOOTLOADER_STRING "5ECE94FE-4C86-11E8-A15B-480FCF35F8E6"
+#define GUID_BOOTLOADER_VALUE { \
+    0xfe, 0x94, 0xce, 0x5e,                        \
+    0x86, 0x4c,                                    \
+    0xe8, 0x11,                                    \
+    0xa1, 0x5b, 0x48, 0x0f, 0xcf, 0x35, 0xf8, 0xe6 \
+}
+
+#endif /* _ZIRCON_GPT_H_ */
diff --git a/include/zircon/image.h b/include/zircon/image.h
new file mode 100644
index 0000000..48ed84b
--- /dev/null
+++ b/include/zircon/image.h
@@ -0,0 +1,478 @@
+/*
+ * Copyright (c) 2018 The Fuchsia Authors
+ *
+ * SPDX-License-Identifier:	BSD-3-Clause
+ */
+
+#ifndef _ZIRCON_IMAGE_H_
+#define _ZIRCON_IMAGE_H_
+
+// Zircon Boot Image format (ZBI).
+//
+// A Zircon Boot Image consists of a container header followed by boot
+// items.  Each boot item has a header (zbi_header_t) and then a payload of
+// zbi_header_t.length bytes, which can be any size.  The zbi_header_t.type
+// field indicates how to interpret the payload.  Many types specify an
+// additional type-specific header that begins a variable-sized payload.
+// zbi_header_t.length does not include the zbi_header_t itself, but does
+// include any type-specific headers as part of the payload.  All fields in
+// all header formats are little-endian.
+//
+// Padding bytes appear after each item as needed to align the payload size
+// up to a ZBI_ALIGNMENT (8-byte) boundary.  This padding is not reflected
+// in the zbi_header_t.length value.
+//
+// A "complete" ZBI can be booted by a Zircon-compatible boot loader.
+// It contains one ZBI_TYPE_KERNEL_{ARCH} boot item that must come first,
+// followed by any number of additional boot items, which must include
+// exactly one ZBI_TYPE_STORAGE_BOOTFS item.
+//
+// A partial ZBI cannot be booted, and is only used during the build process.
+// It contains one or more boot items and can be combined with other ZBIs to
+// make a complete ZBI.
+
+// All items begin at an 8-byte aligned offset into the image.
+#define ZBI_ALIGNMENT           (8)
+
+// Round n up to the next 8 byte boundary
+#define ZBI_ALIGN(n)            (((n) + ZBI_ALIGNMENT - 1) & -ZBI_ALIGNMENT)
+
+// LSW of sha256("bootdata")
+#define ZBI_CONTAINER_MAGIC     (0x868cf7e6)
+
+// LSW of sha256("bootitem")
+#define ZBI_ITEM_MAGIC          (0xb5781729)
+
+// This flag is always required.
+#define ZBI_FLAG_VERSION        (0x00010000)
+
+// ZBI items with the CRC32 flag must have a valid crc32.
+// Otherwise their crc32 field must contain ZBI_ITEM_NO_CRC32
+#define ZBI_FLAG_CRC32          (0x00020000)
+
+// Value for zbi_header_t.crc32 when ZBI_FLAG_CRC32 is not set.
+#define ZBI_ITEM_NO_CRC32       (0x4a87e8d6)
+
+#ifndef __ASSEMBLER__
+// Each header must be 8-byte aligned.  The length field specifies the
+// actual payload length and does not include the size of padding.
+typedef struct {
+    // ZBI_TYPE_* constant, see below.
+    uint32_t type;
+
+    // Size of the payload immediately following this header.  This
+    // does not include the header itself nor any alignment padding
+    // after the payload.
+    uint32_t length;
+
+    // Type-specific extra data.  Each type specifies the use of this
+    // field; see below.  When not explicitly specified, it should be zero.
+    uint32_t extra;
+
+    // Flags for this item.  This must always include ZBI_FLAG_VERSION.
+    // It should contain ZBI_FLAG_CRC32 for any item where it's feasible
+    // to compute the CRC32 at build time.  Other flags are specific to
+    // each type; see below.
+    uint32_t flags;
+
+    // For future expansion.  Set to 0.
+    uint32_t reserved0;
+    uint32_t reserved1;
+
+    // Must be ZBI_ITEM_MAGIC.
+    uint32_t magic;
+
+    // Must be the CRC32 of payload if ZBI_FLAG_CRC32 is set,
+    // otherwise must be ZBI_ITEM_NO_CRC32.
+    uint32_t crc32;
+} zbi_header_t;
+#endif
+
+// Each ZBI starts with a container header.
+//     length:          Total size of the image after this header.
+//                      This includes all item headers, payloads, and padding.
+//                      It does not include the container header itself.
+//                      Must be a multiple of ZBI_ALIGNMENT.
+//     extra:           Must be ZBI_CONTAINER_MAGIC.
+//     flags:           Must be ZBI_FLAG_VERSION and no other flags.
+#define ZBI_TYPE_CONTAINER      (0x544f4f42) // BOOT
+
+// Define a container header in assembly code.  The symbol name is defined
+// as a local label; use .global symbol to make it global.  The length
+// argument can use assembly label arithmetic like any immediate operand.
+#ifdef __ASSEMBLER__
+#define ZBI_CONTAINER_HEADER(symbol, length)    \
+    .balign ZBI_ALIGNMENT;                      \
+    symbol:                                     \
+        .int ZBI_TYPE_CONTAINER;                \
+        .int (length);                          \
+        .int ZBI_CONTAINER_MAGIC;               \
+        .int ZBI_FLAG_VERSION;                  \
+        .int 0;                                 \
+        .int 0;                                 \
+        .int ZBI_ITEM_MAGIC;                    \
+        .int ZBI_ITEM_NO_CRC32;                 \
+    .size symbol, . - symbol;                   \
+    .type symbol, %object
+#endif
+
+
+// The kernel image.  In a complete ZBI this item must always be first,
+// immediately after the ZBI_TYPE_CONTAINER header.  The contiguous memory
+// image of the kernel is formed from the ZBI_TYPE_CONTAINER header, the
+// ZBI_TYPE_KERNEL_{ARCH} header, and the payload.
+//
+// The boot loader loads the whole image starting with the container header
+// through to the end of the kernel item's payload into contiguous physical
+// memory.  It then constructs a partial ZBI elsewhere in memory, which has
+// a ZBI_TYPE_CONTAINER header of its own followed by all the other items
+// that were in the booted ZBI plus other items synthesized by the boot
+// loader to describe the machine.  The precise protocol for transferring
+// control to the kernel's entry point varies by machine.
+//
+// TODO(mcgrathr): On all machines, the kernel requires some amount of
+// scratch memory to be available immediately after the kernel image at
+// boot.  It needs this space for early setup work before it has a chance
+// to read any memory-map information from the boot loader.  Currently, the
+// kernel simply assumes that enough space is available and clobbers some
+// memory after its load image.  (In zircon-image.elf, the IMAGE_RESERVE_END
+// symbol indicates the end of the address range that will be clobbered.)
+// If the boot loader happened to place its constructed ZBI or other reserved
+// areas immediately after the kernel image, things would go badly.
+// We should amend the protocol with the boot loader so that it knows how
+// much space to reserve after the kernel image.  Either zbi_header_t.extra
+// or zbi_kernel_t.reserved could be repurposed for this.
+//
+// x86-64
+//
+//     The kernel assumes it was loaded at a fixed physical address of
+//     0x100000 (1MB).  zbi_kernel_t.entry is the absolute physical address
+//     of the PC location where the kernel will start.
+//     TODO(SEC-31): Perhaps this will change??
+//     The processor is in 64-bit mode with direct virtual to physical
+//     mapping covering the physical memory where the kernel and
+//     bootloader-constructed ZBI were loaded, which must be below 4GB.
+//     The %rbx register (or %ebx, since the high 32 bits must be zero)
+//     holds the physical address of the bootloader-constructed ZBI.
+//     All other registers are unspecified.
+//
+//  ARM64
+//
+//     zbi_kernel_t.entry is an offset from the beginning of the image
+//     (i.e., the ZBI_TYPE_CONTAINER header before the ZBI_TYPE_KERNEL_ARM64
+//     header) to the PC location in the image where the kernel will
+//     start.  The processor is in physical address mode at EL1 or
+//     above.  The kernel image and the bootloader-constructed ZBI each
+//     can be loaded anywhere in physical memory.  The x0 register
+//     holds the physical address of the bootloader-constructed ZBI.
+//     All other registers are unspecified.
+//
+#define ZBI_TYPE_KERNEL_PREFIX     (0x004e524b) // KRN\0
+#define ZBI_TYPE_KERNEL_MASK       (0x00FFFFFF)
+#define ZBI_TYPE_KERNEL_X64        (0x4c4e524b) // KRNL
+#define ZBI_TYPE_KERNEL_ARM64      (0x384e524b) // KRN8
+#define ZBI_IS_KERNEL_BOOTITEM(x)  (((x) & ZBI_TYPE_KERNEL_MASK) ==  \
+                                    ZBI_TYPE_KERNEL_PREFIX)
+
+#ifndef __ASSEMBLER__
+typedef struct {
+    // Entry-point address.  The interpretation of this differs by machine.
+    uint64_t entry;
+    // Reserved for future use.
+    uint64_t reserved;
+} zbi_kernel_t;
+
+// The whole contiguous image loaded into memory by the boot loader.
+typedef struct {
+    zbi_header_t hdr_file;
+    zbi_header_t hdr_kernel;
+    zbi_kernel_t data_kernel;
+    // Some unspecified amount of available memory follows.
+    // TODO(mcgrathr): Make it hdr_kernel.extra bytes?
+    uint8_t reserved[];
+} zircon_kernel_t;
+#endif
+
+
+// A discarded item that should just be ignored.  This is used for an
+// item that was already processed and should be ignored by whatever
+// stage is now looking at the ZBI.  An earlier stage already "consumed"
+// this information, but avoided copying data around to remove it from
+// the ZBI item stream.
+#define ZBI_TYPE_DISCARD        (0x50494b53) // SKIP
+
+
+// ZBI_TYPE_STORAGE_* types represent an image that might otherwise
+// appear on some block storage device, i.e. a RAM disk of some sort.
+// All zbi_header_t fields have the same meanings for all these types.
+// The interpretation of the payload (after possible decompression) is
+// indicated by the specific zbi_header_t.type value.
+//
+// If ZBI_FLAG_STORAGE_COMPRESSED is set in zbi_header_t.flags, then the
+// payload is compressed with LZ4 and zbi_header_t.extra gives the exact
+// size of the decompressed payload.  If ZBI_FLAG_STORAGE_COMPRESSED is
+// not set, then zbi_header_t.extra matches zbi_header_t.length.
+//
+// TODO(mcgrathr): Document or point to the details of the LZ4 header format.
+#define ZBI_FLAG_STORAGE_COMPRESSED     (0x00000001)
+
+// A virtual disk image.  This is meant to be treated as if it were a
+// storage device.  The payload (after decompression) is the contents of
+// the storage device, in whatever format that might be.
+#define ZBI_TYPE_STORAGE_RAMDISK        (0x4b534452) // RDSK
+
+// The /boot filesystem in BOOTFS format, specified below.
+// A complete ZBI must have exactly one ZBI_TYPE_STORAGE_BOOTFS item.
+// Zircon [userboot](../../../../docs/userboot.md) handles the contents
+// of this filesystem.
+#define ZBI_TYPE_STORAGE_BOOTFS         (0x42534642) // BFSB
+
+// The payload (after decompression) of an item in BOOTFS format consists
+// of separate "file" images that are each aligned to ZBI_BOOTFS_PAGE_SIZE
+// bytes from the beginning of the item payload.  The first "file" consists
+// of a zbi_bootfs_header_t followed by directory entries.
+#define ZBI_BOOTFS_PAGE_SIZE            (4096u)
+
+#define ZBI_BOOTFS_PAGE_ALIGN(size) \
+    (((size) + ZBI_BOOTFS_PAGE_SIZE - 1) & -ZBI_BOOTFS_PAGE_SIZE)
+
+#ifndef __ASSEMBLER__
+typedef struct {
+    // Must be ZBI_BOOTFS_MAGIC.
+    uint32_t magic;
+
+    // Size in bytes of all the directory entries.
+    // Does not include the size of the zbi_bootfs_header_t.
+    uint32_t dirsize;
+
+    // Reserved for future use.  Set to 0.
+    uint32_t reserved0;
+    uint32_t reserved1;
+} zbi_bootfs_header_t;
+#endif
+
+// LSW of sha256("bootfs")
+#define ZBI_BOOTFS_MAGIC                (0xa56d3ff9)
+
+// Each directory entry holds a pathname and gives the offset and size
+// of the contents of the file by that name.
+#ifndef __ASSEMBLER__
+typedef struct {
+    // Length of the name[] field at the end.  This length includes the
+    // NUL terminator, which must be present, but does not include any
+    // alignment padding required before the next directory entry.
+    uint32_t name_len;
+
+    // Length of the file in bytes.  This is an exact size that is not
+    // rounded, though the file is always padded with zeros up to a
+    // multiple of ZBI_BOOTFS_PAGE_SIZE.
+    uint32_t data_len;
+
+    // Offset from the beginning of the payload (zbi_bootfs_header_t) to
+    // the file's data.  This must be a multiple of ZBI_BOOTFS_PAGE_SIZE.
+    uint32_t data_off;
+
+    // Pathname of the file, a UTF-8 string.  This must include a NUL
+    // terminator at the end.  It must not begin with a '/', but it may
+    // contain '/' separators for subdirectories.
+    char name[];
+} zbi_bootfs_dirent_t;
+#endif
+
+// Each directory entry has a variable size of [16,268] bytes that
+// must be a multiple of 4 bytes.
+#define ZBI_BOOTFS_DIRENT_SIZE(name_len) \
+    ((sizeof(zbi_bootfs_dirent_t) + (name_len) + 3) & -(size_t)4)
+
+// zbi_bootfs_dirent_t.name_len must be > 1 and <= ZBI_BOOTFS_MAX_NAME_LEN.
+#define ZBI_BOOTFS_MAX_NAME_LEN         (256)
+
+
+// The remaining types are used to communicate information from the boot
+// loader to the kernel.  Usually these are synthesized in memory by the
+// boot loader, but they can also be included in a ZBI along with the
+// kernel and BOOTFS.  Some boot loaders may set the zbi_header_t flags
+// and crc32 fields to zero, though setting them to ZBI_FLAG_VERSION and
+// ZBI_ITEM_NO_CRC32 is specified.  The kernel doesn't check.
+
+
+// A kernel command line fragment, a NUL-terminated UTF-8 string.
+// Multiple ZBI_TYPE_CMDLINE items can appear.  They are treated as if
+// concatented with ' ' between each item, in the order they appear:
+// first items in the complete ZBI containing the kernel; then items in
+// the ZBI synthesized by the boot loader.  The kernel interprets the
+// [whole command line](../../../../docs/kernel_cmdline.md).
+#define ZBI_TYPE_CMDLINE                (0x4c444d43) // CMDL
+
+// The crash log from the previous boot, a UTF-8 string.
+#define ZBI_TYPE_CRASHLOG               (0x4d4f4f42) // BOOM
+
+// Physical memory region that will persist across warm boots.
+// zbi_nvram_t gives the physical base address and length in bytes.
+#define ZBI_TYPE_NVRAM                  (0x4c4c564e) // NVLL
+// This reflects a typo we need to support for a while.
+#define ZBI_TYPE_NVRAM_DEPRECATED       (0x4c4c5643) // CVLL
+#ifndef __ASSEMBLER__
+typedef struct {
+    uint64_t base;
+    uint64_t length;
+} zbi_nvram_t;
+#endif
+
+// Platform ID Information.
+#define ZBI_TYPE_PLATFORM_ID            (0x44494C50) // PLID
+#ifndef __ASSEMBLER__
+typedef struct {
+    uint32_t vid;
+    uint32_t pid;
+    char board_name[32];
+} zbi_platform_id_t;
+#endif
+
+// CPU configuration, a zbi_cpu_config_t header followed by one or more
+// zbi_cpu_cluster_t entries.  zbi_header_t.length must equal
+// zbi_cpu_config_t.cluster_count * sizeof(zbi_cpu_cluster_t).
+#define ZBI_TYPE_CPU_CONFIG             (0x43555043) // CPUC
+#ifndef __ASSEMBLER__
+typedef struct {
+    // Number of CPU cores in the cluster.
+    uint32_t cpu_count;
+
+    // Reserved for future use.  Set to 0.
+    uint32_t type;
+    uint32_t flags;
+    uint32_t reserved;
+} zbi_cpu_cluster_t;
+
+typedef struct {
+    // Number of zbi_cpu_cluster_t entries following this header.
+    uint32_t cluster_count;
+
+    // Reserved for future use.  Set to 0.
+    uint32_t reserved[3];
+
+    // cluster_count entries follow.
+    zbi_cpu_cluster_t clusters[];
+} zbi_cpu_config_t;
+#endif
+
+// Memory configuration, one or more zbi_mem_range_t entries.
+// zbi_header_t.length is sizeof(zbi_mem_range_t) times the number of entries.
+#define ZBI_TYPE_MEM_CONFIG             (0x434D454D) // MEMC
+#ifndef __ASSEMBLER__
+typedef struct {
+    uint64_t    paddr;
+    uint64_t    length;
+    uint32_t    type;
+    uint32_t    reserved;
+} zbi_mem_range_t;
+#endif
+#define ZBI_MEM_RANGE_RAM               (1)
+#define ZBI_MEM_RANGE_PERIPHERAL        (2)
+#define ZBI_MEM_RANGE_RESERVED          (3)
+
+// Kernel driver configuration.  The zbi_header_t.extra field gives a
+// KDRV_* type that determines the payload format.
+// See [driver-config.h](<zircon/boot/driver-config.h>) for details.
+#define ZBI_TYPE_KERNEL_DRIVER          (0x5652444B) // KDRV
+
+// ACPI Root Table Pointer, a uint64_t physical address.
+#define ZBI_TYPE_ACPI_RSDP              (0x50445352) // RSDP
+
+// SMBIOS entry point, a uint64_t physical address.
+#define ZBI_TYPE_SMBIOS                 (0x49424d53) // SMBI
+
+// EFI memory map, a uint64_t entry size followed by a sequence of
+// EFI memory descriptors aligned on that entry size.
+#define ZBI_TYPE_EFI_MEMORY_MAP         (0x4d494645) // EFIM
+
+// EFI system table, a uint64_t physical address.
+#define ZBI_TYPE_EFI_SYSTEM_TABLE       (0x53494645) // EFIS
+
+// E820 memory table, an array of e820entry_t.
+#define ZBI_TYPE_E820_TABLE             (0x30323845) // E820
+
+// Debug serial port, a zbi_uart_t entry.
+#define ZBI_TYPE_DEBUG_UART             (0x54524155) // UART
+#ifndef __ASSEMBLER__
+typedef struct {
+    uint64_t base;
+    uint32_t type;
+    uint32_t irq;
+} zbi_uart_t;
+#endif
+#define ZBI_UART_NONE                   (0)
+#define ZBI_UART_PC_PORT                (1)
+#define ZBI_UART_PC_MMIO                (2)
+
+// Framebuffer parameters, a zbi_swfb_t entry.
+#define ZBI_TYPE_FRAMEBUFFER            (0x42465753) // SWFB
+#ifndef __ASSEMBLER__
+typedef struct {
+    // Physical memory address.
+    uint64_t base;
+
+    // Pixel layout and format.
+    // See [../pixelformat.h](<zircon/pixelformat.h>).
+    uint32_t width;
+    uint32_t height;
+    uint32_t stride;
+    uint32_t format;
+} zbi_swfb_t;
+#endif
+
+
+// ZBI_TYPE_DRV_* types (LSB is 'm') contain driver metadata.
+#define ZBI_TYPE_DRV_METADATA(type)     (((type) & 0xFF) == 0x6D) // 'm'
+
+// MAC address for Ethernet, Wifi, Bluetooth, etc.  zbi_header_t.extra
+// is a board-specific index to specify which device the MAC address
+// applies to.  zbi_header_t.length gives the size in bytes, which
+// varies depending on the type of address appropriate for the device.
+#define ZBI_TYPE_DRV_MAC_ADDRESS        (0x43414D6D) // mMAC
+
+// A partition map for a storage device, a zbi_partition_map_t header
+// followed by one or more zbi_partition_t entries.  zbi_header_t.extra
+// is a board-specific index to specify which device this applies to.
+#define ZBI_TYPE_DRV_PARTITION_MAP      (0x5452506D) // mPRT
+#define ZBI_PARTITION_NAME_LEN          (32)
+#define ZBI_PARTITION_GUID_LEN          (16)
+#ifndef __ASSEMBLER__
+typedef struct {
+    // GUID specifying the format and use of data stored in the partition.
+    uint8_t type_guid[ZBI_PARTITION_GUID_LEN];
+
+    // GUID unique to this partition.
+    uint8_t uniq_guid[ZBI_PARTITION_GUID_LEN];
+
+    // First and last block occupied by this partition.
+    uint64_t first_block;
+    uint64_t last_block;
+
+    // Reserved for future use.  Set to 0.
+    uint64_t flags;
+
+    char name[ZBI_PARTITION_NAME_LEN];
+} zbi_partition_t;
+
+typedef struct {
+    // Total blocks used on the device.
+    uint64_t block_count;
+    // Size of each block in bytes.
+    uint64_t block_size;
+
+    // Number of partitions in the map.
+    uint32_t partition_count;
+
+    // Reserved for future use.
+    uint32_t reserved;
+
+    // Device GUID.
+    uint8_t guid[ZBI_PARTITION_GUID_LEN];
+
+    // parition_count partition entries follow.
+    zbi_partition_t partitions[];
+} zbi_partition_map_t;
+#endif
+
+#endif // _ZIRCON_IMAGE_H_
diff --git a/include/zircon/zircon.h b/include/zircon/zircon.h
new file mode 100644
index 0000000..fb42320
--- /dev/null
+++ b/include/zircon/zircon.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2018 The Fuchsia Authors
+ *
+ * SPDX-License-Identifier:	BSD-3-Clause
+ */
+
+#ifndef _ZIRCON_ZIRCON_H_
+#define _ZIRCON_ZIRCON_H_
+
+#include <compiler.h>
+#include <zircon/image.h>
+#include <zircon/driver-config.h>
+#include <zircon/gpt.h>
+
+/* called before booting to allow board specific additions to the bootdata */
+int zircon_preboot(zbi_header_t* zbi);
+
+void zircon_append_boot_item(zbi_header_t* container, uint32_t type, uint32_t extra,
+                             const void* payload, uint32_t length);
+
+#endif
diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt
index 07bddd9..ae9b520 100644
--- a/scripts/config_whitelist.txt
+++ b/scripts/config_whitelist.txt
@@ -1281,7 +1281,7 @@
 CONFIG_FTUART010_03_BASE
 CONFIG_FTWDT010_BASE
 CONFIG_FTWDT010_WATCHDOG
-CONFIG_FUCHSIA_BOOT_IMAGE
+CONFIG_ZIRCON_BOOT_IMAGE
 CONFIG_FUNC_ISRAM_ADDR
 CONFIG_FWUPDATE_DEBUG
 CONFIG_FZOTG266HD0A_BASE