i did this the other day, pretty simple on the 3g, just download the firmware and when done, hold "option key" (on mac) and click restore in itunes, not sure about xp think its ctrl?
and select the 3.1.3 firmware you downloaded, ill put the link up later for the firmware as its on my macbook at home