Deuteronomy 21:16-17

21:16 In the day he divides his inheritance he must not appoint as firstborn the son of the favorite wife in place of the other wife’s son who is actually the firstborn. 21:17 Rather, he must acknowledge the son of the less loved wife as firstborn and give him the double portion of all he has, for that son is the beginning of his father’s procreative power – to him should go the right of the firstborn.