Both of them are correct!
you can say:早上好 or 上午好。
However, in my view, 早上 prefers the time from 6:00 to 10:00
上午prefers the time from 8:00 to almost 12:00.
Because it contains the word:午, it means noon or midday.
Hope it will help you. If I don't explain it clearly, just let me know. :)