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 && 631ee0f089SNathan Whitehorn (strcmp(part_type, "MBR") == 0 || strcmp(part_type, "BSD") == 0 || 641ee0f089SNathan Whitehorn strcmp(part_type, "GPT") == 0)) 65e25e006dSNathan Whitehorn return (1); 66e25e006dSNathan Whitehorn 672118f387SNathan Whitehorn return (0); 682118f387SNathan Whitehorn } 692118f387SNathan Whitehorn 70*6e15678aSNathan Whitehorn int 71*6e15678aSNathan Whitehorn is_fs_bootable(const char *part_type, const char *fs) 72*6e15678aSNathan Whitehorn { 73*6e15678aSNathan Whitehorn if (strcmp(fs, "freebsd-ufs") == 0) 74*6e15678aSNathan Whitehorn return (1); 75*6e15678aSNathan Whitehorn 76*6e15678aSNathan Whitehorn return (0); 77*6e15678aSNathan Whitehorn } 78*6e15678aSNathan Whitehorn 792118f387SNathan Whitehorn size_t 802118f387SNathan Whitehorn bootpart_size(const char *part_type) { 811ee0f089SNathan Whitehorn size_t platlen = sizeof(platform); 821ee0f089SNathan Whitehorn if (strlen(platform) == 0) 831ee0f089SNathan Whitehorn sysctlbyname("hw.platform", platform, &platlen, NULL, -1); 841ee0f089SNathan Whitehorn 85090dd246SNathan Whitehorn if (strcmp(part_type, "APM") == 0 || strcmp(part_type, "MBR") == 0) 862118f387SNathan Whitehorn return (800*1024); 871ee0f089SNathan Whitehorn if (strcmp(platform, "chrp") == 0 && strcmp(part_type, "GPT") == 0) 881ee0f089SNathan Whitehorn return (800*1024); 892118f387SNathan Whitehorn return (0); 902118f387SNathan Whitehorn } 912118f387SNathan Whitehorn 922118f387SNathan Whitehorn const char * 936b446ed5SNathan Whitehorn bootpart_type(const char *scheme) { 941ee0f089SNathan Whitehorn size_t platlen = sizeof(platform); 951ee0f089SNathan Whitehorn if (strlen(platform) == 0) 961ee0f089SNathan Whitehorn sysctlbyname("hw.platform", platform, &platlen, NULL, -1); 971ee0f089SNathan Whitehorn 981ee0f089SNathan Whitehorn if (strcmp(platform, "chrp") == 0) 991ee0f089SNathan Whitehorn return ("prep-boot"); 1001ee0f089SNathan Whitehorn if (strcmp(platform, "powermac") == 0) 1011ee0f089SNathan Whitehorn return ("apple-boot"); 1021ee0f089SNathan Whitehorn 1036b446ed5SNathan Whitehorn return ("freebsd-boot"); 1046b446ed5SNathan Whitehorn } 1056b446ed5SNathan Whitehorn 1066b446ed5SNathan Whitehorn const char * 1072118f387SNathan Whitehorn bootcode_path(const char *part_type) { 1082118f387SNathan Whitehorn return (NULL); 1092118f387SNathan Whitehorn } 1102118f387SNathan Whitehorn 1112118f387SNathan Whitehorn const char * 112*6e15678aSNathan Whitehorn partcode_path(const char *part_type, const char *fs_type) { 1131ee0f089SNathan Whitehorn size_t platlen = sizeof(platform); 1141ee0f089SNathan Whitehorn if (strlen(platform) == 0) 1151ee0f089SNathan Whitehorn sysctlbyname("hw.platform", platform, &platlen, NULL, -1); 1161ee0f089SNathan Whitehorn 1172118f387SNathan Whitehorn if (strcmp(part_type, "APM") == 0) 1182118f387SNathan Whitehorn return ("/boot/boot1.hfs"); 1191ee0f089SNathan Whitehorn if (strcmp(part_type, "MBR") == 0 || 1201ee0f089SNathan Whitehorn (strcmp(platform, "chrp") == 0 && strcmp(part_type, "GPT") == 0)) 121090dd246SNathan Whitehorn return ("/boot/boot1.elf"); 1222118f387SNathan Whitehorn return (NULL); 1232118f387SNathan Whitehorn } 1242118f387SNathan Whitehorn 125