Try the steps listed below, but make sure that you have downloaded the latest version of iTunes before attempting to do this.
Put the iPhone into DFU mode so you can do an iTunes firmware restore follow these steps:
Open iTunes and connect the iPhone to your Mac or PC.
Press and hold the Home button and the Sleep/Wake button at the same time.
After exactly 10 seconds, release the Sleep/Wake button. Continue holding the home button until iTunes pops up with a message telling you that it has detected an iPhone in recovery mode.
The iPhone screen will remain black.
NOTE***: It may take a few attempts to get your iPhone into DFU mode. Generally, I hold down both buttons then release the Home button just before I think the Apple logo would appear. If you are still holding both buttons down and you see the Apple logo you are holding them down for too long!
Download from iTunes and install the latest firmware (3.1.2/7D11) and install it. Then, when it's done, simply either restore it from a previously created backup, or set it up as a new iPhone and re-sync all of your stuff back onto it.