Skip to contentSkip to conversation

Can you add a signature to the kernel ELF image?

DISCUSSION Adam Nielsen 3 participants 4 messages Nov 24, 2009 – Nov 25, 2009 MIPS

lore
Share & tools
lore
#0 lore raw

Hi all,

I'm trying to port the kernel to an NCD HMX X-Terminal (MIPS R4600), but the one thing I have to do before I can actually boot the image is attach a signature to it. I have the signature 'code' in assembly[1], but I'm not sure how to link it so that it ends up as the first bit of code in the ELF image (the very first instruction is a 'b' to jump over the actual signature text.)

Without this the boot monitor will refuse to boot the kernel. Any suggestions as to how I might accomplish this?

Many thanks,
Adam.

[1] http://www.linux-mips.org/wiki/HMX

#1 lore raw
Quoted 6 lines · Adam Nielsen

Hi all,

I'm trying to port the kernel to an NCD HMX X-Terminal (MIPS R4600), but the one thing I have to do before I can actually boot the image is attach a signature to it. I have the signature 'code' in assembly[1], but I'm not sure how to link it so that it ends up as the first bit of code in the ELF image (the very first instruction is a 'b' to jump over the actual signature text.)

Without this the boot monitor will refuse to boot the kernel. Any suggestions as to how I might accomplish this?

Edit the linker script (arch/mips/kernel/vmlinux.lds.S)

David Daney

#2 lore raw
In reply to Adam Nielsen
Quoted 9 lines · Adam Nielsen

I'm trying to port the kernel to an NCD HMX X-Terminal (MIPS R4600), but the one thing I have to do before I can actually boot the image is attach a signature to it. I have the signature 'code' in assembly[1], but I'm not sure how to link it so that it ends up as the first bit of code in the ELF image (the very first instruction is a 'b' to jump over the actual signature text.)

Without this the boot monitor will refuse to boot the kernel. Any suggestions as to how I might accomplish this?

Take a look at arch/mips/kernel/head.S. This file will be the first on the final linker call's command line, that is head.S's .text section will end at the lowest address.

In head.S there is this

#ifdef CONFIG_BOOT_RAW
/*
* Give us a fighting chance of running if execution beings at the
* kernel load address. This is needed because this platform does
* not have a ELF loader yet.
*/
FEXPORT(__kernel_entry)
j kernel_entry
#endif

ifdef. Add your own magic stuff there, something like

#ifdef CONFIG_NCD_HMX
	b	1f
	nop
	nop
	.word	0x20
	.asciz	"XncdHMX"
	.word	0, 0, 0

#endif

Quoted 1 line

[1] http://www.linux-mips.org/wiki/HMX

The wiki page says something about a CRC but just poking a 0x20 into a constant address is not exactly a CRC calculation. Not sure how this really is meant.

Ralf

#3 lore raw
Quoted 3 lines

Take a look at arch/mips/kernel/head.S. This file will be the first on the final linker call's command line, that is head.S's .text section will end at the lowest address.

Ah excellent, that combined with the linker script (to twiddle load addresses) is just what I'm after.

Quoted 8 lines
#ifdef CONFIG_NCD_HMX
	b	1f
	nop
	nop
	.word	0x20
	.asciz	"XncdHMX"
	.word	0, 0, 0

#endif

Perfect, thanks for the example, that makes it much easier.

Quoted 5 lines
Quoted 1 line

[1] http://www.linux-mips.org/wiki/HMX

The wiki page says something about a CRC but just poking a 0x20 into a constant address is not exactly a CRC calculation. Not sure how this really is meant.

As far as I'm aware 0x20 means "ignore the CRC", I think the CRC itself is covered by one of the zero words.

Cheers,
Adam.