In both the shel rosh (head tefillin) and shel yad (arm tefillin), there are the same four passages written in them; the only difference between them is that in the shel rosh each bayis (compartment) contains one passage, while in the shel yad all four passages are written in the same bayis on one piece of parchment. (Orach Chaim 32:2). Furthermore, these four passages must be written in order as it appears in the Torah which is Kadesh, V’hayah ki yi’vi’achah, She’ma, V’hayah im shamo’a, and if they aren’t, the tefillin are invalid. (ibid 32:1).
There is a well known disagreement between Rashi and Rabbeinu Tam as to what is the correct order of the passages: Rashi holds that it is Kadesh, V’hayah ki yi’vi’achah, She’ma, V’hayah im shamo’a, starting from left to right. Rabbeinu Tam maintains that V’hayah im shamo’a goes before She’ma. The Shulchan Aruch rules in accordance with Rashi (ibid. 34:1). The Mishnah Berurah points out that Rabbeinu Tam is not arguing on the order that it must be written, rather, only on the order that it needs to be placed in the compartments.
The Bach quotes the S’mag and Mordechai, who reported that a pair of tefillin were found in the grave of Yechezkel Hanavi, and the passages appeared in the order of Rashi. Some do not consider this as proof that the ancient tefillin were in fact made according to the opinion of Rashi, since it might have been buried precisely because it was out of order. The Bach rejects this answer, since they could have simply switched it back to the proper order, as we learned that it is only the placing out of order in the compartments that invalidates the tefillin.