Trying to answer With the help of Torah Temimah.
The mitzvah of loving G-d is derived from the verse Devarim 6:5.
In connection with this verse several different definitions of what loving G-d can be made.
- On this verse Rashi says,
Fulfill His commands out of love, for one who acts out of love is not like him (is on a higher plane than one) who acts out of fear. He who serves his master out of fear, if he (the master) troubles him overmuch, leaves him and goes away (Sifrei Devarim 32:1).
Therefore, according to Rashi, mitzvah of loving G-d is an additional requirement which is fulfilled with each and every mitzvah. In this case, one cannot derive prohibition of idolatry as it can be kept simply out of fear of G-d (Devarim 6:13, Devarim 10:20), the second of which Rashi comments:
THOU SHALT FEAR THE LORD THY GOD, and serve Him and cleave to Him; and after you possess all these qualities, then you may swear by His Name.
- Gemara Yoma 86a offers another definition
Abaye said: As it was taught in a baraita that it is stated: “And you shall love the Lord your God” (Deuteronomy 6:5), which means that you shall make the name of Heaven beloved. How should one do so? One should do so in that he should read Torah, and learn Mishna, and serve Torah scholars, and he should be pleasant with people in his business transactions.
This definition, as noted in the Gemara further, when violated can be viewed as desecration of the Name, but not idolatry.
- One can also even follow the statement of Rambam about joint Love-fear (Mishneh Torah, Yesodei haTorah 2:1):
It is a mitzvah to love and fear this glorious and awesome God, as [Deuteronomy 6:5] states: "And you shall love God, your Lord" and, as [Deuteronomy 6:13] states: "Fear God, your Lord."
This definition is probably the closest in implying prohibition of idolatry. As Torah Temimah notes that in case of tribulations a person may say - I do not want to keep the commandments, however because of fear one will still keep them. As one see here, it's brought together with two separate verses, not one. Rambam is not even using a more suitable verse for it Devarim 11:1. Still, these are additional verses, as opposed to explicit prohibitions of idolatry in Sefer Shemos and other books of Torah. Thus, one has to conclude that one can serve idols despite love of Hashem and despite fear of Hashem. Perhaps, a good example - people responding to the miracle that Hashem did for Eliyahu on Mt. Carmel.
- Rambam when formulating his eighth principle of faith, that the Torah that we have is the same as was given to Moshe by Hashem refers to gemara Sanhedin 99a
It is taught in another baraita: “Because he has despised the word of the Lord”; this is a reference to one who says the Torah did not originate from Heaven. And even if one says the entire Torah originated from Heaven except for this verse, i.e., any one verse, claiming that the Holy One, Blessed be He, did not say it but Moses himself said it on his own, this is included in the category of: “Because he has despised the word of the Lord.” And even if one says the entire Torah originated from Heaven except for this inference inferred by the Sages, or except for this a fortiori inference, or except for this verbal analogy, this is included in the category of: “Because he has despised the word of the Lord.”
While the violation here is not idolatry, it seems that it became the basis of the mitzvah of loving G-d is described in (Sefer haChinuch Mitzvah 418) (translation of R. Charles Wengrow):
The substance of the precept is that we should consider and reflect on His commandments and His handiwork, until we attain a concept of Him according to our ability, and we can then feel joy in appreciating Him, with the utmost delight. This is obligatory, an essential love.
The language of the Midrash Sifrei Devarim 33: While it is stated and you shall love, I do not know how a man is to love the omnipresent G-d. Hence, Scripture states, Devarim 6:6 And these matters which I command you today shall be on your heart. For as a result of this you will "recognize" the One who spoke and the world came into existence. In other words, with reflection-understanding in the Torah, the love [of G-d] settles perforce in the heart. And the Sages of blessed memory said, Sifrei Devarim 32 that this love should impel a man to arouse people about love for Him - as we find in the instance of Abraham.
We believe that G-d commands and teaches entire Torah to us every day, as we formulate blessings on the Torah in the present tense. Placing on the heart the commandments is a component of love as stated in Sifrei above, so that violation of commandments is the opposite.
Thus, we have to conclude that fulfilling the mitzvah of loving G-d is contingent on contemplating and fulfilling of ALL commandments, including the multiple prohibitions of idolatry, and not the other way around. Through the Torah, with persistence and time, one gains a conception or appreciation of the Creator who gave the Torah, His immanence and influence in this world; and this must inevitably inculcate love of Him. Since only after fulfiling many commandments one can attain a level of loving G-d, it becomes clear why the mitzvah is placed at the end of the Torah and not at the very beginning.
As a side note, the Mitzvah to fear G-d Sefer haChinuch Mitzva 432, refers to fear of punishment.