Gentoo Installation Bullet-point List

I install Gentoo often enough that the Gentoo Handbook is way too verbose, but not often enough to memorize the steps involved. This list is meant mainly for me, but also for anyone who is comfortable enough in Linux to know what to do with a description like “Partition disk and create file systems”.


Config network, ip addr/dhcpcd

Partition Drive
Create Filesystems

mkswap & swapon

Mount root at /mnt/gentoo
Mount boot at /mnt/gentoo/boot

date

cd /mnt/gentoo

Get stage3 and portage snapshot archives
links http://www.gentoo.org/main/en/mirrors.xml
tar jxvfp stage3*.tar.bz2
tar jxvf portagesnapshot.tar.bz2 -C /mnt/gentoo/usr

Edit /mnt/gentoo/etc/make.conf
Set CHOST CFLAGS; set MAKEOPTS=”-j<2*#ofCPUs>”
See http://gentoo-wiki.com/Safe_Cflags
Consider “-march=native -O2 -pipe”

Set USE flags

mirrorselect -i -o >> /mnt/gentoo/etc/make.conf
mirrorselect -i -r -o >> /mnt/gentoo/etc/make.conf

select locales in /etc/locale.gen

cp /etc/resolve.conf /mnt/gentoo/etc/resolv.conf

mount -t proc none /mnt/gentoo/proc
mount -o rbind /dev /mnt/gentoo/dev

chroot /mnt/gentoo /bin/bash
env-update
source /etc/profile

emerge --sync

eselect profile list
eselect profile set #

locale-gen

emerge vim
emerge pciutils

Choose a timezone

vim /etc/conf.d/clock

mkdir /etc/portage
cat "sys/gentoo-sources -docs symlink" > /etc/portage/package.use

emerge gentoo-sources

config and install kernel
make && make modules_install && make install

setup /etc/fstab

set /etc/conf.d/hostname
setup /etc/conf.d/net
rc-update add net.eth0 default

set root passwd


emerge syslog-ng
rc-update add syslog-ng default
emerge vixie-cron
rc-update add vixie-cron default
emerge slocate
emerge dhcpcd

on x86 emerge grub
on x86_64 emerge grub-static

setup /boot/grub/grub.conf
———————————————————-

default 0
timeout 10
splashimage=(hd0,0)/grub/splash.xpm.gz

title=Gentoo Linux Newest
root (hd0,0)
kernel /vmlinuz root=/dev/hda3 video=vesafb:mtrr:3,ywrap,1024x768-32@85

title=Gentoo Linux Previous
root (hd0,0)
kernel /vmlinuz.old root=/dev/hda3 init=/bin/bb

———————————————————–

grub --no-floppy
grub> root (hd0,0) (Specify where your /boot partition resides)
grub> setup (hd0) (Install GRUB in the MBR)
grub> quit (Exit the GRUB shell)

exit
cd
umount /mnt/gentoo/boot /mnt/gentoo/dev /mnt/gentoo/proc /mnt/gentoo
reboot

Posted in Linux, Open Source, Sysop, Technology | Tagged | Leave a comment

C++/CLI Converting from String to wchar_t and to char*

I recently started working on a managed wrapper for the Terminal Services API, and as my C++/CLI is a bit rusty I ran into some issues which I’m sure are common when trying to handle the impedance mismatch between the managed and unmanaged worlds.

I’m going to take a look at one of those issues here, and that is using System::String with native functions. The Win32 API is one such body of native functions and they fairly consistently take LPTCHAR parameters for strings. This type is a typedef to TCHAR*, TCHAR in turn is a typedef to wchar_t for Unicode builds and char otherwise.

Toll-free bridge with CString

One easy and automatic way to do this conversion is to bridge it through CString, this is a type that is part of Microsoft’s ATL. I believe it was first part of MFC but it’s since been divorced from depending on the rest of MFC and even the ATL proper or it’s server classes; include atlstr.h instead of cstringt.h.

The char type of CString is internally based on TCHAR as well, so depending on if you are doing a Unicode build the internal representation of the CString will be either wchar_t or char. The CLI has no such type differentiation, String is always a wide character string. This means that in Unicode builds we don’t need to do a conversion, but non-Unicode builds will, and CString takes care of this for us through it’s helpfull conversion constructor that accepts a System::String^.


template <class SystemString>
CStringT( SystemString^ pString ) :
CThisSimpleString( StringTraits::GetDefaultManager() )
{
cli::pin_ptr<const System::Char> pChar = PtrToStringChars( pString );
const wchar_t *psz = pChar;
*this = psz;
}

