N5
まで(動詞)
まで(どうし)
Until (something) happens
友達が来るまで、駅をウロウロした。
Until my friend came, I wandered around the station.
Explanation
「dictionary form + まで」 means 'keep doing something until something happens': 「バスが来るまで、本を読む」 (read until the bus comes).
Mixed up with
The verb before it takes the dictionary form, regardless of a past main clause: not 「友達が来たまで待った」 but 「友達が来るまで待った」. While you were waiting, your friend had not come yet.
The main clause after 「まで」 is a continuing action: 「親が帰るまで、テレビを見る」 (watch TV until my parents come home); after 「までに」 it is a one-time action: 「親が帰るまでに、宿題を終わらせる」 (finish my homework before my parents come home).