Skip to contentSkip to conversation

arm: Defer lookup of machine_type and vet of atags to setup.c

RFC In review Grant Likely 4 participants 15 messages Jan 11, 2011 – Feb 7, 2011 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

RFC 1/1 arm: Defer lookup of machine_type and vet of atags to setup.c

Since the debug macros no longer depend on the machine type information, both the machine type lookup and the atags vetting can be deferred to setup_arch() in setup.c which simplifies the code somewhat.

This patch removes both __machine_type_lookup and __vet_atags() from head.S. The atags vetting is moved to setup_arch(). machine_type lookup is already called from setup_machine() in addition to where it was called from head.S.

I've tried to preserve the existing behaviour in this patch so the extra atags vetting is only using when CONFIG_MMU is selected. I may be being overly cautious, and if so then it is probably possible to simplify the code further.

---

Hi Russell,

I'm not sure if this is a valid change or not, but from what I can tell it looks like machine and atag processing no longer needs to be handled as early as head.S. Please take a look and let me know what you think.

I've boot tested this on Tegra and versatile qemu, but that's about it.

Thanks,
g.

 arch/arm/kernel/head-common.S |   35 -----------------------------------
 arch/arm/kernel/head.S        |    5 -----
 arch/arm/kernel/setup.c       |   16 ++++++++++++++++
 3 files changed, 16 insertions(+), 40 deletions(-)
arch/arm/kernel/head-common.S +0 -35
index bbecaac..7956a48 100644
@@ -11,10 +11,6 @@
  *
  */
 
