OED,

Maybe it derives from "Do One Bad" or "Badly", i.e. to do one a bad turn such as inform or betray, much like we say "she did him dirt".

--Jeff