Try to run above, looks like upgraded can bring do_stage2.
root@OpenWrt:/# /sbin/upgraded /tmp/openwrt-sysupgrade.img /lib/upgrade/do_stage2
killall: telnetd: no process killed
do platform_pre_upgrade, kill daemons...
Switching to ramdisk...
My question is how do I to debug this problem?
I double check free memory(48MB), it should be okay(firmware size is 12MB).
Need a guy to guide me how to debug it. Appreciate. Thanks.
you need to make it clear in the title/op that this is your own magic/attempted image generation...
no... don't do this... there are plenty enough hooks available to debug without messing with C and it's unlikely this is related to any issue in that space
generally as a rough clue... most likely candidates are related to;
hanging processes
filesystem setup drama
botched environment
some whacky proc/<cgroup/kexec/selinux> type crap that is effecting the above...
the only thing that seems applicable to 'targeting' /sbin/upgraded is some sort of watchdog failure maybe...
but if you are 'stuck' on diggin deeper... you might have to
insert some C within it... really round about way of
extrapolating where you are falling down in a
target definition
for anything else your going to have to share everything you have and what you based it on... beats hypothesizing...
When you say "I try to run above command", so you mean the ubus call? The sysupgrade script normally copies /sbin/upgraded to /tmp/root before the ubus call, which uses /tmp/root as a chroot. I suspect that part is working fine, you just need to do the copy manually first.
Worth noting too, that the Failed to exec upgraded line gets printed when upgraded returns (it expects it to upgrade and reboot), so even with your replacement that will still happen.
Yes, I run it manually. By the way, I know sysupgrade will install upgraded into /tmp/root.
So, I will remove the install command from sysupgrade, run ubus call manually and check the log.
Thanks.
Ah ok. Poking around the code it seems like either upgraded is not getting executed (unlikely), or something is failing in upgraded before (or just inside) the call to watchdog_init, and not printing anything.
This is based on seeing this when i run sysupgrade:
Thu Jan 1 00:00:22 UTC 1970 upgrade: Commencing upgrade. Closing all shell sessions.
Watchdog handover: fd=3
- watchdog -
...
Those watchdog lines come from watchdog_init.
Have you tried adding a printf very early in the existing upgraded code (at the top of main)? That might narrow it down.
I'd also print out the errno in case execvp fails in sysupgrade.c; that would be something like this:
if (execvp(argv[0], argv))
fprintf(stderr, "upgraded error: %s\n", strerror(errno));
It's always possible for this kind of thing to be caused by hardware or some kind of messed up installation. You could try running it from failsafe or an initramfs (if you haven't already).
It would be helpful to see the actual error number (rather than the return value), as that gives more detail about what went wrong; it will be one of these: https://man.archlinux.org/man/execve.2#ERRORS
Looking at what execvp/execve does, i would definitely classify this as a problem with executing upgraded, as execve doesn't return if the program exits/crashes, only if it fails to execute.