base system hooks for pkgsrc drivers

. rc script and service know to look in /usr/pkg/.. for
	  extra binaries and conf files
	. service split into parsing config and doing RS request
	  so that a new utility (printconfig) can just print the
	  config in machine-parseable format for netconf integration
	. converted all base system eth drivers/netconf
This commit is contained in:
Ben Gras 2011-10-13 12:27:30 +00:00
parent 2c57ee566b
commit 349a158056
32 changed files with 1617 additions and 1256 deletions

View file

@ -5,12 +5,17 @@
# Changes:
#
# Get system config
. /etc/rc.conf
LOCALRC=/usr/etc/rc.local
INETCONF=/etc/inet.conf
RCNET=/etc/rc.net
HOSTS=/etc/hosts
HOSTNAME=/etc/hostname.file
USRKBFILE=/.usrkb
LSPCI=/tmp/lspci.$$
DEVICES=/tmp/devices.$$
step1=""
step2=""
@ -81,7 +86,7 @@ card()
shift 2
while [ $# -gt 0 ]
do
lspci | grep > /dev/null "^$1" && card_avail=1
cat $LSPCI | grep > /dev/null "^$1" && card_avail=1
shift
done
if [ $card_avail -gt 0 ]
@ -94,29 +99,23 @@ card()
printf "%2d. %s %s\n" "$card_number" "$card_mark" "$card_name"
}
first_pcicard=4
cards()
{
card 0 "No Ethernet card (no networking)"
card 1 "Intel Pro/100" "8086:103D" "8086:1064" "8086:1229" "8086:2449" \
"8086:1031" "8086:1032"
card 2 "3Com 501 or 3Com 509 based card"
card 3 "Realtek 8139 based card (also emulated by KVM)" \
"10EC:8139" "02AC:1012" "1065:8139" "1113:1211" "1186:1300" \
"1186:1340" "11DB:1234" "1259:A117" "1259:A11E" "126C:1211" \
"13D1:AB06" "1432:9130" "14EA:AB06" "14EA:AB07" "1500:1360" \
"1743:8139" "4033:1360"
card 4 "Realtek 8169 based card" \
"10EC:8129" "10EC:8167" "10EC:8169" "1186:4300" "1259:C107" \
"1385:8169" "16EC:0116" "1737:1032" "10EC:8168"
card 5 "Realtek 8029 based card (also emulated by Qemu)" "10EC:8029"
card 6 "NE2000, 3com 503 or WD based card (also emulated by Bochs)"
card 7 "AMD LANCE (also emulated by VMWare and VirtualBox)" "1022:2000"
card 8 "Intel PRO/1000 Gigabit" \
"8086:100E" "8086:107C" "8086:10CD" "8086:10D3" "8086:10DE"
card 9 "Attansic/Atheros L2 FastEthernet" "1969:2048"
card 10 "DEC Tulip 21140A in VirtualPC" "1011:0009"
card 11 "Different Ethernet card (no networking)"
card 1 "3Com 501 or 3Com 509 based card"
card 2 "Realtek 8029 based card (also emulated by Qemu)" "10EC:8029"
card 3 "NE2000, 3com 503 or WD based card (also emulated by Bochs)"
n=$first_pcicard
for pcicard in $pci_list
do var=\$pci_descr$pcicard; descr="`eval echo $var`"
var=\$pci_pcilist$pcicard; pcilist="`eval echo $var`"
card $n "$descr" $pcilist
n="`expr $n + 1`"
done
card $first_after_pci "Different Ethernet card (no networking)"
}
warn()
@ -124,6 +123,35 @@ warn()
echo -e "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b ! $1"
}
config_pci_cards() {
rm -f $DEVICES
n=0
# Collect configs from network devices
for dir in $SYSTEM_CONF_DIRS
do for f in $dir/$SYSTEM_CONF_SUBDIR/*
do if [ -f $f ]
then printconfig $f | grep 'type net.*pci device'
fi
done
done >$DEVICES
while read devline
do pcilist="`echo $devline | sed 's/.*pci device //' | sed 's/,.*//'`"
descr="`echo $devline | sed 's/.*,descr //' | sed 's/,.*//'`"
label="`echo $devline | sed 's/.*service //' | sed 's/,.*//'`"
pci_list="$pci_list $n"
eval "pci_pcilist$n=\"$pcilist\""
eval "pci_descr$n=\"$descr\""
eval "pci_label$n=\"$label\""
n="`expr $n + 1`"
done <$DEVICES
first_after_pci=`expr $first_pcicard + $n`
rm -f $DEVICES
}
do_step1()
{
eth_default=0
@ -146,26 +174,28 @@ do_step1()
drv_params()
{
# If this is a known pci device, we only have to set
# the driver.
if [ $1 -ge $first_pcicard -a $1 -lt $first_after_pci ]
then pcicard="`expr $1 - $first_pcicard`"
var=\$pci_label$pcicard; driver="`eval echo $var`"
return
fi
# Other possibilities.
case "$1" in
0) driver=psip0; ;;
1) driver=fxp; ;;
2) driver=dpeth; driverargs="#dpeth_arg='DPETH0=port:irq:memory'";
1) driver=dpeth; driverargs="#dpeth_arg='DPETH0=port:irq:memory'";
test "$v" = 1 && echo ""
test "$v" = 1 && echo "Note: After installing, edit $LOCALRC to the right configuration."
;;
4) driver=rtl8169; ;;
3) driver=rtl8139; ;;
5) driver=dp8390; driverargs="dp8390_arg='DPETH0=pci'"; ;;
6) driver=dp8390; driverargs="dp8390_arg='DPETH0=240:9'";
2) driver=dp8390; driverargs="dp8390_arg='DPETH0=pci'"; ;;
3) driver=dp8390; driverargs="dp8390_arg='DPETH0=240:9'";
test "$v" = 1 && echo ""
test "$v" = 1 && echo "Note: After installing, edit $LOCALRC to the right configuration."
test "$v" = 1 && echo " chose option 4, the defaults for emulation by Bochs have been set."
;;
7) driver="lance"; ;;
8) driver="e1000"; ;;
9) driver="atl2"; ;;
10) driver="dec21140A"; ;;
11) driver="psip0"; ;;
$first_after_pci) driver="psip0"; ;;
*) warn "choose a number"
esac
}
@ -253,6 +283,9 @@ do_step2()
fi
}
# Find pci cards we know about
config_pci_cards
# Parse options
while getopts ":qe:p:aH:i:n:g:d:s:hc" arg; do
case "$arg" in
@ -279,6 +312,9 @@ while getopts ":qe:p:aH:i:n:g:d:s:hc" arg; do
esac
done
# Run lspci once to a temp file
lspci >$LSPCI || exit
# Verify parameter count
if [ "$dhcp" != "yes" ] ; then
if [ $manual_opts -gt 0 ] ; then
@ -329,6 +365,9 @@ else
fi
echo "$driverargs" > $LOCALRC
# Remove temporary lspci output
rm -f $LSPCI
if [ -n "$manual" ]
then
# Backup config file if it exists and we're not running from CD

