1*1c071e93Schristos /* $NetBSD: installboot.h,v 1.4 2016/03/09 15:44:49 christos Exp $ */ 242f593a4Stsutsui 342f593a4Stsutsui /*- 442f593a4Stsutsui * Copyright (c) 2002 The NetBSD Foundation, Inc. 542f593a4Stsutsui * All rights reserved. 642f593a4Stsutsui * 742f593a4Stsutsui * This code is derived from software contributed to The NetBSD Foundation 842f593a4Stsutsui * by Luke Mewburn of Wasabi Systems. 942f593a4Stsutsui * 1042f593a4Stsutsui * Redistribution and use in source and binary forms, with or without 1142f593a4Stsutsui * modification, are permitted provided that the following conditions 1242f593a4Stsutsui * are met: 1342f593a4Stsutsui * 1. Redistributions of source code must retain the above copyright 1442f593a4Stsutsui * notice, this list of conditions and the following disclaimer. 1542f593a4Stsutsui * 2. Redistributions in binary form must reproduce the above copyright 1642f593a4Stsutsui * notice, this list of conditions and the following disclaimer in the 1742f593a4Stsutsui * documentation and/or other materials provided with the distribution. 1842f593a4Stsutsui * 1942f593a4Stsutsui * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2042f593a4Stsutsui * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2142f593a4Stsutsui * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2242f593a4Stsutsui * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2342f593a4Stsutsui * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2442f593a4Stsutsui * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2542f593a4Stsutsui * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2642f593a4Stsutsui * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2742f593a4Stsutsui * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2842f593a4Stsutsui * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2942f593a4Stsutsui * POSSIBILITY OF SUCH DAMAGE. 3042f593a4Stsutsui */ 3142f593a4Stsutsui 3242f593a4Stsutsui #ifndef _INSTALLBOOT_H 3342f593a4Stsutsui #define _INSTALLBOOT_H 3442f593a4Stsutsui 3542f593a4Stsutsui #if HAVE_NBTOOL_CONFIG_H 3642f593a4Stsutsui #include "nbtool_config.h" 3742f593a4Stsutsui #include "../../sys/sys/bootblock.h" 3842f593a4Stsutsui #else 3942f593a4Stsutsui #include <sys/bootblock.h> 4042f593a4Stsutsui #include <sys/endian.h> 4142f593a4Stsutsui #endif 4242f593a4Stsutsui 4342f593a4Stsutsui #include <sys/stat.h> 4442f593a4Stsutsui #include <stdint.h> 4542f593a4Stsutsui 4681d95038Stsutsui #ifndef MAXNAMLEN 4781d95038Stsutsui #define MAXNAMLEN 511 4881d95038Stsutsui #endif 4981d95038Stsutsui 5042f593a4Stsutsui typedef enum { 5142f593a4Stsutsui /* flags from global options */ 5242f593a4Stsutsui IB_VERBOSE = 1<<0, /* verbose operation */ 5342f593a4Stsutsui IB_NOWRITE = 1<<1, /* don't write */ 5442f593a4Stsutsui IB_CLEAR = 1<<2, /* clear boot block */ 5542f593a4Stsutsui 5642f593a4Stsutsui /* flags from -o options */ 5742f593a4Stsutsui IB_ALPHASUM = 1<<8, /* set Alpha checksum */ 5842f593a4Stsutsui IB_APPEND = 1<<9, /* append stage 1 to EO(regular)F */ 5942f593a4Stsutsui IB_SUNSUM = 1<<10, /* set Sun checksum */ 6042f593a4Stsutsui IB_STAGE1START= 1<<11, /* start block for stage 1 provided */ 6142f593a4Stsutsui IB_STAGE2START= 1<<12, /* start block for stage 2 provided */ 6242f593a4Stsutsui IB_COMMAND = 1<<13, /* Amiga commandline option */ 6342f593a4Stsutsui IB_RESETVIDEO = 1<<14, /* i386 reset video */ 6442f593a4Stsutsui IB_CONSOLE = 1<<15, /* i386 console */ 6542f593a4Stsutsui IB_CONSPEED = 1<<16, /* i386 console baud rate */ 6642f593a4Stsutsui IB_TIMEOUT = 1<<17, /* i386 boot timeout */ 6742f593a4Stsutsui IB_PASSWORD = 1<<18, /* i386 boot password */ 6842f593a4Stsutsui IB_KEYMAP = 1<<19, /* i386 console keymap */ 6942f593a4Stsutsui IB_CONSADDR = 1<<20, /* i386 console io address */ 7042f593a4Stsutsui } ib_flags; 7142f593a4Stsutsui 7242f593a4Stsutsui typedef struct { 7342f593a4Stsutsui ib_flags flags; /* flags (see above) */ 7442f593a4Stsutsui struct ib_mach *machine; /* machine details (see below) */ 7542f593a4Stsutsui struct ib_fs *fstype; /* file system details (see below) */ 7642f593a4Stsutsui const char *filesystem; /* name of target file system */ 7742f593a4Stsutsui int fsfd; /* open fd to filesystem */ 7842f593a4Stsutsui struct stat fsstat; /* fstat(2) of fsfd */ 7942f593a4Stsutsui const char *stage1; /* name of stage1 bootstrap */ 8042f593a4Stsutsui int s1fd; /* open fd to stage1 */ 8142f593a4Stsutsui struct stat s1stat; /* fstat(2) of s1fd */ 8242f593a4Stsutsui uint64_t s1start; /* start block of stage1 */ 8342f593a4Stsutsui const char *stage2; /* name of stage2 bootstrap */ 8442f593a4Stsutsui uint64_t s2start; /* start block of stage2 */ 8542f593a4Stsutsui /* parsed -o option=value data */ 8642f593a4Stsutsui const char *command; /* name of command string */ 8742f593a4Stsutsui const char *console; /* name of console */ 8842f593a4Stsutsui int conspeed; /* console baud rate */ 8942f593a4Stsutsui int consaddr; /* console io address */ 9042f593a4Stsutsui const char *password; /* boot password */ 9142f593a4Stsutsui int timeout; /* interactive boot timeout */ 9242f593a4Stsutsui const char *keymap; /* keyboard translations */ 9342f593a4Stsutsui } ib_params; 9442f593a4Stsutsui 9542f593a4Stsutsui typedef struct { 9642f593a4Stsutsui uint64_t block; 9742f593a4Stsutsui uint32_t blocksize; 9842f593a4Stsutsui } ib_block; 9942f593a4Stsutsui 10042f593a4Stsutsui struct ib_mach { 10142f593a4Stsutsui const char *name; 10242f593a4Stsutsui int (*setboot) (ib_params *); 10342f593a4Stsutsui int (*clearboot) (ib_params *); 10442f593a4Stsutsui ib_flags valid_flags; 10542f593a4Stsutsui }; 10642f593a4Stsutsui 10742f593a4Stsutsui struct ib_fs { 10842f593a4Stsutsui /* compile time parameters */ 10942f593a4Stsutsui const char *name; 11042f593a4Stsutsui int (*match) (ib_params *); 11142f593a4Stsutsui int (*findstage2) (ib_params *, uint32_t *, ib_block *); 11242f593a4Stsutsui /* run time fs specific parameters */ 11342f593a4Stsutsui uint32_t blocksize; 11442f593a4Stsutsui uint32_t needswap; 11542f593a4Stsutsui off_t sblockloc; /* location of superblock */ 11642f593a4Stsutsui }; 11742f593a4Stsutsui 11842f593a4Stsutsui typedef enum { 11942f593a4Stsutsui BBINFO_BIG_ENDIAN = 0, 12042f593a4Stsutsui BBINFO_LITTLE_ENDIAN = 1, 12142f593a4Stsutsui } bbinfo_endian; 12242f593a4Stsutsui 12342f593a4Stsutsui struct bbinfo_params { 12442f593a4Stsutsui const char *magic; /* magic string to look for */ 12542f593a4Stsutsui uint32_t offset; /* offset to write start of stage1 */ 12642f593a4Stsutsui uint32_t blocksize; /* blocksize of stage1 */ 12742f593a4Stsutsui uint32_t maxsize; /* max size of stage1 */ 12842f593a4Stsutsui uint32_t headeroffset; /* 12942f593a4Stsutsui * header offset (relative to offset) 13042f593a4Stsutsui * to read stage1 into 13142f593a4Stsutsui */ 13242f593a4Stsutsui bbinfo_endian endian; 13342f593a4Stsutsui }; 13442f593a4Stsutsui 13542f593a4Stsutsui int cd9660_match(ib_params *); 13642f593a4Stsutsui int cd9660_findstage2(ib_params *, uint32_t *, ib_block *); 13742f593a4Stsutsui 13842f593a4Stsutsui int isofncmp(const u_char *, size_t, const u_char *, size_t, int); 139*1c071e93Schristos void isofntrans(const u_char *, int, u_char *, u_short *, int, int, int, int); 14042f593a4Stsutsui 14142f593a4Stsutsui #endif /* _INSTALLBOOT_H */ 142