Port-sparc archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: NetBSD/sparc running on qemu
Just FYI, here is a dumb script I'm using to create
disk image for emulators.
You can use it like this:
% env TOOLDIR=/your/tools/path/for/sparc sh mkbootimage.sh sparc
---
Izumi Tsutsui
---
#! /bin/sh
#
# Copyright (c) 2009 Izumi Tsutsui. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
TESTIMAGE=yes
#MACHINE=amd64
#MACHINE=i386
#MACHINE=pmax
MACHINE=sparc
#MACHINE=sparc64
#MACHINE=sun2
#MACHINE=sun3
#MACHINE=vax
if [ -z ${MACHINE} ]; then
if [ \( -z "$1" \) -o \( ! -z "$2" \) ]; then
echo "usage: $0 MACHINE"
echo "supported MACHINE:" \
"amd64, i386, pmax, sparc, sparc64, sun2, sun3, vax"
exit 1
fi
MACHINE=$1
fi
#
# target dependent info
#
if [ "${MACHINE}" = "amd64" ]; then
MACHINE_ARCH=x86_64
MACHINE_GNU_PLATFORM=x86_64--netbsd # for fdisk(8)
TARGET_ENDIAN=le
KERN_SET=kern-GENERIC
EXTRA_SETS= # nothing
USE_MBR=yes
BOOTDISK=wd0
PRIMARY_BOOT=bootxx_ffsv1
SECONDARY_BOOT=boot
SECONDARY_BOOT_ARG= # nothing
fi
if [ "${MACHINE}" = "i386" ]; then
MACHINE_ARCH=i386
MACHINE_GNU_PLATFORM=i486--netbsdelf # for fdisk(8)
TARGET_ENDIAN=le
KERN_SET=kern-GENERIC
EXTRA_SETS= # nothing
USE_MBR=yes
BOOTDISK=wd0
PRIMARY_BOOT=bootxx_ffsv1
SECONDARY_BOOT=boot
SECONDARY_BOOT_ARG= # nothing
fi
if [ "${MACHINE}" = "pmax" ]; then
MACHINE_ARCH=mipsel
MACHINE_GNU_PLATFORM=mipsel--netbsd # unused
TARGET_ENDIAN=le
KERN_SET=kern-GENERIC
EXTRA_SETS= # nothing
USE_MBR=no
BOOTDISK=sd0
PRIMARY_BOOT=bootxx_ffs
SECONDARY_BOOT= # boot.pmax is extracted from base.tgz
SECONDARY_BOOT_ARG= # nothing
fi
if [ "${MACHINE}" = "sparc" ]; then
MACHINE_ARCH=sparc
MACHINE_GNU_PLATFORM=sparc--netbsdelf # unused
TARGET_ENDIAN=be
KERN_SET=kern-GENERIC
EXTRA_SETS= # nothing
USE_MBR=no
BOOTDISK=sd0
PRIMARY_BOOT=bootxx
SECONDARY_BOOT=boot
SECONDARY_BOOT_ARG=/${SECONDARY_BOOT}
SUNLABEL=${TOOLDIR}/bin/nbsunlabel
fi
if [ "${MACHINE}" = "sparc64" ]; then
MACHINE_ARCH=sparc64
MACHINE_GNU_PLATFORM=sparc64--netbsd # unused
TARGET_ENDIAN=be
KERN_SET=kern-GENERIC
EXTRA_SETS= # nothing
USE_MBR=no
BOOTDISK=sd0
PRIMARY_BOOT=bootblk
# SECONDARY_BOOT=boot
# SECONDARY_BOOT_ARG=/${SECONDARY_BOOT}
SUNLABEL=${TOOLDIR}/bin/nbsunlabel
fi
if [ "${MACHINE}" = "sun2" ]; then
MACHINE_ARCH=m68000
MACHINE_GNU_PLATFORM=m68010--netbsdelf # unused
TARGET_ENDIAN=be
KERN_SET=kern-GENERIC
EXTRA_SETS= # nothing
USE_MBR=no
BOOTDISK=sd0
PRIMARY_BOOT=bootxx
SECONDARY_BOOT=ufsboot
SECONDARY_BOOT_ARG=/${SECONDARY_BOOT}
fi
if [ "${MACHINE}" = "sun3" ]; then
MACHINE_ARCH=m68k
MACHINE_GNU_PLATFORM=m68k--netbsdelf # unused
TARGET_ENDIAN=be
KERN_SET=kern-GENERIC
EXTRA_SETS= # nothing
USE_MBR=no
BOOTDISK=sd0
PRIMARY_BOOT=bootxx
SECONDARY_BOOT=ufsboot
SECONDARY_BOOT_ARG=/${SECONDARY_BOOT}
SUNLABEL=${TOOLDIR}/bin/nbsunlabel
fi
if [ "${MACHINE}" = "vax" ]; then
MACHINE_ARCH=vax
MACHINE_GNU_PLATFORM=vax--netbsdelf # unused
TARGET_ENDIAN=le
KERN_SET=kern-GENERIC
EXTRA_SETS= # nothing
USE_MBR=no
BOOTDISK=ra0
PRIMARY_BOOT=xxboot
SECONDARY_BOOT= # boot is extracted from base.tgz
SECONDARY_BOOT_ARG= # nothing
fi
if [ -z ${MACHINE_ARCH} ]; then
echo "Unsupported MACHINE (${MACHINE})"
exit 1
fi
#
# tooldir settings
#
#NETBSDSRCDIR=/usr/src
#TOOLDIR=/usr/tools/${MACHINE_ARCH}
if [ -z ${NETBSDSRCDIR} ]; then
NETBSDSRCDIR=/usr/src
fi
if [ -z ${TOOLDIR} ]; then
_HOST_OSNAME=`uname -s`
_HOST_OSREL=`uname -r`
_HOST_ARCH=`uname -p 2> /dev/null || uname -m`
TOOLDIRNAME=tooldir.${_HOST_OSNAME}-${_HOST_OSREL}-${_HOST_ARCH}
TOOLDIR=${NETBSDSRCDIR}/obj.${MACHINE}/${TOOLDIRNAME}
if [ ! -d ${TOOLDIR} ]; then
TOOLDIR=${NETBSDSRCDIR}/${TOOLDIRNAME}
fi
fi
if [ ! -d ${TOOLDIR} ]; then
echo 'set TOOLDIR first'; exit 1
fi
if [ ! -x ${TOOLDIR}/bin/nbdisklabel-${MACHINE} ]; then
echo 'build tools first'; exit 1
fi
#
# info about ftp to get binary sets
#
#FTPHOST=ftp.NetBSD.org
#FTPHOST=ftp.jp.NetBSD.org
FTPHOST=nyftp.NetBSD.org
#RELEASE=5.0.1
#RELEASEDIR=pub/NetBSD/NetBSD-${RELEASE}
RELEASEDIR=pub/NetBSD-daily/HEAD/201001140000Z
#
# misc build settings
#
CAT=cat
CP=cp
DD=dd
DISKLABEL=${TOOLDIR}/bin/nbdisklabel-${MACHINE}
FDISK=${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-fdisk
FTP=ftp
#FTP=lukemftp
FTP_OPTIONS=-V
MKDIR=mkdir
RM=rm
SH=sh
SED=sed
TAR=tar
TARGETROOTDIR=targetroot.${MACHINE}
DOWNLOADDIR=download.${MACHINE}
WORKDIR=work.${MACHINE}
IMAGE=${WORKDIR}/${MACHINE}.img
#
# target image size settings
#
IMAGEMB=1024 # 1024MB
SWAPMB=128 # 128MB
IMAGESECTORS=`expr ${IMAGEMB} \* 1024 \* 1024 / 512`
SWAPSECTORS=`expr ${SWAPMB} \* 1024 \* 1024 / 512`
LABELSECTORS=0
if [ "${USE_MBR}" = "yes" ]; then
LABELSECTORS=63 # historical
fi
BSDPARTSECTORS=`expr ${IMAGESECTORS} - ${LABELSECTORS}`
FSSECTORS=`expr ${IMAGESECTORS} - ${SWAPSECTORS} - ${LABELSECTORS}`
FSOFFSET=${LABELSECTORS}
SWAPOFFSET=`expr ${LABELSECTORS} + ${FSSECTORS}`
FSSIZE=`expr ${FSSECTORS} \* 512`
HEADS=64
SECTORS=32
CYLINDERS=`expr ${IMAGESECTORS} / \( ${HEADS} \* ${SECTORS} \)`
FSCYLINDERS=`expr ${FSSECTORS} / \( ${HEADS} \* ${SECTORS} \)`
SWAPCYLINDERS=`expr ${SWAPSECTORS} / \( ${HEADS} \* ${SECTORS} \)`
MBRCYLINDERS=`expr ${IMAGESECTORS} / 255 / 63`
#
# get binary sets
#
URL_SETS=ftp://${FTPHOST}/${RELEASEDIR}/${MACHINE}/binary/sets
SETS="${KERN_SET} base etc ${EXTRA_SETS}"
${MKDIR} -p ${DOWNLOADDIR}
for set in ${SETS}; do
if [ ! -f ${DOWNLOADDIR}/${set}.tgz ]; then
echo Fetching ${set}.tgz...
${FTP} ${FTP_OPTIONS} \
-o ${DOWNLOADDIR}/${set}.tgz ${URL_SETS}/${set}.tgz
fi
done
#
# create targetroot
#
echo Removing ${TARGETROOTDIR}...
${RM} -rf ${TARGETROOTDIR}
${MKDIR} -p ${TARGETROOTDIR}
for set in ${SETS}; do
echo Extracting ${set}...
${TAR} -C ${TARGETROOTDIR} -zxf ${DOWNLOADDIR}/${set}.tgz
done
# XXX /var/spool/ftp/hidden is unreadable
chmod u+r ${TARGETROOTDIR}/var/spool/ftp/hidden
# copy secondary boot for bootstrap
# XXX probabry more machine dependent
if [ ! -z ${SECONDARY_BOOT} ]; then
echo Copying secondary boot...
${CP} ${TARGETROOTDIR}/usr/mdec/${SECONDARY_BOOT} ${TARGETROOTDIR}
fi
#
# create target fs
#
echo Removing ${WORKDIR}...
${RM} -rf ${WORKDIR}
${MKDIR} -p ${WORKDIR}
echo Preparing /etc/fstab...
${CAT} > ${WORKDIR}/fstab <<EOF
/dev/${BOOTDISK}a / ffs rw,log 1 1
/dev/${BOOTDISK}b none none sw 0 0
ptyfs /dev/pts ptyfs rw 0 0
kernfs /kern kernfs rw,noauto 0 0
procfs /proc procfs rw,noauto 0 0
EOF
${CP} ${WORKDIR}/fstab ${TARGETROOTDIR}/etc
echo Setting rc_configured=YES in /etc/rc.conf...
${CAT} ${TARGETROOTDIR}/etc/rc.conf | \
${SED} -e 's/rc_configured=NO/rc_configured=YES/' > ${WORKDIR}/rc.conf
${CP} ${WORKDIR}/rc.conf ${TARGETROOTDIR}/etc
echo Preparing spec file for makefs...
${CAT} ${TARGETROOTDIR}/etc/mtree/* | \
${SED} -e 's/ size=[0-9]*//' > ${WORKDIR}/spec
${SH} ${TARGETROOTDIR}/dev/MAKEDEV -s all | \
${SED} -e '/^\. type=dir/d' -e 's,^\.,./dev,' >> ${WORKDIR}/spec
echo Creating rootfs...
${TOOLDIR}/bin/nbmakefs -M ${FSSIZE} -B ${TARGET_ENDIAN} \
-F ${WORKDIR}/spec -N ${TARGETROOTDIR}/etc \
${WORKDIR}/rootfs ${TARGETROOTDIR}
echo Installing bootstrap...
${TOOLDIR}/bin/nbinstallboot -v -m ${MACHINE} ${WORKDIR}/rootfs \
${TARGETROOTDIR}/usr/mdec/${PRIMARY_BOOT} ${SECONDARY_BOOT_ARG}
echo Creating swap fs
${DD} if=/dev/zero of=${WORKDIR}/swap count=${SWAPSECTORS}
echo Copying target disk image...
if [ ${LABELSECTORS} != 0 ]; then
${DD} if=/dev/zero of=${WORKDIR}/mbrsectors count=${LABELSECTORS}
${CAT} ${WORKDIR}/mbrsectors ${WORKDIR}/rootfs ${WORKDIR}/swap \
> ${IMAGE}
else
${CAT} ${WORKDIR}/rootfs ${WORKDIR}/swap > ${IMAGE}
fi
if [ ${LABELSECTORS} != 0 ]; then
echo creating MBR labels...
${FDISK} -f -u \
-b ${MBRCYLINDERS}/255/63 \
-0 -a -s 169/${FSOFFSET}/${FSSECTORS} \
-i -c ${TARGETROOTDIR}/usr/mdec/mbr \
-F ${IMAGE}
fi
echo Creating disklabel...
${CAT} > ${WORKDIR}/labelproto <<EOF
type: ESDI
disk: image
label:
flags:
bytes/sector: 512
sectors/track: ${SECTORS}
tracks/cylinder: ${HEADS}
sectors/cylinder: `expr ${HEADS} \* ${SECTORS}`
cylinders: ${CYLINDERS}
total sectors: ${IMAGESECTORS}
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0 # microseconds
track-to-track seek: 0 # microseconds
drivedata: 0
8 partitions:
# size offset fstype [fsize bsize cpg/sgs]
a: ${FSSECTORS} ${FSOFFSET} 4.2BSD 1024 8192 16
b: ${SWAPSECTORS} ${SWAPOFFSET} swap
c: ${BSDPARTSECTORS} ${FSOFFSET} unused 0 0
d: ${IMAGESECTORS} 0 unused 0 0
EOF
${DISKLABEL} -R -F ${IMAGE} ${WORKDIR}/labelproto
if [ ! -z ${SUNLABEL} ]; then
echo Creating sun disklabel...
printf 'V ncyl %d\nV nhead %d\nV nsect %d\na %d %d/0/0\nb %d
%d/0/0\nW\n' \
${CYLINDERS} ${HEADS} ${SECTORS} \
${FSOFFSET} ${FSCYLINDERS} ${FSCYLINDERS} ${SWAPCLYINDERS} | \
${SUNLABEL} -nq ${IMAGE}
fi
# XXX some ${MACHINE} needs disklabel for installboot
#${TOOLDIR}/bin/nbinstallboot -vm ${MACHINE} ${MACHINE}.img \
# ${TARGETROOTDIR}/usr/mdec/${PRIMARY_BOOT}
echo Creating image \"${IMAGE}\" complete.
if [ "${TESTIMAGE}" != "yes" ]; then exit; fi
#
# for test on emulators...
#
if [ "${MACHINE}" = "amd64" -a -x /usr/pkg/bin/qemu-system-x86_64 ]; then
qemu-system-x86_64 -hda ${IMAGE} -boot c
fi
if [ "${MACHINE}" = "i386" -a -x /usr/pkg/bin/qemu ]; then
qemu -hda ${IMAGE} -boot c
fi
if [ "${MACHINE}" = "pmax" -a -x /usr/pkg/bin/gxemul ]; then
gxemul -Xe 3max -d ${IMAGE}
fi
if [ "${MACHINE}" = "sparc" -a -x /usr/pkg/bin/qemu-system-sparc ]; then
dd if=/dev/zero of=${WORKDIR}/dummy.iso bs=1m count=1
# XXX dumps core after mountroot()
qemu-system-sparc -hda ${IMAGE} -cdrom ${WORKDIR}/dummy.iso
fi
if [ "${MACHINE}" = "sparc" -a -x /usr/pkg/bin/tmesh ]; then
(cd ${WORKDIR}; ${FTP} ${FTP_OPTION} \
http://people.csail.mit.edu/fredette/tme/sun4-75-rev-2.9.bin )
(cd ${WORKDIR}; ${FTP} ${FTP_OPTION} \
http://people.csail.mit.edu/fredette/tme/SUNW,501-1415.bin )
(cd ${WORKDIR}; ${FTP} ${FTP_OPTION} \
http://people.csail.mit.edu/fredette/tme/SUNW,501-1561.bin )
dd if=/dev/zero bs=1 count=2008 of=${WORKDIR}/my-sun4c-nvram.bin
tme-sun-idprom SS2 8:0:20:0:0:1 >> ${WORKDIR}/my-sun4c-nvram.bin
cp /usr/pkg/share/examples/tme/sun-keyboards.txt ${WORKDIR}
cp /usr/pkg/share/examples/tme/my-sun-macros.txt ${WORKDIR}
${SED} -e 's/^#command/command/' -e 's/my-sun4c-disk/sparc/' \
/usr/pkg/share/examples/tme/SUN4-75 > ${WORKDIR}/SUN4
# XXX
echo see http://people.csail.mit.edu/fredette/tme/sun4-75-nbsd.html \
to get boot prompt.
(cd ${WORKDIR}; tmesh SUN4)
fi
if [ "${MACHINE}" = "sparc64" -a -x /usr/pkg/bin/qemu-system-sparc64 ]; then
dd if=/dev/zero of=${WORKDIR}/dummy.iso bs=1m count=1
# XXX dumps core after mountroot()
qemu-system-sparc64 -hda ${IMAGE} -cdrom ${WORKDIR}/dummy.iso
fi
if [ "${MACHINE}" = "sun2" -a -x /usr/pkg/bin/tmesh ]; then
(cd ${WORKDIR}; ${FTP} ${FTP_OPTION} \
http://people.csail.mit.edu/fredette/tme/sun2-multi-rev-R.bin )
tme-sun-idprom 2/120 8:0:20:0:0:1 > ${WORKDIR}/my-sun2-idprom.bin
cp /usr/pkg/share/examples/tme/sun-keyboards.txt ${WORKDIR}
cp /usr/pkg/share/examples/tme/my-sun-macros.txt ${WORKDIR}
${SED} -e 's/^# command/command/' -e 's/my-sun2-disk/sun2/' \
/usr/pkg/share/examples/tme/SUN2-MULTIBUS > ${WORKDIR}/SUN2
(cd ${WORKDIR}; tmesh SUN2)
fi
if [ "${MACHINE}" = "sun3" -a -x /usr/pkg/bin/tmesh ]; then
(cd ${WORKDIR}; ${FTP} ${FTP_OPTION} \
http://people.csail.mit.edu/fredette/tme/sun3-carrera-rev-3.0.bin )
tme-sun-idprom 3/150 8:0:20:0:0:1 > ${WORKDIR}/my-sun3-idprom.bin
cp /usr/pkg/share/examples/tme/sun3-carrera-eeprom.txt \
${WORKDIR}/my-sun3-eeprom.txt
tme-sun-eeprom < ${WORKDIR}/my-sun3-eeprom.txt \
> ${WORKDIR}/my-sun3-eeprom.bin
cp /usr/pkg/share/examples/tme/sun-keyboards.txt ${WORKDIR}
cp /usr/pkg/share/examples/tme/my-sun-macros.txt ${WORKDIR}
${SED} -e 's/^# command/command/' -e 's/my-sun3-disk/sun3/' \
/usr/pkg/share/examples/tme/SUN3-CARRERA > ${WORKDIR}/SUN3
(cd ${WORKDIR}; tmesh SUN3)
fi
if [ "${MACHINE}" = "vax" -a -x /usr/pkg/bin/simh-vax ]; then
${CAT} > ${WORKDIR}/netbsd.conf <<EOF
load -r /usr/pkg/share/simh/ka655x.bin
set cpu 256m
set rq0 ra92
at rq0 ${MACHINE}.img
boot cpu
EOF
echo type \"boot dua0\" to boot from image.
(cd ${WORKDIR}; simh-vax netbsd.conf)
fi
Home |
Main Index |
Thread Index |
Old Index