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 29*e25e006dSNathan Whitehorn #include <sys/types.h> 30*e25e006dSNathan Whitehorn #include <sys/sysctl.h> 312118f387SNathan Whitehorn #include <string.h> 322118f387SNathan Whitehorn 332118f387SNathan Whitehorn #include "partedit.h" 342118f387SNathan Whitehorn 35*e25e006dSNathan Whitehorn static char platform[255] = ""; 36*e25e006dSNathan Whitehorn 372118f387SNathan Whitehorn const char * 382118f387SNathan Whitehorn default_scheme(void) { 39*e25e006dSNathan Whitehorn size_t platlen = sizeof(platform); 40*e25e006dSNathan Whitehorn if (strlen(platform) == 0) 41*e25e006dSNathan Whitehorn sysctlbyname("hw.platform", platform, &platlen, NULL, -1); 42*e25e006dSNathan Whitehorn 43*e25e006dSNathan Whitehorn if (strcmp(platform, "powermac") == 0) 442118f387SNathan Whitehorn return ("APM"); 45*e25e006dSNathan Whitehorn if (strcmp(platform, "chrp") == 0) 46*e25e006dSNathan Whitehorn return ("MBR"); 47*e25e006dSNathan Whitehorn 48*e25e006dSNathan Whitehorn /* Pick GPT (bootable on PS3) as a generic default */ 49*e25e006dSNathan Whitehorn return ("GPT"); 502118f387SNathan Whitehorn } 512118f387SNathan Whitehorn 522118f387SNathan Whitehorn int 532118f387SNathan Whitehorn is_scheme_bootable(const char *part_type) { 54*e25e006dSNathan Whitehorn size_t platlen = sizeof(platform); 55*e25e006dSNathan Whitehorn if (strlen(platform) == 0) 56*e25e006dSNathan Whitehorn sysctlbyname("hw.platform", platform, &platlen, NULL, -1); 57*e25e006dSNathan Whitehorn 58*e25e006dSNathan Whitehorn if (strcmp(platform, "powermac") == 0 && strcmp(part_type, "APM") == 0) 592118f387SNathan Whitehorn return (1); 60*e25e006dSNathan Whitehorn if (strcmp(platform, "ps3") == 0 && strcmp(part_type, "GPT") == 0) 61*e25e006dSNathan Whitehorn return (1); 62*e25e006dSNathan Whitehorn if (strcmp(platform, "chrp") == 0 && strcmp(part_type, "MBR") == 0) 63*e25e006dSNathan Whitehorn return (1); 64*e25e006dSNathan Whitehorn 652118f387SNathan Whitehorn return (0); 662118f387SNathan Whitehorn } 672118f387SNathan Whitehorn 682118f387SNathan Whitehorn size_t 692118f387SNathan Whitehorn bootpart_size(const char *part_type) { 702118f387SNathan Whitehorn if (strcmp(part_type, "APM") == 0) 712118f387SNathan Whitehorn return (800*1024); 722118f387SNathan Whitehorn return (0); 732118f387SNathan Whitehorn } 742118f387SNathan Whitehorn 752118f387SNathan Whitehorn const char * 762118f387SNathan Whitehorn bootcode_path(const char *part_type) { 772118f387SNathan Whitehorn return (NULL); 782118f387SNathan Whitehorn } 792118f387SNathan Whitehorn 802118f387SNathan Whitehorn const char * 812118f387SNathan Whitehorn partcode_path(const char *part_type) { 822118f387SNathan Whitehorn if (strcmp(part_type, "APM") == 0) 832118f387SNathan Whitehorn return ("/boot/boot1.hfs"); 842118f387SNathan Whitehorn return (NULL); 852118f387SNathan Whitehorn } 862118f387SNathan Whitehorn 87