1# $OpenBSD: install.md,v 1.57 2024/04/09 11:13:51 kettenis Exp $ 2# 3# Copyright (c) 1996 The NetBSD Foundation, Inc. 4# All rights reserved. 5# 6# This code is derived from software contributed to The NetBSD Foundation 7# by Jason R. Thorpe. 8# 9# Redistribution and use in source and binary forms, with or without 10# modification, are permitted provided that the following conditions 11# are met: 12# 1. Redistributions of source code must retain the above copyright 13# notice, this list of conditions and the following disclaimer. 14# 2. Redistributions in binary form must reproduce the above copyright 15# notice, this list of conditions and the following disclaimer in the 16# documentation and/or other materials provided with the distribution. 17# 18# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE 22# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28# POSSIBILITY OF SUCH DAMAGE. 29# 30# 31# machine dependent section of installation/upgrade script. 32# 33 34MOUNT_ARGS_msdos="-o-l" 35 36md_installboot() { 37 local _disk=$1 _mdec _plat 38 39 case $(sysctl -n hw.product) in 40 *AM335x*) _plat=am335x;; 41 *OMAP4*) _plat=panda;; 42 *Cubox-i*|*HummingBoard*) _plat=cubox;; 43 *Wandboard*) _plat=wandboard;; 44 *Nitrogen6*|*'SABRE Lite'*) _plat=nitrogen;; 45 *) ;; # XXX: Handle unknown platform? 46 esac 47 48 if ! installboot -r /mnt ${1}; then 49 echo "\nFailed to install bootblocks." 50 echo "You will not be able to boot OpenBSD from ${1}." 51 exit 52 fi 53 54 # Apply some final tweaks on selected platforms 55 mount ${MOUNT_ARGS_msdos} /dev/${_disk}i /mnt/mnt 56 57 _mdec=/usr/mdec/$_plat 58 59 case $_plat in 60 am335x|panda) 61 cp $_mdec/{MLO,u-boot.img,*.dtb} /mnt/mnt/ 62 ;; 63 cubox|wandboard) 64 cp $_mdec/*.dtb /mnt/mnt/ 65 dd if=$_mdec/SPL of=/dev/${_disk}c bs=1024 seek=1 \ 66 status=none 67 dd if=$_mdec/u-boot.img of=/dev/${_disk}c bs=1024 seek=69 \ 68 status=none 69 ;; 70 nitrogen) 71 cp $_mdec/*.dtb /mnt/mnt/ 72 cat > /tmp/i/boot.cmd<<-__EOT 73 setenv fdtfile imx6q-sabrelite.dtb ; 74 load ${dtype} ${disk}:1 ${fdtaddr} ${fdtfile} ; 75 load ${dtype} ${disk}:1 ${loadaddr} efi/boot/bootarm.efi ; 76 bootefi ${loadaddr} ${fdtaddr} ; 77 __EOT 78 mkuboot -t script -a arm -o linux /tmp/i/boot.cmd \ 79 /mnt/mnt/6x_bootscript 80 ;; 81 esac 82 83 umount /mnt/mnt 84} 85 86md_prep_fdisk() { 87 local _disk=$1 _d 88 89 local bootparttype="C" 90 local bootsectorstart="32768" 91 local bootsectorsize="32768" 92 local bootfstype="msdos" 93 94 while :; do 95 _d=whole 96 if disk_has $_disk mbr; then 97 fdisk $_disk 98 else 99 echo "MBR has invalid signature; not showing it." 100 fi 101 ask "Use (W)hole disk or (E)dit the MBR?" "$_d" 102 case $resp in 103 [wW]*) 104 echo -n "Creating a ${bootfstype} partition and an OpenBSD partition for rest of $_disk..." 105 fdisk -iy -b "${bootsectorsize}@${bootsectorstart}:${bootparttype}" ${_disk} >/dev/null 106 echo "done." 107 installboot -p $_disk 108 return ;; 109 [eE]*) 110 # Manually configure the MBR. 111 cat <<__EOT 112 113You will now create one MBR partition to contain your OpenBSD data 114and one MBR partition on which the OpenBSD boot program is located. 115Neither partition will overlap any other partition. 116 117The OpenBSD MBR partition will have an id of 'A6' and the boot MBR 118partition will have an id of '${bootparttype}' (${bootfstype}). 119The boot partition will be at least 16MB and be the first 'MSDOS' 120partition on the disk. 121 122$(fdisk ${_disk}) 123__EOT 124 fdisk -e ${_disk} 125 disk_has $_disk mbr openbsd && return 126 echo No OpenBSD partition in MBR, try again. ;; 127 esac 128 done 129} 130 131md_prep_disklabel() { 132 local _disk=$1 _f=/tmp/i/fstab.$1 133 134 md_prep_fdisk $_disk 135 136 disklabel_autolayout $_disk $_f || return 137 [[ -s $_f ]] && return 138 139 # Edit disklabel manually. 140 # Abandon all hope, ye who enter here. 141 disklabel -F $_f -E $_disk 142} 143 144md_congrats() { 145} 146 147md_consoleinfo() { 148} 149