Skip to contentSkip to conversation

Early debug UART not working on AM33XX SoC

DISCUSSION Felix Brack 2 participants 10 messages Jan 26, 2022 – Feb 1, 2022

lore
Share & tools
lore
#0 lore raw

Hello Simon,

I am trying to get the current U-Boot master working on the PDU001 board. This involves the use of an early debug UART.

With commit 0dba4586 (arm: Init the debug UART) the early debug UART on the AM33XX SoC doesn't work anymore.

By looking at the code involved I believe a call to setup_clocks_for_console() implemented in clock_am33xx.c before the call to debug_uart_init() is missing. This is also what happens prior to commit 0dba4586 by a call to early_system_init() which in turn calls setup_early_clocks() which then calls setup_clocks_for_console().

My quick and dirty fix consist of inserting a call in crt0.S to setup_clocks_for_console() just before the call to debug_uart_init() which was added in commit 0dba4586. I have guarded this call with #if/#endif testing for CONFIG_AM33XX. The code sequence in crt0.S now looks like this:

#if defined(CONFIG_DEBUG_UART) && CONFIG_IS_ENABLED(SERIAL)
#if defined(CONFIG_AM33XX)
bl setup_clocks_for_console
#endif
bl debug_uart_init
#endif

However, from what I understand the crt0.S is for _all_ ARM boards hence it's probably a bad idea polluting it with such #if/#endif tests for different SoCs. What do you think?

If my quick and dirty fix is not that dirty I would be happy to send a patch which would also include the removal of the currently remaining call to debug_uart_init() in am33xx/board.c

Please apologize my narrow view of the matter dealing only with AM33XX SoCs.

Signature · 1 line
Felix
#1 lore raw

Hi Felix,

Quoted 32 lines · Felix Brack

Hello Simon,

I am trying to get the current U-Boot master working on the PDU001 board. This involves the use of an early debug UART.

With commit 0dba4586 (arm: Init the debug UART) the early debug UART on the AM33XX SoC doesn't work anymore.

By looking at the code involved I believe a call to setup_clocks_for_console() implemented in clock_am33xx.c before the call to debug_uart_init() is missing. This is also what happens prior to commit 0dba4586 by a call to early_system_init() which in turn calls setup_early_clocks() which then calls setup_clocks_for_console().

My quick and dirty fix consist of inserting a call in crt0.S to setup_clocks_for_console() just before the call to debug_uart_init() which was added in commit 0dba4586. I have guarded this call with #if/#endif testing for CONFIG_AM33XX. The code sequence in crt0.S now looks like this:

#if defined(CONFIG_DEBUG_UART) && CONFIG_IS_ENABLED(SERIAL)
#if defined(CONFIG_AM33XX)
bl setup_clocks_for_console
#endif
bl debug_uart_init
#endif

However, from what I understand the crt0.S is for _all_ ARM boards hence it's probably a bad idea polluting it with such #if/#endif tests for different SoCs. What do you think?

Quoted 5 lines

If my quick and dirty fix is not that dirty I would be happy to send a patch which would also include the removal of the currently remaining call to debug_uart_init() in am33xx/board.c

Please apologize my narrow view of the matter dealing only with AM33XX SoCs.

Are you able to put that call into board_debug_uart_init() and enable CONFIG_DEBUG_UART_BOARD_INIT ?

Regards,
Simon

#2 lore raw

Hello Simon,

Quoted 35 lines · Simon Glass

Hi Felix,

Quoted 32 lines · Felix Brack

Hello Simon,

I am trying to get the current U-Boot master working on the PDU001 board. This involves the use of an early debug UART.

With commit 0dba4586 (arm: Init the debug UART) the early debug UART on the AM33XX SoC doesn't work anymore.

By looking at the code involved I believe a call to setup_clocks_for_console() implemented in clock_am33xx.c before the call to debug_uart_init() is missing. This is also what happens prior to commit 0dba4586 by a call to early_system_init() which in turn calls setup_early_clocks() which then calls setup_clocks_for_console().