`PtrToStringChars` retrieves a pointer to the String’s internal memory buffer, no copy here. The pointer returned is then pinned so that the Garbage Collector will not move it while we use it. It then uses an implicit conversion to go from `pin_ptr<const System::Char>` to `const wchar_t*`. Finally it uses the copy assignment operator of CString (which delegates to a base class operator) to copy the contents of the String buffer into itself. In a Unicode build this copy assignment operator decays to a basic memory copy, otherwise a different copy assignment operator is invoked that uses WideCharToMultiByte to convert to the CStrings internal char type.


// This gets called when the right-hand-side pszSrc is the same char type as the internal storage
// It simply delegates to it's base class to copy the source buffer into itself
CStringT& operator=( _In_opt_z_ PCXSTR pszSrc )
{
CThisSimpleString::operator=( pszSrc );

return( *this );
}

// This gets called when the right-hand-side pszSrc has a different char type than the internal storage
// It converts to the internal storage char type directly into it's internal buffer
CStringT& operator=( _In_opt_z_ PCYSTR pszSrc )
{
// nDestLength is in XCHARs
int nDestLength = (pszSrc != NULL) ? StringTraits::GetBaseTypeLength( pszSrc ) : 0;
if( nDestLength > 0 )
{
PXSTR pszBuffer = GetBuffer( nDestLength );
StringTraits::ConvertToBaseType( pszBuffer, nDestLength, pszSrc);
ReleaseBufferSetLength( nDestLength );
}
else
{
Empty();
}

return( *this );
}

static void ConvertToBaseType(_Out_cap_(nDestLength) _CharType* pszDest, _In_ int nDestLength,
_In_count_(nSrcLength) const wchar_t* pszSrc, _In_ int nSrcLength = -1) throw()
{
// nLen is in XCHARs
::WideCharToMultiByte(_AtlGetConversionACP(), 0, pszSrc, nSrcLength, pszDest, nDestLength, NULL, NULL);
}

Now we can use the CString in place of `LPCTSTR` parameter because it has a user-defined conversion operator that simply returns the guts of the CString. This automatically does-the-right-thing when calling functions in Unicode builds and non-Unicode builds, all with no #ifdefs.


operator PCXSTR() const throw()
{
return( m_pszData );
}

`PCXSTR` is a chain of typedefs that eventually, through TCHAR, finds it’s way to a `const wchar_t*`. PCXSTR means “pointer to a const null-terminated string of the same char type I am”, it also has PXSTR and XCHAR typedefs. In addition to the `X` typedefs it also has a set of `Y` typedefs (PCYSTR, PYSTR, YCHAR) that map to the opposite of the `X` typedefs, if the `X` is wchar_t then the `Y` is char. It uses the set of `Y` typedefs to create a number of copy assignment operators and conversion constructors that convert from either character type to the internal type.

Conversion to Mutlibyte UTF8

There is one problem that this doesn’t cover however, and that is how to convert your Unicode String into a `const char*` for use as parameters to functions that don’t have Unicode counterparts. Stan Lippman has a blog post from back in 2004 where he presents a couple of functions to handle this conversion to char* and to std::string. We’ll see some similarities with the CString constructors.


bool To_CharStar( String^ source, char*& target )
{
pin_ptr<const wchar_t> wch = PtrToStringChars( source );
int len = (( source->Length+1) * 2);
target = new char[ len ];
return wcstombs( target, wch, len ) != -1;
}

bool To_string( String^ source, string &target )
{
pin_ptr<const wchar_t> wch = PtrToStringChars( source );
int len = (( source->Length+1) * 2);
char *ch = new char[ len ];
bool result = wcstombs( ch, wch, len ) != -1;
target = ch;
delete ch;
return result;
}

There are a couple problems with these functions. First, they are not reentrant and hence not thread safe, wcstombs keeps a global internal state during the conversion of a string. Second, they only work with UTF-16, which String always is, but it over allocates for simple single-byte character sets like ASCII. Third, they create an unecissary temporary buffer in the case of the std::string converter. And in the case of the char* converter it put the onus of freeing the buffer on the caller, which is doubly dangerous here because since the function uses new[] to allocate the buffer, the caller needs to know to call delete[].

