Skip to contentSkip to conversation

ubootnet

PATCH In review Vladimir 'φ-coder/phcoder' Serbinenko 2 participants 3 messages Apr 9, 2013 – Apr 13, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ubootnet

On Raspberry pi u-boot doesn't support network. Could someone test this?

=== modified file 'grub-core/Makefile.core.def'

Makefile.core.def +6 -0
@@ -1831,6 +1831,12 @@
 };
 
 module = {
+  name = ubootnet;
+  common = net/drivers/uboot/ubootnet.c;
+  enable = uboot;
+};
+
+module = {
   name = efinet;
   common = net/drivers/efi/efinet.c;
   enable = efi;

=== added directory 'grub-core/net/drivers/uboot' === added file 'grub-core/net/drivers/uboot/ubootnet.c'

net/drivers/uboot/ubootnet.c +182 -0

182 lines not on this page · raw message

=== modified file 'include/grub/uboot/uboot.h'

grub/uboot/uboot.h +6 -6
@@ -100,19 +100,19 @@
 /*
  * int API_dev_enum(struct device_info *)
  */
-int uboot_dev_enum (void);
+int EXPORT_FUNC(uboot_dev_enum) (void);
 
-struct device_info *uboot_dev_get (int handle);
+struct device_info *EXPORT_FUNC(uboot_dev_get) (int handle);
 
 /*
  * int API_dev_open(struct device_info *)
  */
-int uboot_dev_open (int handle);
+int EXPORT_FUNC(uboot_dev_open) (int handle);
 
 /*
  * int API_dev_close(struct device_info *)
  */
-int uboot_dev_close (int handle);
+int EXPORT_FUNC(uboot_dev_close) (int handle);
 
 /*
  * Notice: this is for sending network packets only, as U-Boot does not
@@ -134,8 +134,8 @@
 int uboot_dev_read (int handle, void *buf, lbasize_t blocks,
 		    lbastart_t start, lbasize_t * real_blocks);
 
-int uboot_dev_recv (int handle, void *buf, int size, int *real_size);
-int uboot_dev_send (int handle, void *buf, int size);
+int EXPORT_FUNC(uboot_dev_recv) (int handle, void *buf, int size, int *real_size);
+int EXPORT_FUNC(uboot_dev_send) (int handle, void *buf, int size);
 
 /*
  * int API_env_get(const char *name, char **value)
#1 lore raw
Quoted 1 line · Vladimir 'φ-coder/phcoder' Serbinenko

On Raspberry pi u-boot doesn't support network. Could someone test this?

I'm unable to test it, I just have a couple of minor comments.

Quoted 2 lines
net/drivers/uboot/ubootnet.c +0 -0

[...]

net/drivers/uboot/ubootnet.c line 88

Quoted 13 lines
net/drivers/uboot/ubootnet.c +13 -0
+static struct grub_net_buff *
+get_card_packet (struct grub_net_card *dev)
+{
+  int rc;
+  struct ubootnet_data *data = dev->data;
+  grub_uint64_t start_time;
+  struct grub_net_buff *nb;
+  int actual;
+
+  nb = grub_netbuff_alloc (dev->mtu + 64 + 2);
+  if (!nb)
+    {
+      grub_netbuff_free (nb);

This grub_netbuff_free() call is not needed.

Quoted 35 lines
net/drivers/uboot/ubootnet.c +35 -0
+GRUB_MOD_INIT (ubootnet)
+{
+  int devcount, i;
+  int nfound = 0;
+
+  devcount = uboot_dev_enum ();
+
+  for (i = 0; i < devcount; i++)
+    {
+      struct device_info *devinfo = uboot_dev_get (i);
+      struct ubootnet_data *ubdata;
+      struct grub_net_card *card;
+
+      if (!(devinfo->type & DEV_TYP_NET))
+	continue;
+      
+      ubdata = grub_malloc (sizeof (struct ubootnet_data));
+      if (!ubdata)
+	{
+	  grub_print_error ();
+	  return;
+	}
+      card = grub_zalloc (sizeof (struct grub_net_card));
+      if (!card)
+	{
+	  grub_free (ubdata);
+	  grub_print_error ();
+	  return;
+	}
+
+      ubdata->handle = i;
+      ubdata->cookie = devinfo->cookie;
+
+      /* FIXME: Any way to check this?  */
+      card->mtu = 1500;

net/drivers/uboot/ubootnet.c line 161

Quoted 10 lines
net/drivers/uboot/ubootnet.c +10 -0
+
+      grub_memcpy (&(card->default_address.mac), &devinfo->di_net.hwaddr, 6);
+      card->default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
+
+      card->txbufsize = ALIGN_UP (card->mtu, 64) + 256;
+      card->txbuf = grub_zalloc (card->txbufsize);
+      if (!card->txbuf)
+	{
+	  grub_print_error ();
+	  continue;

If this happens, there would be a memory leak since ubdata and card aren't freed.

Quoted 11 lines
net/drivers/uboot/ubootnet.c +11 -0
+	}
+
+      card->data = ubdata;
+      card->flags = 0;
+      card->name = grub_xasprintf ("ubnet_%d", ++nfound);
+      card->idle_poll_delay_ms = 10;
+
+      card->driver = &ubootnet;
+      grub_net_card_register (card);
+    }
+}

net/drivers/uboot/ubootnet.c line 182

Quoted 10 lines
net/drivers/uboot/ubootnet.c +10 -0
+
+void
+grub_ubootdisk_fini (void)
+{
+  struct grub_net_card *card, *next;
+
+  FOR_NET_CARDS_SAFE (card, next) 
+    if (card->driver && grub_strcmp (card->driver->name, "ubnet") == 0)
+      grub_net_card_unregister (card);
+}

card->txbuf, card->data and card itself should be freed as well.

--
Francesco

#2 lore raw

Most issues fixed in ubootnet and ofnet

Quoted 1 line

card->txbuf, card->data and card itself should be freed as well.

Not a good idea. Some connections may still be active. Memory leak is minor.