Showing posts with label FreeBSD. Show all posts
Showing posts with label FreeBSD. Show all posts

Saturday, June 2, 2012

libusb-1.0 and libusbx in OpenBSD ports and NetBSD pkgsrc now

libusb-1.0.9 and libusbx-1.0.11 have OpenBSD/NetBSD support. Now libusb-1.0 and libusb-compat are OpenBSD's ports system. NetBSD's pkgsrc system (okay, pkgsrc is not only for NetBSD) now has both libusb-1.0.9 and libusbx-1.0.11, it also has libusb-compat as well.

On the other hand, at least for the faster moving libusbx, OpenBSD/NetBSD are behind the other supported OS (Linux, Mac OS X and Windows). Hopefully the OpenBSD/NetBSD users can jump in and bridge the gap.

Take note FreeBSD has its own libusb-1.0/libusb-0.1 wrapper on top of its own libusb20 library.

Sunday, April 15, 2012

OpenBSD, NetBSD and libusb-1.0

There is OpenBSD support in libusb.git. Since NetBSD and OpenBSD should have quite similar USB codes, I think that it should work under NetBSD as well.
Therefore I tried the following dirty patch to enable libusb-1.0 experimental support for NetBSD using the OpenBSD backend.
Take note FreeBSD has its own libusb-1.0 implementation which should be more mature than the OpenBSD backends of libusb-1.0 which is very recent.
diff --git a/configure.ac b/configure.ac
index ebbc107..71aad37 100644
--- a/configure.ac
+++ b/configure.ac
@@ -83,6 +83,17 @@ case $host in
       AC_CHECK_HEADERS([poll.h])
       AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
       ;;
+*-netbsd*)
+       AC_DEFINE(OS_OPENBSD, 1, [OpenBSD backend])
+       AC_SUBST(OS_OPENBSD)
+       AC_MSG_RESULT([OpenBSD])
+       backend="openbsd"
+       threads="posix"
+       THREAD_CFLAGS="-pthread"
+       PC_LIBS_PRIVATE="-pthread"
+       AC_CHECK_HEADERS([poll.h])
+       AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
+       ;;
 *-mingw*)
       AC_MSG_RESULT([Windows])
       backend="windows"
And indeed it seems to work under NetBSD (tested with a NetBSD 5.1 VirtualBox VM under Mac OS X Lion)
localhost$ sudo ./listdevs
04d8:fa2e (bus 0, device 2)
I also tested libusb-pbatard's xusb example.
localhost$ sudo ./xusb -d 04d8:fa2e

Opening device...
speed: Unknown

Reading device descriptor:


Reading device descriptor:
           length: 18
     device class: 0
              S/N: 3
          VID:PID: 04D8:FA2E
        bcdDevice: 0001
  iMan:iProd:iSer: 1:2:3
         nb confs: 1

Reading configuration descriptors:
            nb interfaces: 1
             interface[0]: id = 0
interface[0].altsetting[0]: num endpoints = 2
  Class.SubClass.Protocol: 00.00.00
      endpoint[0].address: 01
          max packet size: 0020
         polling interval: 00
      endpoint[1].address: 81
          max packet size: 0020
         polling interval: 00
interface[0].altsetting[1]: num endpoints = 2
  Class.SubClass.Protocol: 00.00.00
      endpoint[0].address: 01
          max packet size: 0040
         polling interval: 00
      endpoint[1].address: 81
          max packet size: 0040
         polling interval: 00

Claiming interface 0...

Reading string descriptors:
  String (0x01): "Travis Robinson"
  String (0x02): "Benchmark Device"
  String (0x03): "LUSBW1"

Releasing interface 0...
Closing device...

Sunday, February 21, 2010

FreeBSD 8.0 First Impression

Now I used FreeBSD 8.0-Release (updated to 8.0-RELEASE-p2) and it seems to be much better than last time, especially in the USB front. I also like the freebsd-update capability. It seems to be faster than last time.

What I like compare to Linux: maybe the BSD license itself. But now I feel GPL/LGPL are not bad either.

