Path: blob/main/usr.sbin/bsdinstall/partedit/partedit_powerpc.c
103499 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2011 Nathan Whitehorn4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#include <sys/types.h>29#include <sys/sysctl.h>30#include <string.h>3132#include "partedit.h"3334static char platform[255] = "";3536const char *37default_scheme(void) {38size_t platlen = sizeof(platform);39if (strlen(platform) == 0)40sysctlbyname("hw.platform", platform, &platlen, NULL, -1);4142if (strcmp(platform, "powermac") == 0)43return ("APM");44if (strcmp(platform, "chrp") == 0 || strcmp(platform, "ps3") == 0 ||45strcmp(platform, "mpc85xx") == 0)46return ("MBR");4748/* Pick GPT as a generic default */49return ("GPT");50}5152int53is_scheme_bootable(const char *part_type) {54size_t platlen = sizeof(platform);55if (strlen(platform) == 0)56sysctlbyname("hw.platform", platform, &platlen, NULL, -1);5758if (strcmp(platform, "powermac") == 0 && strcmp(part_type, "APM") == 0)59return (1);60if (strcmp(platform, "powernv") == 0 && strcmp(part_type, "GPT") == 0)61return (1);62if ((strcmp(platform, "chrp") == 0 || strcmp(platform, "ps3") == 0) &&63(strcmp(part_type, "MBR") == 0 || strcmp(part_type, "BSD") == 0 ||64strcmp(part_type, "GPT") == 0))65return (1);66if (strcmp(platform, "mpc85xx") == 0 && strcmp(part_type, "MBR") == 0)67return (1);6869return (0);70}7172int73is_fs_bootable(const char *part_type, const char *fs)74{75if (strcmp(fs, "freebsd-ufs") == 0)76return (1);7778return (0);79}8081size_t82bootpart_size(const char *part_type)83{84size_t platlen = sizeof(platform);85if (strlen(platform) == 0)86sysctlbyname("hw.platform", platform, &platlen, NULL, -1);8788if (strcmp(part_type, "APM") == 0)89return (800*1024);90if (strcmp(part_type, "BSD") == 0) /* Nothing for nested */91return (0);92if (strcmp(platform, "chrp") == 0)93return (800*1024);94if (strcmp(platform, "ps3") == 0 || strcmp(platform, "powernv") == 0)95return (512*1024*1024);96if (strcmp(platform, "mpc85xx") == 0)97return (16*1024*1024);98return (0);99}100101const char *102bootpart_type(const char *scheme, const char **mountpoint)103{104size_t platlen = sizeof(platform);105if (strlen(platform) == 0)106sysctlbyname("hw.platform", platform, &platlen, NULL, -1);107108if (strcmp(platform, "chrp") == 0)109return ("prep-boot");110if (strcmp(platform, "powermac") == 0)111return ("apple-boot");112if (strcmp(platform, "powernv") == 0 || strcmp(platform, "ps3") == 0) {113*mountpoint = "/boot";114if (strcmp(scheme, "GPT") == 0)115return ("ms-basic-data");116else if (strcmp(scheme, "MBR") == 0)117return ("fat32");118}119if (strcmp(platform, "mpc85xx") == 0) {120*mountpoint = "/boot/uboot";121return ("fat16");122}123124return ("freebsd-boot");125}126127const char *128bootcode_path(const char *part_type) {129return (NULL);130}131132const char *133partcode_path(const char *part_type, const char *fs_type) {134size_t platlen = sizeof(platform);135if (strlen(platform) == 0)136sysctlbyname("hw.platform", platform, &platlen, NULL, -1);137138if (strcmp(part_type, "APM") == 0)139return ("/boot/boot1.hfs");140if (strcmp(platform, "chrp") == 0)141return ("/boot/boot1.elf");142return (NULL);143}144145146147