Boundary layer and stability analysis of natural convection in a porous cavity