Some users have reported an issue in which iTunes displays the error message “The iPhone “name of iPhone” could not be restored. An unknown error occurred (29)” when attempting to update to iOS 4.0, or perform a restore on an iOS 4.0 device.
This issue appears to affect primarily users who have replaced their batteries or some other hardware components through a service such as iFixit. Error 29 indicates a hardware issue, which means that iOS 4.0 may be (accurately or not) triggering some compatibility issues with after-market add-ons or replacements.
Fix
Some users have been able to resolve this issue via the use the utility iRecovery. Instructions are here.