Lets take a whack at implementing these functions in the way of the C++ standard library while solving these deficiencies (thanks to Kniht on freenode ##C++ for helping me distill this).


#include <limits.h>
#include <wchar.h>
#include <algorithm>
#include <stdexcept>

struct ConversionError : std::runtime_error {
ConversionError()
: std::runtime_error("ConversionError")
{}

explicit
ConversionError(std::string const& what)
: std::runtime_error("ConversionError: " + what)
{}

protected:
struct NoPrefix {};

ConversionError(NoPrefix, std::string const& what)
: std::runtime_error(what)
{}
};

template<class OutIter>
struct mboutput_t : std::iterator<wchar_t,void,void,void,void> {
mboutput_t(OutIter out) : _mbstate(), _out(out) {}

mboutput_t& operator++() { return *this; }
mboutput_t& operator++(int) { return *this; }
mboutput_t& operator* () { return *this; }

void operator=(wchar_t wc) {
char buf[MB_LEN_MAX];
int len = ::wcrtomb(buf, wc, &_mbstate);
if (len == -1) {
throw ConversionError("wcrtomb");
}
_out = std::copy(buf, buf + len, _out);
}

mbstate_t _mbstate;
OutIter _out;
};

template<class OutIter>
mboutput_t<OutIter> mboutput(OutIter out) {
return mboutput_t<OutIter>(out);
}

template<class Cont>
mboutput_t<std::back_insert_iterator<Cont> > mb_back_inserter(Cont& c) {
return mboutput(std::back_inserter(c));
}

template<class Cont>
void wcs_to_mb(Cont& c, wchar_t const* s) {
if (s) {
std::copy(s, s + wcslen(s), mb_back_inserter(c));
}
}

This code is completely standards compliant so it will work perfectly well on any standards compliant compiler/OS. In our examples however our source is a System::String and there are two targets we’re interested in, std::string and char*. We can accomplish each of these targets easily using std::copy with our custom mb_back_inserter.


template<class Cont>
void String_to_mb(Cont& c, System::String^ source) {
pin_ptr<const wchar_t> wch = ::PtrToStringChars( source );
wcs_to_mb(c, wch);
}

void ctest(const char* str) {
std::cout << str << std::endl;
}

void stest(const std::string& str) {
std::cout << str << std::endl;
}

void convtest() {
String^ sstr = L"Hello!";

std::vector charStar;
String_to_mb(charStar, sstr);
// vector can be used as a char* by passing &charStar[0] to a function taking char*
ctest(&charStar[0]);

std::string s;
String_to_mb(s, sstr);
// the std::string can be used as-is or it can also produce a char* by calling string::c_str()
stest(s);
ctest(s.c_str());

// the vector and string are automatically deallocated leaving this scope
}

Making effective use of containers, iterators, and wcrtomb(…) we’ve created a solution that doesn’t require caller deallocation and that is reentrant.

Posted in Software Development, Technology | Tagged , , | Leave a comment

Using the GPL as a Dual-Licensing Monopolistic Haven

Can a company control the use of their software intellectual property more completely if they release it under the open-source GNU General Public License (GPL)? I hadn’t really thought about it before, but while researching the OSS position of MySql I read an interesting post on Michael Meeks’ log that alludes to something of this nature.

Philosophically, software is usually released under the GPL for the purpose of freedom, freedom for a user to do what they will with the software as long as they afford the same freedom to those who come after them. This precludes others from hijacking free software and embedding it in a derivative, proprietary, work. Not all FOSS licenses have these restrictions, but the GPL does for the purpose of meeting the goals of the Free Software Foundation.

A number of companies with open-source software released under the GPL have recently started taking advantage of a dual-licensing model to generate revenue. This revenue can be put to a number of uses including, paying developers to work full time on the project, building stock holder value, and generate cash for acquisitions and other investments. Richard Stallman himself even reasons that “selling exceptions” is not any more evil than releasing software under a noncopyleft license such as X11 or BSD.

However, one discipline is required of any organization that wants to use a dual-licensing model; they must require that the copyright of all code contributions be assigned to them. Without this assignment they would have no effective legal right to distribute the software under a proprietary license.

Michael Meeks talks a lot about the pros and cons of copyright assignment, and some of it’s fallacies and downfalls, in the article I linked previously. One downfall that he mentions is that no project that uses this model has a very vibrant community of contributing developers; most of the development is done internally by the organisation’s own developers anyway. If this is the case, then what value does releasing the software under the GPL really give an organisation?

Lets play the roll of a company has a piece of software IP that they want to bring to the market. We are a developer hostile company which is not interested in building a third-party ecosystem around our product. If there is a possibility to generate revenue related to our software, we want it. We’ll go through a couple of scenarios with this software to see how we can accomplish our goals most effectively by twisting the GPL.

We’ve released our software into the market as a closed-source proprietary product and it enjoys some success. As it becomes successful the userbase grows enough that another company, Toolco, sees a market to provide some complimentary feature to our customers. This company uses APIs (public or private) and other integration methods to create closed-source, proprietary plugins or tools that extend the functionality of our product. DMCA Section 1201(f) protects their right to this program-to-program interoperability even to the extent of reverse engineering. Beyond a constant cat and mouse game our company really has no way to limit the distribution of these extensions or to take a piece of the pie, as it were.

Our board of directors sits down for a strategy session and after a couple hours someone recommends something radical. “Lets release our code under the GPL, require copyright assignment for any contributions, and use a dual-licensing model to continue generating revenue. In fact, I expect that most of our development will be done by internal developers still, though users may be able to provide more in-depth help fixing odd bugs.” This may not be so insane after all; there are a number of things that our company gains from this, including some built-in perceived good will and publicity by releasing our large product as an open-source project.

Hey wait, you remember the Toolco guys right? They’ve used some undocumented function calls in one of our libraries to create a backup tool for our product, it works better and has twice the penetration of our own module for which we charge an additional fee. Well, Toolco now has technically created a derivative work of our GPL product by linking to one of it’s libraries. We now have a number of legal recourses to force Toolco out of the market and to also prevent any other companies from creating a product that interoperates with our software.

This may sound tantamount to conspiracy theory but this is exactly what MySql has done, intentionally or not they have slowly been tightening the leash on their open-source software. Internal developers do almost all of the development and any outside contributions must have their copyright assigned to MySql. Around version 4.1 their client libraries were changed from LGPL to GPL only; to distribute software that even has the ability to communicate with an MySql instance you must now either release your source code or pay for a proprietary license. The copyright assignment has allowed them to do this without so much as a query to the MySql community.

Aside from the dual-licensing revenue, they have also begun making a profit from proprietary management and monitoring software. These applications use interfaces to MySql that would make any third-party’s similarly functional package a derivative work and only releasable under the GPL. This has effectively created a legal haven for Oracle as the only company in the world that can make a profit by writing closed software that interoperates with MySql.

The GPL, with a goal to provide software that is free-as-in-speech, has been effectively used as a legal muzzle to strip freedom and competition to an extent that even closed-source proprietary software would have difficulty accomplishing.

Posted in Editorial, Open Source, Technology | Tagged , , , | Leave a comment

Modifying only directory permissions using find

I recently went through my web directories and updated the permissions to be more inline with recommended security practices. When setting web file permissions in Linux you want to set execute permissions on a directory to allow listing and traversal, but you don’t want to set execute permissions on the files for security reasons.

Doing this directory by directory by hand would have been a pain so I decided to get creative. Well as far as script-fu goes this is pretty tame(lame?) but it worked well for me.

To set the permissions on a the /var/www/ folder and all sub-folders of use this command:

find /var/www -type d -print0 | xargs -0 chmod -v 755

Conversely if you only want to update the permissions on only files you can use the same command but substitute -type f for -type d.

The -print0 argument will make find null terminate each of the paths instead of newline terminating them and the -0 argument tells xargs to expect argument terminated by null instead of whitespace. Without these options xargs would misinterpret pathnames with spaces as multiple arguments.

Posted in Linux, Sysop | Leave a comment

Jeff Atwood of Borg-StackOverflow Careers Assimilation

Jeff of BorgI’ve found StackOverflow to be a fun and vibrant community as well as an almost daily touchstone for programming and tech problems. Because of my enjoyment of the site I’ve started listening to the StackOverflow podcast with Jeff Atwood and Joel Spolsky (my opinion of which is another post altogether).

I’ve found Jeff to be rather level-headed and analytical during discussions, Joel on the other hand is quite often disruptive. This I’ve found to be a lot like their blogs though I don’t read them often. I also see these traits surface to varying degrees through Jeff and Joel’s joint venture.

I feel that Jeff has been an exceedingly gracious proprietor of the StackOverflow community, balancing monetization of the site with respect for the well from which their success flows. The well obviously being the thousands of users that spend their time providing content and moderation for the StackOverflow site.

Visitiing the site recently — not logged in — using a family member’s computer I found that the StackOverflow site is totally different for the drive-by Googler, the advertisements are much more prominent and inline with the content. Jeff has had the presence of mind to squelch the advertising for their most loyal and content-providing users, this is brilliant and show that the Golden Rule is in full effect at StackOverflow. And why wouldn’t they do this? It is my understanding that their traffic is somewhere around 80/20% anonymous/member mix, it’s a small tradeoff in revenue to take care of their content stream to ensure it will continue to flow.

Unfortunately with their latest attempt to monetize StackOverflow it seems that Joel’s traits (as PM of the venture) have surfaced more than Jeff should allow. Being the consummate businessman, with an office in New York and a home in The Hamptons, Joel wants to monetize on the traffic and content of StackOverflow with more than advertising. Who can blame him, StackOverflow receives millions of page views a month and is ranked in the top 1000 sites on the internet.

Where else would Joel think to go than his tried and true job listing service. This is comfortable ground for Joel, for years he has been providing employers visibility to a well defined demographic of potential employees for a somewhat standard industry rate of $350 per listing. He has been able to make a good living monetizing his blog traffic for years through advertisements and these job listings and extending this service to the even more laser focused programmer demographic of StackOverflow is a no-brainer.

Up to this point the site at jobs.stackoverflow.com has basically been a mirror of the joelonoftware listing, but in true StackOverflow spirit Jeff and Joel have just recently released a much more in-depth whack at the problem of finding and hiring good developers. I think their idea is genious; leveraging the StackOverflow content and infrastructure (tags, profiles, Q&A) to allow developers to effectively cash-in on the time spent on StackOverflow to woo potential employers, and for employers to get invaluable information about developers that could never be communicated on a simple résumé.

But one word with Unicode characters wasn’t enough, so Jeff and Joel decided that developers should fill out a Curriculum Vitæ (CV) instead of a résumé. I find the distinction that they’ve made here to be refreshing and a great fit for the synergy of a developer’s passion, past experience and StackOverflow répertoire. Besides the time, filling out and publishing a public CV is a no cost proposition provided by the StackOverflow team.

Their plans for monetizing the careers site is two-fold. For the first revenue stream — like the jobs listing — there will be a subscription fee for employers to get access to search developer CVs to the tune of $500 per week up to $5000 per year. If you’ve ever tried to find and hire good developers using the standard method of newspaper/dice/monster, you know that this fee is worth every cent. A recruiting agency will charge you 10-25% of a placment’s salary to send people your way, and more often than not they just use the wet noodle approach and throw developers at you until one sticks. For someone that makes $80K it will cost you $8-20,000 for that single placement.

“So wherein does your quibble lie?” you might ask. Well, it’s in the second of the two revenue streams for the careers site, for the measly pittance of $99/year they’ve decided to throw out the baby with the bathwater. On the other side of the employer’s looking glass developers will need to pony up hard cash in order to “file” their CV to be searchable on the StackOverflow careers site. This is an affront to the content providers of their community and I can’t believe that this token filing fee is worth the bad will that it could generate.

It is done under the guise of filtering out those “who knew that they had no reasonable chance of getting a job”[1]. I think Jeff even believes this, but it’s really just an unfortunate scapegoat for making money at the expense of your content providers.

In their latest podcast Jeff was pretty adamant that the job seekers not be sortable by their StackOverflow reputation, he wants people with little or no reputation to have an equal visibility to those that do. This bodes even worse for their plan of charging job seekers to file their CV.

The kind of people that are passionate and give of their time to answer other’s questions are exactly the kind of developers that I want to hire. And these are exactly the same people that are less likely to view this filing fee in an unfavorable way. These are the kind of developers that program at home, are constantly learning new things, work on OSS projects, and are not 9-5 just-for-the-paycheck programmers. Their loyalty when treated well is often unmatched.

Then there’s the other kind of developer; you know the guy I’m talking about, the smooth talker, usually the “Team Leader”. The guy who drives his Audi to work and knows how to play the corporate game better than he knows how to cut-n-paste code from Google. Their loyalty is usually suspect and their main goal is to either climb the corporate ladder (hence team lead instead of in-the-trenches programmer) or jump ship at any time for a higher salary. StackOverflow is a godsend for these types of programmers as it’s rife with snippets free for the taking.

If their goal was to vet potential job seekers, to provide more value to employers, then money is definitely not the way to do it. Even the “smart hiring managers”[1] will have a hard time filtering out these smooth talkers that are always on the market for the highest bidder. These are exactly the people these “smart hiring managers” don’t want, it is expensive to bring people into a company just to have them bail 60 days later.

At my current job we really, really need some talented developers, and there are 5 job seekers on careers in our area. The Salt Lake job market is a small world, I’m sure that I know a third of the people on the list and that’s what scares me; I know a lot of smooth talking “Team Leaders”. With the current criteria to entry I don’t think I can justify finding out who they are for $500.

So in effect Jeff and Joel have ignored they’re best formula for vetting job seekers and instead have opened the doors for anyone who is willing to pay $99/year. If they were really hard up to make money through this channel they could easily provide free filing for anyone who has generated over X reputation on the site in the last rolling year. Similar to their banner advertising this serves the 80% of people who are willing to pay $99 and pays respect to the 20% truly exceptional developers who they owe the success of their site.

Jeff, please doff the cybernetic business suit!

  1. http://careers.stackoverflow.com/faq#pricing
Posted in Editorial, Software Development | Tagged , | 1 Comment

Subclipse for SVN on Eclipse CDT

Subversion is a great way to work on code in a collaborative fashion. There are a couple subversion plugins that work with Eclipse, one of them is called Subclipse.

To install Subclipse in Eclipse goto the Help menu and choose “Software Updates…”.

Once the “Software Updates and Add-ons” window displays itself we need to add the Subclipse update URL. Choose the “Available Software” tab, click “Add Site” and put in “http://subclipse.tigris.org/update_1.6.x” as the location and click “OK”.

Add Plugin Location

You will now see a new item in the list corresponding to the URL that you just added. Now to add subclipse you need to choose two plugins, subclipse itself and the JavaHL. JavaHL is the API that subclipse uses to talk to your SVN server. You can find these by expanding the tree by clicking the triangle to the left of the URL you just added, and then expanding the Subclipse subnode. After selecting the plugins click install and follow the dialogs through to the end.

Plugin Selection

Now that subclipse is installed, in the top right of Eclipse click the “Open Perspective” icon choose “Other” and choose “SVN Repository Exploring”, this perspective will give you the tools to work with your SVN repo, assuming you aren’t already happily using a tool like TortoiseSVN or the command line client to do so.

Add your repo location to the SVN perspecitve by clicking the icon at the top right of the repositories view and typing in the URL of your repo. Any repositories added here will also show up in other dialogs when working with SVN in Eclipse such as when adding or importing projects.

Add Repository

Adding Your Project to the SVN Repository

To add a project to SVN go back to your development perspective and simply right click on the project in the “Project Explorer”, expand the “Team” subitem and choose “Share Project…”. Now choose what repository to add your project to, click Next.

Choose Repository

Now you will be prompted to choose a folder name for your project in the repo; you can just use the name of the project or specify some folder further down in your repository hierarchy, click Next.

Repository Folder

The wizard will now ask for an initial commit comment, click Finish and your project will be created in the repo, but you will still need to commit your changes for the code to actually show up in SVN.

Ready to Share

Once you clicked Finish Eclipse will ask if you want to open the “Team Synchronizing” perspective. Click yes and once the perspective opens you can simply right click on the root project node and choose commit. You can also do commits from the SVN perspective, or in your development perspective the project right-click menu now has a bunch of SCM options under the Team submenu.

Team SCM Operations

At this point working with SVN in Eclipse is like working with any SCM tool, make changes, commit changes, rinse, repeat.

Importing a Project from SVN

There may be a project in an SVN repo that you want to import, this is fairly simple. Open the workspace that you want to import the project into. Goto “File” and choose “Import”. Expand SVN in the tree and choose “Checkout Project from SVN”, click Next.

Import from SVN

This next dialog lets you choose from which SVN location to pull the project, if you have already added a repo location in the SVN repo perspective it will show on the dialog, otherwise you can specify the location now, click Next. You will now be shown a list of folders on your repository, you can navigate them and click the folder that you’d like to import, click Next.

Choose Project Folder

The next window asks how you would like to setup the local project, including a name and which version to pull. The defaults should usually suffice unless you want to maybe pull and older version or a branch to work on, click Next.

Local Project Properties

The next dialog simply lets you import to a different workspace than the one you currently have mounted. You should already be in the workspace you want to import to so just click finish. The import process will take a moment after which you should see a new project in your workspace.

Congratulations, you’ve successfully imported the project and since it is bound to SVN you can now work on the code with your coworkers!

Posted in Software Development, Technology | Tagged , , , | 1 Comment

USB Communications Device Class on 64-bit Windows

There is a class of device specified by the USB-IF as a Communication Device, this class was meant to to include devices such as modems, and network adapters. This specification is detailed as the Communications Device Class (CDC).

Ever since USB has replaced RS-232 as the predominant method of peripheral connection there has been a need to emulate serial ports over USB. This class has been hijacked somewhat by other devices that want to expose a serial-like interface to software.

This need is born out of a few requirements, ease of development, ease of use, and backwards compatibility.

Ease of Development

In my eyes one problem with USB is that to communicate with any device requires a driver. Up until recently this required a kernel mode driver. Drivers, kernel mode drivers in particular, are difficult to write and to debug, this can add to the manufacturer’s costs as they try to bring a product to market which uses USB.

Beside more specialized devices such as webcams, audio interfaces, mass storage devices there are a very large number of devices that simply need a moderate speed, single channel connection to the PC. These devices are especially suited to implementing the CDC.

Ease of Use

Related to the problems of a custom kernel mode driver is the end-user use case issues. When each manufacturer implements their own driver they also implement their own method of communicating with that driver. This can be via any of an infinite number of methods from shared memory, to a virtual filesystem.

When the device implements the CDC then the device is easily available via a very familiar and well supported serial interface often referred to as a “Virtual Com Port” (VCP). Support for the CDC is usually built into the operating system and the user can begin using the device with little or no driver and software installation.

Backwards Compatibility

Many devices began life as a serial connected device because most embedded processors have built-in UARTs. As these devices have grown with the PC industry they have been required to scale up their interfaces to USB in order to be compatible with contemporary computers. A lot of these devices accomplish this by using a simple Serial-to-USB transceiver chip embedded into the design. I have personally had success converting embedded devices using the FTDI line of products though they do not implement the CDC.

On the other side of the coin is the legacy software that has been written to communicate with devices over the PC’s serial ports. When using a CDC device this software can easily continue to function unmodified with devices that have migrated to USB regardless of whether it is using a native USB stack or a Serial-to-USB transceiver.

Downsides

Of course implementing a CDC device is a tradeoff, like a lot of decisions that you have to make in the world of computers. Some of the downsides are the features that make USB so attractive in the first place. One such feature is multiple communication endpoints; USB devices can expose multiple endpoints to allow software on the PC to communicate with multiple subsystems on the device using a single USB link. Another is interrupt endpoints, these endpoints let the USB device notify software on the PC of time-critical events such as button presses and sensor data within a well-known, and small window of latency.

I am currently working on a cross-platform library to expose USB device endpoints in a fashion similar to TCP ports, I am hoping that this will bring the ease of use of CDC and the power of more advanced USB features into one easy to use library.

Installing a CDC Device on Windows

And now the meat of this post. How do we get CDC devices to show up as a VCP on the system?

Windows does have a built-in driver that exposes a VCP for CDC devices, this driver is implemented in the file called usbser.sys. In Windows the driver implementation is only half of the recipe needed for installation. The other half of this recipe is called an INF file, it’s job is to describe to Windows how to go about installing the driver and what devices it applies to.

For usbser.sys the INF file is fairly simple and can easily be modified to support your device. You will need to know two things about your device, the Vendor ID (VID) and the Product ID (PID). Every USB device in the world has these numbers and they combine to form an identifier that is unique to that specific device. You can find these numbers by opening device manager and double clicking on your “Unknown device” and selecting the “Details” tab.

Vendor and Product IDs

Vendor and Product IDs

In this image you can see a device with VID 03EB and PID 2310, as you’ll see in the INF file we need the whole string “USB\VID_03EB&PID_2310″ to identify the device.

Here is an INF file that installs the usbser.sys driver for this device:

[Version]
Signature="$Windows NT$"
Class=Ports
ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318}
Provider=%ProviderName%
DriverVer=10/15/2009,1.0.0.0

