1# $OpenBSD: install.md,v 1.50 2019/09/25 06:20:23 jsg 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 34NEWFSARGS_msdos="-F 16 -L boot" 35MOUNT_ARGS_msdos="-o-l" 36 37md_installboot() { 38 local _disk=/dev/$1 _mdec _plat 39 40 case $(sysctl -n hw.product) in 41 *AM335x*) _plat=am335x;; 42 *OMAP4*) _plat=panda;; 43 *'Cubietech Cubieboard2'*) _plat=cubie;; 44 *Cubox-i*|*HummingBoard*) _plat=cubox;; 45 *Wandboard*) _plat=wandboard;; 46 *Nitrogen6*|*'SABRE Lite'*) _plat=nitrogen;; 47 *) ;; # XXX: Handle unknown platform? 48 esac 49 50 # Mount MSDOS partition, extract U-Boot and copy UEFI boot program 51 mount ${MOUNT_ARGS_msdos} ${_disk}i /mnt/mnt 52 mkdir -p /mnt/mnt/efi/boot 53 cp /mnt/usr/mdec/BOOTARM.EFI /mnt/mnt/efi/boot/bootarm.efi 54 55 _mdec=/usr/mdec/$_plat 56 57 case $_plat in 58 am335x|panda) 59 cp $_mdec/{MLO,u-boot.img,*.dtb} /mnt/mnt/ 60 ;; 61 cubox|wandboard) 62 cp $_mdec/*.dtb /mnt/mnt/ 63 dd if=$_mdec/SPL of=${_disk}c bs=1024 seek=1 \ 64 >/dev/null 2>&1 65 dd if=$_mdec/u-boot.img of=${_disk}c bs=1024 seek=69 \ 66 >/dev/null 2>&1 67 ;; 68 nitrogen) 69 cp $_mdec/*.dtb /mnt/mnt/ 70 cat > /tmp/i/boot.cmd<<-__EOT 71 setenv fdtfile imx6q-sabrelite.dtb ; 72 load ${dtype} ${disk}:1 ${fdtaddr} ${fdtfile} ; 73 load ${dtype} ${disk}:1 ${loadaddr} efi/boot/bootarm.efi ; 74 bootefi ${loadaddr} ${fdtaddr} ; 75 __EOT 76 mkuboot -t script -a arm -o linux /tmp/i/boot.cmd \ 77 /mnt/mnt/6x_bootscript 78 ;; 79 cubie) 80 cp $_mdec/*.dtb /mnt/mnt/ 81 dd if=$_mdec/u-boot-sunxi-with-spl.bin of=${_disk}c \ 82 bs=1024 seek=8 >/dev/null 2>&1 83 ;; 84 esac 85} 86 87md_prep_fdisk() { 88 local _disk=$1 _d 89 90 local bootparttype="C" 91 local bootsectorstart="32768" 92 local bootsectorsize="32768" 93 local bootsectorend=$(($bootsectorstart + $bootsectorsize)) 94 local bootfstype="msdos" 95 local newfs_args=${NEWFSARGS_msdos} 96 97 while :; do 98 _d=whole 99 if disk_has $_disk mbr; then 100 fdisk $_disk 101 else 102 echo "MBR has invalid signature; not showing it." 103 fi 104 ask "Use (W)hole disk or (E)dit the MBR?" "$_d" 105 case $resp in 106 [wW]*) 107 echo -n "Creating a ${bootfstype} partition and an OpenBSD partition for rest of $_disk..." 108 fdisk -e ${_disk} <<__EOT >/dev/null 109reinit 110e 0 111${bootparttype} 112n 113${bootsectorstart} 114${bootsectorsize} 115f 0 116e 3 117A6 118n 119${bootsectorend} 120 121write 122quit 123__EOT 124 echo "done." 125 disklabel $_disk 2>/dev/null | grep -q "^ i:" || disklabel -w -d $_disk 126 newfs -t ${bootfstype} ${newfs_args} ${_disk}i 127 return ;; 128 [eE]*) 129 # Manually configure the MBR. 130 cat <<__EOT 131 132You will now create one MBR partition to contain your OpenBSD data 133and one MBR partition on which the OpenBSD boot program is located. 134Neither partition will overlap any other partition. 135 136The OpenBSD MBR partition will have an id of 'A6' and the boot MBR 137partition will have an id of '${bootparttype}' (${bootfstype}). 138The boot partition will be at least 16MB and be the first 'MSDOS' 139partition on the disk. 140 141$(fdisk ${_disk}) 142__EOT 143 fdisk -e ${_disk} 144 disk_has $_disk mbr openbsd && return 145 echo No OpenBSD partition in MBR, try again. ;; 146 esac 147 done 148} 149 150md_prep_disklabel() { 151 local _disk=$1 _f=/tmp/i/fstab.$1 152 153 md_prep_fdisk $_disk 154 155 disklabel_autolayout $_disk $_f || return 156 [[ -s $_f ]] && return 157 158 # Edit disklabel manually. 159 # Abandon all hope, ye who enter here. 160 disklabel -F $_f -E $_disk 161} 162 163md_congrats() { 164} 165 166md_consoleinfo() { 167} 168