View file

@ -1,8 +1,11 @@
# Makefile for service
PROG= service
PROGS= service printconfig
SRCS.service=service.c parse.c util.c
SRCS.printconfig=print.c parse.c util.c
BINDIR= /bin
MAN=
MAN.service=
MAN.printconfig=
CPPFLAGS+= -I${MINIXSRCDIR}

View file

@ -0,0 +1,7 @@
struct rs_config {
struct rs_start rs_start; /* RS parameters */
const char *descr; /* human-readable description, if specified */
char *type; /* service type, if specified */
};

1137
commands/service/parse.c Normal file

File diff suppressed because it is too large Load diff

23
commands/service/parse.h Normal file
View file

@ -0,0 +1,23 @@
#define KW_SERVICE "service"
#define KW_UID "uid"
#define KW_SIGMGR "sigmgr"
#define KW_SCHEDULER "scheduler"
#define KW_PRIORITY "priority"
#define KW_QUANTUM "quantum"
#define KW_CPU "cpu"
#define KW_IRQ "irq"
#define KW_IO "io"
#define KW_PCI "pci"
#define KW_DEVICE "device"
#define KW_CLASS "class"
#define KW_SYSTEM "system"
#define KW_IPC "ipc"
#define KW_VM "vm"
#define KW_CONTROL "control"
#define KW_ALL "ALL"
#define KW_ALL_SYS "ALL_SYS"
#define KW_NONE "NONE"
#define KW_BASIC "BASIC"
#define KW_TYPE "type" /* set service type */
#define KW_NET "net" /* ethernet driver type */
#define KW_DESCR "descr" /* human-readable string */