What is not working: my SATA DVD-RW is not recognized at all. This is an Acer M1641 desktop with NVidia 620i/Geforce 7050 based chipset and FreeBSD seems to have big problems with NForce 620i and 630i.

What I do not like: the port system. I have since removed most of the packages initially installed (LXDE, KDE3, KDE 4, QT33, QT4, etc) due to the mass upgrade of libjpeg. It caused big problems to many packages. So now I have a bare-minimum Gnome 2.26 based desktop (dare not update to 2.28). Mass upgrade takes a long time and often the ports are broken. ARCH seems to do a much better job since binary updates are provided. I still like Ubuntu's package system (deb/apt, Synaptic) the best.

My libusb testing on FreeBSD: pk2cmd seems to behave like last time, but now I do not need to recompile the kernel. libusb based programs work better but there are still problems.
http://old.nabble.com/LibUSB-on-FreeBSD--current-%288.x%29-td21642051.html

My OpenOCD test on FreeBSD: FT2232D seems to work, J-Link V3 does not work. J-Link V7 seems to work. All of them works under Linux.
https://lists.berlios.de/pipermail/openocd-development/2010-February/014864.html

My main interests with FreeBSD will be more libusb/MCU related -- to get OpenOCD (J-Link and FTDI, for ARM MCU development) and PICkit 2 (and other PIC related things, for PIC development) to work well under FreeBSD. Now it seems that FreeBSD is an possible platform for MCU development.

Monday, February 15, 2010

FreeBSD 8.0 Installed

After about 1.5 years gap with FreeBSDs, yesterday I finally got FreeBSD 8.0 Release version installed. My main interests are to get some libusb based programs to work under FreeBSD, including the USB demos from Microchip, pk2cmd for PICkit 2.

The installation itself is not flawless. Initially I tried with ACPI disabled (last time it helped) but this resulted in General Protection Fault on this Acer M1641 PC (Nvidia 620i/Geforce 7050 integrated chipset). With ACPI enabled, the install CD can boot up. But the installed could not find the SATA DVD-RW. Luckily the network card was recognized. So I used network install and it was not too bad, faster than I expected. I then spent some time to get Nvidia driver port to work. I have to disable the Linux emulation support in nvidia-driver since I could not download the large Linux emulation base packages (linux_base-f10) due to dead mirrors.

There are some other minor things to fix up, like I need to mount procfs to /proc (edit /etc/fstab) to get the gdm login screen to be able to properly shutdown/reboot the PC.

I tried a few simple programs based on libusb 0.1 and they seem to work fine under FreeBSD 8.0 release. Last time I had to patch the kernel and use the then alternative USB stack from Hans Petter Selasky (FreeBSD USB developer).

Then I tried to build pk2cmd and it seemed to work. The "-s" option does not see to work just as the release note of pk2cmd 1.20 says. I have not tried updating the firmware which was not working last time I tried it.

libusb 1.0 API has not fully been synced by the FreeBSD /usr/include/libusb.h. Luckily Hans says that he will make the libusb 1.0 compatible layer available to FreeBSD.

USB permision setup is now much easier than last time. By default, it seems USB device will have a ugen driver associated. The /dev/ugen* device belong to the operator group. So it is quite easy to add the user to the operator group and then the user can run libusb based program without root privilege.

I had problems to build OpenOCD git code, luckily Tomek Cedro provided a port so that I could build OpenOCD 0.4.0-rc2. I had to update the port system to build libftdi 0.17. This seems to be a prerequisite for OpenOCD.

Overall this time I have more positive views about FreeBSD. It is not as smooth as Ubuntu, but at least it is quite usable.

$ uname -a
FreeBSD MyFreeBSD.WORKGROUP 8.0-RELEASE-p2 FreeBSD 8.0-RELEASE-p2 #0: Tue Jan 5 16:02:27 UTC 2010 root@i386-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC i386

[mcuee@MyFreeBSD /usr/home/mcuee/Desktop/build/pk2cmd/pk2cmdv1.20LinuxMacSource]$ ./pk2cmd -?V

