12118f387SNathan Whitehorn /*- 22118f387SNathan Whitehorn * Copyright (c) 2011 Nathan Whitehorn 32118f387SNathan Whitehorn * All rights reserved. 42118f387SNathan Whitehorn * 52118f387SNathan Whitehorn * Redistribution and use in source and binary forms, with or without 62118f387SNathan Whitehorn * modification, are permitted provided that the following conditions 72118f387SNathan Whitehorn * are met: 82118f387SNathan Whitehorn * 1. Redistributions of source code must retain the above copyright 92118f387SNathan Whitehorn * notice, this list of conditions and the following disclaimer. 102118f387SNathan Whitehorn * 2. Redistributions in binary form must reproduce the above copyright 112118f387SNathan Whitehorn * notice, this list of conditions and the following disclaimer in the 122118f387SNathan Whitehorn * documentation and/or other materials provided with the distribution. 132118f387SNathan Whitehorn * 142118f387SNathan Whitehorn * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 152118f387SNathan Whitehorn * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 162118f387SNathan Whitehorn * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 172118f387SNathan Whitehorn * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 182118f387SNathan Whitehorn * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 192118f387SNathan Whitehorn * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 202118f387SNathan Whitehorn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 212118f387SNathan Whitehorn * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 222118f387SNathan Whitehorn * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 232118f387SNathan Whitehorn * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 242118f387SNathan Whitehorn * SUCH DAMAGE. 252118f387SNathan Whitehorn * 262118f387SNathan Whitehorn * $FreeBSD$ 272118f387SNathan Whitehorn */ 282118f387SNathan Whitehorn 29e25e006dSNathan Whitehorn #include <sys/types.h> 30e25e006dSNathan Whitehorn #include <sys/sysctl.h> 312118f387SNathan Whitehorn #include <string.h> 322118f387SNathan Whitehorn 332118f387SNathan Whitehorn #include "partedit.h" 342118f387SNathan Whitehorn 35e25e006dSNathan Whitehorn static char platform[255] = ""; 36e25e006dSNathan Whitehorn 372118f387SNathan Whitehorn const char * 382118f387SNathan Whitehorn default_scheme(void) { 39e25e006dSNathan Whitehorn size_t platlen = sizeof(platform); 40e25e006dSNathan Whitehorn if (strlen(platform) == 0) 41e25e006dSNathan Whitehorn sysctlbyname("hw.platform", platform, &platlen, NULL, -1); 42e25e006dSNathan Whitehorn 43e25e006dSNathan Whitehorn if (strcmp(platform, "powermac") == 0) 442118f387SNathan Whitehorn return ("APM"); 45e25e006dSNathan Whitehorn if (strcmp(platform, "chrp") == 0) 46e25e006dSNathan Whitehorn return ("MBR"); 47e25e006dSNathan Whitehorn 48e25e006dSNathan Whitehorn /* Pick GPT (bootable on PS3) as a generic default */ 49e25e006dSNathan Whitehorn return ("GPT"); 502118f387SNathan Whitehorn } 512118f387SNathan Whitehorn 522118f387SNathan Whitehorn int 532118f387SNathan Whitehorn is_scheme_bootable(const char *part_type) { 54e25e006dSNathan Whitehorn size_t platlen = sizeof(platform); 55e25e006dSNathan Whitehorn if (strlen(platform) == 0) 56e25e006dSNathan Whitehorn sysctlbyname("hw.platform", platform, &platlen, NULL, -1); 57e25e006dSNathan Whitehorn 58e25e006dSNathan Whitehorn if (strcmp(platform, "powermac") == 0 && strcmp(part_type, "APM") == 0) 592118f387SNathan Whitehorn return (1); 60e25e006dSNathan Whitehorn if (strcmp(platform, "ps3") == 0 && strcmp(part_type, "GPT") == 0) 61e25e006dSNathan Whitehorn return (1); 628d795806SNathan Whitehorn if (strcmp(platform, "chrp") == 0 && 63*1ee0f089SNathan Whitehorn (strcmp(part_type, "MBR") == 0 || strcmp(part_type, "BSD") == 0 || 64*1ee0f089SNathan Whitehorn strcmp(part_type, "GPT") == 0)) 65e25e006dSNathan Whitehorn return (1); 66e25e006dSNathan Whitehorn 672118f387SNathan Whitehorn return (0); 682118f387SNathan Whitehorn } 692118f387SNathan Whitehorn 702118f387SNathan Whitehorn size_t 712118f387SNathan Whitehorn bootpart_size(const char *part_type) { 72*1ee0f089SNathan Whitehorn size_t platlen = sizeof(platform); 73*1ee0f089SNathan Whitehorn if (strlen(platform) == 0) 74*1ee0f089SNathan Whitehorn sysctlbyname("hw.platform", platform, &platlen, NULL, -1); 75*1ee0f089SNathan Whitehorn 76090dd246SNathan Whitehorn if (strcmp(part_type, "APM") == 0 || strcmp(part_type, "MBR") == 0) 772118f387SNathan Whitehorn return (800*1024); 78*1ee0f089SNathan Whitehorn if (strcmp(platform, "chrp") == 0 && strcmp(part_type, "GPT") == 0) 79*1ee0f089SNathan Whitehorn return (800*1024); 802118f387SNathan Whitehorn return (0); 812118f387SNathan Whitehorn } 822118f387SNathan Whitehorn 832118f387SNathan Whitehorn const char * 846b446ed5SNathan Whitehorn bootpart_type(const char *scheme) { 85*1ee0f089SNathan Whitehorn size_t platlen = sizeof(platform); 86*1ee0f089SNathan Whitehorn if (strlen(platform) == 0) 87*1ee0f089SNathan Whitehorn sysctlbyname("hw.platform", platform, &platlen, NULL, -1); 88*1ee0f089SNathan Whitehorn 89*1ee0f089SNathan Whitehorn if (strcmp(platform, "chrp") == 0) 90*1ee0f089SNathan Whitehorn return ("prep-boot"); 91*1ee0f089SNathan Whitehorn if (strcmp(platform, "powermac") == 0) 92*1ee0f089SNathan Whitehorn return ("apple-boot"); 93*1ee0f089SNathan Whitehorn 946b446ed5SNathan Whitehorn return ("freebsd-boot"); 956b446ed5SNathan Whitehorn } 966b446ed5SNathan Whitehorn 976b446ed5SNathan Whitehorn const char * 982118f387SNathan Whitehorn bootcode_path(const char *part_type) { 992118f387SNathan Whitehorn return (NULL); 1002118f387SNathan Whitehorn } 1012118f387SNathan Whitehorn 1022118f387SNathan Whitehorn const char * 1032118f387SNathan Whitehorn partcode_path(const char *part_type) { 104*1ee0f089SNathan Whitehorn size_t platlen = sizeof(platform); 105*1ee0f089SNathan Whitehorn if (strlen(platform) == 0) 106*1ee0f089SNathan Whitehorn sysctlbyname("hw.platform", platform, &platlen, NULL, -1); 107*1ee0f089SNathan Whitehorn 1082118f387SNathan Whitehorn if (strcmp(part_type, "APM") == 0) 1092118f387SNathan Whitehorn return ("/boot/boot1.hfs"); 110*1ee0f089SNathan Whitehorn if (strcmp(part_type, "MBR") == 0 || 111*1ee0f089SNathan Whitehorn (strcmp(platform, "chrp") == 0 && strcmp(part_type, "GPT") == 0)) 112090dd246SNathan Whitehorn return ("/boot/boot1.elf"); 1132118f387SNathan Whitehorn return (NULL); 1142118f387SNathan Whitehorn } 1152118f387SNathan Whitehorn 116