u-boot 的调试方法

Tutorial: Debugging the U-Boot Universal Boot Loader


This section shows you how to use the CodeWarrior debugger to debug the U-Boot universal boot loader. U-Boot resides in flash memory on target systems and boots an embedded Linux image developed for those systems.

Note: The Linux Application Edition of this product does not support debugging the U-Boot bootstrap firmware.

The topics in this section are:

    • Preparing to Debug U-Boot
    • Debugging U-Boot in Flash Memory Before the MMU is Enabled
    • Debugging U-Boot in Flash Memory After the MMU is Enabled
    • Debugging U-Boot in RAM
Preparing to Debug U-Boot

To prepare to debug U-Boot on a target system, you first install on the host Linux computer the Board Support Package (BSP) for the particular target system you want to debug. Then you configure the BSP U-Boot package to place debugger symbolic information in the U-Boot binary executable file. Finally, you create a new CodeWarrior project that you will use to debug U-Boot on the target system.

Note: The first part of this procedure must be performed on a Linux host.

To prepare to debug U-Boot on a target system:

    • On the host computer, where CodeWarrior Development Studio is installed, install the board support package (BSP) for your target system.

    You can obtain BSPs for Freescale Power Architecture target systems from this web page:

    http://www.freescale.com/codewarrior/downloads  
    • Use the tools included with the BSP to build an ELF-format U-Boot image file that includes debugger symbolic information.
      • Make these changes to the file u-boot/config.mk:
    • DBGFLAGS = -g2 -gdwarf-2
    • AFLAGS_DEBUG = -Wa,-gdwarf2
    • OPTFLAGS = -O1

      Note: If you are using a Linux Target Image Builder (LTIB) BSP, you may need to change the optimization flag of the CFLAGS argument in this file:

      LTIBInstallDir/config/platform/board_name/.config

      • If the version of U-Boot included with the BSP modifies any of these registers during startup, comment the appropriate lines in the file u-boot/cpu/mpc85xx/start.S file so that U-Boot will not modify the registers:
    • DBCR0
    • IAC1
    • IAC2
    • DAC1
    • DAC2
      • In the file u-boot/lib_ppc/board.c, change the token debug to the token printf in the statement that includes this string:
      Now running in ram
      • Rebuild U-Boot.

You now have an ELF-format U-Boot binary executable file that contains debugger symbolic information. In addition, you have a U-Boot raw binary (.bin) file that you can write to flash memory on the target board.

Note: It is best to leave the ELF-format U-Boot binary file in this location, so that when you create a CodeWarrior project with the file, the CodeWarrior IDE can find all of the source U-Boot source code files needed to debug the binary file.

Note: The following procedure must be performed using the Professional Edition of this CodeWarrior product.

    • Start the CodeWarrior IDE.
    • Use the CodeWarrior Flash Programmer to write the raw binary U-Boot file (not the ELF-format file) to the flash memory of that target system.

    Refer to the "Flashing U-Boot" section of the target system's BSP User's Guide for instructions that show how to flash U-Boot to the system. This document is typically located in the help/software folder of the BSP.

    Warning: Do not write the ELF-format U-Boot file to flash memory; you must use the raw binary U-Boot file.

    • From the CodeWarrior menu bar, select File > Open.

    The standard Open dialog box appears.

    • Navigate to and select (highlight) the ELF-format U-Boot file containing debugger symbolic information (one of the files you created in the previous step).
    • Click Open.
    • The Choose Debugger dialog box (Figure 3.72) appears.
    Figure 3.72 Choose Debugger Dialog Box


    • Select one of these remote connections:
    • CodeWarrior Ethernet TAP - if you are using an Ethernet TAP run-control device.
    • CodeWarrior USB TAP - if you are using a USB TAP run-control device.

    Note: You must use a JTAG run-control device to debug U-Boot. The CodeWarrior USB TAP and the CodeWarrior Ethernet TAP are each JTAG devices.

    The CodeWarrior IDE creates a CodeWarrior project containing the source files used to build the U-boot binary file. The CodeWarrior project file is located in the same directory as the ELF-format U-Boot file.

    Note: For the IDE to create complete a U-Boot project file, all source files used to build the ELF format U-Boot file must be available. While the IDE is building the new CodeWarrior project, if it cannot find a U-Boot source code file, it displays a dialog box with which you can navigate to and select the file. For each source code file that cannot be found, the IDE logs a message to theProject Creator Log window.

    Once project creation is complete, the IDE displays the project in a project window. (See Figure 3.73.)

    Figure 3.73 CodeWarrior Project Window


