Dynamics of granular stratification