Visa Hankala <[email protected]> wrote:
> On Mon, May 16, 2016 at 01:39:31AM +0200, Kim Lidström wrote:
> > I am nfs booting my edgerouter lite and didn't like to have to manually
> > enter 'cnmac0'
> > as my root device every boot.
> > 
> > This is what I came up with. I stole the idea from macppc and modified
> > it a little.
> > 
> > Am I way off here?
> 
> The idea looks good. The patch format is somewhat broken though. See my
> comments inline.

I like comments! Thanks!

> 
> The buffer allocation errors are not caused by this patch. Have you
> modified cnmac(4)? The driver allocates a fixed number of gather buffers
> and the system has run out of those. Are the cnmac(4) ports transmitting
> at all after the error?
> 

I have not modified cnmac(4) and, from what I have seen during the day,
the ports seem to be transmitting without any hiccups.
I seem to consistently get around 95 megabits per second both up and
down.
The only thing I have noticed was that my phone all of a sudden couldn't
do some DNS lookups (imgur, for example) but that is most likely not
related.

I am in fact sending this email through said ports.

> > +
> > +       if (dp->dev == NULL)
> > +               printf("string [%s] not found\n", bootdev);
> 
> The message is not very helpful.

I agree!

> >         switch (bootdev_class) {
> >         case DV_DISK:
> > -               if ((strcmp(drvrname, "wd") == 0 ||
> > -                   strcmp(drvrname, "sd") == 0 ||
> > -                   strcmp(drvrname, "octcf") == 0 ||
> > -                   strcmp(drvrname, "amdcf") == 0) &&
> > -                   strcmp(name, bootdev) == 0)
> > -                       bootdv = dev;
> > -               break;
> >         case DV_IFNET:
> >                 /*
> > -                * This relies on the onboard Ethernet interface being
> > -                * attached before any other (usb) interface.
> > +                * DV_IFNET relies on the onboard Ethernet interface
> > +                * being attached before any other (usb) interface.
> >                  */
> >                 bootdv = dev;
> 
> bootdv should be set only if the device name matches bootdev. Otherwise
> the system picks always the first device in the device class. With this
> tweak, the comment seems outdated.
> 

I left that comment in there because I wasn't sure if it was still
relevant or not (Do the ethernet interface just happen to be attached
before any other interfaces on my device?) but if that is the case then
ofcourse it should be removed!

Is this patch better? I have tested it by trying both cnmac0, cnmac1 and
cnmac2 as rootdev and it seems to work properly.
I also removed the outdated comment, changed the pointless text (Maybe
it'd be more appropriate to remove it?) and changed a memcpy() to
strlcpy().
Oh, I added that strncmp too!

Index: sys/arch/octeon/octeon/autoconf.c
===================================================================
RCS file: /cvs/src/sys/arch/octeon/octeon/autoconf.c,v
retrieving revision 1.7
diff -u -p -r1.7 autoconf.c
--- sys/arch/octeon/octeon/autoconf.c   20 Jul 2015 19:44:32 -0000     
1.7
+++ sys/arch/octeon/octeon/autoconf.c   16 May 2016 23:52:33 -0000
@@ -44,11 +44,45 @@ cpu_configure(void)
        cold = 0;
 }
 
+struct devmap {
+       char *dev;
+       enum devclass class;
+};
+
+struct devmap *
+findtype(void)
+{
+       static struct devmap devmap[] = {
+               { "wd", DV_DISK },
+               { "sd", DV_DISK },
+               { "octcf", DV_DISK },
+               { "amdcf", DV_DISK },
+               { "cnmac", DV_IFNET },
+               { NULL, DV_DULL }
+       };
+       struct devmap *dp = &devmap[0];
+
+       if (strlen(bootdev) < 2)
+               return(dp);
+
+       while (dp->dev) {
+               if (strncmp(bootdev, dp->dev, strlen(dp->dev)) == 0)
+                       break;
+               dp++;
+       }
+
+       if (dp->dev == NULL)
+               printf("%s is not a valid rootdev\n", bootdev);
+       
+       return(dp);
+}
+
 void
 parse_uboot_root(void)
 {
        char *p;
        size_t len;
+       struct devmap *dp;
 
         /*
          * Turn the U-Boot root device (rootdev=/dev/octcf0) into a
          boot device.
@@ -62,9 +96,10 @@ parse_uboot_root(void)
        if (len <= 2 || len >= sizeof bootdev - 1)
                return;
 
-       memcpy(bootdev, p, len);
-       bootdev[len] = '\0';
-       bootdev_class = DV_DISK;
+       strlcpy(bootdev, p, sizeof bootdev);
+
+       dp = findtype();
+       bootdev_class = dp->class;
 }
 
 void
@@ -83,27 +118,14 @@ device_register(struct device *dev, void
        if (bootdv != NULL)
                return;
 
-       const char *drvrname = dev->dv_cfdata->cf_driver->cd_name;
-       const char *name = dev->dv_xname;
-
        if (dev->dv_class != bootdev_class)
                return;
 
        switch (bootdev_class) {
        case DV_DISK:
-               if ((strcmp(drvrname, "wd") == 0 ||
-                   strcmp(drvrname, "sd") == 0 ||
-                   strcmp(drvrname, "octcf") == 0 ||
-                   strcmp(drvrname, "amdcf") == 0) &&
-                   strcmp(name, bootdev) == 0)
-                       bootdv = dev;
-               break;
        case DV_IFNET:
-               /*
-                * This relies on the onboard Ethernet interface being
-                * attached before any other (usb) interface.
-                */
-               bootdv = dev;
+               if (strncmp(dev->dv_xname, bootdev, strlen(bootdev)) ==
0)
+                       bootdv = dev;
                break;
        default:
                break;

Reply via email to