xref: /netbsd-src/usr.sbin/installboot/installboot.h (revision c1ac8e1a1f981454feca748b662bbeacf0437183)
1*c1ac8e1aStsutsui /*	$NetBSD: installboot.h,v 1.46 2024/05/22 15:42:42 tsutsui Exp $	*/
207e46180Slukem 
307e46180Slukem /*-
407e46180Slukem  * Copyright (c) 2002 The NetBSD Foundation, Inc.
507e46180Slukem  * All rights reserved.
607e46180Slukem  *
707e46180Slukem  * This code is derived from software contributed to The NetBSD Foundation
807e46180Slukem  * by Luke Mewburn of Wasabi Systems.
907e46180Slukem  *
1007e46180Slukem  * Redistribution and use in source and binary forms, with or without
1107e46180Slukem  * modification, are permitted provided that the following conditions
1207e46180Slukem  * are met:
1307e46180Slukem  * 1. Redistributions of source code must retain the above copyright
1407e46180Slukem  *    notice, this list of conditions and the following disclaimer.
1507e46180Slukem  * 2. Redistributions in binary form must reproduce the above copyright
1607e46180Slukem  *    notice, this list of conditions and the following disclaimer in the
1707e46180Slukem  *    documentation and/or other materials provided with the distribution.
1807e46180Slukem  *
1907e46180Slukem  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2007e46180Slukem  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2107e46180Slukem  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2207e46180Slukem  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2307e46180Slukem  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2407e46180Slukem  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2507e46180Slukem  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2607e46180Slukem  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2707e46180Slukem  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2807e46180Slukem  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2907e46180Slukem  * POSSIBILITY OF SUCH DAMAGE.
3007e46180Slukem  */
3107e46180Slukem 
3207e46180Slukem #ifndef	_INSTALLBOOT_H
3307e46180Slukem #define	_INSTALLBOOT_H
3407e46180Slukem 
35171d6532Slukem #if HAVE_NBTOOL_CONFIG_H
36171d6532Slukem #include "nbtool_config.h"
371279ab0cSlukem #include "../../sys/sys/bootblock.h"
381279ab0cSlukem #else
391279ab0cSlukem #include <sys/bootblock.h>
400283225fSlukem #include <sys/endian.h>
4133ce139eSbjh21 #endif
4233ce139eSbjh21 
43932b7524Slukem #include <sys/stat.h>
44932b7524Slukem #include <stdint.h>
45932b7524Slukem 
4607e46180Slukem typedef enum {
4707e46180Slukem 				/* flags from global options */
4807e46180Slukem 	IB_VERBOSE =	1<<0,		/* verbose operation */
4907e46180Slukem 	IB_NOWRITE =	1<<1,		/* don't write */
5007e46180Slukem 	IB_CLEAR =	1<<2,		/* clear boot block */
518c893c96Sdsl 	IB_EDIT =	1<<3,		/* edit boot parameters */
52486d4119Sdsl 	IB_FORCE =	1<<4,		/* Ignore some consistency checks */
5307e46180Slukem 
5407e46180Slukem 				/* flags from -o options */
5507e46180Slukem 	IB_ALPHASUM =	1<<8,		/* set Alpha checksum */
56454998fcSlukem 	IB_APPEND =	1<<9,		/* append stage 1 to EO(regular)F */
5707e46180Slukem 	IB_SUNSUM =	1<<10,		/* set Sun checksum */
581bdd92eeSlukem 	IB_STAGE1START=	1<<11,		/* start block for stage 1 provided */
591bdd92eeSlukem 	IB_STAGE2START=	1<<12,		/* start block for stage 2 provided */
60e7852b05Smhitch 	IB_COMMAND = 	1<<13,		/* Amiga commandline option */
61ed45ba76Sdsl 	IB_RESETVIDEO =	1<<14,		/* i386 reset video */
62ed45ba76Sdsl 	IB_CONSOLE =	1<<15,		/* i386 console */
63ed45ba76Sdsl 	IB_CONSPEED =	1<<16,		/* i386 console baud rate */
64ed45ba76Sdsl 	IB_TIMEOUT =	1<<17,		/* i386 boot timeout */
65ed45ba76Sdsl 	IB_PASSWORD =	1<<18,		/* i386 boot password */
667b024ef6Sdsl 	IB_KEYMAP = 	1<<19,		/* i386 console keymap */
670b10fdb3Sdsl 	IB_CONSADDR = 	1<<20,		/* i386 console io address */
6879f027bbSdrochner 	IB_MODULES =	1<<21,		/* i386: load modules */
6979f027bbSdrochner 	IB_BOOTCONF = 	1<<22,		/* i386: read boot.conf */
7002d67d10Sthorpej 
7102d67d10Sthorpej 	IB_BOARD =	1<<23,		/* evb*: board specification */
7202d67d10Sthorpej 	IB_DTB=		1<<24,		/* evb*: device tree blob */
7302d67d10Sthorpej 
7402d67d10Sthorpej 	/* IB_MEDIA is required for some evb*, but not all. */
7502d67d10Sthorpej 	IB_MEDIA =	1<<25,		/* evb*: boot media type */
7607e46180Slukem } ib_flags;
7707e46180Slukem 
7802d67d10Sthorpej typedef enum {
7902d67d10Sthorpej 
8002d67d10Sthorpej 	MF_UBOOT =	1<<0,		/* platform (maybe) uses u-boot */
8102d67d10Sthorpej } m_flags;
8202d67d10Sthorpej 
8307e46180Slukem typedef struct {
841bdd92eeSlukem 	ib_flags	 flags;		/* flags (see above) */
851bdd92eeSlukem 	struct ib_mach	*machine;	/* machine details (see below) */
861bdd92eeSlukem 	struct ib_fs	*fstype;	/* file system details (see below) */
871bdd92eeSlukem 	const char	*filesystem;	/* name of target file system */
881bdd92eeSlukem 	int		 fsfd;		/*  open fd to filesystem */
89932b7524Slukem 	struct stat	 fsstat;	/*  fstat(2) of fsfd */
901bdd92eeSlukem 	const char	*stage1;	/* name of stage1 bootstrap */
911bdd92eeSlukem 	int		 s1fd;		/*  open fd to stage1 */
92932b7524Slukem 	struct stat	 s1stat;	/*  fstat(2) of s1fd */
9342614ed3Sfvdl 	uint64_t	 s1start;	/*  start block of stage1 */
941bdd92eeSlukem 	const char	*stage2;	/* name of stage2 bootstrap */
9542614ed3Sfvdl 	uint64_t	 s2start;	/*  start block of stage2 */
9617ad8eceStsutsui 	uint32_t	 sectorsize;	/* sector size of target fs */
97317b3a69Sbrook 	const char	*uboot_paths;	/* u-boot paths */
98ed45ba76Sdsl 		/* parsed -o option=value data */
99ed45ba76Sdsl 	const char	*command;	/* name of command string */
100ed45ba76Sdsl 	const char	*console;	/* name of console */
101ed45ba76Sdsl 	int		 conspeed;	/* console baud rate */
1020b10fdb3Sdsl 	int		 consaddr;	/* console io address */
103ed45ba76Sdsl 	const char	*password;	/* boot password */
104ed45ba76Sdsl 	int		 timeout;	/* interactive boot timeout */
1057b024ef6Sdsl 	const char	*keymap;	/* keyboard translations */
10602d67d10Sthorpej 	const char	*board;		/* board specification */
10702d67d10Sthorpej 	const char	*dtb;		/* dtb specification */
10802d67d10Sthorpej 	const char	*media;		/* boot media type */
10902d67d10Sthorpej 
11002d67d10Sthorpej 		/* temporary working data */
11102d67d10Sthorpej 	void		*mach_data;	/* platform-specific data */
11207e46180Slukem } ib_params;
11307e46180Slukem 
1148eb8919eSlukem typedef struct {
11542614ed3Sfvdl 	uint64_t	block;
1168eb8919eSlukem 	uint32_t	blocksize;
1178eb8919eSlukem } ib_block;
1188eb8919eSlukem 
11907e46180Slukem struct ib_mach {
12007e46180Slukem 	const char	*name;
12107e46180Slukem 	int		(*setboot)	(ib_params *);
12207e46180Slukem 	int		(*clearboot)	(ib_params *);
1238c893c96Sdsl 	int		(*editboot)	(ib_params *);
12402d67d10Sthorpej 	void		(*usage)	(ib_params *);
125ed45ba76Sdsl 	ib_flags	valid_flags;
12602d67d10Sthorpej 	m_flags		mach_flags;
12707e46180Slukem };
12807e46180Slukem 
1298eb8919eSlukem struct ib_fs {
1301bdd92eeSlukem 		/* compile time parameters */
1318eb8919eSlukem 	const char	*name;
1328eb8919eSlukem 	int		(*match)	(ib_params *);
1338eb8919eSlukem 	int		(*findstage2)	(ib_params *, uint32_t *, ib_block *);
1341bdd92eeSlukem 		/* run time fs specific parameters */
1351bdd92eeSlukem 	uint32_t	 blocksize;
1361bdd92eeSlukem 	uint32_t	 needswap;
13742614ed3Sfvdl 	off_t		sblockloc;	/* location of superblock */
138373c7523Sjdc 	off_t		offset;		/* file system offset (e.g. RAID) */
1398eb8919eSlukem };
14007e46180Slukem 
141d22f5cffSlukem typedef enum {
142d22f5cffSlukem 	BBINFO_BIG_ENDIAN =	0,
143d22f5cffSlukem 	BBINFO_LITTLE_ENDIAN =	1,
144d22f5cffSlukem } bbinfo_endian;
145d22f5cffSlukem 
146966b42a3Slukem struct bbinfo_params {
147d22f5cffSlukem 	const char	*magic;		/* magic string to look for */
148d22f5cffSlukem 	uint32_t	offset;		/* offset to write start of stage1 */
149d22f5cffSlukem 	uint32_t	blocksize;	/* blocksize of stage1 */
150d22f5cffSlukem 	uint32_t	maxsize;	/* max size of stage1 */
151d22f5cffSlukem 	uint32_t	headeroffset;	/*
152d22f5cffSlukem 					 * header offset (relative to offset)
153d22f5cffSlukem 					 * to read stage1 into
154d22f5cffSlukem 					 */
155d22f5cffSlukem 	bbinfo_endian	endian;
156966b42a3Slukem };
157966b42a3Slukem 
158b418df24Smatt extern struct ib_mach	* const machines[];
1598eb8919eSlukem extern struct ib_fs	fstypes[];
16007e46180Slukem 
1618eb8919eSlukem 	/* installboot.c */
1628eb8919eSlukem uint16_t	compute_sunsum(const uint16_t *);
1638eb8919eSlukem int		set_sunsum(ib_params *, uint16_t *, uint16_t);
16438cd7942Slukem int		no_setboot(ib_params *);
16538cd7942Slukem int		no_clearboot(ib_params *);
1668c893c96Sdsl int		no_editboot(ib_params *);
16738cd7942Slukem 
168966b42a3Slukem 	/* bbinfo.c */
169d22f5cffSlukem int		shared_bbinfo_clearboot(ib_params *, struct bbinfo_params *,
170d22f5cffSlukem 		    int (*)(ib_params *, struct bbinfo_params *, uint8_t *));
171966b42a3Slukem int		shared_bbinfo_setboot(ib_params *, struct bbinfo_params *,
172d22f5cffSlukem 		    int (*)(ib_params *, struct bbinfo_params *, uint8_t *));
173966b42a3Slukem 
1744882e3f0Stsutsui 	/* cd9660.c */
1754882e3f0Stsutsui int		cd9660_match(ib_params *);
1764882e3f0Stsutsui int		cd9660_findstage2(ib_params *, uint32_t *, ib_block *);
1774882e3f0Stsutsui 
178448aa2adStsutsui 	/* ext2fs.c */
179448aa2adStsutsui int		ext2fs_match(ib_params *);
180448aa2adStsutsui int		ext2fs_findstage2(ib_params *, uint32_t *, ib_block *);
181448aa2adStsutsui 
182448aa2adStsutsui 	/* ffs.c */
1838eb8919eSlukem int		ffs_match(ib_params *);
1848eb8919eSlukem int		ffs_findstage2(ib_params *, uint32_t *, ib_block *);
185373c7523Sjdc int		raid_match(ib_params *);
186448aa2adStsutsui 
187448aa2adStsutsui 	/* fstypes.c */
188448aa2adStsutsui int		hardcode_stage2(ib_params *, uint32_t *, ib_block *);
18980ae5fb6Slukem int		raw_match(ib_params *);
19080ae5fb6Slukem int		raw_findstage2(ib_params *, uint32_t *, ib_block *);
1918eb8919eSlukem 
1928eb8919eSlukem 	/* machines.c */
19313b9ae1eSdsl extern struct ib_mach ib_mach_alpha;
19413b9ae1eSdsl extern struct ib_mach ib_mach_amd64;
19513b9ae1eSdsl extern struct ib_mach ib_mach_amiga;
19602d67d10Sthorpej extern struct ib_mach ib_mach_evbarm;
197696896edSthorpej extern struct ib_mach ib_mach_evbmips;
19813b9ae1eSdsl extern struct ib_mach ib_mach_ews4800mips;
19913b9ae1eSdsl extern struct ib_mach ib_mach_hp300;
2006d3ceb1dSskrll extern struct ib_mach ib_mach_hppa;
20113b9ae1eSdsl extern struct ib_mach ib_mach_i386;
202973bc97bSuwe extern struct ib_mach ib_mach_landisk;
20313b9ae1eSdsl extern struct ib_mach ib_mach_macppc;
20413b9ae1eSdsl extern struct ib_mach ib_mach_news68k;
20513b9ae1eSdsl extern struct ib_mach ib_mach_newsmips;
20613b9ae1eSdsl extern struct ib_mach ib_mach_next68k;
20713b9ae1eSdsl extern struct ib_mach ib_mach_pmax;
20813b9ae1eSdsl extern struct ib_mach ib_mach_sparc;
20913b9ae1eSdsl extern struct ib_mach ib_mach_sparc64;
21013b9ae1eSdsl extern struct ib_mach ib_mach_sun2;
21113b9ae1eSdsl extern struct ib_mach ib_mach_sun3;
21213b9ae1eSdsl extern struct ib_mach ib_mach_vax;
21313b9ae1eSdsl extern struct ib_mach ib_mach_x68k;
2148eb8919eSlukem 
21507e46180Slukem #endif	/* _INSTALLBOOT_H */
216