-#define ATAG_CORE 0x54410001
-#define ATAG_CORE_SIZE ((2*4 + 3*4) >> 2)
-#define ATAG_CORE_SIZE_EMPTY ((2*4) >> 2)
-
 /*
  * Exception handling.  Something went wrong and we can't proceed.  We
  * ought to tell the user, but since we don't have any guarantee that
@@ -101,37 +97,6 @@ __lookup_machine_type_data:
 	.long	__arch_info_end
 	.size	__lookup_machine_type_data, . - __lookup_machine_type_data
 
-/* Determine validity of the r2 atags pointer.  The heuristic requires
- * that the pointer be aligned, in the first 16k of physical RAM and
- * that the ATAG_CORE marker is first and present.  Future revisions
- * of this function may be more lenient with the physical address and
- * may also be able to move the ATAGS block if necessary.
- *
- * r8  = machinfo
- *
- * Returns:
- *  r2 either valid atags pointer, or zero
- *  r5, r6 corrupted
- */
-__vet_atags:
-	tst	r2, #0x3			@ aligned?
-	bne	1f
-
-	ldr	r5, [r2, #0]			@ is first tag ATAG_CORE?
-	cmp	r5, #ATAG_CORE_SIZE
-	cmpne	r5, #ATAG_CORE_SIZE_EMPTY
-	bne	1f
-	ldr	r5, [r2, #4]
-	ldr	r6, =ATAG_CORE
-	cmp	r5, r6
-	bne	1f
-
-	mov	pc, lr				@ atag pointer is ok
-
-1:	mov	r2, #0
-	mov	pc, lr
-ENDPROC(__vet_atags)
-
 /*
  * The following fragment of code is executed with the MMU on in MMU mode,
  * and uses absolute addresses; this is not position independent.
arch/arm/kernel/head.S +0 -5
index 6bd82d2..9c0e938 100644
@@ -87,11 +87,6 @@ ENTRY(stext)
 	movs	r10, r5				@ invalid processor (r5=0)?
  THUMB( it	eq )		@ force fixup-able long branch encoding
 	beq	__error_p			@ yes, error 'p'
-	bl	__lookup_machine_type		@ r5=machinfo
-	movs	r8, r5				@ invalid machine (r5=0)?
- THUMB( it	eq )		@ force fixup-able long branch encoding
-	beq	__error_a			@ yes, error 'a'
-	bl	__vet_atags
 #ifdef CONFIG_SMP_ON_UP
 	bl	__fixup_smp
 #endif
arch/arm/kernel/setup.c +16 -0
index 336f14e..cd28089 100644
@@ -814,6 +814,22 @@ void __init setup_arch(char **cmdline_p)
 	if (mdesc->soft_reboot)
 		reboot_setup("s");
 
+#if defined(CONFIG_MMU)
+	/*
+	 * Determine validity of the atags pointer.  The heuristic requires
+	 * that the pointer be aligned, and that the ATAG_CORE marker is
+	 * first and present.
+	 */
+	if (__atags_pointer & 0x3)
+		__atags_pointer = 0;
+	if (__atags_pointer) {
+		struct tag *t = phys_to_virt(__atags_pointer);
+		if ((t->hdr.size != tag_size(tag_core)) &&
+		    (t->hdr.size != sizeof(struct tag_header)) &&
+		    (t->hdr.tag != ATAG_CORE))
+			__atags_pointer = 0;
+	}
+#endif
 	if (__atags_pointer)
 		tags = phys_to_virt(__atags_pointer);
 	else if (mdesc->boot_params)
#1 lore raw
Quoted 9 lines · Grant Likely

Since the debug macros no longer depend on the machine type information, both the machine type lookup and the atags vetting can be deferred to setup_arch() in setup.c which simplifies the code somewhat.

This patch removes both __machine_type_lookup and __vet_atags() from head.S. The atags vetting is moved to setup_arch(). machine_type lookup is already called from setup_machine() in addition to where it was called from head.S.

While at it, you could also remove the code for __lookup_machine_type, lookup_machine_type and __error_a, replacing that with a C implementation living in setup.c instead. If this code is not called from head.S anymore, there is no reason to keep it there any longer.

Nicolas

#2 lore raw
Quoted 12 lines · Nicolas Pitre
Quoted 9 lines · Grant Likely

Since the debug macros no longer depend on the machine type information, both the machine type lookup and the atags vetting can be deferred to setup_arch() in setup.c which simplifies the code somewhat.

This patch removes both __machine_type_lookup and __vet_atags() from head.S. ?The atags vetting is moved to setup_arch(). ?machine_type lookup is already called from setup_machine() in addition to where it was called from head.S.

Quoted 4 lines

While at it, you could also remove the code for __lookup_machine_type, lookup_machine_type and __error_a, replacing that with a C implementation living in setup.c instead. ?If this code is not called from head.S anymore, there is no reason to keep it there any longer.

Certainly. I'll draft that up as a separate patch and post it tomorrow.

g.

#3 lore raw
In reply to Grant Likely
Quoted 6 lines · Grant Likely
arch/arm/kernel/head.S +0 -0
index 6bd82d2..9c0e938 100644
@@ -87,11 +87,6 @@ ENTRY(stext)
 	movs	r10, r5				@ invalid processor (r5=0)?

arch/arm/kernel/head.S ENTRY(stext) · line 92

Quoted 10 lines
arch/arm/kernel/head.S +0 -5
  THUMB( it	eq )		@ force fixup-able long branch encoding
 	beq	__error_p			@ yes, error 'p'
-	bl	__lookup_machine_type		@ r5=machinfo
-	movs	r8, r5				@ invalid machine (r5=0)?
- THUMB( it	eq )		@ force fixup-able long branch encoding
-	beq	__error_a			@ yes, error 'a'
-	bl	__vet_atags
 #ifdef CONFIG_SMP_ON_UP
 	bl	__fixup_smp
 #endif

Don't forget to update the comments as well - there's two of them.

#4 lore raw
Quoted 11 lines · Russell King - ARM Linux
Quoted 10 lines · Grant Likely
arch/arm/kernel/head.S +0 -2
index 6bd82d2..9c0e938 100644
@@ -87,11 +87,6 @@ ENTRY(stext)
 	movs	r10, r5				@ invalid processor (r5=0)?
  THUMB( it	eq )		@ force fixup-able long branch encoding
 	beq	__error_p			@ yes, error 'p'
-	bl	__lookup_machine_type		@ r5=machinfo
-	movs	r8, r5				@ invalid machine (r5=0)?
Quoted 8 lines

arch/arm/kernel/head.S ENTRY(stext) · line 92

Quoted 6 lines
arch/arm/kernel/head.S +0 -3
- THUMB( it	eq )		@ force fixup-able long branch encoding
-	beq	__error_a			@ yes, error 'a'
-	bl	__vet_atags
 #ifdef CONFIG_SMP_ON_UP
 	bl	__fixup_smp
 #endif

Don't forget to update the comments as well - there's two of them.

I'm not entirely clear on what you're referring to here. Are you talking about the secondary cpu entry point? I've fixed up that comment now as well as a s/__lookup_machine_type/__lookup_processor_type/ typo right before the call to __enable_mmu.

I've also removed the machine type lookup from head-nommu.S and I'll repost the patch later today.

Thanks for the review,
g.

#5 lore raw
Quoted 21 lines · Grant Likely
Quoted 11 lines · Russell King - ARM Linux
Quoted 10 lines · Grant Likely
arch/arm/kernel/head.S +0 -2
index 6bd82d2..9c0e938 100644
@@ -87,11 +87,6 @@ ENTRY(stext)
 	movs	r10, r5				@ invalid processor (r5=0)?
  THUMB( it	eq )		@ force fixup-able long branch encoding
 	beq	__error_p			@ yes, error 'p'
-	bl	__lookup_machine_type		@ r5=machinfo
-	movs	r8, r5				@ invalid machine (r5=0)?
Quoted 8 lines

arch/arm/kernel/head.S ENTRY(stext) · line 92

Quoted 6 lines
arch/arm/kernel/head.S +0 -3
- THUMB( it	eq )		@ force fixup-able long branch encoding
-	beq	__error_a			@ yes, error 'a'
-	bl	__vet_atags
 #ifdef CONFIG_SMP_ON_UP
 	bl	__fixup_smp
 #endif

Don't forget to update the comments as well - there's two of them.

Quoted 4 lines

I'm not entirely clear on what you're referring to here. Are you talking about the secondary cpu entry point? I've fixed up that comment now as well as a s/__lookup_machine_type/__lookup_processor_type/ typo right before the call to __enable_mmu.

In the above code, __lookup_machine_type is called, which to be consistent with __lookup_processor_type, returns its value in r5. This is then copied to r8, which is the only point that r8 is initialized.

The remainder of the code used to make use of r8 to load various fields from the machine record, and so there's a couple of comments indicating that this is the case. These comments are left behind after your patch and so are misleading.

Shall I assume that you've already searched the head*.S files to make sure that r8 isn't used before you removed its initialization? ;-)

#6 lore raw
Quoted 27 lines · Russell King - ARM Linux
Quoted 21 lines · Grant Likely
Quoted 11 lines · Russell King - ARM Linux
Quoted 10 lines · Grant Likely
arch/arm/kernel/head.S +0 -0
index 6bd82d2..9c0e938 100644
@@ -87,11 +87,6 @@ ENTRY(stext)

? movs ? ?r10, r5 ? ? ? ? ? ? ? ? ? ? ? ? @ invalid processor (r5=0)? ? THUMB( it ? ? ? eq ) ? ? ? ? ? ?@ force fixup-able long branch encoding ? beq ? ? __error_p ? ? ? ? ? ? ? ? ? ? ? @ yes, error 'p'
- bl ? ? ?__lookup_machine_type ? ? ? ? ? @ r5=machinfo
- movs ? ?r8, r5 ? ? ? ? ? ? ? ? ? ? ? ? ?@ invalid machine (r5=0)?

Quoted 8 lines
Quoted 6 lines

- THUMB( it ? ? ? eq ) ? ? ? ? ? ?@ force fixup-able long branch encoding
- beq ? ? __error_a ? ? ? ? ? ? ? ? ? ? ? @ yes, error 'a'
- bl ? ? ?__vet_atags
?#ifdef CONFIG_SMP_ON_UP
? bl ? ? ?__fixup_smp
?#endif

Don't forget to update the comments as well - there's two of them.

Quoted 4 lines

I'm not entirely clear on what you're referring to here. ?Are you talking about the secondary cpu entry point? ?I've fixed up that comment now as well as a s/__lookup_machine_type/__lookup_processor_type/ typo right before the call to __enable_mmu.

Quoted 8 lines

In the above code, __lookup_machine_type is called, which to be consistent with __lookup_processor_type, returns its value in r5. ?This is then copied to r8, which is the only point that r8 is initialized.

The remainder of the code used to make use of r8 to load various fields from the machine record, and so there's a couple of comments indicating that this is the case. ?These comments are left behind after your patch and so are misleading.

Ah, right. I'll clean those up.

Quoted 2 lines

Shall I assume that you've already searched the head*.S files to make sure that r8 isn't used before you removed its initialization? ;-)