Executable Version: 1.20.00
Device File Version: 1.55.00
OS Firmware Version: 2.32.00

Operation Succeeded

Monday, September 22, 2008

Acer M1641 Ubuntu 8.04 Shutdown Problem Solved

I could not find any BIOS updates to Acer M1641. Therefore I have to use "acpi=off pnpbios=off" option. There was still a problem. Reboot works. Shutdown does not work as it hangs.

Similar bugs were reported for Ubuntu 8.04.
1) https://bugs.launchpad.net/ubuntu/+bug/193125
2) http://ubuntuforums.org/showthread.php?t=699506
3) http://ubuntuforums.org/showthread.php?t=698972

The solution in the Launchpad bug report works.

This is certainly not an old PC and Vista 32bit SP1 works fine. However I tend to believe this is more an Acer Bios bug. Actually FreeBSD 7 hangs during startup. If I disabled ACPI in BIOS, FreeBSD 7 will complain about GPF (General Protection Fault) no matter which option I select for startup. If I enable ACPI in BIOS, it could not find the disk. So I could not run FreeBSD 7 at all with this new PC. So Ubuntu 8.04 is at least better than FreeBSD 7 in this aspect.

FreeBSD problem with Acer M1641 is reported here.
http://unix.derkeiler.com/Mailing-Lists/FreeBSD/questions/2008-08/msg00806.html

Notes on 10-April-2009:
The latest kernel does not need the options any more for Ubuntu 8.04.

Wednesday, July 2, 2008

Cross-platform pk2cmd 1.10 released

Microchip has released a cross-platform version of pk2cmd
V1.10. It works under Windows, Mac OS X and Linux. It is
also partially working under FreeBSD. I am proud to
have contributed the development by providing some ideas
and carry out quite some testing under Linux and FreeBSD.


Announcement:
http://forum.microchip.com/tm.aspx?m=349078

Download:
http://www.microchip.com/pickit2

My blog has quite some articles about pk2cmd under
Linux and FreeBSD.
http://mcuee.blogspot.com/search/label/PICKit

Saturday, December 22, 2007

NetBSD 4.0 upgrade -- smooth process

I installed NetBSD 3.1 sometime ago. I also used the pkgsrc binary CD to install GNOME so that I had a basic working installation.

One of the annoying 'feature' of NetBSD 3.1 is that it is not compliant to multi-boot so that grub will not be able to pass the kernel parameters to it. Therefore I need to answer several questions before I can boot into NetBSD. Somehow pkg_add did not work well with ftp.netbsd.org.

So now NetBSD 4.0 is just out. So I update the existing installation to it today. It is a very smooth process. More importantly, it is compatible with multiboot and grub has no problem to boot NetBSD 4.0 now. The existing 3.1 binary packages are still working. pkg_add is now working as well with ftp.netbsd.org even though it still prints out some error messages.

Since I have got PICkit 2 to work under FreeBSD (with HPS USB stack), I will try to get it to work under NetBSD. But I have never used NetBSD before, this might take some time.

Saturday, December 8, 2007

Impressions of Some Linux/BSD Distributions

Before Fall 2002, I was mainly playing with Linux (Slackware, Redhat, Mandrake, Corel, Caldera, etc) but still use Windows mostly at home. I was not using Linux between Fall 2002 and Spring 2005.

I started to try out Linux again with Ubuntu 5.04 and I liked it quite a lot. Then I was trying to 5.10 and it was not as good so I started to look at Fedora as well (Core 4). Soon I fixed the problem with 5.10 and then I found 6.06 LTS a great distribution that I am still running it as the main distribution now. I also tried Ubuntu 6.10/7.04 and they were good as well. Now I have Ubuntu 7.10 installed. Initially it is not good (problem with USplash screen) but I solved it. Firefox 1.5 under Ubuntu 6.06 is not that good but switching to swiftfox seems to solve the problem. Firefox 2.0 under Ubuntu 7.10 initially is very bad but once I remove xgl/compiz stuff it becomes better now.