[MANUFACTURER]
%ProviderName%=DeviceList, NTx86, NTamd64

[DeviceList.NTx86]
%AtmelEVK1105CDC%=DriverInstall,USB\VID_03eb&PID_2310

[DeviceList.NTamd64]
%AtmelEVK1105CDC%=DriverInstall,USB\VID_03eb&PID_2310

[DriverInstall]
include=mdmcpq.inf
CopyFiles=FakeModemCopyFileSection
AddReg=LowerFilterAddReg,SerialPropPageAddReg

[DriverInstall.Services]
include = mdmcpq.inf
AddService = usbser, 0x00000002, LowerFilter_Service_Inst

; This adds the serial port property tab to the device properties dialog
[SerialPropPageAddReg]
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"

[Strings]
ProviderName = "CDC Driver"
AtmelEVK1105CDC = "Atmel EVK1105 Virtual Com Port

To use this with your own device make an entry under the [DeviceList.NTx86] and [DeviceList.NTamd64] sections but using your own alias between the %…%, and place your device ID string to the right of the equals, while leaving the rest of the line intact. Then also simply make an entry in the [Strings] section with your alias and a string that you want to show as the name of the device in device manager.

Save the INF file and in device manager right-click on the device, choose “Update Driver Software..”, then select “Browse my computer for driver software”, navigate to the directory where you saved the INF and click Next.

