Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Make netboot generate a BTINFO_NET bootinfo node for the...
details: https://anonhg.NetBSD.org/src/rev/b013fc1c1ed5
branches: trunk
changeset: 754927:b013fc1c1ed5
user: phx <phx%NetBSD.org@localhost>
date: Sun May 16 11:27:49 2010 +0000
description:
Make netboot generate a BTINFO_NET bootinfo node for the Synology sk(4) NIC.
It will pass the MAC address, which is read from Flash ROM, into the kernel.
The kernel creates a "mac-address" device-property, which is used by sk(4),
when given, before reading the MAC from its EEPROM.
diffstat:
sys/arch/sandpoint/include/bootinfo.h | 9 +++-
sys/arch/sandpoint/sandpoint/autoconf.c | 44 +++++++++++-----
sys/arch/sandpoint/stand/netboot/brdsetup.c | 76 ++++++++++++++++++++++++++++-
sys/arch/sandpoint/stand/netboot/globals.h | 3 +-
sys/arch/sandpoint/stand/netboot/main.c | 10 +++-
sys/arch/sandpoint/stand/netboot/skg.c | 19 ++----
sys/dev/pci/if_sk.c | 23 ++++++--
7 files changed, 147 insertions(+), 37 deletions(-)
diffs (truncated from 349 to 300 lines):
diff -r 70476fed2781 -r b013fc1c1ed5 sys/arch/sandpoint/include/bootinfo.h
--- a/sys/arch/sandpoint/include/bootinfo.h Sun May 16 11:20:01 2010 +0000
+++ b/sys/arch/sandpoint/include/bootinfo.h Sun May 16 11:27:49 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bootinfo.h,v 1.4 2007/10/17 19:56:56 garbled Exp $ */
+/* $NetBSD: bootinfo.h,v 1.5 2010/05/16 11:27:49 phx Exp $ */
/*
* Copyright (c) 1997
@@ -42,6 +42,7 @@
#define BTINFO_CLOCK 4
#define BTINFO_BOOTPATH 5
#define BTINFO_ROOTDEVICE 6
+#define BTINFO_NET 7
struct btinfo_magic {
struct btinfo_common common;
@@ -76,6 +77,12 @@
unsigned cookie;
};
+struct btinfo_net {
+ struct btinfo_common common;
+ char devname[16];
+ uint8_t mac_address[6];
+};
+
#define BOOTINFO_MAXSIZE 4096
#ifdef _KERNEL
diff -r 70476fed2781 -r b013fc1c1ed5 sys/arch/sandpoint/sandpoint/autoconf.c
--- a/sys/arch/sandpoint/sandpoint/autoconf.c Sun May 16 11:20:01 2010 +0000
+++ b/sys/arch/sandpoint/sandpoint/autoconf.c Sun May 16 11:27:49 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: autoconf.c,v 1.19 2009/03/18 10:22:35 cegger Exp $ */
+/* $NetBSD: autoconf.c,v 1.20 2010/05/16 11:27:49 phx Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -35,22 +35,25 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.19 2009/03/18 10:22:35 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.20 2010/05/16 11:27:49 phx Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/device.h>
+
+#include <dev/cons.h>
#include <dev/pci/pcivar.h>
+#include <net/if.h>
+#include <net/if_ether.h>
+
#include <machine/bootinfo.h>
+#include <machine/pio.h>
static struct btinfo_rootdevice *bi_rdev;
static struct btinfo_bootpath *bi_path;
-
-#include <dev/cons.h>
-#include <machine/pio.h>
-
+static struct btinfo_net *bi_net;
/*
* Determine i/o configuration for a machine.
@@ -61,6 +64,7 @@
bi_rdev = lookup_bootinfo(BTINFO_ROOTDEVICE);
bi_path = lookup_bootinfo(BTINFO_BOOTPATH);
+ bi_net = lookup_bootinfo(BTINFO_NET);
if (config_rootfound("mainbus", NULL) == NULL)
panic("configure: mainbus not configured");
@@ -85,18 +89,28 @@
void
device_register(struct device *dev, void *aux)
{
+ struct pci_attach_args *pa;
- if (bi_rdev == NULL)
- return; /* no clue to determine */
+ if (dev->dv_class == DV_IFNET) {
+ pa = aux;
+ if (bi_rdev != NULL && device_is_a(dev, bi_rdev->devname)
+ && bi_rdev->cookie == pa->pa_tag)
+ booted_device = dev;
+ if (bi_net != NULL && device_is_a(dev, bi_net->devname)) {
+ prop_data_t pd;
- if (dev->dv_class == DV_IFNET
- && device_is_a(dev, bi_rdev->devname)) {
- struct pci_attach_args *pa = aux;
-
- if (bi_rdev->cookie == pa->pa_tag)
- booted_device = dev;
+ pd = prop_data_create_data_nocopy(bi_net->mac_address,
+ ETHER_ADDR_LEN);
+ KASSERT(pd != NULL);
+ if (prop_dictionary_set(device_properties(dev),
+ "mac-address", pd) == false)
+ printf("WARNING: unable to set mac-addr "
+ "property for %s\n", dev->dv_xname);
+ prop_object_release(pd);
+ bi_net = NULL; /* do it just once */
+ }
}
- if (dev->dv_class == DV_DISK
+ if (bi_rdev != NULL && dev->dv_class == DV_DISK
&& device_is_a(dev, bi_rdev->devname)) {
booted_device = dev;
booted_partition = 0;
diff -r 70476fed2781 -r b013fc1c1ed5 sys/arch/sandpoint/stand/netboot/brdsetup.c
--- a/sys/arch/sandpoint/stand/netboot/brdsetup.c Sun May 16 11:20:01 2010 +0000
+++ b/sys/arch/sandpoint/stand/netboot/brdsetup.c Sun May 16 11:27:49 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: brdsetup.c,v 1.13 2010/05/13 10:40:02 phx Exp $ */
+/* $NetBSD: brdsetup.c,v 1.14 2010/05/16 11:27:49 phx Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -707,3 +707,77 @@
break;
}
}
+
+struct fis_dir_entry {
+ char name[16];
+ uint32_t startaddr;
+ uint32_t loadaddr;
+ uint32_t flashsize;
+ uint32_t entryaddr;
+ uint32_t filesize;
+ char pad[256 - (16 + 5 * sizeof(uint32_t))];
+};
+
+#define FIS_LOWER_LIMIT 0xfff00000
+
+/*
+ * Look for a Redboot-style Flash Image System FIS-directory and
+ * return a pointer to the start address of the requested file.
+ */
+static void *
+redboot_fis_lookup(const char *filename)
+{
+ static const char FISdirname[16] = {
+ 'F', 'I', 'S', ' ',
+ 'd', 'i', 'r', 'e', 'c', 't', 'o', 'r', 'y', 0, 0, 0
+ };
+ struct fis_dir_entry *dir;
+
+ /*
+ * The FIS directory is usually in the last sector of the flash.
+ * But we do not know the sector size (erase size), so start
+ * at 0xffffff00 and scan backwards in steps of the FIS directory
+ * entry size (0x100).
+ */
+ for (dir = (struct fis_dir_entry *)0xffffff00;
+ (uint32_t)dir >= FIS_LOWER_LIMIT; dir--)
+ if (memcmp(dir->name, FISdirname, sizeof(FISdirname)) == 0)
+ break;
+ if ((uint32_t)dir < FIS_LOWER_LIMIT) {
+ printf("No FIS directory found!\n");
+ return NULL;
+ }
+
+ /* Now find filename by scanning the directory from beginning. */
+ dir = (struct fis_dir_entry *)dir->startaddr;
+ while (dir->name[0] != 0xff && (uint32_t)dir < 0xffffff00) {
+ if (strcmp(dir->name, filename) == 0)
+ return (void *)dir->startaddr; /* found */
+ dir++;
+ }
+ printf("\"%s\" not found in FIS directory!\n", filename);
+ return NULL;
+}
+
+/*
+ * For cost saving reasons some NAS boxes are missing the ROM for the
+ * NIC's ethernet address and keep it in their Flash memory.
+ */
+void
+read_mac_from_flash(uint8_t *mac)
+{
+ uint8_t *p;
+
+ if (brdtype == BRD_SYNOLOGY) {
+ p = redboot_fis_lookup("vendor");
+ if (p != NULL) {
+ memcpy(mac, p, 6);
+ return;
+ }
+ } else
+ printf("Warning: This board has no known method defined "
+ "to determine its MAC address!\n");
+
+ /* set to 00:00:00:00:00:00 in case of error */
+ memset(mac, 0, 6);
+}
diff -r 70476fed2781 -r b013fc1c1ed5 sys/arch/sandpoint/stand/netboot/globals.h
--- a/sys/arch/sandpoint/stand/netboot/globals.h Sun May 16 11:20:01 2010 +0000
+++ b/sys/arch/sandpoint/stand/netboot/globals.h Sun May 16 11:27:49 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: globals.h,v 1.14 2010/05/08 19:41:07 phx Exp $ */
+/* $NetBSD: globals.h,v 1.15 2010/05/16 11:27:49 phx Exp $ */
/* clock feed */
#ifndef EXT_CLK_FREQ
@@ -23,6 +23,7 @@
extern uint32_t cpuclock, busclock;
unsigned mpc107memsize(void);
+void read_mac_from_flash(uint8_t *);
/* PPC processor ctl */
void __syncicache(void *, size_t);
diff -r 70476fed2781 -r b013fc1c1ed5 sys/arch/sandpoint/stand/netboot/main.c
--- a/sys/arch/sandpoint/stand/netboot/main.c Sun May 16 11:20:01 2010 +0000
+++ b/sys/arch/sandpoint/stand/netboot/main.c Sun May 16 11:27:49 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.28 2010/05/13 10:40:02 phx Exp $ */
+/* $NetBSD: main.c,v 1.29 2010/05/16 11:27:49 phx Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -69,6 +69,7 @@
struct btinfo_clock bi_clk;
struct btinfo_bootpath bi_path;
struct btinfo_rootdevice bi_rdev;
+ struct btinfo_net bi_net;
unsigned long marks[MARK_MAX];
unsigned lata[1][2], lnif[1][2];
unsigned memsize, tag;
@@ -158,12 +159,19 @@
snprintf(bi_path.bootpath, sizeof(bi_path.bootpath), bootfile);
snprintf(bi_rdev.devname, sizeof(bi_rdev.devname), rootdev);
bi_rdev.cookie = tag; /* PCI tag for fxp netboot case */
+ if (brdtype == BRD_SYNOLOGY) {
+ /* need to set MAC address for Marvell-SKnet */
+ strcpy(bi_net.devname, "sk");
+ memcpy(bi_net.mac_address, en, sizeof(en));
+ }
bi_add(&bi_cons, BTINFO_CONSOLE, sizeof(bi_cons));
bi_add(&bi_mem, BTINFO_MEMORY, sizeof(bi_mem));
bi_add(&bi_clk, BTINFO_CLOCK, sizeof(bi_clk));
bi_add(&bi_path, BTINFO_BOOTPATH, sizeof(bi_path));
bi_add(&bi_rdev, BTINFO_ROOTDEVICE, sizeof(bi_rdev));
+ if (brdtype == BRD_SYNOLOGY)
+ bi_add(&bi_net, BTINFO_NET, sizeof(bi_net));
printf("entry=%p, ssym=%p, esym=%p\n",
(void *)marks[MARK_ENTRY],
diff -r 70476fed2781 -r b013fc1c1ed5 sys/arch/sandpoint/stand/netboot/skg.c
--- a/sys/arch/sandpoint/stand/netboot/skg.c Sun May 16 11:20:01 2010 +0000
+++ b/sys/arch/sandpoint/stand/netboot/skg.c Sun May 16 11:27:49 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: skg.c,v 1.2 2010/05/03 18:55:09 phx Exp $ */
+/* $NetBSD: skg.c,v 1.3 2010/05/16 11:27:49 phx Exp $ */
/*-
* Copyright (c) 2010 Frank Wille.
@@ -227,25 +227,20 @@
/* read ethernet address */
en = data;
- for (i = 0; i < 6; i++)
- en[i] = CSR_READ_1(l, SK_MAC0 + i);
+ if (brdtype == BRD_SYNOLOGY)
+ read_mac_from_flash(en);
+ else
+ for (i = 0; i < 6; i++)
+ en[i] = CSR_READ_1(l, SK_MAC0 + i);
printf("MAC address %02x:%02x:%02x:%02x:%02x:%02x\n",
en[0], en[1], en[2], en[3], en[4], en[5]);
printf("PHY %d (%04x.%04x)\n", l->phy,
mii_read(l, l->phy, 2), mii_read(l, l->phy, 3));
/* set station address */
- for (i = 0; i < 3; i++) {
-#if 0
- CSR_WRITE_2(l, YUKON_SA1 + i * 4,
- CSR_READ_2(l, SK_MAC0 + i * 2));
- CSR_WRITE_2(l, YUKON_SA2 + i * 4,
- CSR_READ_2(l, SK_MAC1 + i * 2));
-#else
+ for (i = 0; i < 3; i++)
CSR_WRITE_2(l, YUKON_SA1 + i * 4,
(en[i * 2] << 8) | en[i * 2 + 1]);
-#endif
- }
/* configure RX and TX MAC FIFO */
CSR_WRITE_1(l, SK_RXMF1_CTRL_TEST, RFCTL_RESET_CLEAR);
diff -r 70476fed2781 -r b013fc1c1ed5 sys/dev/pci/if_sk.c
--- a/sys/dev/pci/if_sk.c Sun May 16 11:20:01 2010 +0000
Home |
Main Index |
Thread Index |
Old Index