xref: /freebsd/usr.sbin/bsdinstall/partedit/partedit_powerpc.c (revision 8befcf7be199ab5e496593cb563a3a7b9e0170e9)
12118f387SNathan Whitehorn /*-
21de7b4b8SPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
31de7b4b8SPedro F. Giffuni  *
42118f387SNathan Whitehorn  * Copyright (c) 2011 Nathan Whitehorn
52118f387SNathan Whitehorn  * All rights reserved.
62118f387SNathan Whitehorn  *
72118f387SNathan Whitehorn  * Redistribution and use in source and binary forms, with or without
82118f387SNathan Whitehorn  * modification, are permitted provided that the following conditions
92118f387SNathan Whitehorn  * are met:
102118f387SNathan Whitehorn  * 1. Redistributions of source code must retain the above copyright
112118f387SNathan Whitehorn  *    notice, this list of conditions and the following disclaimer.
122118f387SNathan Whitehorn  * 2. Redistributions in binary form must reproduce the above copyright
132118f387SNathan Whitehorn  *    notice, this list of conditions and the following disclaimer in the
142118f387SNathan Whitehorn  *    documentation and/or other materials provided with the distribution.
152118f387SNathan Whitehorn  *
162118f387SNathan Whitehorn  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
172118f387SNathan Whitehorn  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
182118f387SNathan Whitehorn  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
192118f387SNathan Whitehorn  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
202118f387SNathan Whitehorn  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
212118f387SNathan Whitehorn  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
222118f387SNathan Whitehorn  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
232118f387SNathan Whitehorn  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
242118f387SNathan Whitehorn  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
252118f387SNathan Whitehorn  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
262118f387SNathan Whitehorn  * SUCH DAMAGE.
272118f387SNathan Whitehorn  *
282118f387SNathan Whitehorn  * $FreeBSD$
292118f387SNathan Whitehorn  */
302118f387SNathan Whitehorn 
31e25e006dSNathan Whitehorn #include <sys/types.h>
32e25e006dSNathan Whitehorn #include <sys/sysctl.h>
332118f387SNathan Whitehorn #include <string.h>
342118f387SNathan Whitehorn 
352118f387SNathan Whitehorn #include "partedit.h"
362118f387SNathan Whitehorn 
37e25e006dSNathan Whitehorn static char platform[255] = "";
38e25e006dSNathan Whitehorn 
392118f387SNathan Whitehorn const char *
402118f387SNathan Whitehorn default_scheme(void) {
41e25e006dSNathan Whitehorn 	size_t platlen = sizeof(platform);
42e25e006dSNathan Whitehorn 	if (strlen(platform) == 0)
43e25e006dSNathan Whitehorn 		sysctlbyname("hw.platform", platform, &platlen, NULL, -1);
44e25e006dSNathan Whitehorn 
45e25e006dSNathan Whitehorn 	if (strcmp(platform, "powermac") == 0)
462118f387SNathan Whitehorn 		return ("APM");
47*8befcf7bSNathan Whitehorn 	if (strcmp(platform, "chrp") == 0 || strcmp(platform, "ps3") == 0)
48e25e006dSNathan Whitehorn 		return ("MBR");
49e25e006dSNathan Whitehorn 
50*8befcf7bSNathan Whitehorn 	/* Pick GPT as a generic default */
51e25e006dSNathan Whitehorn 	return ("GPT");
522118f387SNathan Whitehorn }
532118f387SNathan Whitehorn 
542118f387SNathan Whitehorn int
552118f387SNathan Whitehorn is_scheme_bootable(const char *part_type) {
56e25e006dSNathan Whitehorn 	size_t platlen = sizeof(platform);
57e25e006dSNathan Whitehorn 	if (strlen(platform) == 0)
58e25e006dSNathan Whitehorn 		sysctlbyname("hw.platform", platform, &platlen, NULL, -1);
59e25e006dSNathan Whitehorn 
60e25e006dSNathan Whitehorn 	if (strcmp(platform, "powermac") == 0 && strcmp(part_type, "APM") == 0)
612118f387SNathan Whitehorn 		return (1);
62*8befcf7bSNathan Whitehorn 	if (strcmp(platform, "powernv") == 0 && strcmp(part_type, "GPT") == 0)
63e25e006dSNathan Whitehorn 		return (1);
64*8befcf7bSNathan Whitehorn 	if ((strcmp(platform, "chrp") == 0 || strcmp(platform, "ps3") == 0) &&
651ee0f089SNathan Whitehorn 	    (strcmp(part_type, "MBR") == 0 || strcmp(part_type, "BSD") == 0 ||
661ee0f089SNathan Whitehorn 	     strcmp(part_type, "GPT") == 0))
67e25e006dSNathan Whitehorn 		return (1);
68e25e006dSNathan Whitehorn 
692118f387SNathan Whitehorn 	return (0);
702118f387SNathan Whitehorn }
712118f387SNathan Whitehorn 
726e15678aSNathan Whitehorn int
736e15678aSNathan Whitehorn is_fs_bootable(const char *part_type, const char *fs)
746e15678aSNathan Whitehorn {
756e15678aSNathan Whitehorn 	if (strcmp(fs, "freebsd-ufs") == 0)
766e15678aSNathan Whitehorn 		return (1);
776e15678aSNathan Whitehorn 
786e15678aSNathan Whitehorn 	return (0);
796e15678aSNathan Whitehorn }
806e15678aSNathan Whitehorn 
812118f387SNathan Whitehorn size_t
82*8befcf7bSNathan Whitehorn bootpart_size(const char *part_type)
83*8befcf7bSNathan Whitehorn {
841ee0f089SNathan Whitehorn 	size_t platlen = sizeof(platform);
851ee0f089SNathan Whitehorn 	if (strlen(platform) == 0)
861ee0f089SNathan Whitehorn 		sysctlbyname("hw.platform", platform, &platlen, NULL, -1);
871ee0f089SNathan Whitehorn 
88*8befcf7bSNathan Whitehorn 	if (strcmp(part_type, "APM") == 0)
892118f387SNathan Whitehorn 		return (800*1024);
90*8befcf7bSNathan Whitehorn 	if (strcmp(part_type, "BSD") == 0) /* Nothing for nested */
91*8befcf7bSNathan Whitehorn 		return (0);
92*8befcf7bSNathan Whitehorn 	if (strcmp(platform, "chrp") == 0)
931ee0f089SNathan Whitehorn 		return (800*1024);
94*8befcf7bSNathan Whitehorn 	if (strcmp(platform, "ps3") == 0 || strcmp(platform, "powernv") == 0)
95*8befcf7bSNathan Whitehorn 		return (512*1024*1024);
962118f387SNathan Whitehorn 	return (0);
972118f387SNathan Whitehorn }
982118f387SNathan Whitehorn 
992118f387SNathan Whitehorn const char *
100*8befcf7bSNathan Whitehorn bootpart_type(const char *scheme, const char **mountpoint)
101*8befcf7bSNathan Whitehorn {
1021ee0f089SNathan Whitehorn 	size_t platlen = sizeof(platform);
1031ee0f089SNathan Whitehorn 	if (strlen(platform) == 0)
1041ee0f089SNathan Whitehorn 		sysctlbyname("hw.platform", platform, &platlen, NULL, -1);
1051ee0f089SNathan Whitehorn 
1061ee0f089SNathan Whitehorn 	if (strcmp(platform, "chrp") == 0)
1071ee0f089SNathan Whitehorn 		return ("prep-boot");
1081ee0f089SNathan Whitehorn 	if (strcmp(platform, "powermac") == 0)
1091ee0f089SNathan Whitehorn 		return ("apple-boot");
110*8befcf7bSNathan Whitehorn 	if (strcmp(platform, "powernv") == 0 || strcmp(platform, "ps3") == 0) {
111*8befcf7bSNathan Whitehorn 		*mountpoint = "/boot";
112*8befcf7bSNathan Whitehorn 		if (strcmp(scheme, "GPT") == 0)
113*8befcf7bSNathan Whitehorn 			return ("ms-basic-data");
114*8befcf7bSNathan Whitehorn 		else if (strcmp(scheme, "MBR") == 0)
115*8befcf7bSNathan Whitehorn 			return ("fat32");
116*8befcf7bSNathan Whitehorn 	}
1171ee0f089SNathan Whitehorn 
1186b446ed5SNathan Whitehorn 	return ("freebsd-boot");
1196b446ed5SNathan Whitehorn }
1206b446ed5SNathan Whitehorn 
1216b446ed5SNathan Whitehorn const char *
1222118f387SNathan Whitehorn bootcode_path(const char *part_type) {
1232118f387SNathan Whitehorn 	return (NULL);
1242118f387SNathan Whitehorn }
1252118f387SNathan Whitehorn 
1262118f387SNathan Whitehorn const char *
1276e15678aSNathan Whitehorn partcode_path(const char *part_type, const char *fs_type) {
1281ee0f089SNathan Whitehorn 	size_t platlen = sizeof(platform);
1291ee0f089SNathan Whitehorn 	if (strlen(platform) == 0)
1301ee0f089SNathan Whitehorn 		sysctlbyname("hw.platform", platform, &platlen, NULL, -1);
1311ee0f089SNathan Whitehorn 
1322118f387SNathan Whitehorn 	if (strcmp(part_type, "APM") == 0)
1332118f387SNathan Whitehorn 		return ("/boot/boot1.hfs");
134*8befcf7bSNathan Whitehorn 	if (strcmp(platform, "chrp") == 0)
135090dd246SNathan Whitehorn 		return ("/boot/boot1.elf");
1362118f387SNathan Whitehorn 	return (NULL);
1372118f387SNathan Whitehorn }
1382118f387SNathan Whitehorn 
139