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.

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?

> 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   15 May 2016 23:28: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("string [%s] not found\n", bootdev);

The message is not very helpful.

> +
> +       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.
> @@ -64,7 +98,9 @@ parse_uboot_root(void)
> 
>         memcpy(bootdev, p, len);
>         bootdev[len] = '\0';
> -       bootdev_class = DV_DISK;
> +
> +       dp = findtype();
> +       bootdev_class = dp->class;
>  }
> 
>  void
> @@ -82,26 +118,16 @@ 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.
> +                * 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.

        switch (bootdev_class) {                                                
        case DV_DISK:                                                           
        case DV_IFNET:                                                          
                if (strcmp(name, bootdev) == 0)                                 
                        bootdv = dev;                                           
                break;                                                          
        default:                                                                
                break;                                                          
        }

>                 break;
> @@ -120,3 +146,4 @@ struct nam2blk nam2blk[] = {
>         { "amdcf",      19 },
>         { NULL,         -1 }
>  };
> +
> 

Reply via email to