Porting+U-Boot+To+Your+Board

download Porting+U-Boot+To+Your+Board

of 8

description

Porting+U-Boot+To+Your+Board

Transcript of Porting+U-Boot+To+Your+Board

  • Last update: 2010/11/30 04:43 bootloaders:u-boot:portinghttp://docs.blackfin.uclinux.org/doku.php?id=bootloaders:u-boot:porting

    Porting U-Boot To Your BoardSo you have a new custom Blackfin board and you want to get Das U-Boot up and running on it?Here's the document for you. Unfortunately, it isn't the only document you're going to need. Youshould also make sure to have the HRM for your Blackfin variant, as well as all the datasheets for allthe main parts on your board (that you will be configuring in U-Boot). Since it is the job of U-Boot toinitialize all the low-level hardware details, you're going to need to know the hardware settings.

    For the purposes of this document, we will be creating a new BF537 board code named cow.Whether your board is based on a different processor or you've got a cooler name, these detailsshould be easily replaceable.

    Here is a quick list of the files/directories in U-Boot that you will need to modify/create:

    top-level Makefile and MAKEALL and MAINTAINERSlboard configuration file: include/configs/bf537-cow.hlboard directory: boards/bf537-cow/l

    Top-level Build

    Makefile

    In the top-level Makefile, simply locate the Blackfin section where the variable BFIN_BOARDS isdeclared and add your board to it. The Blackfin portions of the makefile use this variable to set upeverything else for the selected board.

    BFIN_BOARDS += bf537-cow

    If you generate any non-standard files in your Board Directory, you will also need to update theclean target to have those files removed. Common files (like objects *.o) are automatically removedfor you.

    MAKEALL

    If you plan on contributing your board back to the Blackfin U-Boot mainline, you should update theMAKEALL script. Locate the LIST_blackfin variable and add your board to the end of it.

    LIST_blackfin=" \ ... bf537-cow"

    This script is used to quickly run compile tests for all available Blackfin boards. The Blackfin U-Bootmaintainer uses this when making board-independent changes so as to be sure that no boards break(and if they do, he will fix them for you).

    http://docs.blackfin.uclinux.org/ Printed on 2011/09/07 12:54

  • http://docs.blackfin.uclinux.org/doku.php?id=bootloaders:u-boot:portingbootloaders:u-boot:porting Last update: 2010/11/30 04:43

    MAINTAINERS

    If you plan on contributing your board back to the Blackfin U-Boot mainline, you should update theMAINTAINERS list. Locate the Blackfin Systems section and add your contact e-mail and board(s)to the end of it. Feel free to add the Blackfin development mailing list as well.

    ...# Blackfin Systems:...Some Developer

    BF537-COW BF537...

    Board Configuration File

    This file is the heart of your board setup. It describes all of the features to enable, drivers to include,and settings. Here we'll cover the key defines and give pointers to further documentation.

    Once you tackle the Blackfin options below, check out the customizing page for the next steps.

    Format

    Please make sure your board configuration file has this general format:

    /* Some copyright / license info */ #ifndef __CONFIG_BF537_COW_H__#define __CONFIG_BF537_COW_H__ /* this must come first */#include ... /* this sets up the default list of enabled commands */#include /* Undo any settings you don't like from the config_cmd_default.h */ #endif

    Blackfin Settings

    There are a few Blackfin specific defines you must setup.

    Printed on 2011/09/07 12:54 http://docs.blackfin.uclinux.org/

  • Last update: 2010/11/30 04:43 bootloaders:u-boot:portinghttp://docs.blackfin.uclinux.org/doku.php?id=bootloaders:u-boot:porting

    CONFIG_BFIN_CPU

    This is a short string that represents the desired Blackfin processor and its silicon version. So if wewant to target silicon revision 0.3 of the BF537 for our board:

    #define CONFIG_BFIN_CPU bf537-0.3

    CONFIG_BFIN_BOOT_MODE

    This controls the expected boot method of your board. Generally speaking, the code attempts to beboot-mode agnostic, but this isn't always the case. Make sure this actually matches your BMODEpins. Keep in mind that U-Boot supports more boot modes than your Blackfin variant may, so onlyselect ones that your Blackfin variant actually supports. See the Blackfin Boot ROM Boot Modessection for more information.

    When changing boot modes, make sure you run make clean first to ensure all files are properlyrecompiled.

    If we want to create an LDR which can boot over the UART, then we would do something like:

    #define CONFIG_BFIN_BOOT_MODE BFIN_BOOT_UART

    Here is the complete list of possible values for BFIN_BOOT_MODE:

    file: branches/2010R1/arch/blackfin/include/asm/config-pre.h

    /* line 20 to 33 */#define BFIN_BOOT_BYPASS 1 /* bypass bootrom */#define BFIN_BOOT_PARA 2 /* boot ldr out of parallel flash */#define BFIN_BOOT_SPI_MASTER 3 /* boot ldr out of serial flash */#define BFIN_BOOT_SPI_SLAVE 4 /* boot ldr as spi slave */#define BFIN_BOOT_TWI_MASTER 5 /* boot ldr over twi device */#define BFIN_BOOT_TWI_SLAVE 6 /* boot ldr over twi slave */#define BFIN_BOOT_UART 7 /* boot ldr over uart */#define BFIN_BOOT_IDLE 8 /* do nothing, just idle */#define BFIN_BOOT_FIFO 9 /* boot ldr out of FIFO */#define BFIN_BOOT_MEM 10 /* boot ldr out of memory (warmboot) */#define BFIN_BOOT_16HOST_DMA 11 /* boot ldr from 16-bit host dma */#define BFIN_BOOT_8HOST_DMA 12 /* boot ldr from 8-bit host dma */#define BFIN_BOOT_NAND 13 /* boot ldr from nand flash */

    CONFIG_UART_CONSOLE

    Simply define this to the UART number you have setup as your console. So if you are using UART0,just do:

    #define CONFIG_UART_CONSOLE 0

    http://docs.blackfin.uclinux.org/ Printed on 2011/09/07 12:54

  • http://docs.blackfin.uclinux.org/doku.php?id=bootloaders:u-boot:portingbootloaders:u-boot:porting Last update: 2010/11/30 04:43

    Clock Settings

    These set of defines are used to control the clock settings for your board. They are directly used toprogram the PLL and related registers. Only basic validity checks are performed (at the registerlevel). No checks are performed to make sure datasheet compliance.

    You should consult the PLL Registers chapter of the HRM for your Blackfin variant.

    CONFIG_CLKIN_HZ - The clock input frequencylCONFIG_CLKIN_HALF - Cut input frequency in halflCONFIG_PLL_BYPASS - Bypass the PLLlCONFIG_VCO_MULT - Clock input multiplierlCONFIG_CCLK_DIV - Core clock dividerlCONFIG_SCLK_DIV - System clock dividerl

    For quick reference, the clock calculations are:

    Core: (CLKIN / (2 ^ CLKIN_HALF) * VCO_MULT) / CCLK_DIVSystem: (CLKIN / (2 ^ CLKIN_HALF) * VCO_MULT) / SCLK_DIV

    Direct Settings

    If you want to just program a register directly, you can use the CONFIG__VAL define. So if you wishto program the VR_CTL MMR with a specific setting, you can set CONFIG_VR_CTL_VAL in yourboard configuration.

    Asynchronous Memory Bus Settings

    There are a few defines that correlate directly to the registers. On all Blackfin's you have to define:

    CONFIG_EBIU_AMGCTL_VAL - Global Memory ControllCONFIG_EBIU_AMBCTL0_VAL - Bank 0 and Bank 1 ControllCONFIG_EBIU_AMBCTL1_VAL - Bank 2 and Bank 3 Controll

    On some newer Blackfin's (as older ones do not have these settings), you will have to define:

    CONFIG_EBIU_MBSCTL_VAL - Memory Bank Select ControllCONFIG_EBIU_MODE_VAL - Memory Mode ControllCONFIG_EBIU_FCTL_VAL - Flash Controll

    For exact meanings of a particular register, consult the HRM for your processor and any devicesthat you will have hooked up to these banks.

    External Memory Settings

    For Blackfin's that have SDRAM, you will need to define:

    CONFIG_EBIU_SDRRC_VAL - SDRAM Refresh Rate Controll

    Printed on 2011/09/07 12:54 http://docs.blackfin.uclinux.org/

  • Last update: 2010/11/30 04:43 bootloaders:u-boot:portinghttp://docs.blackfin.uclinux.org/doku.php?id=bootloaders:u-boot:porting

    CONFIG_EBIU_SDBCTL_VAL - SDRAM Bank ControllCONFIG_EBIU_SDGCTL_VAL - SDRAM Global Controll

    For Blackfin's that have DDR, you will need to define:

    CONFIG_EBIU_DDRCTL0_VAL - DDR ControllCONFIG_EBIU_DDRCTL1_VAL - DDR ControllCONFIG_EBIU_DDRCTL2_VAL - DDR ControllCONFIG_EBIU_DDRCTL3_VAL - (Optional) DDR ControllCONFIG_EBIU_RSTCTL_VAL - (Optional) DDR Reset Controll

    For exact meanings of a particular register, consult the HRM for your processor and the datasheetsfor the memory module you are using.

    Calculating DDR/SDRAM Settings

    For assistance in calculating the Blackfin settings based on your memory's timings, please see theSDRAM page.

    Board Directory

    This is where all of your board-specific files and code lives. There are three files that you arerequired to have in here. Those are:

    Makefile - list all files to generatelconfig.mk - custom compiler flagslbf537-cow.c - a C file named exactly the same as your boardl

    Makefile

    You can use this common template in any board directory:

    # BF537-COW board makefile

    include $(TOPDIR)/config.mk

    LIB = $(obj)lib$(BOARD).a

    COBJS := $(BOARD).oSOBJS :=

    SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c)OBJS := $(addprefix $(obj),$(COBJS))SOBJS := $(addprefix $(obj),$(SOBJS))

    $(LIB): $(obj).depend $(OBJS) $(SOBJS) u-boot.lds $(AR) $(ARFLAGS) $@ $(OBJS) $(SOBJS)

    http://docs.blackfin.uclinux.org/ Printed on 2011/09/07 12:54

  • http://docs.blackfin.uclinux.org/doku.php?id=bootloaders:u-boot:portingbootloaders:u-boot:porting Last update: 2010/11/30 04:43

    clean: rm -f $(SOBJS) $(OBJS)

    distclean: clean rm -f $(LIB) core *.bak $(obj).depend

    include $(SRCTREE)/rules.mk

    sinclude $(obj).depend

    If you have more C files or assembly (.S) files to compile, simply add them to the COBJS or SOBJSvariable as appropriate.

    Board Build Flags

    If you wish to add custom compiler flags for your board, then the config.mk file is the place for it.Simply append the variable in question (like PLATFORM_RELFLAGS or PLATFORM_CPPFLAGS)with whatever flag you want.

    Keep in mind that the TEXT_BASE variable is not used by the Blackfin platform, so do not set it.

    Most people will use this simply to tweak the flags given to the ldr utility when generating theu-boot.ldr file.

    # This is not actually used for Blackfin boards so do not change it#TEXT_BASE = do-not-use-me

    #PLATFORM_RELFLAGS += -some-gcc-flag#PLATFORM_CPPFLAGS += -DMY_CRAZY_DEFINE

    # Setup LDR_FLAGS according to our boot mode (BFIN_BOOT_MODE variable isdefined automatically)LDR_FLAGS-BFIN_BOOT_UART = --port g --gpio 6LDR_FLAGS += $(LDR_FLAGS-$(BFIN_BOOT_MODE))

    Board C File

    This is generally where you put the core/required functions that are needed by common U-Boot code.We'll cover the functions you should be sure to actually implement.

    checkboard

    Used to check random board specific details before initializing drivers. Usually just prints out abanner for your board. Return a value of zero to indicate success or return non-zero to indicatefailure (in which case the board should hang or reboot).

    int checkboard(void){

    Printed on 2011/09/07 12:54 http://docs.blackfin.uclinux.org/

  • Last update: 2010/11/30 04:43 bootloaders:u-boot:portinghttp://docs.blackfin.uclinux.org/doku.php?id=bootloaders:u-boot:porting

    printf("Board: BF537 cow board\n"); printf(" Support: http://cow.town/\n"); return 0;}

    board_reset

    This function is optional. If you need to tweak the hardware some how before performing a softsystem reset, then place those details here.

    void board_reset(void){ /* do something weird */}

    misc_init_r

    This function is where you place miscellaneous board initialization code. This is run after prettymuch everything else has been initialized but before the main execution of the console shell. Sameas the checkboard function -- return zero for success, non-zero to panic the board. Make sure youdefine CONFIG_MISC_INIT_R in your board configuration file.

    int misc_init_r(void){ /* do random stuff */}

    MAC address management

    If your board has ethernet capabilities and your MAC does not have a dedicated EEPROM for storingthe MAC address, and you have not hardcoded the MAC address in your board configuration file, youmust implement this sort of code in your board's misc_init_r() function. If your MAC does have adedicated EEPROM, then the U-Boot driver will take care of this function for you.

    The purpose of this semi-complicated system is to allow you to store/retrieve the MAC address fromwherever you like. For example, the BF537-STAMP utilizes a sector of parallel flash for storing theMAC address in a persistent manner.

    For more information, consult the doc/README.enetaddr file.

    int misc_init_r(void){... uchar enetaddr[6];

    http://docs.blackfin.uclinux.org/ Printed on 2011/09/07 12:54

  • http://docs.blackfin.uclinux.org/doku.php?id=bootloaders:u-boot:portingbootloaders:u-boot:porting Last update: 2010/11/30 04:43

    if (!eth_getenv_enetaddr("ethaddr", enetaddr)) { /* we cram the MAC in the last flash sector */ memcpy(enetaddr, (void *)0x203F0000, 6); eth_setenv_enetaddr("ethaddr", mac_addr); }...}

    board_eth_init

    The board_eth_init() function is the board callback function for registering your ethernet devices.Here you call the different network driver init functions and return their result.

    file: branches/2010R1/board/bf537-stamp/bf537-stamp.c

    /* line 79 to 83 */int board_eth_init(bd_t *bis){ return bfin_EMAC_initialize(bis);}

    More Information

    The memory layout guide may help you for customizing where to place U-Boot's code and data.

    From:http://docs.blackfin.uclinux.org/ - Analog Devices | Mixed-signal and Digital Signal Processing ICs

    Permanent link:http://docs.blackfin.uclinux.org/doku.php?id=bootloaders:u-boot:porting

    Last update: 2010/11/30 04:43

    Printed on 2011/09/07 12:54 http://docs.blackfin.uclinux.org/

    CONFIG_BFIN_CPUCONFIG_BFIN_BOOT_MODECONFIG_UART_CONSOLEClock SettingsDirect Settings

    Asynchronous Memory Bus SettingsExternal Memory SettingsCalculating DDR/SDRAM Settings

    checkboardboard_resetmisc_init_rMAC address management

    board_eth_init