1 // Copyright 2016 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #pragma once 6 7 #include <stddef.h> 8 #include <stdint.h> 9 10 // clang-format off 11 12 #define BOOTLOADER_VERSION "0.7.13" 13 14 #define NB_MAGIC 0xAA774217 15 #define NB_DEBUGLOG_MAGIC 0xAEAE1123 16 17 #define NB_SERVER_PORT 33330 18 #define NB_ADVERT_PORT 33331 19 #define NB_CMD_PORT_START 33332 20 #define NB_CMD_PORT_END 33339 21 #define NB_TFTP_OUTGOING_PORT 33340 22 #define NB_TFTP_INCOMING_PORT 33341 23 24 25 #define NB_COMMAND 1 // arg=0, data=command 26 #define NB_SEND_FILE 2 // arg=size, data=filename 27 #define NB_DATA 3 // arg=offset, data=data 28 #define NB_BOOT 4 // arg=0 29 #define NB_QUERY 5 // arg=0, data=hostname (or "*") 30 #define NB_SHELL_CMD 6 // arg=0, data=command string 31 #define NB_OPEN 7 // arg=O_RDONLY|O_WRONLY, data=filename 32 #define NB_READ 8 // arg=blocknum 33 #define NB_WRITE 9 // arg=blocknum, data=data 34 #define NB_CLOSE 10 // arg=0 35 #define NB_LAST_DATA 11 // arg=offset, data=data 36 #define NB_REBOOT 12 // arg=0 37 38 #define NB_ACK 0 // arg=0 or -err, NB_READ: data=data 39 #define NB_FILE_RECEIVED 0x70000001 // arg=size 40 41 #define NB_ADVERTISE 0x77777777 42 43 #define NB_ERROR 0x80000000 44 #define NB_ERROR_BAD_CMD 0x80000001 45 #define NB_ERROR_BAD_PARAM 0x80000002 46 #define NB_ERROR_TOO_LARGE 0x80000003 47 #define NB_ERROR_BAD_FILE 0x80000004 48 49 #define NB_VERSION_1_0 0x0001000 50 #define NB_VERSION_1_1 0x0001010 51 #define NB_VERSION_1_2 0x0001020 52 #define NB_VERSION_1_3 0x0001030 53 #define NB_VERSION_CURRENT NB_VERSION_1_3 54 55 #define NB_FILENAME_PREFIX "<<netboot>>" 56 #define NB_KERNEL_FILENAME NB_FILENAME_PREFIX "kernel.bin" 57 #define NB_RAMDISK_FILENAME NB_FILENAME_PREFIX "ramdisk.bin" 58 #define NB_CMDLINE_FILENAME NB_FILENAME_PREFIX "cmdline" 59 60 #define NB_IMAGE_PREFIX "<<image>>" 61 #define NB_FVM_HOST_FILENAME "sparse.fvm" 62 #define NB_FVM_FILENAME NB_IMAGE_PREFIX NB_FVM_HOST_FILENAME 63 #define NB_BOOTLOADER_HOST_FILENAME "bootloader.img" 64 #define NB_BOOTLOADER_FILENAME NB_IMAGE_PREFIX NB_BOOTLOADER_HOST_FILENAME 65 #define NB_EFI_HOST_FILENAME "efi.img" 66 #define NB_EFI_FILENAME NB_IMAGE_PREFIX NB_EFI_HOST_FILENAME 67 #define NB_KERNC_HOST_FILENAME "kernc.img" 68 #define NB_KERNC_FILENAME NB_IMAGE_PREFIX NB_KERNC_HOST_FILENAME 69 #define NB_ZIRCONA_HOST_FILENAME "zircona.img" 70 #define NB_ZIRCONA_FILENAME NB_IMAGE_PREFIX NB_ZIRCONA_HOST_FILENAME 71 #define NB_ZIRCONB_HOST_FILENAME "zirconb.img" 72 #define NB_ZIRCONB_FILENAME NB_IMAGE_PREFIX NB_ZIRCONB_HOST_FILENAME 73 #define NB_ZIRCONR_HOST_FILENAME "zirconr.img" 74 #define NB_ZIRCONR_FILENAME NB_IMAGE_PREFIX NB_ZIRCONR_HOST_FILENAME 75 #define NB_VBMETAA_HOST_FILENAME "vbmetaa.img" 76 #define NB_VBMETAA_FILENAME NB_IMAGE_PREFIX NB_VBMETAA_HOST_FILENAME 77 #define NB_VBMETAB_HOST_FILENAME "vbmetab.img" 78 #define NB_VBMETAB_FILENAME NB_IMAGE_PREFIX NB_VBMETAB_HOST_FILENAME 79 #define NB_SSHAUTH_HOST_FILENAME "authorized_keys" 80 #define NB_SSHAUTH_FILENAME NB_IMAGE_PREFIX NB_SSHAUTH_HOST_FILENAME 81 82 typedef struct nbmsg_t { 83 uint32_t magic; 84 uint32_t cookie; 85 uint32_t cmd; 86 uint32_t arg; 87 uint8_t data[0]; 88 } nbmsg; 89 90 typedef struct nbfile_t { 91 uint8_t* data; 92 size_t size; // max size of buffer 93 size_t offset; // write pointer 94 } nbfile; 95 96 int netboot_init(const char* nodename); 97 const char* netboot_nodename(void); 98 int netboot_poll(void); 99 void netboot_close(void); 100 101 // Ask for a buffer suitable to put the file /name/ in 102 // Return NULL to indicate /name/ is not wanted. 103 nbfile* netboot_get_buffer(const char* name, size_t size); 104 105 #define DEBUGLOG_PORT 33337 106 #define DEBUGLOG_ACK_PORT 33338 107 108 #define MAX_LOG_DATA 1216 109 #define MAX_NODENAME_LENGTH 64 110 111 typedef struct logpacket { 112 uint32_t magic; 113 uint32_t seqno; 114 char nodename[MAX_NODENAME_LENGTH]; 115 char data[MAX_LOG_DATA]; 116 } logpacket_t; 117