You now have CodeWarrior project with which you can debug the U-Boot bootstrap firmware.

Note: While debugging U-Boot on 86xx, if address translations has not been enabled and you set a breakpoint in a part of code after the address translation is done, this breakpoint will not be hit. Breakpoints can be used until enable address translation is done. You can use step into to debug through the address translation section (breakpoints / step over / run to cursor cannot be used). After the translation is enabled, you can start using again the hardware breakpoints. A breakpoint set in the c) part of code while debugging in the a) part of code will not be hit.

During a typical U-Boot start-up sequence, the target processor starts executing U-Boot in flash memory. U-Boot then enables the Memory Management Unit (MMU), and relocates itself to RAM.

CodeWarrior build target settings required to debug U-Boot in flash memory differ from the settings required to debug U-Boot in RAM. Therefore, you must use individual CodeWarrior debug sessions to debug the flash memory and RAM sections:

    • "Debugging U-Boot in Flash Memory Before the MMU is Enabled"

    This procedure shows how to debug U-Boot in flash memory before the memory management unit (MMU) is initialized.

    • "Debugging U-Boot in Flash Memory After the MMU is Enabled"

    This procedure shows how to debug U-Boot in flash memory after the memory management unit (MMU) is initialized.

    • "Debugging U-Boot in RAM"

    This procedure shows how to debug U-Boot in RAM.

Debugging U-Boot in Flash Memory Before the MMU is Enabled

To debug U-Boot in flash memory before the target board's memory management unit (MMU) is enabled:

    • Start the CodeWarrior IDE.
    • Open the CodeWarrior U-Boot project you created in section "Preparing to Debug U-Boot".
    • From the CodeWarrior menu bar, select Edit > Debug Settings.

    The Target Settings window (Figure 3.74) appears.

    Figure 3.74 Target Settings Window


    • From the Target Settings Panels list, select Debugger Settings

    The Debugger Settings panel (Figure 3.75) appears.

    Figure 3.75 Debugger Settings Panel


    • Check the Stop on Application Launch checkbox.
    • Select the Program entry point option button.
    • From the Target Settings Panels list, select Remote Debugging.

    The Remote Debugging settings panel (Figure 3.76) appears.

    Figure 3.76 Remote Debugging Settings Panel


    • From the Connection list box, select one of these remote connections:
    • CodeWarrior Ethernet TAP
    • CodeWarrior USB TAP
    • Click the Edit Connection button.
    • When the IDE displays a dialog box asking if you want to continue, click OK.

    The Edit Connection dialog box (Figure 3.77) appears, displaying the configuration for the selected remote connection.

    Figure 3.77 Edit Connection Dialog Box


    • Check the Reset Target on Launch checkbox.
    • Click OK.

    The Edit Connection dialog box disappears.

    • From the Target Settings Panels list, select Debugger PIC Settings.

    The Debugger PIC Settings settings panel (Figure 3.78) appears.

    Figure 3.78 Debugger PIC Settings Panel


    • Check the Alternate Load Address checkbox.

    Note: An alternate load address causes the debugger to assume that all sections have been relocated to RAM. If you specify no alternate load address, the debugger can display source code only for sections in flash memory. If you specify an alternate load address, the debugger can display source code only for sections in RAM.

    • In the Alternate Load Address text box, type the hexadecimal form of the memory address at which the U-Boot image was written to flash memory.
    • From the Target Settings Panels list, select EPPC Debugger Settings.

    The EPPC Debugger Settings settings panel (Figure 3.79) appears.

    Figure 3.79 EPPC Debugger Settings Panel


    • From the Processor Family list box, select the family of the target processor.
    • From the Target Processor list box, select the target processor.
    • From the Target OS list box, select Bareboard.
    • Check the Use Target Initialization File checkbox.
    • Click Browse to display a dialog box with which you can navigate to and select the target initialization file for the target system.
    • In the Program Download Options area, clear all the checkboxes in the Initial Launch and Successive Runs sections.
    • Click the Save button.
    • Close the Target Settings window.

    The Target Settings window disappears. The CodeWarrior IDE saves your changes to target settings.

    • On the host computer running the CodeWarrior IDE, start a terminal emulator program such as minicom.
    • Configure the terminal emulator as shown in Table 3.24.
    Table 3.24 Terminal Emulator Configuration Settings?
    bits per second
    115200
    data bits
    8
    parity
    none
    stop bits
    1
    hardware flow control
    none
    software flow control
    none
    • Power on or reset the target system.

    The system resets.The terminal emulator displays U-Boot status messages.

    Note: If U-Boot asks for the MAC address of the board's Ethernet interface, enter a valid MAC address, such as 00:01:03:00:01:04.

    U-Boot finishes initialization and displays this message (where N is the number of seconds left before autoboot starts):

    Hit any key to stop autoboot: N  
    • Stop the autoboot process by pressing any key on the keyboard.

    The U-Boot command prompt appears:

    -->  
    • From the CodeWarrior menu bar, select Debug > Attach To Process.

    The CodeWarrior debugger connects to the target system and displays a debugger window.

    • From the CodeWarrior menu bar, select Debug > Stop.

    The debugger halts U-Boot execution and displays disassembled code in the Source pane of the debugger window (See Figure 3.80).

    Figure 3.80 Attach To Process - Debugger Window


    • Select Debug > EPPC > Hard Reset.

    The debugger sends a hard reset signal to the board. The debugger window displays the __start section. You can debug from this point up to the first blr instruction in start.S.

