Barotropic instability of coastal flows as a boundary-value problem: linear and non-linear theory