CDC Driver Install

CDC Driver Install

Here is a screenshot of the device in device manager with the driver installed.

Installed Device

Installed Device

You will get a warning that the driver is not signed, well, the fact is that the driver itself is signed, but the INF and driver as a package is not signed. I’ll detail in another post the differences, what they mean to 64-bit Windows, and how to actually sign the package.

Speaking of 64-bit, this INF works perfectly well on any 32 or 64-bit Windows from XP up to Windows 7 for any device that implements the CDC.

Posted in Hardware, Technology | Tagged , | 2 Comments

Palm Afraid of anti-”TiVoization”

Palm Inc. with the release of their Linux powered smartphone called the Pre, now has a vested interest in the group of manufacturers using Linux as their embedded OS. As opposed to companies like Apple and their BSD based OSX in the iPhone Linux devices have certain source code disclosure obligations under the GNU Public License.

When a new manufacturer enters this group with such an innovative device hackers are ecstatic because they see something that they can shape and mold to do things with that the manufacturer is too scared to do or doesn’t care about. This will make content and network providers nervous as it would cause weak DRM to be ineffective and possibly allow networks to be abused or be used in such a way as to deprive the provider of fees (think a free tethering application which is usually a monthly charge).

TiVo Inc. as part of this group is in a similar position with their Linux-powered DVR; when it was found that they were storing the raw and perfect mpeg2 bitstream from the DirecTV sattelites on the TiVo’s hard drive unenecrypted much end-user DVD burning and sharing ensued. Needless to say DirecTV was not happy with this, and thus began the TiVo lockdown.