Debugging U-Boot in Flash Memory After the MMU is Enabled

To debug U-Boot in flash memory after the target board's memory management unit (MMU) is enabled:

    • Start the CodeWarrior IDE.
    • Open the CodeWarrior U-Boot project you created in section "Preparing to Debug U-Boot".
    • From the CodeWarrior menu bar, select Edit > Debug Settings.

    The Target Settings window (Figure 3.74) appears.

    Figure 3.81 Target Settings Window


    • From the Target Settings Panels list, select Debugger Settings

    The Debugger Settings panel (Figure 3.75) appears.

    Figure 3.82 Debugger Settings Panel


    • Check the Stop on Application Launch checkbox.
    • Select the Program entry point option button.
    • From the Target Settings Panels list, select Remote Debugging.

    The Remote Debugging settings panel (Figure 3.76) appears.

    Figure 3.83 Remote Debugging Settings Panel


    • From the Connection list box, select one of these remote connections:
    • CodeWarrior Ethernet TAP
    • CodeWarrior USB TAP
    • Click the Edit Connection button.
    • When the IDE displays a dialog box asking if you want to continue, click OK.

    The Edit Connection dialog box (Figure 3.77) appears, displaying the configuration for the selected remote connection.

    Figure 3.84 Edit Connection Dialog Box


    • Check the Reset Target on Launch checkbox.
    • Click OK.

    The Edit Connection dialog box disappears.

    • From the Target Settings Panels list, select Debugger PIC Settings.

    The Debugger PIC Settings settings panel (Figure 3.78) appears.

    Figure 3.85 Debugger PIC Settings Panel


    • Clear the Alternate Load Address checkbox.

    Note: An alternate load address causes the debugger to assume that all sections have been relocated to RAM. If you specify no alternate load address, the debugger can display source code only for sections in flash memory. If you specify an alternate load address, the debugger can display source code only for sections in RAM.

    • From the Target Settings Panels list, select EPPC Debugger Settings.

    The EPPC Debugger Settings settings panel (Figure 3.79) appears.

    Figure 3.86 EPPC Debugger Settings Panel


    • From the Processor Family list box, select the family of the target processor.
    • From the Target Processor list box, select the target processor.
    • From the Target OS list box, select Bareboard.
    • Check the Use Target Initialization File checkbox.
    • Click Browse to display a dialog box with which you can navigate to and select the target initialization file for the target system.
    • In the Program Download Options area, clear all the checkboxes in the Initial Launch and Successive Runs sections.
    • Click the Save button.
    • Close the Target Settings window.

    The Target Settings window disappears. The CodeWarrior IDE saves your changes to target settings.

    • On the host computer running the CodeWarrior IDE, start a terminal emulator program such as minicom.
    • Configure the terminal emulator as shown in Table 3.24.
    Table 3.25 Terminal Emulator Configuration Settings?
    bits per second
    115200
    data bits
    8
    parity
    none
    stop bits
    1
    hardware flow control
    none
    software flow control
    none
    • Power on or reset the target system.

    The system resets.The terminal emulator displays U-Boot status messages.

    Note: If U-Boot asks for the MAC address of the board's Ethernet interface, enter a valid MAC address, such as 00:01:03:00:01:04.

    U-Boot finishes initialization and displays this message (where N is the number of seconds left before autoboot starts):

    Hit any key to stop autoboot: N  
    • Stop the autoboot process by pressing any key on the keyboard.

    The U-Boot command prompt appears:

    -->  
    • From the CodeWarrior menu bar, select Debug > Attach To Process.

    The CodeWarrior debugger connects to the target system and displays a debugger window.

    • From the CodeWarrior menu bar, select Debug > Stop.

    The debugger halts U-Boot execution and displays disassembled code in the Source pane of the debugger window (See Figure 3.80).

    Figure 3.87 Attach To Process - Debugger Window


    • Select Debug > EPPC > Hard Reset.

    The debugger sends a hard reset signal to the board. The debugger window displays the __start section. You can debug from this point up to the first blr instruction in start.S.

    • Select Window > Symbolics Window.

    The Symbolics Window (Figure 3.88) appears.

    • In the Executables list, select u-boot.
    • In the Files list, select board.c.
    • In the Functions list, select board_init_f.
    • The IDE displays the source code of the board_init_f() function in the Source pane (as shown in Figure 3.88).
    Figure 3.88 Symbolics Window - Flash Board Initialization Function


    • In the Source pane, right-click the first line of the board_init_f() function with a tick mark in the breakpoint column on the left side of the window.

    A contextual menu appears, as shown in Figure 3.89.

    Figure 3.89 Debugger Window - Contextual Menu


    • From the contextual menu, select Set Hardware Breakpoint.

    The IDE sets the hardware breakpoint on the selected line of code. A blue diamond symbol appears over the tick mark in the breakpoint column, indicating that a hardware breakpoint is set.

    • Close the Symbolics Window.
    • From the CodeWarrior menu bar, select Debug > EPPC > Hard Reset.

    The debugger resets the target system and halts U-Boot execution at the start of U-Boot.

    • Select Project > Run.

    The debugger starts U-Boot execution. When execution reaches the hardware breakpoint, the debugger halts execution. A debugger window (Figure 3.90) appears, showing the source code of the board_init_f() function.

    Figure 3.90 Debugger Window - Stopped At Hardware Breakpoint


    Note: In this debugger window, the blue arrow indicates that the program counter (PC) is at the line of code on which you set the hardware breakpoint.

