u-boot factory reset



First time customizing u-boot, forgive my basic question.

To implement a factory reset, my initramfs expects a ‘factoryreset’ kernel parameter to format an overlay FS partition before mounting it.

The target machine is a Tegra TX2.

I’m able to use the Volume Up button for factory reset, which is gpio-313 . When starting the board if I press the button say 5s, I’d like to add the ‘factoryreset’ parameter to the boot parameters

I think I could use this syntax @uboot_var('factoryreset') in the KERNEL_ROOTSPEC variable and have the variable set either to '' or 'factoryreset'

Maybe, I should append distro_bootcmd to add the gpio pin reading to set factoryreset variable before proceeding with the boot sequence.

But how can I add the variable and have it set if the if the gpio pin is at a certain state?