On the other hand, FC5/FC6 and Fedora 7 were also not bad so I was using Fedora as the 2nd option to Ubuntu. Fedora 8 is a disaster (despite the flawless installation process) that it did not boot after installation due to the bug associated with FreeBSD partitions. So now I do not have a Fedora installation.

I tried to use OpenSuse as well, it is rather sophiscated but I feel it is relative slow. OpenSuse 10.2 installation is not good that it writes the Grub bootloader without asking and messed up my Grub. I have to boot to Ubuntu 6.06 and recover the bootloader. BTW, for Grub recover, it seems that Knoppix is good. OpenSuse 10.3 installation is flawless but trying compiz caused the system not to boot so I gave up.

I tried to use Arch Linux and it is quite good in terms of upgrading (versionless) but I do not find it offer anything more than Ubuntu.

I tried to use Gentoo for two days and it was a pain due to dead mirrors and long compiling process. And since I have FreeBSD installed, I do not need another source based distribution. FreeBSD does offer something Linux does not offer -- a BSD licensed kernel and userland. FreeBSD is not as easy to use as Linux but it is quite usable as well. I am also trying out NetBSD but I feel it is not good for desktop usage.

PClinuxOS looks nice and in the end it does not offer anything better than Ubuntu (maybe KDE is better under PClinuxOS).

So now I have Ubuntu 6.06/7.10 and FreeBSD 7.0 Beta. I will try out other things from time to time.

I still use Windows XP SP2 at home occassionaly but mostly I am using Ubuntu.

Tuesday, November 20, 2007

New FC8 install hangs at the message "Creating root device"

http://www.fedoraforum.org/forum/showthread.php?t=171223&page=2&pp=15

I had the exact same problem as post #15. I have two HDDs in the system. Windows/Ubuntu (6.06 and 7.10) are in the SATA HDD. I installed Fedore 8 on the IDE HDD which has also Windows DATA partitions and Linux DATA partitions along with FreeBSD 7-Beta.

I ended up going back to Fedora 7 which is working fine. It is really a pity. The installation process from the live CD was quite smooth. It just did not boot after the "flawless" installation.

Sunday, November 11, 2007

Setting up permissions for USB ports to use libusb for FreeBSD

During the testing of pk2cmd port for FreeBSD, I found a great resource on setting up permissions for USB ports to use libusb or other programs under Linux/BSD.
http://www.gphoto.org/doc/manual/permissions-usb.html

There is no udev under FreeBSD. It is called devfs rule. To set up proper usb device persimmion so that I can run pk2cmd without being root, I need to do the following.

Steps:
1. Create group "usb" and add the user name to it.
[Added on 22-Dec-2007]
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/users-groups.html
[mcuee@localhost /usr/home/mcuee]$ su -
Password:
localhost# pw groupadd usb (this may not be necessary for FreeBSD 7.0 Beta)
localhost# pw groupmod usb -M mcuee (your_user_name here, mine is "mcuee")
localhost# pw groupshow usb
usb:*:1003:mcuee

2. Edit /etc/devfs.rules to add the following lines.
[usb_devices=10]
add path 'ugen*' mode 0660 group usb
add path 'da*s*' mode 0660 group usb
3. Edit /etc/devfs.conf and add following lines: [Confirmed that this
is necessary]
perm usb0 0660
own usb0 root:usb
perm usb1 0660
own usb1 root:usb
4. Edit /etc/rc.conf and add the following lines:
# Set the default devfs ruleset.
devfs_system_ruleset="usb
_devices"
5. Activate the changes by running the following command (no reboot required):
localhost# /etc/rc.d/devfs start

6. Testing:
localhost# exit
logout

===[mcuee] ~/Desktop/build/pk2cmd4bsd # ls -la /dev/ugen0*
crw-rw---- 1 root usb 0, 138 Nov 1 22:31 /dev/ugen0
crw-rw---- 1 root usb 0, 120 Nov 1 22:56 /dev/ugen0

