How to update jailbroken iPhone 3GS iOS 4.1 to 5.1?
Put your device in DFU mode. (http://www.iclarified.com/entry/index.php?enid=1034 and http://www.ihackintosh.com/2009/06/recovery-mode-and-dfu-mode/). 
Connect to iTunes and it should prompt you with a box saying that your iPhone is in DFU mode and needs to be restored.

Sometimes it's possible to backup your phone and restore from that one once updated. Will not recommend it though; did that with my iPod and it didn't work perfectly afterwards.