My quick and dirty fix consist of inserting a call in crt0.S to setup_clocks_for_console() just before the call to debug_uart_init() which was added in commit 0dba4586. I have guarded this call with #if/#endif testing for CONFIG_AM33XX. The code sequence in crt0.S now looks like this:

#if defined(CONFIG_DEBUG_UART) && CONFIG_IS_ENABLED(SERIAL)
#if defined(CONFIG_AM33XX)
bl setup_clocks_for_console
#endif
bl debug_uart_init
#endif

However, from what I understand the crt0.S is for _all_ ARM boards hence it's probably a bad idea polluting it with such #if/#endif tests for different SoCs. What do you think?

Quoted 9 lines
Quoted 5 lines

If my quick and dirty fix is not that dirty I would be happy to send a patch which would also include the removal of the currently remaining call to debug_uart_init() in am33xx/board.c

Please apologize my narrow view of the matter dealing only with AM33XX SoCs.

Are you able to put that call into board_debug_uart_init() and enable CONFIG_DEBUG_UART_BOARD_INIT ?

Sure I can but there two drawbacks:
1. this fixes the problem only for my board, others might remain broken
2. the now redundant call to setup_early_clocks() in am33xx/board.c remains (at least it does not seem to hurt ;-))

I will prepare a patch with a modified board_debug_uart_init() for the PDU001 board then.

Signature · 1 line
Many thanks for your help and kind regards, Felix
#3 lore raw

Hi Felix,

Quoted 43 lines · Felix Brack

Hello Simon,

Quoted 39 lines · Simon Glass

Hi Felix,

Quoted 36 lines · Felix Brack

Hello Simon,

I am trying to get the current U-Boot master working on the PDU001 board. This involves the use of an early debug UART.

With commit 0dba4586 (arm: Init the debug UART) the early debug UART on the AM33XX SoC doesn't work anymore.

By looking at the code involved I believe a call to setup_clocks_for_console() implemented in clock_am33xx.c before the call to debug_uart_init() is missing. This is also what happens prior to commit 0dba4586 by a call to early_system_init() which in turn calls setup_early_clocks() which then calls setup_clocks_for_console().

My quick and dirty fix consist of inserting a call in crt0.S to setup_clocks_for_console() just before the call to debug_uart_init() which was added in commit 0dba4586. I have guarded this call with #if/#endif testing for CONFIG_AM33XX. The code sequence in crt0.S now looks like this:

#if defined(CONFIG_DEBUG_UART) && CONFIG_IS_ENABLED(SERIAL)
#if defined(CONFIG_AM33XX)
bl setup_clocks_for_console
#endif
bl debug_uart_init
#endif

However, from what I understand the crt0.S is for _all_ ARM boards hence it's probably a bad idea polluting it with such #if/#endif tests for different SoCs. What do you think?

If my quick and dirty fix is not that dirty I would be happy to send a patch which would also include the removal of the currently remaining call to debug_uart_init() in am33xx/board.c

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Please apologize my narrow view of the matter dealing only with AM33XX SoCs.

Are you able to put that call into board_debug_uart_init() and enable CONFIG_DEBUG_UART_BOARD_INIT ?

Sure I can but there two drawbacks:
1. this fixes the problem only for my board, others might remain broken

I suggest you make the function common to all boards that need it.

Quoted 2 lines

2. the now redundant call to setup_early_clocks() in am33xx/board.c remains (at least it does not seem to hurt ;-))

Yes, it is possible to use flags to avoid that, but might not be worth it.

Quoted 7 lines

I will prepare a patch with a modified board_debug_uart_init() for the PDU001 board then.

--
Many thanks for your help and kind regards, Felix

Regards,
Simon

#4 lore raw

Hello Simon

Quoted 48 lines · Simon Glass

Hi Felix,

Quoted 45 lines · Felix Brack

Hello Simon,

Quoted 41 lines · Simon Glass

