Jump to content

U-Boot porting: Difference between revisions

From postmarketOS Wiki
Dsankouski (talk | contribs)
Dsankouski (talk | contribs)
Line 26: Line 26:
== Getting uart debug output ==
== Getting uart debug output ==
{{todo|add raw c and assemble examples. Also config options for debug_uart.h What init code to comment out}}
{{todo|add raw c and assemble examples. Also config options for debug_uart.h What init code to comment out}}
You can get debug output from particular *.c file by adding  
You can get debug output from particular *.c file by adding <code>#define DEBUG</code> at the top of file, and calling <code>debug("debug output");</code> where you need.
#define DEBUG
 
at the top of file, and calling  
debug("debug output");  
where you need.
== Finding base address ==
== Finding base address ==
{{todo|How to dump PC register on ARM, to know RAM range to dump}}
{{todo|How to dump PC register on ARM, to know RAM range to dump}}

Revision as of 19:21, 7 October 2020

It is possible to port u-boot on your phone, even if there is no SOC support in uboot tree (because stock bootloader initialized hardware for us). First thing to focus on should be getting u-boot shell prompt.

Preparation

  1. Find uboot code
  2. Before starting uboot porting, you should get access to the stock bootloader uart port. Make sure you can see stock bootloader logs.
  3. Search uboot code for a uart driver, compatible with your SOC. It is good, if it support debug(i.e. include debug_uart.h)

Create basic configuration and build

Add board files

TODO TODO: add more specific info

Add simple board, see examples.

TODO TODO: Create template

Examples

  1. Add exynos7420 espresso board
  2. Add exynos7420 SOC support

Building

Install arm cross compiler Build:

export CROSS_COMPILE=aarch64-linux-gnu- 
make <$board_name>_defconfig
make
TODO TODO: How to assemble android boot image

Getting uart debug output

TODO TODO: add raw c and assemble examples. Also config options for debug_uart.h What init code to comment out

You can get debug output from particular *.c file by adding #define DEBUG at the top of file, and calling debug("debug output"); where you need.

Finding base address

TODO TODO: How to dump PC register on ARM, to know RAM range to dump

You should tell u-boot base address, i.e. address in RAM, where stock bootloader load u-boot. Do it with CONFIG_SYS_TEXT_BASE option. Without that knowledge u-boot will fail on `/common/board_f.c` file in function `init_sequence_f`. This function contains list of initcall addresses, and if CONFIG_SYS_TEXT_BASE does not match with address u-boot resides, you CPU will jump in wrong address and execute irrelevant code, leaving you with unpredictable uart output and results.

To find u-boot base address, you should dump RAM, where u-boot presumably resides, and find, at what address uboot image starts. Result should be placed in CONFIG_SYS_TEXT_BASE

Ram dump code example:

   char *val;
   val = 0x40001000;
   debug("0x40001000 - 0x40101000 \n");
   for(int i=0 ; i < 0x100000; i++) {
           if ((i & 0xf) == 0) {
               debug("\n%.8x: ", val + i); // new line every 16 symbols
           }
           debug("%.2x ", *(val + i));
       }
   debug("\n");

Creating basic device tree

TODO TODO: Add Template and examples

Congrats! You should now get a u-boot console prompt!