ports/183236: [patch] sysutils/hal: MMC/SD support and USB fix

Alberto Villa avilla at FreeBSD.org
Wed Oct 23 12:00:02 UTC 2013


>Number:         183236
>Category:       ports
>Synopsis:       [patch] sysutils/hal: MMC/SD support and USB fix
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Oct 23 12:00:01 UTC 2013
>Closed-Date:
>Last-Modified:
>Originator:     Alberto Villa
>Release:        FreeBSD 10.0-ALPHA5 amd64
>Organization:
>Environment:
FreeBSD indiana.smith 10.0-ALPHA5 FreeBSD 10.0-ALPHA5 #0: Thu Oct 10 11:04:43 CEST 2013     root at indiana.smith:/usr/obj/usr/src/sys/HPDV6  amd64
>Description:
MMC/SD
Memory cards are currently detected as generic storage; thus, no "hotpluggable" nor "removable" properties are set.

USB
umass(4) devices can be detected as generic storage (again, no "hotpluggable" nor "removable" properties) in two/three cases:
- a device is inserted when the umass(4) driver is not yet loaded (with autoload on);
- a device is quickly removed and reinserted;
- a USB device and another (any) device are added at the same time.
This is caused by USB and SCSI different detection techniques in HAL: USB devices are added based on devd(8) USB "notify" events, while SCSI buses are added when probing the system for new devices, which happens on *any* devd(8) "add" event (and in many other occasions). It's quite easy for a SCSI bus to be marked as child of "computer", then.
>How-To-Repeat:
MMC/SD
Insert a MMC/SD card while in GNOME or KDE: a generic hard disk is detected (with no option to mount as a user, by default).

