Phase retrieval using boundary conditions