You may now use the features of the CodeWarrior debugger to step through the source code and debug U-Boot in flash memory.

Debugging U-Boot in RAM

To debug U-Boot in RAM:

    • On the host computer, start a terminal emulator program such as minicom.
    • Configure the terminal emulator as shown in Table 3.26.
    Table 3.26 Terminal Emulator Configuration Settings?
    bits per second
    115200
    data bits
    8
    parity
    none
    stop bits
    1
    hardware flow control
    none
    software flow control
    none
    • Reset or power on the target system.

    The system resets.The terminal emulator displays U-Boot status messages (as shown in Figure 3.91).

    • If U-Boot asks for the MAC address of the board's Ethernet interface, enter a valid MAC address, such as 00:01:03:00:01:04.

    U-Boot finishes initialization and displays this message (where N is the number of seconds left before autoboot starts):

    Hit any key to stop autoboot: N  
    • Press a key on your keyboard to stop the autoboot process.

    The U-Boot command prompt appears (as shown in Figure 3.91):

    -->  
    Figure 3.91 U-Boot Startup Messages


    • Write down the memory address from this U-Boot startup message (as shown in Figure 3.91):
    Now running in RAM - U-Boot at: address  
    • Start the CodeWarrior IDE.
    • Open the CodeWarrior U-Boot project you created in section "Preparing to Debug U-Boot".
    • From the CodeWarrior menu bar, select Edit > Debug Settings.

    The Target Settings window (Figure 3.92) appears.

    Figure 3.92 Target Settings Window


    • From the Target Settings Panels list, select Debugger Settings

    The Debugger Settings panel (Figure 3.93) appears.

    Figure 3.93 Debugger Settings Panel


    • Check the Stop on Application Launch checkbox.
    • Select the Program entry point option button.
    • From the Target Settings Panels list, select Remote Debugging.

    The Remote Debugging settings panel (Figure 3.94) appears.

    Figure 3.94 Remote Debugging Settings Panel


    • From the Connection list box, select one of these remote connections:
    • CodeWarrior Ethernet TAP
    • CodeWarrior USB TAP
    • Click the Edit Connection button.
    • When the IDE displays a dialog box asking if you want to continue, click OK.

    The Edit Connection dialog box (Figure 3.95) appears, displaying the configuration for the selected remote connection.

    Figure 3.95 Edit Connection Dialog Box


    • Check the Reset Target on Launch checkbox.
    • Click OK.

    The Edit Connection dialog box disappears.

    • From the Target Settings Panels list, select Debugger PIC Settings.

    The Debugger PIC Settings settings panel (Figure 3.96) appears.

    Figure 3.96 Debugger PIC Settings Panel


    • Check the Alternate Load Address checkbox.
    • In the Alternate Load Address text box, enter the memory address you wrote down earlier, from the U-Boot startup messages displayed in the terminal emulator.

    Use the format: 0xFFFFFFFF

    Note: An alternate load address causes the debugger to assume that all sections have been relocated to RAM. If you specify no alternate load address, the debugger can display source code only for sections in flash memory. If you specify an alternate load address, the debugger can display source code only for sections in RAM.

    • From the Target Settings Panels list, select EPPC Debugger Settings.

    The EPPC Debugger Settings settings panel (Figure 3.79) appears.

    Figure 3.97 EPPC Debugger Settings Panel


    • From the Processor Family list box, select the family of the target processor.
    • From the Target Processor list box, select the target processor.
    • From the Target OS list box, select Bareboard.
    • Check the Use Target Initialization File checkbox.
    • Click Browse to display a dialog box with which you can navigate to and select the target initialization file for the target system.
    • In the Program Download Options area, clear all the checkboxes in the Initial Launch and Successive Runs sections.
    • Click the Save button.
    • Close the Target Settings window.

    The Target Settings window disappears. The CodeWarrior IDE saves your changes to target settings.

    • From the CodeWarrior menu bar, select Debug > Attach To Process.

    The CodeWarrior debugger connects to the target system and displays a debugger window.

    • From the CodeWarrior menu bar, select Debug > Stop.

    The debugger halts U-Boot execution and displays disassembled code in the Source pane of the debugger window (See Figure 3.98).

    Figure 3.98 Attach To Process - Debugger Window


    • Select Window > Symbolics Window.

    The Symbolics Window (Figure 3.99) appears.

    • In the Executables list, select u-boot.
    • In the Files list, select board.c.
    • In the Functions list, select board_init_r.
    • The IDE displays the source code of the board_init_r() function in the Source pane (as shown in Figure 3.88).
    Figure 3.99 Symbolics Window - RAM Board Initialization Function


    • In the Source pane, right-click the first line of the board_init_r() function with a tick mark in the breakpoint column.

    A contextual menu appears, as shown in Figure 3.89.

    Figure 3.100 Debugger Window - Contextual Menu


    • From the contextual menu, select Set Hardware Breakpoint.

    The IDE sets the hardware breakpoint on the selected line of code. A blue triangle appears over the tick mark in the breakpoint column, indicating that a hardware breakpoint is set.

    • Close the Symbolics Window.
    • From the CodeWarrior menu bar, select Debug > EPPC > Hard Reset.

    The debugger resets the target system and halts U-Boot execution at the start of U-Boot.

    • Select Project > Run.
    • The debugger starts U-Boot execution. When execution reaches the hardware breakpoint, the debugger halts execution. A debugger window (Figure 3.90) appears, showing the source code of the board_init_f() function.
    Figure 3.101 Debugger Window - Stopped At Hardware Breakpoint


    Note: In this debugger window, the blue arrow indicates that the program counter (PC) is at the line of code on which you set the hardware breakpoint.

You may now use the features of the CodeWarrior debugger to step through the source code and debug U-Boot in RAM.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值