USB
Insert a thumb device when umass(4) is not loaded, or quickly remove and reinsert it: first time, a generic hard disk (with "removable" on, but "hotpluggable" off) will appear; from now on, reinserting the device will only make a generic, unmountable (by default), hard disk appear.
>Fix:
MMC/SD
The attached patch adds very basic support for MultiMediaCard and Secure Digital devices (hf-memcard.*), with room for other types, should someone want to implement them (I'm not even sure FreeBSD supports them). It doesn't respect HAL specification as it doesn't populate the "mmc" namespace, but it is enough to make the cards recognizable to desktop device mounters.

USB
I've added two properties to the SCSI bus device, "scsi_host.freebsd.driver" and "scsi_host.freebsd.unit", to be able to correctly configure the derived storage device even when no USB interface exists (yet). When the USB interface is created, it will find the orphan SCSI bus and make it its child. A cleaner solution would require an important modification of the FreeBSD HAL backend, really not worth the time considering that HAL is discontinued.

The patch also updates LIB_DEPENDS to make it adhere to the new standard.

Patch attached with submission follows:

Index: Makefile
===================================================================
--- Makefile	(revision 330321)
+++ Makefile	(working copy)
@@ -4,7 +4,7 @@
 
 PORTNAME=	hal
 DISTVERSION=	0.5.14
-PORTREVISION=	21
+PORTREVISION=	22
 CATEGORIES=	sysutils
 MASTER_SITES=	http://hal.freedesktop.org/releases/
 
@@ -13,9 +13,9 @@
 
 BUILD_DEPENDS=	${LOCALBASE}/include/linux/videodev2.h:${PORTSDIR}/multimedia/v4l_compat
 # keep shlib version, to prevent confusion with polkit-* from sysutils/polkit
-LIB_DEPENDS=	polkit.2:${PORTSDIR}/sysutils/policykit \
-		volume_id:${PORTSDIR}/devel/libvolume_id \
-		ck-connector:${PORTSDIR}/sysutils/consolekit
+LIB_DEPENDS=	libpolkit.so.2:${PORTSDIR}/sysutils/policykit \
+		libvolume_id.so:${PORTSDIR}/devel/libvolume_id \
+		libck-connector.so:${PORTSDIR}/sysutils/consolekit
 RUN_DEPENDS=	${LOCALBASE}/share/pciids/pci.ids:${PORTSDIR}/misc/pciids
 
 USES=		pathfix gettext gmake pkgconfig
Index: files/patch-hald_freebsd_Makefile.in
===================================================================
--- files/patch-hald_freebsd_Makefile.in	(revision 0)
+++ files/patch-hald_freebsd_Makefile.in	(working copy)
@@ -0,0 +1,36 @@
+--- ./hald/freebsd/Makefile.in.orig	2009-11-30 23:22:38.000000000 +0100
++++ ./hald/freebsd/Makefile.in	2013-10-22 02:07:00.268399458 +0200
+@@ -59,13 +59,14 @@
+ 	hf-pcmcia.c hf-pcmcia.h hf-scsi.c hf-scsi.h hf-serial.c \
+ 	hf-serial.h hf-sound.c hf-sound.h hf-storage.c hf-storage.h \
+ 	hf-usb.c hf-usb.h hf-util.c hf-util.h hf-volume.c hf-volume.h \
+-	osspec.c hal-file-monitor.c hf-usb2.c hf-usb2.h
++	osspec.c hal-file-monitor.c hf-usb2.c hf-usb2.h \
++	hf-memcard.c hf-memcard.h
+ @HAVE_LIBUSB20_TRUE at am__objects_1 = hf-usb2.lo
+ am_libhald_freebsd_la_OBJECTS = hf-acpi.lo hf-ata.lo hf-block.lo \
+ 	hf-computer.lo hf-devd.lo hf-devtree.lo hf-drm.lo hf-net.lo \
+ 	hf-pci.lo hf-pcmcia.lo hf-scsi.lo hf-serial.lo hf-sound.lo \
+ 	hf-storage.lo hf-usb.lo hf-util.lo hf-volume.lo osspec.lo \
+-	hal-file-monitor.lo $(am__objects_1)
++	hf-memcard.lo hal-file-monitor.lo $(am__objects_1)
+ libhald_freebsd_la_OBJECTS = $(am_libhald_freebsd_la_OBJECTS)
+ AM_V_lt = $(am__v_lt_$(V))
+ am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY))
+@@ -325,7 +326,7 @@
+ 	hf-scsi.c hf-scsi.h hf-serial.c hf-serial.h hf-sound.c \
+ 	hf-sound.h hf-storage.c hf-storage.h hf-usb.c hf-usb.h \
+ 	hf-util.c hf-util.h hf-volume.c hf-volume.h osspec.c \
+-	hal-file-monitor.c $(am__append_1)
++	hf-memcard.c hf-memcard.h hal-file-monitor.c $(am__append_1)
+ libhald_freebsd_la_LDFLAGS = -lcam $(am__append_2)
+ EXTRA_DIST = README TODO
+ all: all-recursive
+@@ -388,6 +389,7 @@
+ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/hf-devd.Plo at am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/hf-devtree.Plo at am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/hf-drm.Plo at am__quote@
++ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/hf-memcard.Plo at am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/hf-net.Plo at am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/hf-pci.Plo at am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/hf-pcmcia.Plo at am__quote@
Index: files/patch-hald_freebsd_hf-devtree.c
===================================================================
--- files/patch-hald_freebsd_hf-devtree.c	(revision 0)
+++ files/patch-hald_freebsd_hf-devtree.c	(working copy)
@@ -0,0 +1,21 @@
+--- ./hald/freebsd/hf-devtree.c.orig	2009-09-17 15:47:14.000000000 +0200
++++ ./hald/freebsd/hf-devtree.c	2013-10-22 02:16:42.548388644 +0200
+@@ -36,6 +36,7 @@
+ #include "hf-ata.h"
+ #include "hf-block.h"
+ #include "hf-drm.h"
++#include "hf-memcard.h"
+ #include "hf-pcmcia.h"
+ #include "hf-storage.h"
+ #include "hf-util.h"
+@@ -388,7 +389,9 @@
+   { "psm",		hf_devtree_psm_set_properties		},
+   { "sio",		NULL					},
+   { "speaker",		NULL					},
+-  { "usbus",		NULL					}
++  { "usbus",		NULL					},
++  { "mmc",		hf_mmc_host_set_properties		},
++  { "mmcsd",		hf_mmc_set_properties			}
+ };
+ 
+ static void
Index: files/patch-hald_freebsd_hf-memcard.c
===================================================================
--- files/patch-hald_freebsd_hf-memcard.c	(revision 0)
+++ files/patch-hald_freebsd_hf-memcard.c	(working copy)
@@ -0,0 +1,109 @@
+--- ./hald/freebsd/hf-memcard.c.orig	2013-10-22 01:49:10.228430727 +0200
++++ ./hald/freebsd/hf-memcard.c	2013-10-22 01:48:06.869268391 +0200
+@@ -0,0 +1,106 @@
++/***************************************************************************
++ * CVSID: $Id$
++ *
++ * hf-memcard.c : memory card support
++ *
++ * Copyright (C) 2013 Alberto Villa <avilla at FreeBSD.org>
++ *
++ * This program is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation; either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ *
++ **************************************************************************/
++
++#ifdef HAVE_CONFIG_H
++#  include <config.h>
++#endif
++
++#include <string.h>
++#include <errno.h>
++#include <stdlib.h>
++#include <unistd.h>
++
++#include "../logger.h"
++
++#include "hf-memcard.h"
++#include "hf-block.h"
++#include "hf-devtree.h"
++#include "hf-storage.h"
++#include "hf-util.h"
++
++static HalDevice *
++hf_memcard_block_device_new (HalDevice *parent,
++                             const char *driver,
++                             int unit,
++                             const char *drive_type)
++{
++  HalDevice *device;
++  char devname[16];
++
++  snprintf(devname, sizeof(devname), "%s%d", driver, unit);
++
++  g_return_val_if_fail(HAL_IS_DEVICE(parent), NULL);
++  g_return_val_if_fail(devname != NULL, NULL);
++
++  device = hf_device_new(parent);
++
++  hf_devtree_device_set_name(device, devname);
++  hf_block_device_enable(device, devname);
++
++  hf_storage_device_enable(device);
++
++  hal_device_copy_property(parent, "info.subsystem", device, "storage.bus");
++  hal_device_property_set_string(device, "storage.originating_device", hal_device_get_udi(parent));
++  hal_device_property_set_bool(device, "storage.removable", TRUE);
++  hal_device_property_set_bool(device, "storage.media_check_enabled", TRUE);
++  hal_device_property_set_bool(device, "storage.removable.support_async_notification", FALSE);
++  hal_device_property_set_bool(device, "storage.hotpluggable", TRUE);
++  if (drive_type)
++    {
++      hal_device_property_set_string(device, "storage.drive_type", drive_type);
++    }
++
++  if (hf_device_preprobe(device))
++    {
++      hf_block_device_complete(device, device, FALSE);
++      hf_device_add(device);
++      hf_storage_device_probe(device, FALSE);
++    }
++
++  return device;
++}
++
++void
++hf_mmc_host_set_properties (HalDevice *device)
++{
++  hal_device_property_set_string(device, "info.subsystem", "mmc_host");
++  hal_device_copy_property(device, "freebsd.unit", device, "mmc_host.host");
++}
++
++void
++hf_mmc_set_properties (HalDevice *device)
++{
++  HalDevice *block_device;
++
++  hal_device_property_set_string(device, "info.subsystem", "mmc");
++
++  hf_memcard_block_device_new(device,
++                              hal_device_property_get_string(device, "freebsd.driver"),
++                              hal_device_property_get_int(device, "freebsd.unit"),
++                              "sd_mmc");
++
++  /* This information belongs to the block device. */
++  hal_device_property_remove(device, "freebsd.device_file");
++  hal_device_property_remove(device, "freebsd.driver");
++  hal_device_property_remove(device, "freebsd.unit");
++}
Index: files/patch-hald_freebsd_hf-memcard.h
===================================================================
--- files/patch-hald_freebsd_hf-memcard.h	(revision 0)
+++ files/patch-hald_freebsd_hf-memcard.h	(working copy)
@@ -0,0 +1,39 @@
+--- ./hald/freebsd/hf-memcard.h.orig	2013-10-22 01:49:12.608421644 +0200
++++ ./hald/freebsd/hf-memcard.h	2013-10-22 01:41:55.228962237 +0200
+@@ -0,0 +1,36 @@
++/***************************************************************************
++ * CVSID: $Id$
++ *
++ * hf-memcard.h : memory card support
++ *
++ * Copyright (C) 2013 Alberto Villa <avilla at FreeBSD.org>
++ *
++ * This program is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation; either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
++ *
++ **************************************************************************/
++
++#ifndef _HF_MEMCARD_H
++#define _HF_MEMCARD_H
++
++#ifdef HAVE_CONFIG_H
++#  include <config.h>
++#endif
++
++#include "../device.h"
++
++void hf_mmc_host_set_properties (HalDevice *device);
++void hf_mmc_set_properties (HalDevice *device);
++
++#endif /* _HF_MEMCARD_H */
Index: files/patch-hald_freebsd_hf-scsi.c
===================================================================
--- files/patch-hald_freebsd_hf-scsi.c	(revision 0)
+++ files/patch-hald_freebsd_hf-scsi.c	(working copy)
@@ -0,0 +1,28 @@
+--- ./hald/freebsd/hf-scsi.c.orig	2009-08-24 14:42:29.000000000 +0200
++++ ./hald/freebsd/hf-scsi.c	2013-10-23 13:11:08.979758920 +0200
+@@ -223,7 +223,7 @@
+ 	      hal_device_copy_property(parent, "scsi.lun", device, "storage.lun");
+ 	      /* do not stop here, in case it's an umass device */
+ 	    }
+-	  else if (! strcmp(bus, "usb"))
++	  else if (hal_device_has_property(parent, "scsi_host.freebsd.driver") && ! strcmp(hal_device_property_get_string(parent, "scsi_host.freebsd.driver"), "umass"))
+ 	    {
+ 	      hal_device_property_set_string(device, "storage.bus", "usb");
+ 	      hal_device_property_set_string(device, "storage.originating_device", hal_device_get_udi(parent));
+@@ -508,6 +508,16 @@
+ 	      if (! parent || ! hal_device_property_get_bool(parent, "info.ignore"))
+ 		{
+ 		  device = hf_scsi_bus_device_new(parent, match);
++		  /*
++		   * Due to synchronization problems, the SCSI bus could be
++		   * created before the USB interface. Mark it as a USB mass
++		   * storage device to ensure it is detected as such.
++		   */
++		  if (! strcmp(match->dev_name, "umass-sim"))
++		    {
++		      hal_device_property_set_string(device, "scsi_host.freebsd.driver", "umass");
++		      hal_device_property_set_int(device, "scsi_host.freebsd.unit", match->unit_number);
++		    }
+ 		  hf_device_preprobe_and_add(device);
+ 		}
+ 	    }
Index: files/patch-hald_freebsd_hf-usb2.c
===================================================================
--- files/patch-hald_freebsd_hf-usb2.c	(revision 329938)
+++ files/patch-hald_freebsd_hf-usb2.c	(working copy)
@@ -1,5 +1,5 @@
---- hald/freebsd/hf-usb2.c.orig	2009-08-24 14:42:29.000000000 +0200
-+++ hald/freebsd/hf-usb2.c	2011-06-28 16:18:02.000000000 +0200
+--- ./hald/freebsd/hf-usb2.c.orig	2009-08-24 14:42:29.000000000 +0200
++++ ./hald/freebsd/hf-usb2.c	2013-10-23 13:10:36.639758556 +0200
 @@ -22,7 +22,7 @@
   **************************************************************************/
  
@@ -9,7 +9,7 @@
  #endif
  
  #include <string.h>
-@@ -42,246 +42,200 @@
+@@ -42,246 +42,213 @@
  static struct libusb20_backend *hf_usb2_be = NULL;
  
  static void
@@ -94,6 +94,19 @@
 +
 +			hf_usb_device_compute_udi(device);
 +			hf_device_add(device);
++
++			/*
++			 * The SCSI bus could already exist; make it a child of
++			 * this USB interface.
++			 */
++			if (driver && !strcmp(driver, "umass")) {
++				HalDevice *scsi_bus;
++				scsi_bus = hf_device_store_match(hald_get_gdl(),
++				    "scsi_host.freebsd.driver", HAL_PROPERTY_TYPE_STRING, driver,
++				    "scsi_host.freebsd.unit", HAL_PROPERTY_TYPE_INT32, hal_device_property_get_int(device, "freebsd.unit"), NULL);
++				if (scsi_bus)
++					hal_device_property_set_string(scsi_bus, "info.parent", hal_device_get_udi(device));
++			}
 +		}
 +	}
  }


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-ports-bugs mailing list