Hi Felix,

Quoted 37 lines · Felix Brack

Hello Simon,

I am trying to get the current U-Boot master working on the PDU001 board. This involves the use of an early debug UART.

With commit 0dba4586 (arm: Init the debug UART) the early debug UART on the AM33XX SoC doesn't work anymore.

By looking at the code involved I believe a call to setup_clocks_for_console() implemented in clock_am33xx.c before the call to debug_uart_init() is missing. This is also what happens prior to commit 0dba4586 by a call to early_system_init() which in turn calls setup_early_clocks() which then calls setup_clocks_for_console().

My quick and dirty fix consist of inserting a call in crt0.S to setup_clocks_for_console() just before the call to debug_uart_init() which was added in commit 0dba4586. I have guarded this call with #if/#endif testing for CONFIG_AM33XX. The code sequence in crt0.S now looks like this:

#if defined(CONFIG_DEBUG_UART) && CONFIG_IS_ENABLED(SERIAL)
#if defined(CONFIG_AM33XX)
bl setup_clocks_for_console
#endif
bl debug_uart_init
#endif

However, from what I understand the crt0.S is for _all_ ARM boards hence it's probably a bad idea polluting it with such #if/#endif tests for different SoCs. What do you think?

If my quick and dirty fix is not that dirty I would be happy to send a patch which would also include the removal of the currently remaining call to debug_uart_init() in am33xx/board.c

Please apologize my narrow view of the matter dealing only with AM33XX SoCs.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Are you able to put that call into board_debug_uart_init() and enable CONFIG_DEBUG_UART_BOARD_INIT ?

Sure I can but there two drawbacks:
1. this fixes the problem only for my board, others might remain broken

I suggest you make the function common to all boards that need it.

I will check that. Maybe the board_debug_uart_init() is not the right place then as it is board specific. Probably better to have a AM33XX platform specific function.

Having said that there is still something I don't understand: commit 0dba4586 has added a call to debug_uart_init() in crt0.S but not removed any existing call to debug_uart_init(). Hence this function is called twice. Is this intentional (and if so, why ?) or are the remaining calls some sort of leftovers?

Quoted 15 lines
Quoted 2 lines

2. the now redundant call to setup_early_clocks() in am33xx/board.c remains (at least it does not seem to hurt ;-))

Yes, it is possible to use flags to avoid that, but might not be worth it.

Quoted 7 lines

I will prepare a patch with a modified board_debug_uart_init() for the PDU001 board then.

--
Many thanks for your help and kind regards, Felix

Regards,
Simon

Signature · 1 line
Regards, Felix
#5 lore raw

Hi Felix,

Quoted 55 lines · Felix Brack

Hello Simon

Quoted 51 lines · Simon Glass

Hi Felix,

Quoted 48 lines · Felix Brack

Hello Simon,

Quoted 44 lines · Simon Glass

Hi Felix,

Quoted 32 lines · Felix Brack

Hello Simon,

I am trying to get the current U-Boot master working on the PDU001 board. This involves the use of an early debug UART.

With commit 0dba4586 (arm: Init the debug UART) the early debug UART on the AM33XX SoC doesn't work anymore.

By looking at the code involved I believe a call to setup_clocks_for_console() implemented in clock_am33xx.c before the call to debug_uart_init() is missing. This is also what happens prior to commit 0dba4586 by a call to early_system_init() which in turn calls setup_early_clocks() which then calls setup_clocks_for_console().

My quick and dirty fix consist of inserting a call in crt0.S to setup_clocks_for_console() just before the call to debug_uart_init() which was added in commit 0dba4586. I have guarded this call with #if/#endif testing for CONFIG_AM33XX. The code sequence in crt0.S now looks like this:

#if defined(CONFIG_DEBUG_UART) && CONFIG_IS_ENABLED(SERIAL)
#if defined(CONFIG_AM33XX)
bl setup_clocks_for_console
#endif
bl debug_uart_init
#endif

