mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Antony Pavlov <antonynpavlov@gmail.com>
Cc: barebox@lists.infradead.org
Subject: Re: [RFC v2 6/8] bootm: add kexec ELF support
Date: Wed, 7 Dec 2016 20:59:04 +0100	[thread overview]
Message-ID: <20161207195904.xajaxegfpqawmwcm@pengutronix.de> (raw)
In-Reply-To: <20161205094033.31569-7-antonynpavlov@gmail.com>

On Mon, Dec 05, 2016 at 12:40:31PM +0300, Antony Pavlov wrote:
> Also introduce reboot() for starting already loaded
> via kexec ELF segments.
> 
> Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
> ---
>  include/linux/reboot.h      | 14 ++++++++++++++
>  lib/kexec/Makefile          |  1 +
>  lib/kexec/kexec-bootm-elf.c | 37 +++++++++++++++++++++++++++++++++++++
>  3 files changed, 52 insertions(+)
> 
> diff --git a/include/linux/reboot.h b/include/linux/reboot.h
> new file mode 100644
> index 0000000..454ed33
> --- /dev/null
> +++ b/include/linux/reboot.h
> @@ -0,0 +1,14 @@
> +#ifndef _LINUX_REBOOT_H
> +#define _LINUX_REBOOT_H
> +
> +/*
> + * Commands accepted by the _reboot() system call.
> + *
> + * KEXEC       Restart system using a previously loaded Linux kernel
> + */
> +
> +#define	LINUX_REBOOT_CMD_KEXEC		0x45584543
> +
> +extern int reboot(int cmd);
> +
> +#endif /* _LINUX_REBOOT_H */
> diff --git a/lib/kexec/Makefile b/lib/kexec/Makefile
> index 8febef1..2f3dc1d 100644
> --- a/lib/kexec/Makefile
> +++ b/lib/kexec/Makefile
> @@ -1,3 +1,4 @@
>  obj-y	+= kexec.o
>  obj-y	+= kexec-elf.o
>  obj-y	+= kexec-elf-exec.o
> +obj-y	+= kexec-bootm-elf.o
> diff --git a/lib/kexec/kexec-bootm-elf.c b/lib/kexec/kexec-bootm-elf.c
> new file mode 100644
> index 0000000..ceef6c7
> --- /dev/null
> +++ b/lib/kexec/kexec-bootm-elf.c
> @@ -0,0 +1,37 @@
> +#include <bootm.h>
> +#include <init.h>
> +#include <binfmt.h>
> +#include <errno.h>
> +#include <linux/reboot.h>
> +#include <environment.h>
> +
> +#include "kexec.h"
> +
> +static int do_bootm_elf(struct image_data *data)
> +{
> +	kexec_load_file(data->os_file, 0);
> +	setenv("global.bootm.image", data->os_file);
> +	reboot(LINUX_REBOOT_CMD_KEXEC);
> +
> +	return -ERESTARTSYS;
> +}
> +
> +static struct image_handler elf_handler = {
> +	.name = "ELF",
> +	.bootm = do_bootm_elf,
> +	.filetype = filetype_elf,
> +};
> +
> +static struct binfmt_hook binfmt_elf_hook = {
> +	.type = filetype_elf,
> +	.exec = "bootm",
> +};
> +
> +static int elf_register_image_handler(void)
> +{
> +	register_image_handler(&elf_handler);
> +	binfmt_register(&binfmt_elf_hook);
> +
> +	return 0;
> +}
> +late_initcall(elf_register_image_handler);

The code needed to actually start a kexec kernel is architecture
specific, so the registration of the ELF handler should be done by this
architecture specific code. Then you also don't need this awkward reboot()
stuff. I'm thinking of a

int bootm_register_kexec_handler(int (*do_bootm)(struct image_data *data));

to be called by MIPS or malta specific code.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2016-12-07 19:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-05  9:40 [RFC v2 0/8] MIPS: use kexec to load ELF linux images Antony Pavlov
2016-12-05  9:40 ` [RFC v2 1/8] MIPS: add virt_to_phys() and phys_to_virt() Antony Pavlov
2016-12-05  9:40 ` [RFC v2 2/8] MIPS: c-r4k: add support for secondary cache Antony Pavlov
2016-12-05  9:40 ` [RFC v2 3/8] resource: add create_resource() helper function Antony Pavlov
2016-12-05  9:40 ` [RFC v2 4/8] import initial kexec stuff Antony Pavlov
2016-12-07 19:47   ` Sascha Hauer
2016-12-08  7:24     ` Antony Pavlov
2016-12-05  9:40 ` [RFC v2 5/8] filetype: add ELF type Antony Pavlov
2016-12-05  9:40 ` [RFC v2 6/8] bootm: add kexec ELF support Antony Pavlov
2016-12-07 19:59   ` Sascha Hauer [this message]
2016-12-08  7:29     ` Antony Pavlov
2016-12-05  9:40 ` [RFC v2 7/8] MIPS: add kexec ELF loading support Antony Pavlov
2016-12-05  9:40 ` [RFC v2 8/8] MIPS: malta: enable kexec Antony Pavlov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161207195904.xajaxegfpqawmwcm@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=antonynpavlov@gmail.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox