2003-10-13 13:37:45 +04:00
|
|
|
#!/usr/bin/awk -
|
|
|
|
#
|
2019-06-13 23:54:04 +03:00
|
|
|
# $NetBSD: MAKEDEV.awk,v 1.26 2019/06/13 20:54:04 christos Exp $
|
2003-10-13 13:37:45 +04:00
|
|
|
#
|
|
|
|
# Copyright (c) 2003 The NetBSD Foundation, Inc.
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
# by Jaromir Dolecek.
|
|
|
|
#
|
|
|
|
# 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
# ``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 FOUNDATION OR CONTRIBUTORS
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
2003-10-15 23:43:00 +04:00
|
|
|
# Script to generate platform MAKEDEV script from MI template, MD
|
|
|
|
# MAKEDEV.conf and MD/MI major lists
|
|
|
|
#
|
|
|
|
# Uses environment variables MACHINE/MACHINE_ARCH to select
|
|
|
|
# appropriate files, and NETBSDSRCDIR to get root of source tree.
|
|
|
|
|
2003-10-13 13:37:45 +04:00
|
|
|
BEGIN {
|
|
|
|
# top of source tree, used to find major number list in kernel
|
|
|
|
# sources
|
2003-12-19 09:04:16 +03:00
|
|
|
machine = ENVIRON["MACHINE"]
|
|
|
|
maarch = ENVIRON["MACHINE_ARCH"]
|
|
|
|
srcdir = ENVIRON["NETBSDSRCDIR"]
|
|
|
|
if (!machine || !maarch || !srcdir) {
|
|
|
|
print "ERROR: 'MACHINE', 'MACHINE_ARCH' and 'NETBSDSRCDIR' must be set in environment" > "/dev/stderr"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
top = srcdir "/sys/"
|
2003-10-13 13:37:45 +04:00
|
|
|
if (system("test -d '" top "'") != 0) {
|
2003-10-17 23:01:49 +04:00
|
|
|
print "ERROR: can't find top of kernel source tree ('" top "' not a directory)" > "/dev/stderr"
|
2003-10-13 13:37:45 +04:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# file with major definitions
|
|
|
|
majors[0] = "conf/majors"
|
2019-06-13 23:54:04 +03:00
|
|
|
if ((index(maarch, "arm") != 0 || index(maarch, "aarch64")) && system("test -f '" top "arch/" machine "/conf/majors." machine "'") != 0)
|
2003-10-13 13:37:45 +04:00
|
|
|
majors[1] = "arch/arm/conf/majors.arm32";
|
2007-04-08 13:35:21 +04:00
|
|
|
else if (machine == "sbmips")
|
2003-10-24 12:27:26 +04:00
|
|
|
majors[1] = "arch/evbmips/conf/majors.evbmips";
|
2010-03-30 11:30:03 +04:00
|
|
|
else if ((maarch == "powerpc" || maarch == "powerpc64") && system("test -f '" top "arch/" machine "/conf/majors." machine "'") != 0)
|
2007-12-10 20:57:24 +03:00
|
|
|
majors[1] = "arch/powerpc/conf/majors.powerpc";
|
2003-10-24 12:27:26 +04:00
|
|
|
else
|
2003-10-13 13:37:45 +04:00
|
|
|
majors[1] = "arch/" machine "/conf/majors." machine;
|
2014-09-19 13:01:05 +04:00
|
|
|
nm = 2;
|
2003-10-13 13:37:45 +04:00
|
|
|
|
|
|
|
# process all files with majors and fill the chr[] and blk[]
|
|
|
|
# arrays, used in template processing
|
2014-09-19 13:01:05 +04:00
|
|
|
for (m = 0; m < nm; m++) {
|
2003-10-13 13:37:45 +04:00
|
|
|
file = top majors[m]
|
2003-10-17 23:01:49 +04:00
|
|
|
if (system("test -f '" file "'") != 0) {
|
|
|
|
print "ERROR: can't find majors file '" file "'" > "/dev/stderr"
|
|
|
|
exit 1
|
|
|
|
}
|
2003-10-13 13:37:45 +04:00
|
|
|
while (getline < file) {
|
2014-09-19 13:01:05 +04:00
|
|
|
if ($1 == "include") {
|
|
|
|
majors[nm++] = substr($2, 2, length($2)-2);
|
|
|
|
} else if ($1 == "device-major") {
|
2003-10-13 13:37:45 +04:00
|
|
|
if ($3 == "char") {
|
|
|
|
chr[$2] = $4
|
|
|
|
if ($5 == "block")
|
|
|
|
blk[$2] = $6
|
|
|
|
} else if ($3 == "block")
|
|
|
|
blk[$2] = $4
|
|
|
|
}
|
|
|
|
}
|
2003-10-19 23:07:26 +04:00
|
|
|
close(file)
|
2003-10-13 13:37:45 +04:00
|
|
|
}
|
2007-03-09 16:57:54 +03:00
|
|
|
CONSOLE_CMAJOR = chr["cons"]
|
|
|
|
if (CONSOLE_CMAJOR == "") {
|
|
|
|
print "ERROR: no entry for 'cons' in majors file" > "/dev/stderr"
|
|
|
|
exit 1
|
|
|
|
}
|
2003-10-13 13:37:45 +04:00
|
|
|
|
2003-10-19 23:07:26 +04:00
|
|
|
# read MD config file for MD device targets
|
2003-12-19 09:04:16 +03:00
|
|
|
cfgfile = srcdir "/etc/etc." machine "/MAKEDEV.conf"
|
2003-10-19 23:07:26 +04:00
|
|
|
if (system("test -f '" cfgfile "'") != 0) {
|
2003-10-24 23:57:36 +04:00
|
|
|
print "ERROR: no platform MAKEDEV.conf - '" cfgfile "' doesn't exist" > "/dev/stderr"
|
2003-10-19 23:07:26 +04:00
|
|
|
exit 1
|
|
|
|
}
|
2004-01-14 23:37:51 +03:00
|
|
|
# skip first two lines
|
|
|
|
getline CONFRCSID < cfgfile # RCS Id
|
|
|
|
getline < cfgfile # blank line
|
2003-10-15 23:43:00 +04:00
|
|
|
MDDEV = 0 # MD device targets
|
|
|
|
while (getline < cfgfile) {
|
2003-10-19 23:07:26 +04:00
|
|
|
if (MDDEV)
|
|
|
|
MDDEV = MDDEV "\n" $0
|
|
|
|
else
|
|
|
|
MDDEV = $0
|
|
|
|
}
|
|
|
|
close(cfgfile)
|
|
|
|
|
|
|
|
# determine number of partitions used by platform
|
|
|
|
# there are three variants in tree:
|
|
|
|
# 1. MAXPARTITIONS = 8
|
|
|
|
# 2. MAXPARTITIONS = 16 with no back compat mapping
|
|
|
|
# 3. MAXPARTITIONS = 16 with back compat with old limit of 8
|
|
|
|
# currently all archs, which moved from 8->16 use same
|
|
|
|
# scheme for mapping disk minors, high minor offset
|
|
|
|
# if this changes, the below needs to be adjusted and
|
|
|
|
# additional makedisk_p16foo needs to be added
|
|
|
|
incdir = machine
|
|
|
|
diskpartitions = 0
|
|
|
|
diskbackcompat = 0
|
|
|
|
while (1) {
|
|
|
|
inc = top "arch/" incdir "/include/disklabel.h"
|
|
|
|
if (system("test -f '" inc "'") != 0) {
|
|
|
|
print "ERROR: can't find kernel include file '" inc "'" > "/dev/stderr"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
incdir = 0
|
|
|
|
while (getline < inc) {
|
2003-10-24 12:27:26 +04:00
|
|
|
if ($1 == "#define" && $2 == "MAXPARTITIONS")
|
2003-10-19 23:07:26 +04:00
|
|
|
diskpartitions = $3
|
2003-10-24 12:27:26 +04:00
|
|
|
else if ($1 == "#define" && $2 == "OLDMAXPARTITIONS")
|
|
|
|
diskbackcompat = $3
|
|
|
|
else if ($1 == "#define" && $2 == "RAW_PART")
|
|
|
|
RAWDISK_OFF = $3
|
2005-06-15 00:47:46 +04:00
|
|
|
else if ($1 == "#include" &&
|
|
|
|
$2 ~ "<.*/disklabel.h>" &&
|
|
|
|
$2 !~ ".*nbinclude.*")
|
|
|
|
{
|
2003-10-19 23:07:26 +04:00
|
|
|
# wrapper, switch to the right file
|
|
|
|
incdir = substr($2, 2)
|
|
|
|
sub("/.*", "", incdir)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-03-17 02:08:10 +03:00
|
|
|
close(inc)
|
2003-10-19 23:07:26 +04:00
|
|
|
|
|
|
|
if (diskpartitions)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!incdir) {
|
|
|
|
print "ERROR: can't determine MAXPARTITIONS from include file '" inc "'" > "/dev/stderr"
|
|
|
|
exit 1
|
|
|
|
}
|
2003-10-15 23:43:00 +04:00
|
|
|
}
|
2003-10-19 23:07:26 +04:00
|
|
|
MKDISK = "makedisk_p" diskpartitions # routine to create disk devs
|
2003-10-24 12:27:26 +04:00
|
|
|
DISKMINOROFFSET = diskpartitions
|
|
|
|
if (diskbackcompat) {
|
2003-10-19 23:07:26 +04:00
|
|
|
MKDISK = MKDISK "high"
|
2003-10-24 12:27:26 +04:00
|
|
|
DISKMINOROFFSET = diskbackcompat
|
|
|
|
}
|
|
|
|
RAWDISK_NAME = sprintf("%c", 97 + RAWDISK_OFF) # a+offset
|
2003-10-15 23:43:00 +04:00
|
|
|
|
2003-12-19 09:04:16 +03:00
|
|
|
# read etc/master.passwd for user name->UID mapping
|
|
|
|
idfile = srcdir "/etc/master.passwd"
|
|
|
|
if (system("test -f '" idfile "'") != 0) {
|
|
|
|
print "ERROR: can't find password file '" idfile "'" > "/dev/stderr"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
oldFS=FS
|
|
|
|
FS=":"
|
|
|
|
while (getline < idfile) {
|
|
|
|
uid[$1] = $3
|
|
|
|
}
|
|
|
|
close(idfile)
|
|
|
|
FS=oldFS
|
|
|
|
|
|
|
|
# read etc/group for group name->GID mapping
|
|
|
|
idfile = srcdir "/etc/group"
|
|
|
|
if (system("test -f '" idfile "'") != 0) {
|
|
|
|
print "ERROR: can't find group file '" idfile "'" > "/dev/stderr"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
oldFS=FS
|
|
|
|
FS=":"
|
|
|
|
while (getline < idfile) {
|
|
|
|
gid[$1] = $3
|
|
|
|
}
|
|
|
|
close(idfile)
|
|
|
|
FS=oldFS
|
|
|
|
|
2003-10-13 13:37:45 +04:00
|
|
|
# initially no substitutions
|
|
|
|
devsubst = 0
|
|
|
|
deventry = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
/%MI_DEVICES_BEGIN%/ {
|
|
|
|
devsubst = 1;
|
|
|
|
next
|
|
|
|
}
|
|
|
|
|
|
|
|
/%MI_DEVICES_END%/ {
|
|
|
|
devsubst = 0;
|
|
|
|
next
|
|
|
|
}
|
|
|
|
|
2004-01-14 23:37:51 +03:00
|
|
|
# output 'Generated from' lines
|
|
|
|
/\$[N]etBSD/ {
|
|
|
|
print "#"
|
|
|
|
print "# Generated from:"
|
|
|
|
|
|
|
|
# MAKEDEV.awk (this script) RCS Id
|
2019-06-13 23:54:04 +03:00
|
|
|
ARCSID = "$NetBSD: MAKEDEV.awk,v 1.26 2019/06/13 20:54:04 christos Exp $"
|
2004-01-14 23:37:51 +03:00
|
|
|
gsub(/\$/, "", ARCSID)
|
|
|
|
print "# " ARCSID
|
|
|
|
|
|
|
|
# MAKEDEV.tmpl RCS Id
|
|
|
|
gsub(/\$/, "")
|
|
|
|
print $0
|
|
|
|
|
|
|
|
# MD MAKEDEV.conf RCS Id
|
|
|
|
# strip leading hash and insert machine subdirectory name
|
|
|
|
gsub(/\$/, "", CONFRCSID)
|
|
|
|
sub(/^\# /, "", CONFRCSID)
|
|
|
|
sub(/MAKEDEV.conf/, "etc." machine "/MAKEDEV.conf", CONFRCSID)
|
|
|
|
print "# " CONFRCSID
|
|
|
|
|
|
|
|
next # don't print the RCS Id line again
|
|
|
|
}
|
|
|
|
|
|
|
|
# filter the 'PLEASE RUN ...' paragraph
|
|
|
|
/^\# PLEASE RUN/, /^\#\#\#\#\#\#/ {
|
|
|
|
next
|
|
|
|
}
|
|
|
|
|
|
|
|
# filter the device list
|
|
|
|
/^\# Tapes/,/^$/ {
|
|
|
|
next
|
|
|
|
}
|
|
|
|
|
2003-10-17 23:01:49 +04:00
|
|
|
# filter the two unneeded makedisk_p* routines, leave only
|
|
|
|
# the one used
|
2003-12-09 02:49:25 +03:00
|
|
|
/^makedisk_p8\(\) \{/, /^\}/ {
|
2003-10-17 23:01:49 +04:00
|
|
|
if (MKDISK != "makedisk_p8")
|
|
|
|
next;
|
|
|
|
}
|
2003-12-09 02:49:25 +03:00
|
|
|
/^makedisk_p16\(\) \{/, /^\}/ {
|
2003-10-17 23:01:49 +04:00
|
|
|
if (MKDISK != "makedisk_p16")
|
|
|
|
next;
|
|
|
|
}
|
2003-12-09 02:49:25 +03:00
|
|
|
/^makedisk_p16high\(\) \{/, /^\}/ {
|
2003-10-17 23:01:49 +04:00
|
|
|
if (MKDISK != "makedisk_p16high")
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2003-12-19 09:04:16 +03:00
|
|
|
# special cases aside, handle normal line
|
2003-10-13 13:37:45 +04:00
|
|
|
{
|
2003-10-26 16:40:46 +03:00
|
|
|
sub(/^%MD_DEVICES%/, MDDEV)
|
|
|
|
sub(/%MKDISK%/, MKDISK)
|
|
|
|
sub(/%DISKMINOROFFSET%/, DISKMINOROFFSET)
|
|
|
|
sub(/%RAWDISK_OFF%/, RAWDISK_OFF)
|
|
|
|
sub(/%RAWDISK_NAME%/, RAWDISK_NAME)
|
2007-03-09 16:57:54 +03:00
|
|
|
sub(/%CONSOLE_CMAJOR%/, CONSOLE_CMAJOR)
|
2004-03-19 01:51:59 +03:00
|
|
|
parsed = ""
|
|
|
|
line = $0
|
2013-05-20 15:37:02 +04:00
|
|
|
while (match(line, /%[gu]id_[_a-z]*%/)) {
|
2004-03-19 01:51:59 +03:00
|
|
|
typ = substr(line, RSTART + 1, 3);
|
|
|
|
nam = substr(line, RSTART + 5, RLENGTH - 6);
|
|
|
|
if (typ == "uid") {
|
|
|
|
if (!(nam in uid)) {
|
|
|
|
print "ERROR unmatched uid in `" $0 "'" > \
|
|
|
|
"/dev/stderr"
|
|
|
|
exit 1
|
|
|
|
} else
|
|
|
|
id = uid[nam];
|
|
|
|
} else {
|
|
|
|
if (!(nam in gid)) {
|
|
|
|
print "ERROR unmatched gid in `" $0 "'" > \
|
|
|
|
"/dev/stderr"
|
|
|
|
exit 1
|
|
|
|
} else
|
|
|
|
id = gid[nam];
|
|
|
|
}
|
2004-04-23 03:02:39 +04:00
|
|
|
parsed = parsed substr(line, 1, RSTART - 1) id
|
2004-03-19 01:51:59 +03:00
|
|
|
line = substr(line, RSTART + RLENGTH)
|
2003-12-19 09:04:16 +03:00
|
|
|
}
|
2004-03-19 01:51:59 +03:00
|
|
|
$0 = parsed line
|
2003-10-15 23:43:00 +04:00
|
|
|
|
2003-10-13 13:37:45 +04:00
|
|
|
# if device substitutions are not active, do nothing more
|
|
|
|
if (!devsubst) {
|
|
|
|
print
|
|
|
|
next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# first line of device entry
|
|
|
|
/^[a-z].*\)$/ {
|
|
|
|
if (length(deventry) > 0) {
|
|
|
|
# We have a previous entry to print. Replace all known
|
|
|
|
# character and block devices. If no unknown character
|
|
|
|
# or block device definition remains within the entry,
|
|
|
|
# print it to output, otherwise scrap it.
|
2004-03-19 01:51:59 +03:00
|
|
|
parsed = ""
|
|
|
|
while (match(deventry, /%[a-z]*_(blk|chr)%/)) {
|
|
|
|
nam = substr(deventry, RSTART + 1, RLENGTH - 6);
|
|
|
|
typ = substr(deventry, RSTART + RLENGTH - 4, 3);
|
|
|
|
if (typ == "blk") {
|
|
|
|
if (!(nam in blk)) {
|
|
|
|
deventry = $0
|
|
|
|
next
|
|
|
|
} else
|
|
|
|
dev = blk[nam];
|
|
|
|
} else {
|
|
|
|
if (!(nam in chr)) {
|
|
|
|
deventry = $0
|
|
|
|
next
|
|
|
|
} else
|
|
|
|
dev = chr[nam];
|
|
|
|
}
|
2004-04-23 03:02:39 +04:00
|
|
|
parsed = parsed substr(deventry, 1, RSTART - 1) dev
|
2004-03-19 01:51:59 +03:00
|
|
|
deventry = substr(deventry, RSTART + RLENGTH)
|
|
|
|
}
|
2003-10-13 13:37:45 +04:00
|
|
|
|
2004-03-19 01:51:59 +03:00
|
|
|
print parsed deventry
|
2003-10-13 13:37:45 +04:00
|
|
|
}
|
|
|
|
deventry = $0
|
|
|
|
next
|
|
|
|
}
|
|
|
|
|
|
|
|
# template line within device substitution section - just keep appending
|
|
|
|
# to the current entry
|
|
|
|
{
|
|
|
|
deventry = deventry "\n" $0
|
|
|
|
}
|