However, from what I understand the crt0.S is for _all_ ARM boards hence it's probably a bad idea polluting it with such #if/#endif tests for different SoCs. What do you think?

Quoted 5 lines

If my quick and dirty fix is not that dirty I would be happy to send a patch which would also include the removal of the currently remaining call to debug_uart_init() in am33xx/board.c

Please apologize my narrow view of the matter dealing only with AM33XX SoCs.

Are you able to put that call into board_debug_uart_init() and enable CONFIG_DEBUG_UART_BOARD_INIT ?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Sure I can but there two drawbacks:
1. this fixes the problem only for my board, others might remain broken

I suggest you make the function common to all boards that need it.

I will check that. Maybe the board_debug_uart_init() is not the right place then as it is board specific. Probably better to have a AM33XX platform specific function.

Despite the board_ prefix you can define it in an SoC file, for example. It may not always be board-specific.

Quoted 6 lines

Having said that there is still something I don't understand: commit 0dba4586 has added a call to debug_uart_init() in crt0.S but not removed any existing call to debug_uart_init(). Hence this function is called twice. Is this intentional (and if so, why ?) or are the remaining calls some sort of leftovers?

Just that I was not confident removing it from the various affected boards since some have the same problem as you found with yours. Calling it twice is generally fine.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

2. the now redundant call to setup_early_clocks() in am33xx/board.c remains (at least it does not seem to hurt ;-))

Quoted 8 lines
Quoted 8 lines

Yes, it is possible to use flags to avoid that, but might not be worth it.

Quoted 6 lines

I will prepare a patch with a modified board_debug_uart_init() for the PDU001 board then.

--
Many thanks for your help and kind regards, Felix

Regards,
Simon

#6 lore raw

Hello Simon,

Quoted 61 lines · Simon Glass

Hi Felix,

Quoted 58 lines · Felix Brack

Hello Simon

Quoted 54 lines · Simon Glass

Hi Felix,

Quoted 50 lines · Felix Brack

Hello Simon,

Quoted 35 lines · Simon Glass

Hi Felix,

Quoted 32 lines · Felix Brack

Hello Simon,

I am trying to get the current U-Boot master working on the PDU001 board. This involves the use of an early debug UART.

With commit 0dba4586 (arm: Init the debug UART) the early debug UART on the AM33XX SoC doesn't work anymore.

By looking at the code involved I believe a call to setup_clocks_for_console() implemented in clock_am33xx.c before the call to debug_uart_init() is missing. This is also what happens prior to commit 0dba4586 by a call to early_system_init() which in turn calls setup_early_clocks() which then calls setup_clocks_for_console().

My quick and dirty fix consist of inserting a call in crt0.S to setup_clocks_for_console() just before the call to debug_uart_init() which was added in commit 0dba4586. I have guarded this call with #if/#endif testing for CONFIG_AM33XX. The code sequence in crt0.S now looks like this:

#if defined(CONFIG_DEBUG_UART) && CONFIG_IS_ENABLED(SERIAL)
#if defined(CONFIG_AM33XX)
bl setup_clocks_for_console
#endif
bl debug_uart_init
#endif

However, from what I understand the crt0.S is for _all_ ARM boards hence it's probably a bad idea polluting it with such #if/#endif tests for different SoCs. What do you think?

Quoted 9 lines
Quoted 5 lines

If my quick and dirty fix is not that dirty I would be happy to send a patch which would also include the removal of the currently remaining call to debug_uart_init() in am33xx/board.c

Please apologize my narrow view of the matter dealing only with AM33XX SoCs.

Are you able to put that call into board_debug_uart_init() and enable CONFIG_DEBUG_UART_BOARD_INIT ?

Sure I can but there two drawbacks:
1. this fixes the problem only for my board, others might remain broken

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

I suggest you make the function common to all boards that need it.

I will check that. Maybe the board_debug_uart_init() is not the right place then as it is board specific. Probably better to have a AM33XX platform specific function.

