GPIO: Initial state?

What is the initial state of a GPIO after boot ?
I think, that this is defined in dts file, first of all. But what happens, in case I change the value of the GPIO programmatically, and then do a reboot/powercycle ? Is the last state of the GPIO preserved ?

No, rebooting implies resetting 'everything' and you end up with the default (as indeed specified by DTS) configuration; everything else would be a bug (or at least very questionable). If you have a need to retain state, you will need to store it explicitly - and re-apply it (e.g. via your service's init script).

Thats what I expected, frankly speaking. Because this explains a nasty timing bug/issue because of the 'late' /etc/rc.d/S94gpio_switch:
On my RUT955 I am fighting a spurious error regarding starting up the built-in LTE-modem using second (non-default) SIM.
Effect is, that modem reports, it does not properly detect the SIM.
Which most likely is caused by interfering the modem startup using default SIM1, and then switching the GPIO to select SIM2, as specified in /etc/config/system/...sim_select.

I moved S94gpio_switch to S19gpio_switch, which actually seems to fix this timing issue. Although I consider it a 'dirty-fix'.
May be, it is a good idea to have S19gpio_switch as default ?