xref: /freebsd/usr.sbin/bsdinstall/partedit/partedit_efi.c (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
17b08a307SMitchell Horne /*
27b08a307SMitchell Horne  * Copyright (C) 2016 Cavium Inc.
37b08a307SMitchell Horne  * All rights reserved.
47b08a307SMitchell Horne  *
57b08a307SMitchell Horne  * Developed by Semihalf.
67b08a307SMitchell Horne  * Based on work by Nathan Whitehorn.
77b08a307SMitchell Horne  *
87b08a307SMitchell Horne  * Redistribution and use in source and binary forms, with or without
97b08a307SMitchell Horne  * modification, are permitted provided that the following conditions
107b08a307SMitchell Horne  * are met:
117b08a307SMitchell Horne  * 1. Redistributions of source code must retain the above copyright
127b08a307SMitchell Horne  *    notice, this list of conditions and the following disclaimer.
137b08a307SMitchell Horne  * 2. Redistributions in binary form must reproduce the above copyright
147b08a307SMitchell Horne  *    notice, this list of conditions and the following disclaimer in the
157b08a307SMitchell Horne  *    documentation and/or other materials provided with the distribution.
167b08a307SMitchell Horne  *
177b08a307SMitchell Horne  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
187b08a307SMitchell Horne  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
197b08a307SMitchell Horne  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
207b08a307SMitchell Horne  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
217b08a307SMitchell Horne  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
227b08a307SMitchell Horne  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
237b08a307SMitchell Horne  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
247b08a307SMitchell Horne  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
257b08a307SMitchell Horne  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
267b08a307SMitchell Horne  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
277b08a307SMitchell Horne  * SUCH DAMAGE.
287b08a307SMitchell Horne  */
297b08a307SMitchell Horne 
307b08a307SMitchell Horne #include <sys/types.h>
317b08a307SMitchell Horne #include <string.h>
327b08a307SMitchell Horne 
337b08a307SMitchell Horne #include "partedit.h"
347b08a307SMitchell Horne 
357b08a307SMitchell Horne /*
367b08a307SMitchell Horne  * partedit implementation for platforms on which the installer only offers
377b08a307SMitchell Horne  * UEFI-based boot. Currently, this includes arm64 and RISC-V.
387b08a307SMitchell Horne  */
397b08a307SMitchell Horne 
407b08a307SMitchell Horne /* EFI partition size in bytes */
417b08a307SMitchell Horne #define	EFI_BOOTPART_SIZE	(260 * 1024 * 1024)
427b08a307SMitchell Horne 
437b08a307SMitchell Horne const char *
default_scheme(void)447b08a307SMitchell Horne default_scheme(void)
457b08a307SMitchell Horne {
467b08a307SMitchell Horne 
477b08a307SMitchell Horne 	return ("GPT");
487b08a307SMitchell Horne }
497b08a307SMitchell Horne 
507b08a307SMitchell Horne int
is_scheme_bootable(const char * part_type)517b08a307SMitchell Horne is_scheme_bootable(const char *part_type)
527b08a307SMitchell Horne {
537b08a307SMitchell Horne 
547b08a307SMitchell Horne 	if (strcmp(part_type, "GPT") == 0)
557b08a307SMitchell Horne 		return (1);
567b08a307SMitchell Horne 
577b08a307SMitchell Horne 	return (0);
587b08a307SMitchell Horne }
597b08a307SMitchell Horne 
607b08a307SMitchell Horne int
is_fs_bootable(const char * part_type,const char * fs)617b08a307SMitchell Horne is_fs_bootable(const char *part_type, const char *fs)
627b08a307SMitchell Horne {
637b08a307SMitchell Horne 
647b08a307SMitchell Horne 	if (strcmp(fs, "freebsd-ufs") == 0)
657b08a307SMitchell Horne 		return (1);
667b08a307SMitchell Horne 
677b08a307SMitchell Horne 	return (0);
687b08a307SMitchell Horne }
697b08a307SMitchell Horne 
707b08a307SMitchell Horne size_t
bootpart_size(const char * scheme)717b08a307SMitchell Horne bootpart_size(const char *scheme)
727b08a307SMitchell Horne {
737b08a307SMitchell Horne 
747b08a307SMitchell Horne 	/* We only support GPT with EFI */
757b08a307SMitchell Horne 	if (strcmp(scheme, "GPT") != 0)
767b08a307SMitchell Horne 		return (0);
777b08a307SMitchell Horne 
787b08a307SMitchell Horne 	return (EFI_BOOTPART_SIZE);
797b08a307SMitchell Horne }
807b08a307SMitchell Horne 
817b08a307SMitchell Horne const char *
bootpart_type(const char * scheme,const char ** mountpoint)827b08a307SMitchell Horne bootpart_type(const char *scheme, const char **mountpoint)
837b08a307SMitchell Horne {
847b08a307SMitchell Horne 
857b08a307SMitchell Horne 	/* Only EFI is supported as boot partition */
86*0b7472b3SNathan Whitehorn 	*mountpoint = "/boot/efi";
877b08a307SMitchell Horne 	return ("efi");
887b08a307SMitchell Horne }
897b08a307SMitchell Horne 
907b08a307SMitchell Horne const char *
bootcode_path(const char * part_type)917b08a307SMitchell Horne bootcode_path(const char *part_type)
927b08a307SMitchell Horne {
937b08a307SMitchell Horne 
947b08a307SMitchell Horne 	return (NULL);
957b08a307SMitchell Horne }
967b08a307SMitchell Horne 
977b08a307SMitchell Horne const char *
partcode_path(const char * part_type,const char * fs_type)987b08a307SMitchell Horne partcode_path(const char *part_type, const char *fs_type)
997b08a307SMitchell Horne {
1007b08a307SMitchell Horne 
1017b08a307SMitchell Horne 	/* No boot partition data. */
1027b08a307SMitchell Horne 	return (NULL);
1037b08a307SMitchell Horne }
1047b08a307SMitchell Horne 
105