Have you already updated your device to the version iOS4 and want to unlock your 3GS? Firstly there was Redsn0w, now PwnageTool is available, which can easily help you. Here is a simple and easy tutorial for jailbreaking iPhone 3GS (old bootrom). Warning: this is not an official release and therefore may be some bugs that can destroy your device or delete some important information. So be careful while using it!
iPhone 2G and iPod touch 1G do not officially support iOS 4. However there is a project called WhiteD00r that aims to bring iOS 4 functionality to iPhone 2G users with a custom firmware bundle.
This bundle is created by Matteo Morando and is based on firmware 3.1.3. It is built with PwnageTool. It incorporates several utilities to adds iOS 4 features such as multitasking, wallpaper, tethering, sms count, and more.
There are 3 different versions -- Lite and Full for iPhone 2G and one for iPod touch 1G. Here is the complete feature list: