menu: simplify usage for clients
[barebox-mini2440.git] / Documentation / porting.txt
blobccfe598a741a8d818fc157b0ad14b2de98f5d82c
2 When porting from old barebox the follwing steps must be taken (please complain
3 if there's something missing here ;)
6 - Most of the macros in include/configs/yourboard.h can be removed, especially
7   the CONFIG_COMMANDS section. The goal is to remove this file entirely, but
8   for now some values are still needed here. If you think some things are better
9   configured with the Kconfig system feel free to add them there.
11 - The linker script needs a new section for the initcalls. The handling of the
12   barebox command table has changed, too. (The commands are now sorted by the
13   linker instead at runtime.) To change it you need an entry like the following
14   in your linker script:
16 #include <asm-generic/barebox.lds.h>
18         __barebox_cmd_start = .;
19         .barebox_cmd : { BAREBOX_CMDS }
20         __barebox_cmd_end = .;
22         __barebox_initcalls_start = .;
23         .barebox_initcalls : { INITCALLS }
24         __barebox_initcalls_end = .;
26 - Rename your linker script to barebox.lds.S and add the following entry to the
27   Makefile to make sure the linker script is generated:
29 extra-y += barebox.lds
31 - Register the devices present in your system in the board specific .c file.
32   To see anything you have to at least register a console. In scb9328.c this
33   looks like this:
35         static struct device_d scb9328_serial_device = {
36                 .name     = "imx_serial",
37                 .map_base = IMX_UART1_BASE,
38                 .size     = 4096,
39         };
41         static int scb9328_console_init(void)
42         {
43                 register_device(&scb9328_serial_device);
44                 return 0;
45         }
47         console_initcall(scb9328_console_init);
49 - For most boards you will have to register a cfi_flash device. NAND flash
50   is not ported yet.
52 - Call devfs_add_partition() to add an environment partition for your device:
53   devfs_add_partition("nor0", 0x40000, 0x20000, "env0");
54   This will add an area starting at 0x40000 of size 0x20000 of the device
55   nor0 as env0.
57 - Port missing drivers. Depending on the driver this can a be rather simple
58   process:
60   Serial drivers
61   - Declare all functions static.
62   - in your probe function fill in a struct console_device and register it
63     with console_register()
65   Ethernet drivers
66   - Basically do the same as with serial drivers.
67   - Identify the parts of the driver which handle the MAC address. There are
68     now two functions handling them in struct eth_device. 
70     get_mac_address() retrieve the MAC address from the EEPROM if one is
71                       connected. If you don't have an EEPROM just return -1.
72     set_mac_address() set the MAC address in the device. All magic previously
73                       done with getenv/setenv(ethaddr) must be removed.
75     During startup barebox calls get_mac_address() to see if an EEPROM is
76     connected. If so, it calls set_mac_address() with this address. This
77     is done even if networking is not used during startup. This makes sure
78     that the MAC address is set in the device and Linux can pick it up later.
79   - There is now (the beginning of) generic phy support. When porting drivers
80     it is recommended to use it. The phy support currently only starts generic
81     autonegotiation, so if you have some fancy things to do (or have gigabit
82     ethernet) you'll have to extend the phy layer first. Although this is
83     extra work, it will pay off some day, as phy support is a great source
84     of duplicated code. see drivers/net/dm9000.c or drivers/net/fec_mpc5200.c
85     for examples.
87 - Add a clocksource for your system. PowerPCs have a generic decrementer
88   counter, so if you have a PowerPC you have nothing to do here. On ARM
89   this is SoC dependent. See Documentation/timekeeping.txt for further
90   information.
92 - Adjust start.S. On PowerPC there is at least the Problem that the relocation
93   offset is defined at compile time. It is easily possible to determine the
94   address barebox is currently starting from at runtime and thus allowing it
95   barebox to be started at any address. Look at the relocation code and replace
96   TEXT_BASE with the following calculation of the runtime address:
98         bl     calc_source     /* Calculate Source Address             */
99 calc_source:
100         mfspr   r4,  LR
101         subi    r4, r4, (calc_source - _start)
102         subi    r4, r4, 0x100
104   (I'm almost sure that PowerPC has a dedicated instruction for this, un-
105   fortunately I know next to nothing of PowerPC assembler, so if you have
106   a better way to archieve this, please write to the list.)
108   On PowerPC barebox now runs at the address it was linked to, so you have
109   to adjust TEXT_BASE to be in RAM. This makes the various fixup relocation
110   functions unnecessary. On PowerPC the removal of -fPIC saves around 10% of
111   binary space. It also simplifies debugging because you will see the correct
112   addresses in the objdump without doing offset calculation.
114 - On ARM most of the duplicate code under cpu/arm* is already merged into
115   arch/arm/cpu. The start.S files are missing though.