[Added on 22-Dec-2007]
===[mcuee] ~/Desktop/build/pk2cmd4bsd # lsusb
Bus /dev/usb1 Device /dev/ugen0: ID 04d8:0033 Microchip Technology, Inc.

===[mcuee] ~/Desktop/build/pk2cmd4bsd # ./pk2cmd -PPIC12F675 -I

Locating USB Microchip PICkit2 (vendor 0x04d8/product 0x0033)
Found USB PICkit as device '/dev/ugen0' on USB bus /dev/usb1
Communication established. PICkit2 firmware version is 2.10.0

Device ID = 0FC3

Operation Succeeded

Thursday, November 1, 2007

PK2CMD Ported to Linux and FreeBSD

PK2CMD is a 32-bit command line interface for the PICkit 2 Programmer. It is available for download from the PICkit 2 webpage: http://www.microchip.com/pickit2 .

Microchip has released the source code here:
http://ww1.microchip.com/downloads/en/DeviceDoc/PICkit2_PK2CMD_SourceV1_00.zip

Jeff Post has since released the Linux port of PK2CMD here:
http://home.pacbell.net/theposts/picmicro/pk2cmdLinux-0.1.tar.gz

Take note that CFLAGS -fpermissive may need to be added to avoid compiling error with later version of g++ (for example: under Ubuntu 7.04/7.10).

It might needs some modification to work under Mac OS X.

I've also tried it under FreeBSD 7.0 Beta. I need to get the alternative USB Stack from Hans Petter Selasky (HPS) to get it work. It should work under other version of FreeBSD which HPS stack supports.

To get the HPS USB stack for FreeBSD, follow the following instruction.

svn --username anonsvn --password anonsvn checkout svn://svn.turbocat.net/i4b
cd i4b/trunk/i4b/FreeBSD.usb
make S=../src package
make install
Follow the "make help" instructions.

One patch required is the file "ugen.c". In the function
"ugen_open_pipe_read()",
find the line "case UE_INTERRUPT:" and then some lines further down you will find:
/* first transfer clears stall */
sce->read_stall = 1; //---> Chaneg this to "0".
Then recompile and install the "ugen" module and/or kernel.

PICkit 2 with FreeBSD (old):
http://lists.freebsd.org/pipermail/freebsd-usb/2007-April/003177.html

PICkit 2 with FreeBSD (new):
http://lists.freebsd.org/pipermail/freebsd-usb/2007-October/004057.html

Sample running session:
===[mcuee] ~/Desktop/build/pk2cmd4bsd # uname -a
FreeBSD FreeBsd.Mshome 7.0-BETA1 FreeBSD 7.0-BETA1 #2: Thu Nov 1
19:56:07 SGT 2007
root@FreeBsd.Mshome:/home/obj/home/src/sys
/USBDEBUG i386
===[mcuee] ~/Desktop/build/pk2cmd4bsd # sudo ./pk2cmd -PPIC12F675 -I

Locating USB Microchip PICkit2 (vendor 0x04d8/product 0x0033)
Found USB PICkit as device '/dev/ugen0' on USB bus /dev/usb1
Communication established. PICkit2 firmware version is 2.10.0

Device ID = 0FC3

Operation Succeeded
===[mcuee] ~/Desktop/build/pk2cmd4bsd # sudo ./pk2cmd -PPIC12F675 -GF12F675.hex

Locating USB Microchip PICkit2 (vendor 0x04d8/product 0x0033)
Found USB PICkit as device '/dev/ugen0' on USB bus /dev/usb1
Communication established. PICkit2 firmware version is 2.10.0

Read successfully.

Operation Succeeded
===[mcuee] ~/Desktop/build/pk2cmd4bsd # sudo ./pk2cmd -PPIC12F675 -Y
-F12F675.hex

Locating USB Microchip PICkit2 (vendor 0x04d8/product 0x0033)
Found USB PICkit as device '/dev/ugen0' on USB bus /dev/usb1
Communication established. PICkit2 firmware version is 2.10.0

PICkit 2 Verify Report
1-11-2007, 20:04:10
Device Type: PIC12F675