97
commands/service/print.c Normal file
View file

@ -0,0 +1,97 @@
#include <stdarg.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <pwd.h>
#include <unistd.h>
#include <limits.h>
#include <lib.h>
#include <minix/config.h>
#include <minix/com.h>
#include <minix/const.h>
#include <minix/type.h>
#include <minix/ipc.h>
#include <minix/rs.h>
#include <minix/syslib.h>
#include <minix/bitmap.h>
#include <paths.h>
#include <minix/sef.h>
#include <minix/dmap.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <configfile.h>
#include <machine/archtypes.h>
#include <timers.h>
#include <err.h>
#include "config.h"
#include "proto.h"
#include "parse.h"
#define MAXDEPTH 10
static struct {
const char *field, *str;
} configstack[MAXDEPTH];
int depth = 0;
void printstack(void)
{
int i;
for(i = 0; i < depth; i++)
printf("%s %s,", configstack[i].field,
configstack[i].str);
}
void print(const char *field, const char *str)
{
printstack();
printf("%s %s\n", field, str);
}
void push(const char *field, const char *str)
{
assert(depth < MAXDEPTH);
configstack[depth].field = field;
configstack[depth].str = str;
depth++;
printstack();
printf("\n");
}
int main(int argc, char **argv)
{
struct rs_config config;
const char *label;
int id;
if(argc != 2) {
fprintf(stderr, "usage: %s <config>\n", argv[0]);
return 1;
}
memset(&config, 0, sizeof(config));
if(!(label = parse_config(NULL, 1, argv[1], &config)))
errx(1, "parse_config failed");
push(KW_SERVICE, label);
if(config.type) push(KW_TYPE, config.type);
if(config.descr) push(KW_DESCR, config.descr);
if(config.rs_start.rss_nr_pci_id > 0) {
printstack();
printf("%s %s ", KW_PCI, KW_DEVICE);
for(id = 0; id < config.rs_start.rss_nr_pci_id; id++) {
printf("%04X:%04X ",
config.rs_start.rss_pci_id[id].vid,
config.rs_start.rss_pci_id[id].did);
}
printf("\n");
}
}

3
commands/service/proto.h Normal file
View file

@ -0,0 +1,3 @@
void fatal(char *fmt, ...);
const char *parse_config(char *progname, int custom, char *configname,
struct rs_config *config);

File diff suppressed because it is too large Load diff

17
commands/service/util.c Normal file
View file

@ -0,0 +1,17 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
void fatal(char *fmt, ...)
{
va_list ap;
fprintf(stderr, "fatal error: ");
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
exit(1);
}

View file

@ -9,7 +9,9 @@
_PROTOTYPE(char *itoa, (int _n));
#ifndef __NBSD_LIBC
_PROTOTYPE(char *getpass, (const char *_prompt));
#ifdef __ACK__
_PROTOTYPE(void swab, (char *_from, char *_to, int _count));
#endif
#endif /* !_NBSD_LIBC */
/* Miscellaneous MINIX. */

View file

@ -2,6 +2,10 @@
PROG= atl2
SRCS= atl2.c
FILES=$(PROG).conf
FILESNAME=$(PROG)
FILESDIR= /etc/system.conf.d
DPADD+= ${LIBNETDRIVER} ${LIBSYS}
LDADD+= -lnetdriver -lsys

15
drivers/atl2/atl2.conf Normal file
View file

@ -0,0 +1,15 @@
service atl2
{
type net;
descr "Attansic/Atheros L2 FastEthernet";
system
UMAP # 14
IRQCTL # 19
;
pci device 1969/2048;
ipc
SYSTEM pm rs tty ds vm
pci inet lwip
;
};

View file

