do_config_generate() {
	[ -f /etc/board.json ] || {
		# This allows /etc/board.d/* scripts to use values from the uboot environment
		mkdir -p /tmp/.uci
		[ -f /etc/uci-defaults/30_uboot-envtools ] && (. /etc/uci-defaults/30_uboot-envtools)

		echo "- generating board file -"
		/bin/board_detect /tmp/board.json
		mv /tmp/board.json /etc/board.json

		/bin/config_generate > /dev/null
	}
}

boot_hook_add preinit_main do_config_generate
boot_hook_add initramfs do_config_generate
