The game you're describing is almost certainly Motherload. You pilot a small mining ship, dig through layers of underground terrain to collect ore and minerals, and return to a large, square, station-like mothership to refuel, upgrade, and cash in your haul.
A quick search for "Motherload" will pull it right up. It's a Flash-era classic that fits your description of the square mothership perfectly.