@ -4,6 +4,10 @@
PROG= dec21140A
SRCS= dec21140A.c
FILES=$(PROG).conf
FILESNAME=$(PROG)
FILESDIR= /etc/system.conf.d
DPADD+= ${LIBNETDRIVER} ${LIBSYS}
LDADD+= -lnetdriver -lsys

View file

@ -0,0 +1,17 @@
service dec21140A
{
type net;
descr "DEC Tulip 21140A in VirtualPC";
system
UMAP # 14
IRQCTL # 19
DEVIO # 21
;
pci device 1011/0009;
ipc
SYSTEM pm rs log tty ds vm
pci inet lwip
;
};

View file

@ -4,6 +4,10 @@
PROG= e1000
SRCS= e1000.c
FILES=$(PROG).conf
FILESNAME=$(PROG)
FILESDIR= /etc/system.conf.d
DPADD+= ${LIBNETDRIVER} ${LIBSYS} ${LIBTIMERS}
LDADD+= -lnetdriver -lsys -ltimers

20
drivers/e1000/e1000.conf Normal file
View file

@ -0,0 +1,20 @@
service e1000
{
type net;
descr "Intel PRO/1000 Gigabit";
system
UMAP # 14
IRQCTL # 19
DEVIO # 21
;
pci device 8086/100e;
pci device 8086/107c;
pci device 8086/10cd;
pci device 8086/10d3;
pci device 8086/10de;
pci device 8086/105e;
ipc
SYSTEM pm rs log tty ds vm
pci inet lwip ;
};

View file

@ -2,6 +2,10 @@
PROG= fxp
SRCS= fxp.c mii.c
FILES=$(PROG).conf
FILESNAME=$(PROG)
FILESDIR= /etc/system.conf.d
DPADD+= ${LIBNETDRIVER} ${LIBSYS} ${LIBTIMERS}
LDADD+= -lnetdriver -lsys -ltimers

22
drivers/fxp/fxp.conf Normal file
View file

@ -0,0 +1,22 @@
service fxp
{
type net;
descr "Intel PRO/100";
system
UMAP # 14
IRQCTL # 19
DEVIO # 21
;
pci device 8086/1031;
pci device 8086/1032;
pci device 8086/103d;
pci device 8086/1064;
pci device 8086/1229;
pci device 8086/2449;
ipc
SYSTEM pm rs log tty ds vm
pci inet lwip amddev
;
};

View file

@ -2,6 +2,10 @@
PROG= lance
SRCS= lance.c
FILES=$(PROG).conf
FILESNAME=$(PROG)
FILESDIR= /etc/system.conf.d
DPADD+= ${LIBNETDRIVER} ${LIBSYS}
LDADD+= -lnetdriver -lsys

14
drivers/lance/lance.conf Normal file
View file

@ -0,0 +1,14 @@
service lance
{
type net;
descr "AMD LANCE (also emulated by VMWare and VirtualBox)";
system
UMAP # 14
IRQCTL # 19
DEVIO # 21
;
pci device 1022/2000;
uid 0;
};

View file

@ -2,6 +2,10 @@
PROG= rtl8139
SRCS= rtl8139.c liveupdate.c
FILES=$(PROG).conf
FILESNAME=$(PROG)
FILESDIR= /etc/system.conf.d
DPADD+= ${LIBNETDRIVER} ${LIBSYS} ${LIBTIMERS}
LDADD+= -lnetdriver -lsys -ltimers

View file

@ -0,0 +1,32 @@
service rtl8139
{
type net;
descr "Realtek 8139 based card";
system
UMAP # 14
IRQCTL # 19
DEVIO # 21
;
pci device 10ec/8139;
pci device 02ac/1012;
pci device 1065/8139;
pci device 1113/1211;
pci device 1186/1300;
pci device 1186/1340;
pci device 11db/1234;
pci device 1259/a117;
pci device 1259/a11e;
pci device 126c/1211;
pci device 13d1/ab06;
pci device 1432/9130;
pci device 14ea/ab06;
pci device 14ea/ab07;
pci device 1500/1360;
pci device 1743/8139;
pci device 4033/1360;
ipc
SYSTEM pm rs log tty ds vm
pci inet lwip amddev
;
};

