d2dcm: Fix and consolidate persistent_ram code