Despite the board_ prefix you can define it in an SoC file, for example. It may not always be board-specific.

Thanks for the hint! In fact I was not aware of that. However for the PDU001 board board_debug_uart_init() must remain with the board as it (also) configures the pin multiplexer which is specific to the PDU001 board.

For the patch to be useful for other boards too, I think a platform specific function is required. A weak function named something like platform_debug_uart_init(). This function could then be implemented in the platform specific board.c file, in my case the one for AM33XX.

But where to place the default, empty implementation? In the common file board_init.c probably?

Frankly I don't feel really comfortable with my own proposal above. It sounds a little bit like patchwork to me. On the other hand I don't see a better solution given the fact that it should solve not just my problem. Should I use it as foundation for sending a patch anyway?

Quoted 11 lines
Quoted 6 lines

Having said that there is still something I don't understand: commit 0dba4586 has added a call to debug_uart_init() in crt0.S but not removed any existing call to debug_uart_init(). Hence this function is called twice. Is this intentional (and if so, why ?) or are the remaining calls some sort of leftovers?

Just that I was not confident removing it from the various affected boards since some have the same problem as you found with yours. Calling it twice is generally fine.

Agreed. It is just a little bit confusing especially with DEBUG_UART_ANNOUNCE enabled.

Quoted 16 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

2. the now redundant call to setup_early_clocks() in am33xx/board.c remains (at least it does not seem to hurt ;-))

Quoted 8 lines
Quoted 8 lines

Yes, it is possible to use flags to avoid that, but might not be worth it.

Quoted 6 lines

I will prepare a patch with a modified board_debug_uart_init() for the PDU001 board then.

--
Many thanks for your help and kind regards, Felix

Regards,
Simon

Signature · 1 line
Regards, Felix
#7 lore raw

Hi Felix,

Quoted 74 lines · Felix Brack

Hello Simon,

Quoted 61 lines · Simon Glass

Hi Felix,

Quoted 58 lines · Felix Brack

Hello Simon

Quoted 54 lines · Simon Glass

Hi Felix,

Quoted 50 lines · Felix Brack

Hello Simon,

Quoted 35 lines · Simon Glass

Hi Felix,

Quoted 32 lines · Felix Brack

Hello Simon,

I am trying to get the current U-Boot master working on the PDU001 board. This involves the use of an early debug UART.

With commit 0dba4586 (arm: Init the debug UART) the early debug UART on the AM33XX SoC doesn't work anymore.

By looking at the code involved I believe a call to setup_clocks_for_console() implemented in clock_am33xx.c before the call to debug_uart_init() is missing. This is also what happens prior to commit 0dba4586 by a call to early_system_init() which in turn calls setup_early_clocks() which then calls setup_clocks_for_console().

My quick and dirty fix consist of inserting a call in crt0.S to setup_clocks_for_console() just before the call to debug_uart_init() which was added in commit 0dba4586. I have guarded this call with #if/#endif testing for CONFIG_AM33XX. The code sequence in crt0.S now looks like this:

#if defined(CONFIG_DEBUG_UART) && CONFIG_IS_ENABLED(SERIAL)
#if defined(CONFIG_AM33XX)
bl setup_clocks_for_console
#endif
bl debug_uart_init
#endif

However, from what I understand the crt0.S is for _all_ ARM boards hence it's probably a bad idea polluting it with such #if/#endif tests for different SoCs. What do you think?

Quoted 9 lines
Quoted 5 lines

If my quick and dirty fix is not that dirty I would be happy to send a patch which would also include the removal of the currently remaining call to debug_uart_init() in am33xx/board.c

Please apologize my narrow view of the matter dealing only with AM33XX SoCs.

Are you able to put that call into board_debug_uart_init() and enable CONFIG_DEBUG_UART_BOARD_INIT ?

Sure I can but there two drawbacks:
1. this fixes the problem only for my board, others might remain broken

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

I suggest you make the function common to all boards that need it.