One of the main tenets of the 3rd and latest version of GNU Public License [GPLv3] is to block TiVoization. TiVoization refers to the popular time-shifting DVR made by TiVo Inc. and how it used GPL software internally (Linux, et. al.) but actively blocked end users from exercising their rights provided to them by the GPL by locking down the hardware so that software changes could not be effected.

From an article by Richard Stallman: “One major danger that GPLv3 will block is tivoization. Tivoization means computers (called “appliances”) contain GPL-covered software that you can’t change, because the appliance shuts down if it detects modified software. The usual motive for tivoization is that the software has features the manufacturer thinks lots of people won’t like. The manufacturers of these computers take advantage of the freedom that free software provides, but they don’t let you do likewise.” Why Upgrade to GPLv3

Some code is flexible in its license and gives the user the option of “either version 2 of the License, or (at your option) any later version”. One such piece of code is found in the Linux kernel drivers drivers/usb/class/cdc-acm.c. Obviously GPLv3 and GPLv2 are incompatible and with the Linux kernel being licensed under GPLv2 we can’t have drivers that are GPLv3, but I would be able to use any of that code in my GPLv3 application because the original author gave me the option to license the code under any later version of the GPL. In fact, that clause also makes it easier for the Linux kernel to move to GPLv3 if there was ever a great attempt to do so.