Yup!

Looks like I've hit a hiccup though. When I remove the first call to __lookup_machine_type, then it is only called after the MMU is turned on and the kernel is no longer able to output the list of configured machine ids when it doesn't recognize the value in r1 (tested with qemu versatile emulation). I'm still investigating, so I'll defer reposting the patch until I've got this issue solved.

g.

Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
#7 lore raw
Quoted 6 lines · Grant Likely

Looks like I've hit a hiccup though. When I remove the first call to __lookup_machine_type, then it is only called after the MMU is turned on and the kernel is no longer able to output the list of configured machine ids when it doesn't recognize the value in r1 (tested with qemu versatile emulation). I'm still investigating, so I'll defer reposting the patch until I've got this issue solved.

It only does this when DEBUG_LL is enabled - at which point you have printascii, printhex8, etc available (although there's no prototype for them.)

You could use snprintf() to format a message and then use printascii() (conditional on CONFIG_DEBUG_LL as the existing code does) as well as printk("%s", buffer). That means if you have a debugger you can dump the kernel ring buffer and see the message, or see it via the serial port/debugging channel if DEBUG_LL is enabled.

#8 lore raw
Quoted 12 lines · Russell King - ARM Linux
Quoted 6 lines · Grant Likely

Looks like I've hit a hiccup though. ?When I remove the first call to __lookup_machine_type, then it is only called after the MMU is turned on and the kernel is no longer able to output the list of configured machine ids when it doesn't recognize the value in r1 (tested with qemu versatile emulation). ?I'm still investigating, so I'll defer reposting the patch until I've got this issue solved.

It only does this when DEBUG_LL is enabled - at which point you have printascii, printhex8, etc available (although there's no prototype for them.)

Quoted 5 lines

You could use snprintf() to format a message and then use printascii() (conditional on CONFIG_DEBUG_LL as the existing code does) as well as printk("%s", buffer). ?That means if you have a debugger you can dump the kernel ring buffer and see the message, or see it via the serial port/debugging channel if DEBUG_LL is enabled.

Actually it looks like the real problem is that the mmu has been turned on, but the virtual mappings for devices have not yet been established, and so the debug macros aren't using a valid address. I'm using printk to get output into the ring buffer in my patch to rework lookup_machine_type() in C, and that does indeed output to the ring buffer, but the kernel cannot spit stuff out the serial port.

It looks like I'd need to get past paging_init() in order to get ll_debug working between turning on the mmu and paging_init(), but paging_init() needs the mdesc pointer, and the whole point of the error message is that the mdesc pointer is unknown! I don't see any code that sets up a debug mapping of the uart before paging_init time.
I could try to implement something like that, but it is looking to be
more complicated than it is worth when the current code works just fine.

Let me know if I've missed something, but I think I should drop the removal of __lookup_machine_type from head.S from my patch.

g.

Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
#9 lore raw
Quoted 3 lines · Grant Likely

Actually it looks like the real problem is that the mmu has been turned on, but the virtual mappings for devices have not yet been established, and so the debug macros aren't using a valid address.

They should be, as they're valid for use from assembly prior to MMU turn-on, assembly after MMU turn-on and C code.

If CONFIG_DEBUG_LL is enabled, create_page_tables() should be setting up the necessary initial mappings for printascii() to work.

Maybe the efforts to unify that stuff ended up breaking the printascii debugging mechanism, and we now require a new debugging mechanism to debug the printascii debugging mechanism... :-P

I've used it on Versatile Express during the last week and it did work right from before setup_arch() was called.

Quoted 5 lines

It looks like I'd need to get past paging_init() in order to get ll_debug working between turning on the mmu and paging_init(), but paging_init() needs the mdesc pointer, and the whole point of the error message is that the mdesc pointer is unknown! I don't see any code that sets up a debug mapping of the uart before paging_init time.

See the #ifdef CONFIG_DEBUG_LL section in create_page_tables in head.S

#10 lore raw
In reply to Grant Likely
Quoted 3 lines · Grant Likely

Actually it looks like the real problem is that the mmu has been turned on, but the virtual mappings for devices have not yet been established, and so the debug macros aren't using a valid address.

A temporary virtual mapping should be there -- look for addruart in head.S.

Quoted 9 lines

I'm using printk to get output into the ring buffer in my patch to rework lookup_machine_type() in C, and that does indeed output to the ring buffer, but the kernel cannot spit stuff out the serial port.

It looks like I'd need to get past paging_init() in order to get ll_debug working between turning on the mmu and paging_init(), but paging_init() needs the mdesc pointer, and the whole point of the error message is that the mdesc pointer is unknown! I don't see any code that sets up a debug mapping of the uart before paging_init time.

See above.

Quoted 3 lines

I could try to implement something like that, but it is looking to be
more complicated than it is worth when the current code works just fine.

My bet is that there is a bug with the current code that you are exposing.

Quoted 2 lines

Let me know if I've missed something, but I think I should drop the removal of __lookup_machine_type from head.S from my patch.

It's not the location of that code which is a problem. Even if you leave that code in place, you want to call it later and I bet that the display would be broken even if __lookup_machine_type doesn't move.

Nicolas

#11 lore raw
Quoted 8 lines · Nicolas Pitre
Quoted 3 lines · Grant Likely

Actually it looks like the real problem is that the mmu has been turned on, but the virtual mappings for devices have not yet been established, and so the debug macros aren't using a valid address.

A temporary virtual mapping should be there -- look for addruart in head.S.

Hi Russell and Nicolas,

Oops, yes all the early debug stuff works fine. Stupid human trick on my end, but I've sorted it out now. Thanks for the help. I'll have patches to post later today.

g.

Quoted 30 lines
Quoted 10 lines

I'm using printk to get output into the ring buffer in my patch to rework lookup_machine_type() in C, and that does indeed output to the ring buffer, but the kernel cannot spit stuff out the serial port.

It looks like I'd need to get past paging_init() in order to get ll_debug working between turning on the mmu and paging_init(), but paging_init() needs the mdesc pointer, and the whole point of the error message is that the mdesc pointer is unknown! ?I don't see any code that sets up a debug mapping of the uart before paging_init time.

See above.

Quoted 3 lines

?I could try to implement something like that, but it is looking to be more complicated than it is worth when the current code works just fine.

My bet is that there is a bug with the current code that you are exposing.

Quoted 2 lines

Let me know if I've missed something, but I think I should drop the removal of __lookup_machine_type from head.S from my patch.

It's not the location of that code which is a problem. ?Even if you leave that code in place, you want to call it later and I bet that the display would be broken even if __lookup_machine_type doesn't move.

Nicolas

Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
#12 lore raw
Quoted 7 lines · Grant Likely
Quoted 6 lines · Nicolas Pitre
Quoted 3 lines · Grant Likely

Actually it looks like the real problem is that the mmu has been turned on, but the virtual mappings for devices have not yet been established, and so the debug macros aren't using a valid address.

Quoted 8 lines
Quoted 2 lines

A temporary virtual mapping should be there -- look for addruart in head.S.

Hi Russell and Nicolas,

Oops, yes all the early debug stuff works fine. Stupid human trick on my end, but I've sorted it out now. Thanks for the help. I'll have patches to post later today.

I just hacked this up, and on Versatile (real hardware) it produces the below for an invalid r1 value - and of course works for a proper r1 value.

Uncompressing Linux... done, booting the kernel.

Error: unrecognized/unsupported machine ID (r1 = 0x00123456).

Available machine support:

ID (hex)        NAME
00000183        ARM-Versatile PB
0000025e        ARM-Versatile AB

Please check your kernel config and/or bootloader.

arch/arm/kernel/head-common.S +0 -88
index bbecaac..c84b57d 100644
@@ -25,81 +25,6 @@
  * machine ID for example).
  */
 	__HEAD
-__error_a:
-#ifdef CONFIG_DEBUG_LL
-	mov	r4, r1				@ preserve machine ID
-	adr	r0, str_a1
-	bl	printascii
-	mov	r0, r4
-	bl	printhex8
-	adr	r0, str_a2
-	bl	printascii
-	adr	r3, __lookup_machine_type_data
-	ldmia	r3, {r4, r5, r6}		@ get machine desc list
-	sub	r4, r3, r4			@ get offset between virt&phys
-	add	r5, r5, r4			@ convert virt addresses to
-	add	r6, r6, r4			@ physical address space
-1:	ldr	r0, [r5, #MACHINFO_TYPE]	@ get machine type
-	bl	printhex8
-	mov	r0, #'\t'
-	bl	printch
-	ldr     r0, [r5, #MACHINFO_NAME]	@ get machine name
-	add	r0, r0, r4
-	bl	printascii
-	mov	r0, #'\n'
-	bl	printch
-	add	r5, r5, #SIZEOF_MACHINE_DESC	@ next machine_desc
-	cmp	r5, r6
-	blo	1b
-	adr	r0, str_a3
-	bl	printascii
-	b	__error
-ENDPROC(__error_a)
-
-str_a1:	.asciz	"\nError: unrecognized/unsupported machine ID (r1 = 0x"
-str_a2:	.asciz	").\n\nAvailable machine support:\n\nID (hex)\tNAME\n"
-str_a3:	.asciz	"\nPlease check your kernel config and/or bootloader.\n"
-	.align
-#endif
-
-/*
- * Lookup machine architecture in the linker-build list of architectures.
- * Note that we can't use the absolute addresses for the __arch_info
- * lists since we aren't running with the MMU on (and therefore, we are
- * not in the correct address space).  We have to calculate the offset.
- *
- *  r1 = machine architecture number
- * Returns:
- *  r3, r4, r6 corrupted
- *  r5 = mach_info pointer in physical address space
- */
-__lookup_machine_type:
-	adr	r3, __lookup_machine_type_data
-	ldmia	r3, {r4, r5, r6}
-	sub	r3, r3, r4			@ get offset between virt&phys
-	add	r5, r5, r3			@ convert virt addresses to
-	add	r6, r6, r3			@ physical address space
-1:	ldr	r3, [r5, #MACHINFO_TYPE]	@ get machine type
-	teq	r3, r1				@ matches loader number?
-	beq	2f				@ found
-	add	r5, r5, #SIZEOF_MACHINE_DESC	@ next machine_desc
-	cmp	r5, r6
-	blo	1b
-	mov	r5, #0				@ unknown machine
-2:	mov	pc, lr
-ENDPROC(__lookup_machine_type)
-
-/*
- * Look in arch/arm/kernel/arch.[ch] for information about the
- * __arch_info structures.
- */
-	.align	2
-	.type	__lookup_machine_type_data, %object
-__lookup_machine_type_data:
-	.long	.
-	.long	__arch_info_begin
-	.long	__arch_info_end
-	.size	__lookup_machine_type_data, . - __lookup_machine_type_data
 
 /* Determine validity of the r2 atags pointer.  The heuristic requires
  * that the pointer be aligned, in the first 16k of physical RAM and
@@ -107,8 +32,6 @@ __lookup_machine_type_data:
  * of this function may be more lenient with the physical address and
  * may also be able to move the ATAGS block if necessary.
  *
- * r8  = machinfo
- *
  * Returns:
  *  r2 either valid atags pointer, or zero
  *  r5, r6 corrupted
@@ -183,17 +106,6 @@ __mmap_switched_data:
 	.size	__mmap_switched_data, . - __mmap_switched_data
 
 /*
- * This provides a C-API version of __lookup_machine_type
- */
-ENTRY(lookup_machine_type)
-	stmfd	sp!, {r4 - r6, lr}
-	mov	r1, r0
-	bl	__lookup_machine_type
-	mov	r0, r5
-	ldmfd	sp!, {r4 - r6, pc}
-ENDPROC(lookup_machine_type)
-
-/*
  * This provides a C-API version of __lookup_processor_type
  */
 ENTRY(lookup_processor_type)
arch/arm/kernel/head-nommu.S +0 -3
index 814ce1a..6b1e0ad 100644
@@ -44,9 +44,6 @@ ENTRY(stext)
 	bl	__lookup_processor_type		@ r5=procinfo r9=cpuid
 	movs	r10, r5				@ invalid processor (r5=0)?
 	beq	__error_p				@ yes, error 'p'
-	bl	__lookup_machine_type		@ r5=machinfo
-	movs	r8, r5				@ invalid machine (r5=0)?
-	beq	__error_a			@ yes, error 'a'
 
 	adr	lr, BSYM(__after_proc_init)	@ return (PIC) address
  ARM(	add	pc, r10, #PROCINFO_INITFUNC	)
arch/arm/kernel/head.S +2 -7
index 06aed19..084db6c 100644
@@ -87,14 +87,10 @@ ENTRY(stext)
 	movs	r10, r5				@ invalid processor (r5=0)?
  THUMB( it	eq )		@ force fixup-able long branch encoding
 	beq	__error_p			@ yes, error 'p'
-	bl	__lookup_machine_type		@ r5=machinfo
-	movs	r8, r5				@ invalid machine (r5=0)?
- THUMB( it	eq )		@ force fixup-able long branch encoding
-	beq	__error_a			@ yes, error 'a'
 
 	/*
 	 * r1 = machine no, r2 = atags,
-	 * r8 = machinfo, r9 = cpuid, r10 = procinfo
+	 * r9 = cpuid, r10 = procinfo
 	 */
 	bl	__vet_atags
 #ifdef CONFIG_SMP_ON_UP
@@ -108,7 +104,7 @@ ENTRY(stext)
 	/*
 	 * The following calls CPU specific code in a position independent
 	 * manner.  See arch/arm/mm/proc-*.S for details.  r10 = base of
-	 * xxx_proc_info structure selected by __lookup_machine_type
+	 * xxx_proc_info structure selected by __lookup_processor_type
 	 * above.  On return, the CPU will be ready for the MMU to be
 	 * turned on, and r0 will hold the CPU control register value.
 	 */
@@ -127,7 +123,6 @@ ENDPROC(stext)
  * amount which are required to get the kernel running, which
  * generally means mapping in the kernel code.
  *
- * r8  = machinfo
  * r9  = cpuid
  * r10 = procinfo
  *
arch/arm/kernel/setup.c +38 -1
index 7c5499d..eb952a7 100644
@@ -308,7 +308,44 @@ static void __init cacheid_init(void)
  * already provide the required functionality.
  */
 extern struct proc_info_list *lookup_processor_type(unsigned int);
-extern struct machine_desc *lookup_machine_type(unsigned int);
+
+static void __init early_print(const char *str, ...)
+{
+	extern void printascii(const char *);
+	char buf[256];
+	va_list ap;
+
+	va_start(ap, str);
+	vsnprintf(buf, sizeof(buf), str, ap);
+	va_end(ap);
+
+#ifdef CONFIG_DEBUG_LL
+	printascii(buf);
+#endif
+	printk("%s", buf);
+}
+
+static struct machine_desc * __init lookup_machine_type(unsigned int type)
+{
+	extern struct machine_desc __arch_info_begin[], __arch_info_end[];
+	struct machine_desc *p;
+
+	for (p = __arch_info_begin; p < __arch_info_end; p++)
+		if (type == p->nr)
+			return p;
+
+	early_print("\n"
+		"Error: unrecognized/unsupported machine ID (r1 = 0x%08x).\n\n"
+		"Available machine support:\n\nID (hex)\tNAME\n", type);
+
+	for (p = __arch_info_begin; p < __arch_info_end; p++)
+		early_print("%08x\t%s\n", p->nr, p->name);
+
+	early_print("\nPlease check your kernel config and/or bootloader.\n");
+
+	while (true)
+		/* can't use cpu_relax() here as it may require MMU setup */;
+}
 
 static void __init feat_v6_fixup(void)
 {
author Acked-by
#13 lore raw
Quoted 13 lines · Russell King - ARM Linux
Quoted 12 lines · Grant Likely
Quoted 8 lines · Nicolas Pitre
Quoted 3 lines · Grant Likely

Actually it looks like the real problem is that the mmu has been turned on, but the virtual mappings for devices have not yet been established, and so the debug macros aren't using a valid address.

A temporary virtual mapping should be there -- look for addruart in head.S.

Hi Russell and Nicolas,

Quoted 7 lines
Quoted 3 lines

Oops, yes all the early debug stuff works fine. ?Stupid human trick on my end, but I've sorted it out now. ?Thanks for the help. ?I'll have patches to post later today.

I just hacked this up, and on Versatile (real hardware) it produces the below for an invalid r1 value - and of course works for a proper r1 value.

Heh, that look pretty close to identical to what I was just about to send.

I'll send the updated atags patch rebased and retested on top of this one.

g.

Quoted 229 lines

Uncompressing Linux... done, booting the kernel.

Error: unrecognized/unsupported machine ID (r1 = 0x00123456).

Available machine support:

ID (hex) ? ? ? ?NAME
00000183 ? ? ? ?ARM-Versatile PB
0000025e ? ? ? ?ARM-Versatile AB

Please check your kernel config and/or bootloader.

arch/arm/kernel/head-common.S +0 -0
index bbecaac..c84b57d 100644
@@ -25,81 +25,6 @@

?* machine ID for example).
?*/
? ? ? ?__HEAD

arch/arm/kernel/head-common.S +0 -75
-__error_a:
-#ifdef CONFIG_DEBUG_LL
- ? ? ? mov ? ? r4, r1 ? ? ? ? ? ? ? ? ? ? ? ? ?@ preserve machine ID
- ? ? ? adr ? ? r0, str_a1
- ? ? ? bl ? ? ?printascii
- ? ? ? mov ? ? r0, r4
- ? ? ? bl ? ? ?printhex8
- ? ? ? adr ? ? r0, str_a2
- ? ? ? bl ? ? ?printascii
- ? ? ? adr ? ? r3, __lookup_machine_type_data
- ? ? ? ldmia ? r3, {r4, r5, r6} ? ? ? ? ? ? ? ?@ get machine desc list
- ? ? ? sub ? ? r4, r3, r4 ? ? ? ? ? ? ? ? ? ? ?@ get offset between virt&phys
- ? ? ? add ? ? r5, r5, r4 ? ? ? ? ? ? ? ? ? ? ?@ convert virt addresses to
- ? ? ? add ? ? r6, r6, r4 ? ? ? ? ? ? ? ? ? ? ?@ physical address space
-1: ? ? ldr ? ? r0, [r5, #MACHINFO_TYPE] ? ? ? ?@ get machine type
- ? ? ? bl ? ? ?printhex8
- ? ? ? mov ? ? r0, #'\t'
- ? ? ? bl ? ? ?printch
- ? ? ? ldr ? ? r0, [r5, #MACHINFO_NAME] ? ? ? ?@ get machine name
- ? ? ? add ? ? r0, r0, r4
- ? ? ? bl ? ? ?printascii
- ? ? ? mov ? ? r0, #'\n'
- ? ? ? bl ? ? ?printch
- ? ? ? add ? ? r5, r5, #SIZEOF_MACHINE_DESC ? ?@ next machine_desc
- ? ? ? cmp ? ? r5, r6
- ? ? ? blo ? ? 1b
- ? ? ? adr ? ? r0, str_a3
- ? ? ? bl ? ? ?printascii
- ? ? ? b ? ? ? __error
-ENDPROC(__error_a)
-
-str_a1: ? ? ? ?.asciz ?"\nError: unrecognized/unsupported machine ID (r1 = 0x"
-str_a2: ? ? ? ?.asciz ?").\n\nAvailable machine support:\n\nID (hex)\tNAME\n"
-str_a3: ? ? ? ?.asciz ?"\nPlease check your kernel config and/or bootloader.\n"
- ? ? ? .align
-#endif
-
-/*
- * Lookup machine architecture in the linker-build list of architectures.
- * Note that we can't use the absolute addresses for the __arch_info
- * lists since we aren't running with the MMU on (and therefore, we are
- * not in the correct address space). ?We have to calculate the offset.
- *
- * ?r1 = machine architecture number
- * Returns:
- * ?r3, r4, r6 corrupted
- * ?r5 = mach_info pointer in physical address space
- */
-__lookup_machine_type:
- ? ? ? adr ? ? r3, __lookup_machine_type_data
- ? ? ? ldmia ? r3, {r4, r5, r6}
- ? ? ? sub ? ? r3, r3, r4 ? ? ? ? ? ? ? ? ? ? ?@ get offset between virt&phys
- ? ? ? add ? ? r5, r5, r3 ? ? ? ? ? ? ? ? ? ? ?@ convert virt addresses to
- ? ? ? add ? ? r6, r6, r3 ? ? ? ? ? ? ? ? ? ? ?@ physical address space
-1: ? ? ldr ? ? r3, [r5, #MACHINFO_TYPE] ? ? ? ?@ get machine type
- ? ? ? teq ? ? r3, r1 ? ? ? ? ? ? ? ? ? ? ? ? ?@ matches loader number?
- ? ? ? beq ? ? 2f ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?@ found
- ? ? ? add ? ? r5, r5, #SIZEOF_MACHINE_DESC ? ?@ next machine_desc
- ? ? ? cmp ? ? r5, r6
- ? ? ? blo ? ? 1b
- ? ? ? mov ? ? r5, #0 ? ? ? ? ? ? ? ? ? ? ? ? ?@ unknown machine
-2: ? ? mov ? ? pc, lr
-ENDPROC(__lookup_machine_type)
-
-/*
- * Look in arch/arm/kernel/arch.[ch] for information about the
- * __arch_info structures.
- */
- ? ? ? .align ?2
- ? ? ? .type ? __lookup_machine_type_data, %object
-__lookup_machine_type_data:
- ? ? ? .long ? .
- ? ? ? .long ? __arch_info_begin
- ? ? ? .long ? __arch_info_end
- ? ? ? .size ? __lookup_machine_type_data, . - __lookup_machine_type_data

?/* Determine validity of the r2 atags pointer. ?The heuristic requires ?* that the pointer be aligned, in the first 16k of physical RAM and

arch/arm/kernel/head-common.S +0 -0
@@ -107,8 +32,6 @@ __lookup_machine_type_data:

?* of this function may be more lenient with the physical address and ?* may also be able to move the ATAGS block if necessary. ?*
- * r8 ?= machinfo
- *
?* Returns:
?* ?r2 either valid atags pointer, or zero
?* ?r5, r6 corrupted

arch/arm/kernel/head-common.S +0 -0
@@ -183,17 +106,6 @@ __mmap_switched_data:

? ? ? ?.size ? __mmap_switched_data, . - __mmap_switched_data

?/*
- * This provides a C-API version of __lookup_machine_type
- */

arch/arm/kernel/head-common.S +0 -9
-ENTRY(lookup_machine_type)
- ? ? ? stmfd ? sp!, {r4 - r6, lr}
- ? ? ? mov ? ? r1, r0
- ? ? ? bl ? ? ?__lookup_machine_type
- ? ? ? mov ? ? r0, r5
- ? ? ? ldmfd ? sp!, {r4 - r6, pc}
-ENDPROC(lookup_machine_type)
-
-/*

?* This provides a C-API version of __lookup_processor_type ?*/
?ENTRY(lookup_processor_type)

arch/arm/kernel/head-nommu.S +0 -0
index 814ce1a..6b1e0ad 100644
@@ -44,9 +44,6 @@ ENTRY(stext)

? ? ? ?bl ? ? ?__lookup_processor_type ? ? ? ? @ r5=procinfo r9=cpuid ? ? ? ?movs ? ?r10, r5 ? ? ? ? ? ? ? ? ? ? ? ? @ invalid processor (r5=0)? ? ? ? ?beq ? ? __error_p ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? @ yes, error 'p'
- ? ? ? bl ? ? ?__lookup_machine_type ? ? ? ? ? @ r5=machinfo
- ? ? ? movs ? ?r8, r5 ? ? ? ? ? ? ? ? ? ? ? ? ?@ invalid machine (r5=0)?
- ? ? ? beq ? ? __error_a ? ? ? ? ? ? ? ? ? ? ? @ yes, error 'a'

? ? ? ?adr ? ? lr, BSYM(__after_proc_init) ? ? @ return (PIC) address ?ARM( ?add ? ? pc, r10, #PROCINFO_INITFUNC ? ? )

arch/arm/kernel/head.S +0 -0
index 06aed19..084db6c 100644
@@ -87,14 +87,10 @@ ENTRY(stext)

? ? ? ?movs ? ?r10, r5 ? ? ? ? ? ? ? ? ? ? ? ? @ invalid processor (r5=0)? ?THUMB( it ? ? eq ) ? ? ? ? ? ?@ force fixup-able long branch encoding ? ? ? ?beq ? ? __error_p ? ? ? ? ? ? ? ? ? ? ? @ yes, error 'p'
- ? ? ? bl ? ? ?__lookup_machine_type ? ? ? ? ? @ r5=machinfo
- ? ? ? movs ? ?r8, r5 ? ? ? ? ? ? ? ? ? ? ? ? ?@ invalid machine (r5=0)?
- THUMB( it ? ? eq ) ? ? ? ? ? ?@ force fixup-able long branch encoding
- ? ? ? beq ? ? __error_a ? ? ? ? ? ? ? ? ? ? ? @ yes, error 'a'

? ? ? ?/*
? ? ? ? * r1 = machine no, r2 = atags,
- ? ? ? ?* r8 = machinfo, r9 = cpuid, r10 = procinfo
+ ? ? ? ?* r9 = cpuid, r10 = procinfo
? ? ? ? */
? ? ? ?bl ? ? ?__vet_atags
?#ifdef CONFIG_SMP_ON_UP

arch/arm/kernel/head.S +0 -0
@@ -108,7 +104,7 @@ ENTRY(stext)

? ? ? ?/*
? ? ? ? * The following calls CPU specific code in a position independent ? ? ? ? * manner. ?See arch/arm/mm/proc-*.S for details. ?r10 = base of
- ? ? ? ?* xxx_proc_info structure selected by __lookup_machine_type
+ ? ? ? ?* xxx_proc_info structure selected by __lookup_processor_type ? ? ? ? * above. ?On return, the CPU will be ready for the MMU to be ? ? ? ? * turned on, and r0 will hold the CPU control register value. ? ? ? ? */

arch/arm/kernel/head.S +0 -0
@@ -127,7 +123,6 @@ ENDPROC(stext)

?* amount which are required to get the kernel running, which ?* generally means mapping in the kernel code.
?*
- * r8 ?= machinfo
?* r9 ?= cpuid
?* r10 = procinfo
?*

arch/arm/kernel/setup.c +0 -0
index 7c5499d..eb952a7 100644
@@ -308,7 +308,44 @@ static void __init cacheid_init(void)

?* already provide the required functionality.
?*/
?extern struct proc_info_list *lookup_processor_type(unsigned int);

arch/arm/kernel/setup.c +38 -1
-extern struct machine_desc *lookup_machine_type(unsigned int);
+
+static void __init early_print(const char *str, ...)
+{
+ ? ? ? extern void printascii(const char *);
+ ? ? ? char buf[256];
+ ? ? ? va_list ap;
+
+ ? ? ? va_start(ap, str);
+ ? ? ? vsnprintf(buf, sizeof(buf), str, ap);
+ ? ? ? va_end(ap);
+
+#ifdef CONFIG_DEBUG_LL
+ ? ? ? printascii(buf);
+#endif
+ ? ? ? printk("%s", buf);
+}
+
+static struct machine_desc * __init lookup_machine_type(unsigned int type)
+{
+ ? ? ? extern struct machine_desc __arch_info_begin[], __arch_info_end[];
+ ? ? ? struct machine_desc *p;
+
+ ? ? ? for (p = __arch_info_begin; p < __arch_info_end; p++)
+ ? ? ? ? ? ? ? if (type == p->nr)
+ ? ? ? ? ? ? ? ? ? ? ? return p;
+
+ ? ? ? early_print("\n"
+ ? ? ? ? ? ? ? "Error: unrecognized/unsupported machine ID (r1 = 0x%08x).\n\n"
+ ? ? ? ? ? ? ? "Available machine support:\n\nID (hex)\tNAME\n", type);
+
+ ? ? ? for (p = __arch_info_begin; p < __arch_info_end; p++)
+ ? ? ? ? ? ? ? early_print("%08x\t%s\n", p->nr, p->name);
+
+ ? ? ? early_print("\nPlease check your kernel config and/or bootloader.\n");
+
+ ? ? ? while (true)
+ ? ? ? ? ? ? ? /* can't use cpu_relax() here as it may require MMU setup */;
+}

?static void __init feat_v6_fixup(void)
?{

Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
Tested-by
#14 lore raw
Quoted 19 lines · Grant Likely
Quoted 17 lines · Russell King - ARM Linux
Quoted 15 lines · Grant Likely
Quoted 8 lines · Nicolas Pitre
Quoted 3 lines · Grant Likely

Actually it looks like the real problem is that the mmu has been turned on, but the virtual mappings for devices have not yet been established, and so the debug macros aren't using a valid address.

A temporary virtual mapping should be there -- look for addruart in head.S.

Hi Russell and Nicolas,

Oops, yes all the early debug stuff works fine. ?Stupid human trick on my end, but I've sorted it out now. ?Thanks for the help. ?I'll have patches to post later today.

Quoted 7 lines
Quoted 3 lines

I just hacked this up, and on Versatile (real hardware) it produces the below for an invalid r1 value - and of course works for a proper r1 value.

Heh, that look pretty close to identical to what I was just about to send.