View file

@ -2,6 +2,10 @@
PROG= rtl8169
SRCS= rtl8169.c
FILES=$(PROG).conf
FILESNAME=$(PROG)
FILESDIR= /etc/system.conf.d
DPADD+= ${LIBNETDRIVER} ${LIBSYS} ${LIBTIMERS}
LDADD+= -lnetdriver -lsys -ltimers

View file

@ -0,0 +1,25 @@
service rtl8169
{
type net;
descr "Realtek 8169 based card";
system
UMAP # 14
IRQCTL # 19
DEVIO # 21
;
pci device 10ec/8129;
pci device 10ec/8167;
pci device 10ec/8169;
pci device 10ec/8168;
pci device 1186/4300;
pci device 1259/c107;
pci device 1385/8169;
pci device 16ec/0116;
pci device 1737/1032;
ipc
SYSTEM pm rs log tty ds vm
pci inet lwip amddev
;
};

View file

@ -1,6 +1,7 @@
ETC=/etc/
USR=/usr/
USRETC=/usr/etc/
DEFAULTS=/etc/defaults
FILES1=group hostname.file inet.conf motd.install mtab profile \
protocols rc services termcap ttytab utmp rc.cd binary_sizes \
binary_sizes.big binary_sizes.xxl syslog.conf rc.daemons.dist \
@ -9,6 +10,7 @@ FILES1=group hostname.file inet.conf motd.install mtab profile \
PWFILES=master.passwd
FILES3=daily dhcptags.conf rc
DEFAULTFILES=minix.rc.conf
USRFILES=Makefile
TOOL_PWD_MKDB= pwd_mkdb
@ -23,6 +25,7 @@ install:: installpw # installpw needed to bootstrap pw db
@echo "Making hierarchy.."
sh mtree.sh mtree/minix.tree
@for f in $(FILES3); do if [ -f $(USRETC)/$$f ]; then :; else cp usr/$$f $(USRETC); chmod 755 $(USRETC)/$$f; fi; done
for f in $(DEFAULTFILES); do cp $$f $(DEFAULTS); chmod 644 $(DEFAULTS)/$$f; done
@echo "Making devices.."
p=`pwd` && cd /dev && sh $$p/../commands/MAKEDEV/MAKEDEV.sh null
p=`pwd` && cd /dev && sh $$p/../commands/MAKEDEV/MAKEDEV.sh std 2>/dev/null

11
etc/minix.rc.conf Normal file
View file

@ -0,0 +1,11 @@
# Minix-specific rc.conf default values
# Where to find servers/drivers binaries
PKG_SERVICE_DIR=/usr/pkg/minixservices
SERVICES_DIRS="/usr/sbin $PKG_SERVICE_DIR"
# Where to find system.conf files and system.conf.d directories
# for servers/drivers
SYSTEM_CONF_SUBDIR=system.conf.d
PKG_SYSTEM_CONF_DIR=/usr/pkg/etc
SYSTEM_CONF_DIRS="/etc $PKG_SYSTEM_CONF_DIR"

View file

@ -4,6 +4,7 @@
755 root operator /dev
/dev/mouse -> /dev/kbdaux
755 root operator /etc
755 root operator /etc/defaults
755 root operator /etc/system.conf.d
755 root operator /boot
755 root operator /boot/image

View file

@ -13,6 +13,10 @@ if [ -r /etc/defaults/rc.conf ]; then
. /etc/defaults/rc.conf
fi
if [ -r /etc/defaults/minix.rc.conf ]; then
. /etc/defaults/minix.rc.conf
fi
# If this is not set to YES, the system will drop into single-user mode.
# (Doesn't matter for Minix.)
rc_configured=NO

View file