So why, while adding some functionality to this file, did Palm take it upon themselves to remove from the license this right? As there were 6 other copyright holders over the last 10 years how do they figure that they had that right?

Here is an excerpt from the patch showing where Palm excised the license text that allowed the use of this source under the GPLv3. There may be other similar changes but I cite this as my only example as I have not personally reviewed the over 350,000 lines of code in this patch or any of the other 50+ patches. Palm Open Source Packages

Palm-diff

I don’t know if I want to welcome another poor-sport manufacturer to the group, hopefully this was just an accident/misunderstanding that will be rectified and not repeated. It really would be great to see a manufacturer embrace the hacker subculture kind of like id’s early games. But maybe having a device be too open takes some of the excitement out of the game for hackers (see the lackluster response to the openmoko).

For another post I need to complain about the fashion in which Palm is providing these patches to the community, obviously they are using GIT and could allow anonymous access which at least preserve the change history. This is really detrimental to the upstream and downstream projects as there is no chance that Linus is going allow a 350,000 line patch to to be applied to the Linux kernel.

Posted in Uncategorized | Leave a comment

Windows 7 RC Fish

When the Win7 beta was released Microsoft had a witty default background greet new users. The background consisting of a Betta (get it? beta, Betta?) fish and 7 bubbles was a well-done, light and colorful. Now that the Win7 RC is in the hands of the masses the Betta background doesn’t seem to fit.

So in the vein of the original background I’ve put together the official, unofficial Win7 RC background; enjoy.

Windows 7 RC Background

Windows 7 RC Background

Posted in Technology | Tagged , , , , , , | Leave a comment