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 && 638d795806SNathan Whitehorn (strcmp(part_type, "MBR") == 0 || strcmp(part_type, "BSD") == 0)) 64e25e006dSNathan Whitehorn return (1); 65e25e006dSNathan Whitehorn 662118f387SNathan Whitehorn return (0); 672118f387SNathan Whitehorn } 682118f387SNathan Whitehorn 692118f387SNathan Whitehorn size_t 702118f387SNathan Whitehorn bootpart_size(const char *part_type) { 71090dd246SNathan Whitehorn if (strcmp(part_type, "APM") == 0 || strcmp(part_type, "MBR") == 0) 722118f387SNathan Whitehorn return (800*1024); 732118f387SNathan Whitehorn return (0); 742118f387SNathan Whitehorn } 752118f387SNathan Whitehorn 762118f387SNathan Whitehorn const char * 77*6b446ed5SNathan Whitehorn bootpart_type(const char *scheme) { 78*6b446ed5SNathan Whitehorn return ("freebsd-boot"); 79*6b446ed5SNathan Whitehorn } 80*6b446ed5SNathan Whitehorn 81*6b446ed5SNathan Whitehorn const char * 822118f387SNathan Whitehorn bootcode_path(const char *part_type) { 832118f387SNathan Whitehorn return (NULL); 842118f387SNathan Whitehorn } 852118f387SNathan Whitehorn 862118f387SNathan Whitehorn const char * 872118f387SNathan Whitehorn partcode_path(const char *part_type) { 882118f387SNathan Whitehorn if (strcmp(part_type, "APM") == 0) 892118f387SNathan Whitehorn return ("/boot/boot1.hfs"); 90090dd246SNathan Whitehorn if (strcmp(part_type, "MBR") == 0) 91090dd246SNathan Whitehorn return ("/boot/boot1.elf"); 922118f387SNathan Whitehorn return (NULL); 932118f387SNathan Whitehorn } 942118f387SNathan Whitehorn 95