@ -285,66 +285,6 @@ service dpeth
uid 0;
};
service lance
{
system
UMAP # 14
IRQCTL # 19
DEVIO # 21
;
pci device 1022/2000;
uid 0;
};
service rtl8139
{
system
UMAP # 14
IRQCTL # 19
DEVIO # 21
;
pci device 10ec/8139;
pci device 02ac/1012;
pci device 1065/8139;
pci device 1113/1211;
pci device 1186/1300;
pci device 1186/1340;
pci device 11db/1234;
pci device 1259/a117;
pci device 1259/a11e;
pci device 126c/1211;
pci device 13d1/ab06;
pci device 1432/9130;
pci device 14ea/ab06;
pci device 14ea/ab07;
pci device 1500/1360;
pci device 1743/8139;
pci device 4033/1360;
ipc
SYSTEM pm rs log tty ds vm
pci inet lwip amddev
;
};
service fxp
{
system
UMAP # 14
IRQCTL # 19
DEVIO # 21
;
pci device 8086/1031;
pci device 8086/1032;
pci device 8086/103d;
pci device 8086/1064;
pci device 8086/1229;
pci device 8086/2449;
ipc
SYSTEM pm rs log tty ds vm
pci inet lwip amddev
;
};
service inet
{
uid 0;
@ -552,28 +492,6 @@ service osscore
uid 0;
};
service rtl8169
{
system
UMAP # 14
IRQCTL # 19
DEVIO # 21
;
pci device 10ec/8129;
pci device 10ec/8167;
pci device 10ec/8169;
pci device 10ec/8168;
pci device 1186/4300;
pci device 1259/c107;
pci device 1385/8169;
pci device 16ec/0116;
pci device 1737/1032;
ipc
SYSTEM pm rs log tty ds vm
pci inet lwip amddev
;
};
service filter
{
ipc
@ -587,51 +505,6 @@ service filter
;
};
service e1000
{
system
UMAP # 14
IRQCTL # 19
DEVIO # 21
;
pci device 8086/100e;
pci device 8086/107c;
pci device 8086/10cd;
pci device 8086/10d3;
pci device 8086/10de;
pci device 8086/105e;
ipc
SYSTEM pm rs log tty ds vm
pci inet lwip ;
};
service atl2
{
system
UMAP # 14
IRQCTL # 19
;
pci device 1969/2048;
ipc
SYSTEM pm rs tty ds vm
pci inet lwip
;
};
service dec21140A
{
system
UMAP # 14
IRQCTL # 19
DEVIO # 21
;
pci device 1011/0009;
ipc
SYSTEM pm rs log tty ds vm
pci inet lwip
;
};
service hello
{
system

View file

@ -3,6 +3,14 @@
RANDOM_FILE=/usr/adm/random.dat
LOCAL_FILE=/usr/etc/rc.local
# Get $SERVICES_DIRS
. /etc/rc.conf
# Directories to find services in
if [ ! "$SERVICES_DIRS" ]
then SERVICES_DIRS=/usr/sbin
fi
case "$#:$1" in
1:start|1:stop|1:down)
action=$1
@ -69,8 +77,18 @@ up()
if disabled $service; then return; fi
# Service is not disabled. Try to bring it up.
echo -n " $service"
service $opt up /usr/sbin/$service "$@"
found=""
for dir in $SERVICES_DIRS
do bin=$dir/$service
if [ -x $bin -a -z "$found" ]
then service $opt up $bin "$@"
echo -n " $service"
found=yes
fi
done
if [ -z "$found" ]
then echo " ($service not found in $SERVICES_DIRS)"
fi
}
get_eth_labels() {

View file

@ -63,6 +63,7 @@
#define _PATH_SERVICE "/bin/service"
#define _PATH_SYSTEM_CONF "/etc/system.conf"
#define _PATH_SYSTEM_CONF_DIR "/etc/system.conf.d"
#define _PATH_SYSTEM_CONF_PKG_DIR "/usr/pkg/etc/system.conf.d"
/* Provide trailing slash, since mostly used for building pathnames. */
#define _PATH_DEV "/dev/"

View file

@ -6,6 +6,7 @@
#define _PATH_SYSTEM_CONF "/etc/system.conf"
#define _PATH_SYSTEM_CONF_DIR "/etc/system.conf.d"
#define _PATH_SYSTEM_CONF_PKG_DIR "/usr/pkg/etc/system.conf.d"
#define _PATH_DHCPCONF "/etc/dhcp.conf"
#define _PATH_DHCPPID "/usr/run/dhcpd.pid"