Bug 183236 - [patch] sysutils/hal: MMC/SD support and USB fix
Summary: [patch] sysutils/hal: MMC/SD support and USB fix
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Alberto Villa
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-23 13:00 UTC by Alberto Villa
Modified: 2013-11-12 17:40 UTC (History)
0 users

See Also:


Attachments
file.diff (12.53 KB, patch)
2013-10-23 13:00 UTC, Alberto Villa
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alberto Villa freebsd_committer freebsd_triage 2013-10-23 13:00:01 UTC
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.

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:
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.
Comment 1 Edwin Groothuis freebsd_committer freebsd_triage 2013-10-23 13:00:14 UTC
Responsible Changed
From-To: freebsd-ports-bugs->gnome

Over to maintainer (via the GNATS Auto Assign Tool)
Comment 2 Alberto Villa freebsd_committer freebsd_triage 2013-11-12 17:34:02 UTC
Responsible Changed
From-To: gnome->avilla

Taking after maintainer timeout.
Comment 3 dfilter service freebsd_committer freebsd_triage 2013-11-12 17:36:08 UTC
Author: avilla
Date: Tue Nov 12 17:35:53 2013
New Revision: 333593
URL: http://svnweb.freebsd.org/changeset/ports/333593

Log:
  - Fix USB storage detection.
  - Add MMC/SD support.
  - Update LIB_DEPENDS to new format.
  
  PR:		183236
  Submitted by:	avilla (myself)
  Approved by:	gnome (maintainer timeout)
  
  - Fix plist when PREFIX != LOCALBASE
  
  Reported by:	poudriere testport

Added:
  head/sysutils/hal/files/patch-hald_freebsd_Makefile.in   (contents, props changed)
  head/sysutils/hal/files/patch-hald_freebsd_hf-devtree.c   (contents, props changed)
  head/sysutils/hal/files/patch-hald_freebsd_hf-memcard.c   (contents, props changed)
  head/sysutils/hal/files/patch-hald_freebsd_hf-memcard.h   (contents, props changed)
  head/sysutils/hal/files/patch-hald_freebsd_hf-scsi.c   (contents, props changed)
Modified:
  head/sysutils/hal/Makefile
  head/sysutils/hal/files/patch-hald_freebsd_hf-usb2.c   (contents, props changed)
  head/sysutils/hal/pkg-plist

Modified: head/sysutils/hal/Makefile
==============================================================================
--- head/sysutils/hal/Makefile	Tue Nov 12 17:30:33 2013	(r333592)
+++ head/sysutils/hal/Makefile	Tue Nov 12 17:35:53 2013	(r333593)
@@ -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 @@ COMMENT=	Hardware Abstraction Layer for 
 
 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

Added: head/sysutils/hal/files/patch-hald_freebsd_Makefile.in
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/hal/files/patch-hald_freebsd_Makefile.in	Tue Nov 12 17:35:53 2013	(r333593)
@@ -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@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@./$(DEPDIR)/hf-devd.Plo@am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hf-devtree.Plo@am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hf-drm.Plo@am__quote@
++@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hf-memcard.Plo@am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hf-net.Plo@am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hf-pci.Plo@am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hf-pcmcia.Plo@am__quote@

Added: head/sysutils/hal/files/patch-hald_freebsd_hf-devtree.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/hal/files/patch-hald_freebsd_hf-devtree.c	Tue Nov 12 17:35:53 2013	(r333593)
@@ -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

Added: head/sysutils/hal/files/patch-hald_freebsd_hf-memcard.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/hal/files/patch-hald_freebsd_hf-memcard.c	Tue Nov 12 17:35:53 2013	(r333593)
@@ -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@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");
++}

Added: head/sysutils/hal/files/patch-hald_freebsd_hf-memcard.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/hal/files/patch-hald_freebsd_hf-memcard.h	Tue Nov 12 17:35:53 2013	(r333593)
@@ -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@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 */

Added: head/sysutils/hal/files/patch-hald_freebsd_hf-scsi.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/hal/files/patch-hald_freebsd_hf-scsi.c	Tue Nov 12 17:35:53 2013	(r333593)
@@ -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);
+ 		}
+ 	    }

Modified: head/sysutils/hal/files/patch-hald_freebsd_hf-usb2.c
==============================================================================
--- head/sysutils/hal/files/patch-hald_freebsd_hf-usb2.c	Tue Nov 12 17:30:33 2013	(r333592)
+++ head/sysutils/hal/files/patch-hald_freebsd_hf-usb2.c	Tue Nov 12 17:35:53 2013	(r333593)
@@ -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));
++			}
 +		}
 +	}
  }

Modified: head/sysutils/hal/pkg-plist
==============================================================================
--- head/sysutils/hal/pkg-plist	Tue Nov 12 17:30:33 2013	(r333592)
+++ head/sysutils/hal/pkg-plist	Tue Nov 12 17:35:53 2013	(r333593)
@@ -70,6 +70,13 @@ libexec/hald-probe-storage
 libexec/hald-probe-volume
 libexec/hald-runner
 sbin/hald
+share/PolicyKit/policy/org.freedesktop.hal.dockstation.policy
+share/PolicyKit/policy/org.freedesktop.hal.killswitch.policy
+share/PolicyKit/policy/org.freedesktop.hal.leds.policy
+share/PolicyKit/policy/org.freedesktop.hal.policy
+share/PolicyKit/policy/org.freedesktop.hal.power-management.policy
+share/PolicyKit/policy/org.freedesktop.hal.storage.policy
+share/PolicyKit/policy/org.freedesktop.hal.wol.policy
 %%PORTDOCS%%%%DOCSDIR%%/README.freebsd
 %%PORTDOCS%%%%DOCSDIR%%/README.fuse
 %%DATADIR%%/dist/hal.conf
@@ -89,13 +96,6 @@ sbin/hald
 %%DATADIR%%/fdi/policy/10osvendor/20-storage-methods.fdi
 %%DATADIR%%/fdi/policy/10osvendor/30-wol.fdi
 %%DATADIR%%/mount-fuse
-share/PolicyKit/policy/org.freedesktop.hal.dockstation.policy
-share/PolicyKit/policy/org.freedesktop.hal.killswitch.policy
-share/PolicyKit/policy/org.freedesktop.hal.leds.policy
-share/PolicyKit/policy/org.freedesktop.hal.policy
-share/PolicyKit/policy/org.freedesktop.hal.power-management.policy
-share/PolicyKit/policy/org.freedesktop.hal.storage.policy
-share/PolicyKit/policy/org.freedesktop.hal.wol.policy
 @exec mkdir -p %D/%%DATADIR%%/fdi/policy/20thirdparty
 @exec mkdir -p %D/%%DATADIR%%/fdi/preprobe/10osvendor
 @exec mkdir -p %D/%%DATADIR%%/fdi/preprobe/20thirdparty
@@ -112,6 +112,8 @@ share/PolicyKit/policy/org.freedesktop.h
 @dirrm %%DATADIR%%/dist
 @dirrm %%DATADIR%%
 @dirrm %%DOCSDIR%%
+@dirrmtry share/PolicyKit/policy
+@dirrmtry share/PolicyKit
 @dirrm libexec/hal/scripts/freebsd
 @dirrm libexec/hal/scripts
 @dirrm libexec/hal
_______________________________________________
svn-ports-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-ports-all
To unsubscribe, send any mail to "svn-ports-all-unsubscribe@freebsd.org"
Comment 4 Alberto Villa freebsd_committer freebsd_triage 2013-11-12 17:36:45 UTC
State Changed
From-To: open->closed

Patch committed.