Skip to content

how to reboot into partition with new firmware but no systemd? #2095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
matthuisman opened this issue Jul 3, 2017 · 4 comments
Closed

how to reboot into partition with new firmware but no systemd? #2095

matthuisman opened this issue Jul 3, 2017 · 4 comments

Comments

@matthuisman
Copy link

matthuisman commented Jul 3, 2017

I am trying to get Batocera OS rebooting into another partition.
They have just updated to 4.9.
The /sys/module/bcm2709/parameters/reboot_part path is no longer present.

If I try the reboot [part], it gives the error.
So, it looks like it's using an "old" reboot that doesn't know about the extra partition parameter?

Is there any other way to set the reboot part?
Or, is their a newer "reboot" I can compile?
Or, is there any simple C code I could compile to achieve it?
I can't fully change the system, but I could copy in a executable and run it if need be to get the result.

I see most systems have switched to systemd and it appears systemd takes care of the reboot now.
This OS is using systemvinit.
And I assume the reboot program is from busybox or something..

Looks like this is the code needs to be run:
syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, reboot_arg);

Is there any compiled "reboot" or "halt" that uses this update line?
Maybe mainline busybox or something like that?
I fear if I just compile a C file with that in it, it's not doing a proper "reboot".

@pelwell
Copy link
Contributor

pelwell commented Jul 3, 2017

The RPi firmware still uses the same mechanism as before, but the board support code now uses the standard reboot handling mechanism - passing a command string containing the partition number to the kernel_restart function.

It sounds like Batocera is using a command (shell script?) that writes the supplied partition number into a module parameter exposed by the old BCM2708/9 board support code. This code no longer exists, hence the failure you are seeing. Instead it needs a small utility - conventionally called reboot under Linux - that invokes the reboot system call (http://man7.org/linux/man-pages/man2/reboot.2.html) passing in the required magic numbers, LINUX_REBOOT_CMD_RESTART2 and the string with the partition number.

You'll have to raise this with the Batocera devs.

@pelwell pelwell closed this as completed Jul 3, 2017
@matthuisman
Copy link
Author

matthuisman commented Jul 3, 2017

Hi @pelwell ,

yes, it already has the reboot utility (which symlinks to halt).
But, it seems this utility is older and doesn't know about the extra parameter.

I was asking is there some source code for the reboot / halt utility (with the extra parameter) that I can compile? Or even that I can modify with the extra parameter myself.

I'm just unsure where the source code for reboot / halt is kept?

@matthuisman
Copy link
Author

matthuisman commented Jul 4, 2017

Ended up with this

#include <linux/reboot.h>
#include <sys/syscall.h>
#include <signal.h>
#include <stdlib.h>

int main(int argc, char *argv[])  {
    char *param = NULL;
    int cmd;
    
    if(argc == 2) {
        param = argv[1];
        cmd = LINUX_REBOOT_CMD_RESTART2;
    }
    else {
        cmd = LINUX_REBOOT_CMD_RESTART;
    }

    sync();
    system("/etc/init.d/rcK || /etc/init.d/rc 0");

    sync();
    syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, cmd, param);
    
    return 0;
}

Seems to do what I need.
It's only a fallback if

  1. no /sys/module/bcm2709 exists
  2. and reboot [parameter] fails

reboot 6 || (echo 6 > /sys/module/bcm270?/parameters/reboot_part && reboot) || custom_reboot 6

@pelwell
Copy link
Contributor

pelwell commented Jul 4, 2017

Raspbian uses systemd, and reboot, poweroff etc. are symlinked to systemctl, the source for which can be found here: https://github.com/systemd/systemd/blob/master/src/systemctl/systemctl.c

I found the source to a simpler shutdown command here: http://util-linux.sourcearchive.com/documentation/2.14/shutdown_8c-source.html
It includes killing init, turning off swap etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants