romfs: check the dirent before use it

System will crash when the romfs is erased. Add checks before using them
to avoid it.
romfs: rewrite mkromfs.py