H-FGK formalism for black-hole solutions of N=2, d=4 and d=5 supergravity