[RFC v2 4/8] import initial kexec stuff

Antony Pavlov antonynpavlov at gmail.com
Wed Dec 7 23:24:22 PST 2016


On Wed, 7 Dec 2016 20:47:55 +0100
Sascha Hauer <s.hauer at pengutronix.de> wrote:

> 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?

Yes, original code has some formatting problems. I have noted that fact in RFC v2 0/0 message.

> > +
> > +	/* 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.

Good shot! I'll drop this code.

> 
> > +		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 |


-- 
Best regards,
  Antony Pavlov



More information about the barebox mailing list