[RFC v2 4/8] import initial kexec stuff
Sascha Hauer
s.hauer at pengutronix.de
Wed Dec 7 11:47:55 PST 2016
On Mon, Dec 05, 2016 at 12:40:29PM +0300, Antony Pavlov wrote:
> Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
> Signed-off-by: Peter Mamonov <pmamonov at gmail.com>
The commit message could be a bit more verbose and at least mention
where this code is derived from and from which version.
> +
> +static int build_mem_ehdr(const char *buf, off_t len, struct mem_ehdr *ehdr)
> +{
> + unsigned char e_ident[EI_NIDENT];
> + int result;
> +
> + memset(ehdr, 0, sizeof(*ehdr));
> +
> + if ((size_t)len < sizeof(e_ident)) {
> + printf("Buffer is too small to hold ELF e_ident\n");
> +
> + return -1;
> + }
> +
> + memcpy(e_ident, buf, sizeof(e_ident));
> +
> + ehdr->ei_class = e_ident[EI_CLASS];
> + ehdr->ei_data = e_ident[EI_DATA];
> + if ( (ehdr->ei_class != ELFCLASS32) &&
> + (ehdr->ei_class != ELFCLASS64))
> + {
> + printf("Not a supported ELF class\n");
> + return -1;
> + }
> +
> + if ( (ehdr->ei_data != ELFDATA2LSB) &&
> + (ehdr->ei_data != ELFDATA2MSB))
> + {
> + printf("Not a supported ELF data format\n");
> + return -1;
> + }
> +
> + result = -1;
> + if (ehdr->ei_class == ELFCLASS32) {
> + result = build_mem_elf32_ehdr(buf, len, ehdr);
> + }
The opening braces are sometimes on the same line and sometimees on a
new line. Is this from the original code?
> +
> + /* Now walk and normalize the notes */
> + ehdr->e_note = xmalloc(sizeof(*ehdr->e_note) * ehdr->e_notenum);
> + for (i = 0, note = note_start; note < note_end;
> + note += note_size, i++) {
> + const unsigned char *name, *desc;
> + ElfNN_Nhdr hdr;
> + read_nhdr(ehdr, &hdr, note);
> + note_size = sizeof(hdr);
> + name = note + note_size;
> + note_size += (hdr.n_namesz + 3) & ~3;
> + desc = note + note_size;
> + note_size += (hdr.n_descsz + 3) & ~3;
> +
> + if ((hdr.n_namesz != 0) && (name[hdr.n_namesz -1] != '\0')) {
> + /* If note name string is not null terminated, just
> + * warn user about it and continue processing. This
> + * allows us to parse /proc/kcore on older kernels
> + * where /proc/kcore elf notes were not null
> + * terminated. It has been fixed in 2.6.19.
> + */
> + printf("Warning: Elf Note name is not null "
> + "terminated\n");
> + }
Is this relevant for barebox? We do not parse /proc/kcore.
> + ehdr->e_note[i].n_type = hdr.n_type;
> + ehdr->e_note[i].n_name = (char *)name;
> + ehdr->e_note[i].n_desc = desc;
> + ehdr->e_note[i].n_descsz = hdr.n_descsz;
> +
> + }
> +
> + return 0;
> +}
> +
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 |
More information about the barebox
mailing list