I will check that. Maybe the board_debug_uart_init() is not the right place then as it is board specific. Probably better to have a AM33XX platform specific function.

Despite the board_ prefix you can define it in an SoC file, for example. It may not always be board-specific.

Quoted 8 lines

Thanks for the hint! In fact I was not aware of that. However for the PDU001 board board_debug_uart_init() must remain with the board as it (also) configures the pin multiplexer which is specific to the PDU001 board.

For the patch to be useful for other boards too, I think a platform specific function is required. A weak function named something like platform_debug_uart_init(). This function could then be implemented in the platform specific board.c file, in my case the one for AM33XX.

Would it be OK to create a non-weak function that is called from board_debug_uart_init()?

But yes we could create another function. How about soc_debug_uart_init() as a name, though?

Quoted 3 lines

But where to place the default, empty implementation? In the common file board_init.c probably?

At present we have a CONFIG option to enable board_debug_uart_init() so we could do the same for soc. But should it run first or second? That is why I feel that doing everything from board_debug_uart_init() might be better.

Quoted 13 lines

Frankly I don't feel really comfortable with my own proposal above. It sounds a little bit like patchwork to me. On the other hand I don't see a better solution given the fact that it should solve not just my problem. Should I use it as foundation for sending a patch anyway?

Quoted 7 lines
Quoted 6 lines

Having said that there is still something I don't understand: commit 0dba4586 has added a call to debug_uart_init() in crt0.S but not removed any existing call to debug_uart_init(). Hence this function is called twice. Is this intentional (and if so, why ?) or are the remaining calls some sort of leftovers?

Quoted 6 lines
Quoted 4 lines

Just that I was not confident removing it from the various affected boards since some have the same problem as you found with yours. Calling it twice is generally fine.

Agreed. It is just a little bit confusing especially with DEBUG_UART_ANNOUNCE enabled.

I will do a patch to remove them and see what happens.

Regards,
Simon

#8 lore raw

Hello Simon,

Quoted 81 lines · Simon Glass

Hi Felix,

Quoted 78 lines · Felix Brack

Hello Simon,

Quoted 61 lines · Simon Glass

Hi Felix,

Quoted 58 lines · Felix Brack

Hello Simon

Quoted 54 lines · Simon Glass

Hi Felix,

Quoted 50 lines · Felix Brack

Hello Simon,

Quoted 35 lines · Simon Glass

Hi Felix,

Quoted 32 lines · Felix Brack

Hello Simon,

I am trying to get the current U-Boot master working on the PDU001 board. This involves the use of an early debug UART.

With commit 0dba4586 (arm: Init the debug UART) the early debug UART on the AM33XX SoC doesn't work anymore.

By looking at the code involved I believe a call to setup_clocks_for_console() implemented in clock_am33xx.c before the call to debug_uart_init() is missing. This is also what happens prior to commit 0dba4586 by a call to early_system_init() which in turn calls setup_early_clocks() which then calls setup_clocks_for_console().

My quick and dirty fix consist of inserting a call in crt0.S to setup_clocks_for_console() just before the call to debug_uart_init() which was added in commit 0dba4586. I have guarded this call with #if/#endif testing for CONFIG_AM33XX. The code sequence in crt0.S now looks like this:

#if defined(CONFIG_DEBUG_UART) && CONFIG_IS_ENABLED(SERIAL)
#if defined(CONFIG_AM33XX)
bl setup_clocks_for_console
#endif
bl debug_uart_init
#endif

However, from what I understand the crt0.S is for _all_ ARM boards hence it's probably a bad idea polluting it with such #if/#endif tests for different SoCs. What do you think?

Quoted 9 lines
Quoted 5 lines

If my quick and dirty fix is not that dirty I would be happy to send a patch which would also include the removal of the currently remaining call to debug_uart_init() in am33xx/board.c

Please apologize my narrow view of the matter dealing only with AM33XX SoCs.

Are you able to put that call into board_debug_uart_init() and enable CONFIG_DEBUG_UART_BOARD_INIT ?

