After the fight with hashirama senju, madara was heavily wounded, but got his senju dna blah blah blah.
He used the gedo mazo to heal himself, and survive to get rinnegan.
So, How did he get it.
He summoned it of course! anyone with rinnegan can summon gedo mazo.
Hang on, he didnt have rinnegan...