Warning: This method no longer works. To jailbreak the latest firmware, check out greenpois0n/limera1n/Pwnage Tool
The Pwnage Tool by the DevTeam hacker group allows you to create custom iPhone firmwares for the purpose of jailbreaking, to get full control over your device (see why you should jailbreak here).
Currently, the Pwnage Tool version 4.0 allows you to update your previously jailbroken device to firmware 4.0, without losing the jailbreak data. However, it will NOT unlock the device, enabling it to be used with different GSM carriers worldwide.
Please note that this tool will NOT work if you have the iPhone 2G, newer iPhone 3GS, newer iPod Touch G2 or the iPod Touch G3. (On the newer 3GS, go to Settings –> General –> About, the fourth and fifth digit of the serial number should be greater than 40 and on the newer iPod Touch, serial number begins with ‘MC’.)