Sure I can but there two drawbacks:
1. this fixes the problem only for my board, others might remain broken

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

I suggest you make the function common to all boards that need it.

I will check that. Maybe the board_debug_uart_init() is not the right place then as it is board specific. Probably better to have a AM33XX platform specific function.

Despite the board_ prefix you can define it in an SoC file, for example. It may not always be board-specific.

Thanks for the hint! In fact I was not aware of that. However for the PDU001 board board_debug_uart_init() must remain with the board as it (also) configures the pin multiplexer which is specific to the PDU001 board.

Quoted 8 lines
Quoted 4 lines

For the patch to be useful for other boards too, I think a platform specific function is required. A weak function named something like platform_debug_uart_init(). This function could then be implemented in the platform specific board.c file, in my case the one for AM33XX.

Would it be OK to create a non-weak function that is called from board_debug_uart_init()?

From what I understand board_debug_uart_init() is (and should remain) a board specific function. Looking at the boards enabling CONFIG_AM33XX I believe mine is currently the only one using board_debug_uart_init(). Hence all other boards enabling CONFIG_AM33XX would have to add a similar board_debug_uart_init() function to get fixed. In fact all ARM boards would probably have to do so.
I think "board" is the wrong "level" to fix this, "SoC or platform" is the better "level".
By the way: my quick and dirt fix does exactly that. It adds a call to setup_clocks_for_console() in my board's board_debug_uart_init(). So for me that would be fine.

Quoted 3 lines

But yes we could create another function. How about soc_debug_uart_init() as a name, though?

Agreed. It is probably better to use soc_ instead of platform_. The idea behind using a weak function is as follows: it allows placing the call to the new function soc_debug_uart_init() in the generic debug_uart_init() function found in debug_uart.h, just before the existing call to board_debug_uart_init(). This would make it available to everybody.

Quoted 6 lines
Quoted 3 lines

But where to place the default, empty implementation? In the common file board_init.c probably?

At present we have a CONFIG option to enable board_debug_uart_init() so we could do the same for soc. But should it run first or second?

Yes using CONFIG options is of course possible too. But then my idea of placing it into the generic debug_uart_init() function is bad. From my point of view such a new function should be called first. I would justify that decision with the idea of the more generic things (related to the SoC/platform) to be done before the more specific things (related to the board). But that could just as well be inverted by somebody having a different point of view.

Quoted 3 lines

That is why I feel that doing everything from board_debug_uart_init() might be better.

Absolutely, as proven by my quick and (probably not so) dirty fix described above. But this is then best left to the individual ARM board maintainers. I only know how to fix this for AM33XX boards. I don't even know if it is a problem on none AM33XX boards at all.

Quoted 24 lines
Quoted 13 lines

Frankly I don't feel really comfortable with my own proposal above. It sounds a little bit like patchwork to me. On the other hand I don't see a better solution given the fact that it should solve not just my problem. Should I use it as foundation for sending a patch anyway?

Quoted 7 lines
Quoted 6 lines

Having said that there is still something I don't understand: commit 0dba4586 has added a call to debug_uart_init() in crt0.S but not removed any existing call to debug_uart_init(). Hence this function is called twice. Is this intentional (and if so, why ?) or are the remaining calls some sort of leftovers?

Quoted 6 lines
Quoted 4 lines

Just that I was not confident removing it from the various affected boards since some have the same problem as you found with yours. Calling it twice is generally fine.

Agreed. It is just a little bit confusing especially with DEBUG_UART_ANNOUNCE enabled.

I will do a patch to remove them and see what happens.

Regards,
Simon

Signature · 1 line
Regards, Felix
#9 lore raw
In reply to Simon Glass

Hello Simon

Quoted 114 lines · Simon Glass

Hi Felix,

Quoted 74 lines · Felix Brack

Hello Simon,

Quoted 61 lines · Simon Glass

Hi Felix,

Quoted 58 lines · Felix Brack

Hello Simon

