I want to preserve some configuration files after upgrade, and want to install new ones with my new firmware.
I know sysupgrade.conf, and I know that if I put files to the build directory under files/ it will be put to the image. I also know the uci-defaults folder.
The question is which is the order files are overwritten/executed after upgrade?
files are copied to the filesystem from the files folder
uci-defaults executed
config files overwritten from the previous installation
One "gotcha" to be aware of is that the process copies executables from the "old" file system into a memory-backed file system. It typically "just works", but if you've messes around with busybox options and/or replaced the expected applets with other software (such as the "stand-alone" versions) you might have some surprises.
/etc/sysupgrade.conf will impact the process. The files expected to be preserved/overwritten can be seen with sysupgrade -l (ell)
config files overwritten from the previous installation.
Config files to be preserved in sysupgrade are appended as a .tar.gz to the sysupgrade image at the end of flashing before booting. (depends a bit on target. E.g. for mvebu they are written to the separate syscfg partition.)
pre-init routine extracts that archive rather early in the first boot process after flashing. https://github.com/openwrt/openwrt/blob/master/package/base-files/files/lib/preinit/80_mount_root