Verify Succeeded.

Operation Succeeded

Wednesday, October 17, 2007

PICkit 2 and PICDEM FS USB Demo Board Under FreeBSD

With the help of Hans, I am able to get the PICDEM FS USB Demo Board demo mode (interrupt transfer) work under FreeBSD using his USB stack under FreeBSD 6.2 Stable. This is a byproduct of getting the PICkit 2 work again under FreeBSD.

One patch required is the file "ugen.c". In the function "ugen_open_pipe_read()",
find the line "case UE_INTERRUPT:" and then some lines further down you will find:
/* first transfer clears stall */
sce->read_stall = 1;

Chaneg this to "0".
Then recompile and install the "ugen" module and/or kernel.

Links to the FreeBSD USB Mailing List thread:
http://lists.freebsd.org/pipermail/freebsd-usb/2007-October/004057.html

http://lists.freebsd.org/pipermail/freebsd-usb/2007-October/004063.html

The bootloader (bulk transfer) is not working yet.
http://lists.freebsd.org/pipermail/freebsd-usb/2007-October/004058.html

Friday, May 18, 2007

PIC Development Tools under FreeBSD

I am mainly a Linux user and Ubuntu is my preferred distribution. However from time to time I will also try other Linux distributions and FreeBSD.

Right now I have a small installation of FreeBSD 6 Stable. It is not as easy to use as Linux but it is definitely usable. The following is a list of links for PIC MCU development tools under FreeBSD.

FreeBSD has ports for gputils/sdcc/gpsim/picp/pikdev.
http://www.freebsd.org/ports/

It is also possible to build Piklab under FreeBSD.
http://piklab.sourceforge.net/wiki/index.php/Compilation_for_FreeBSD

PICStart+ works under FreeBSD with picp.

Wisp628 works under FreeBSD with xwisp2.
http://www.robh.nl/picsoft.php

JALv2 works under FreeBSD as well.
http://www.casadeyork.com/jalv2/
http://www.casadeyork.com/jalv2/jalv21src.zip

The main problem under FreeBSD is the lack of device drivers. But they are catching up. One of the things in development is the alternative USB stack by Hans Petter Selasky (http://www.turbocat.net/~hselasky/usb4bsd/). With his help I am now able to run pk2 and piklab to support PICKit 2 under FreeBSD.

For more detail, please refer to the following mailing list thread.

http://lists.freebsd.org/pipermail/freebsd-usb/2007-April/003182.html

You need to run the alternative USB stack (maybe you will need to use the stable or current branch) and apply the following patch to ugen.c in order to get pk2 to work. Maybe the patch is already in the latest version of the USB stack.

==== ugen.c#12 - ugen.c ====
@@ -637,9 +637,12 @@
{
return (EIO);
}
- /* setup clear stall */
- sce->xfer_out[0]->clearstall_xfer =
- sce->xfer_out[1];
+
+ if ((ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
+ /* setup clear stall */
+ sce->xfer_out[0]->clearstall_xfer =
+ sce->xfer_out[1];
+ }
break;

case UE_ISOCHRONOUS:
@@ -759,10 +762,6 @@
return (EIO);
}

- /* setup clear stall */
- sce->xfer_in[0]->clearstall_xfer =
- sce->xfer_in[1];
-
usbd_transfer_start(sce->xfer_in[0]);
PRINTFN(5, ("interrupt open done\n"));
break;
@@ -1322,6 +1321,17 @@

USBD_CHECK_STATUS(xfer);

+ tr_error:
+ if (xfer->error != USBD_CANCELLED) {
+ /* setup clear stall */
+ xfer->clearstall_xfer = sce->xfer_out[1];
+
+ /* start clear-stall */
+ usbd_start_hardware(xfer);
+ return;
+ }
+ return;
+
tr_transferred:

PRINTFN(5, ("xfer=%p actlen=%d\n",
@@ -1362,7 +1372,7 @@
return;

tr_setup:
- tr_error:
+ xfer->clearstall_xfer = NULL;
usbd_start_hardware(xfer);
return;
}