Quoted 54 lines · Simon Glass

Hi Felix,

Quoted 50 lines · Felix Brack

Hello Simon,

Quoted 35 lines · Simon Glass

Hi Felix,

Quoted 32 lines · Felix Brack

Hello Simon,

I am trying to get the current U-Boot master working on the PDU001 board. This involves the use of an early debug UART.

With commit 0dba4586 (arm: Init the debug UART) the early debug UART on the AM33XX SoC doesn't work anymore.

By looking at the code involved I believe a call to setup_clocks_for_console() implemented in clock_am33xx.c before the call to debug_uart_init() is missing. This is also what happens prior to commit 0dba4586 by a call to early_system_init() which in turn calls setup_early_clocks() which then calls setup_clocks_for_console().

My quick and dirty fix consist of inserting a call in crt0.S to setup_clocks_for_console() just before the call to debug_uart_init() which was added in commit 0dba4586. I have guarded this call with #if/#endif testing for CONFIG_AM33XX. The code sequence in crt0.S now looks like this:

#if defined(CONFIG_DEBUG_UART) && CONFIG_IS_ENABLED(SERIAL)
#if defined(CONFIG_AM33XX)
bl setup_clocks_for_console
#endif
bl debug_uart_init
#endif

However, from what I understand the crt0.S is for _all_ ARM boards hence it's probably a bad idea polluting it with such #if/#endif tests for different SoCs. What do you think?

Quoted 9 lines
Quoted 5 lines

If my quick and dirty fix is not that dirty I would be happy to send a patch which would also include the removal of the currently remaining call to debug_uart_init() in am33xx/board.c

Please apologize my narrow view of the matter dealing only with AM33XX SoCs.

Are you able to put that call into board_debug_uart_init() and enable CONFIG_DEBUG_UART_BOARD_INIT ?

Sure I can but there two drawbacks:
1. this fixes the problem only for my board, others might remain broken

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

I suggest you make the function common to all boards that need it.

I will check that. Maybe the board_debug_uart_init() is not the right place then as it is board specific. Probably better to have a AM33XX platform specific function.

Despite the board_ prefix you can define it in an SoC file, for example. It may not always be board-specific.

Quoted 8 lines

Thanks for the hint! In fact I was not aware of that. However for the PDU001 board board_debug_uart_init() must remain with the board as it (also) configures the pin multiplexer which is specific to the PDU001 board.

For the patch to be useful for other boards too, I think a platform specific function is required. A weak function named something like platform_debug_uart_init(). This function could then be implemented in the platform specific board.c file, in my case the one for AM33XX.

Would it be OK to create a non-weak function that is called from board_debug_uart_init()?

But yes we could create another function. How about soc_debug_uart_init() as a name, though?

Quoted 3 lines

But where to place the default, empty implementation? In the common file board_init.c probably?

At present we have a CONFIG option to enable board_debug_uart_init() so we could do the same for soc. But should it run first or second? That is why I feel that doing everything from board_debug_uart_init() might be better.

Quoted 13 lines

Frankly I don't feel really comfortable with my own proposal above. It sounds a little bit like patchwork to me. On the other hand I don't see a better solution given the fact that it should solve not just my problem. Should I use it as foundation for sending a patch anyway?

Quoted 7 lines
Quoted 6 lines

Having said that there is still something I don't understand: commit 0dba4586 has added a call to debug_uart_init() in crt0.S but not removed any existing call to debug_uart_init(). Hence this function is called twice. Is this intentional (and if so, why ?) or are the remaining calls some sort of leftovers?

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Just that I was not confident removing it from the various affected boards since some have the same problem as you found with yours. Calling it twice is generally fine.

Agreed. It is just a little bit confusing especially with DEBUG_UART_ANNOUNCE enabled.

I will do a patch to remove them and see what happens.

Great! I can't imagine that this should provoke any additional problems.

Quoted 3 lines

Regards,
Simon

Signature · 1 line
Regards, Felix