Logic of the word 上午 (shànɡwǔ, morning)
上午, 下午 has the same logic as 上週, 下週. 上 is a prefix meaning previous, before, and 上午 means before noon.
If you must assign a meaning to 上 in 早上 and 晚上, I would interpret it to be a suffix meaning at, during, in, or within. 早上/晚上 means during or in the morning/evening.

用在名詞後。表示一定的處所或範圍。(Used after a noun, indicating a specific location or [within a specific] range.)

《孟子・梁惠王上》：＂王坐於堂上，有牽牛而過堂下者，王見之曰：＇牛何之？＇＂
《戰國策・秦策一》：＂人生世上，勢位富貴， 蓋可忽乎哉！＂
《醒世恒言・三孝廉讓產立高名》：＂有一人姓許名武，字長文，十五歲上，父母雙亡。＂
巴金　《探索集・懷念老舍同志》：＂在他們的心上、在他們的筆下，他至今仍然活着。＂