Add device nodes recursively

Fix #5988