Skip to contentSkip to conversation

Create generic board init and move ARM and x86 to it

RFC PATCH New Simon Glass 4 participants 45 messages Dec 28, 2011 – Jan 9, 2012

Subsystems (11)
lore
Share & tools
lore
#0 lore raw

cover Create generic board init and move ARM and x86 to it

This series creates a generic board.c implementation which contains the essential functions of the various arch/xxx/lib/board.c files.

What is the motivation for this change?

1. There is a lot of repeated code in the board.c files. Any change to things like setting up the baud rate requires a change in 10 separate places.

2. Since there are 10 separate files, adding a new feature which requires initialisation is painful since it must be independently added in 10 places.

3. As time goes by the architectures naturely diverge since there is limited pressure to compare features or even CONFIG options against simiilar things in other board.c files.

4. New architectures must implement all the features all over again, and sometimes in subtley different ways. This places an unfair burden on getting a new architecture fully functional and running with U-Boot.

5. While it is a bit of a tricky change, I believe it is worthwhile and achievable. There is no requirement that all code be common, only that the code that is common should be located in common/board.c rather than arch/xxx/lib/board.c.

All the functions of board_init_f() and board_init_r() are broken into separate function calls so that they can easily be included or excluded for a particular architecture. It also makes it easier to adopt Graeme's initcall proposal later if desired.

Generic relocation is used (see previous series) but now rather than calling relocate_code() to do everything, we call the individual relocation steps one by one. Again this makes it easier to leave things out, particularly for SPL.

ARM is a relatively large board.c file and one which I can test, therefore I think it is a good target for this series. On the other hand, x86 is relatively small and simple, but different enough that it introduces a few issues to be solved. So I have chosen both ARM and x86 for this series.

The next target should probably be PowerPC, since it is large and has some additional features. I suspect we may want to leave some of these very architecture-specific functions in arch/powerpc/lib/board.c, taking out only the generic code. I haven't felt a strong need to do this for ARM/x86, but we could even go as far as putting the initcall list into the architecture-specific board file if the architecture adds a lot of unusual calls.

A generic global_data structure is also required. This might upset a few people. Here is my basic reasoning: most fields are the same, all architectures include and need it, most global_data.h files already have
#ifdefs to select fields for a particular SOC, so it is hard to
see why architecures are different in this area. We can perhaps add a way to put architecture-specific fields into a separate header file, but for now I have judged that to be counter-productive.

There was dicussion on the list about passing gd_t around as a parameter to pre-relocation init functions. I think this makes sense, but it can be done as a separate change, and this series does not require it.

While this series needs to stand on its own (as with the link script cleanup series and the generic relocation series) the goal is the unification of the board init code. So I hope we can address issues with this in mind, rather than focusing too narrowly on particular ARM or x86 issues.

Comments welcome. Note that the x86 side of this still needs a fair bit of work, sorry.

Simon Glass (19):
Introduce generic global_data
Make relocation functions global
Add basic initcall implementation
define CONFIG_SYS_LEGACY_BOARD everywhere
Add generic post-relocation board_r.c
Add generic pre-relocation board_f.c
Add spl load feature
switch ARM over to generic board
arm: Remove unused code in board.c, global_data.h Add CONFIG_SYS_SYM_OFFSETS to support offset symbols
x86: Remove compiler warning in sc520_timer.c
x86: Remove dead code in eNET
x86: Add processor library and relocation functions Tidy up asm/generic sections.h to include x86 symbols Add fields required by x86 to global_data
x86: Change stub example to use asm-generic/sections.h
x86: Add initial memory barrier macros
Bring in x86 to unified board architecture
x86: Remove unused board/global_data code

 README                             |    5 +
 arch/arm/include/asm/global_data.h |   77 +-----
 arch/arm/include/asm/u-boot-arm.h  |    4 -
 arch/arm/lib/board.c               |  622 +-----------------------------------
 arch/avr32/config.mk               |    3 +
 arch/blackfin/config.mk            |    3 +
 arch/m68k/config.mk                |    3 +
 arch/microblaze/config.mk          |    3 +
 arch/mips/config.mk                |    3 +
 arch/nds32/config.mk               |    3 +
 arch/nios2/config.mk               |    3 +
 arch/powerpc/config.mk             |    3 +
 arch/sandbox/config.mk             |    3 +
 arch/sh/config.mk                  |    3 +
 arch/sparc/config.mk               |    3 +
 arch/x86/config.mk                 |    3 -
 arch/x86/cpu/sc520/sc520_timer.c   |    2 +-
 arch/x86/include/asm/global_data.h |   57 +----
 arch/x86/include/asm/io.h          |    8 +
 arch/x86/include/asm/reloc.h       |   32 ++
 arch/x86/include/asm/u-boot-x86.h  |    8 -
 arch/x86/lib/Makefile              |    1 +
 arch/x86/lib/board.c               |  452 +--------------------------
 arch/x86/lib/proc.S                |   67 ++++
 board/eNET/eNET.c                  |    5 -
 board/freescale/p2020come/Makefile |    6 +
 common/Makefile                    |    7 +-
 common/board_f.c                   |  461 ++++++++++++++++++++++++++
 common/board_r.c                   |  385 ++++++++++++++++++++++
 common/reloc.c                     |   46 +++-
 config.mk                          |    4 +
 examples/standalone/stubs.c        |    7 +-
 include/asm-generic/global_data.h  |  129 ++++++++
 include/asm-generic/sections.h     |   29 ++
 include/initcall.h                 |   25 ++
 include/reloc.h                    |   16 +
 lib/Makefile                       |    1 +
 lib/initcall.c                     |   41 +++
 38 files changed, 1308 insertions(+), 1225 deletions(-)
 create mode 100644 arch/x86/include/asm/reloc.h
 create mode 100644 arch/x86/lib/proc.S
 create mode 100644 common/board_f.c
 create mode 100644 common/board_r.c
 create mode 100644 include/asm-generic/global_data.h
 create mode 100644 include/initcall.h
 create mode 100644 lib/initcall.c
Signature · 1 line
1.7.3.1
#1 lore raw

RFC PATCH 1/19 Introduce generic global_data

We want to unify the global_data structure. Most fields are common across architectures, but there are a fair number of SOC-specific additions. It isn't clear how best to deal with these, but for now we just use #ifdef.

Checkpatch warnings here might be unavoidable:

warning: include/asm-generic/global_data.h,43: do not add new typedefs
warning: include/asm-generic/global_data.h,117: Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt
warning: include/asm-generic/global_data.h,121: storage class should be at the beginning of the declaration

---
 include/asm-generic/global_data.h |  125 +++++++++++++++++++++++++++++++++++++
 1 files changed, 125 insertions(+), 0 deletions(-)
 create mode 100644 include/asm-generic/global_data.h
include/asm-generic/global_data.h new file +125 -0
new file mode 100644
index 0000000..16fee5a
@@ -0,0 +1,125 @@
+/*
+ * (C) Copyright 2002-2010
+ * Wolfgang Denk, DENX Software Engineering, wd at denx.de.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef	__ASM_GENERIC_GBL_DATA_H
+#define __ASM_GENERIC_GBL_DATA_H
+/*
+ * The following data structure is placed in some memory which is
+ * available very early after boot (like DPRAM on MPC8xx/MPC82xx, or
+ * some locked parts of the data cache) to allow for a minimum set of
+ * global variables during system initialization (until we have set
+ * up the memory controller so that we can use RAM).
+ *
+ * Keep it *SMALL* and remember to set GENERATED_GBL_DATA_SIZE > sizeof(gd_t)
+ *
+ * sjg at chromium.org: Well it would be nice to have a generic one of these
+ * since so many fields are similar. But it means that everyone architecture
+ * will want to add its own nutty fields. Perhaps that is no bad thing since
+ * it shows up inconsistences and might produce downward pressure on the
+ * number of fields.
+ */
+
+#ifndef __ASSEMBLY__
+typedef struct global_data {
+	bd_t		*bd;
+	unsigned long	flags;
+	unsigned long	baudrate;
+	unsigned long	have_console;	/* serial_init() was called */
+#ifdef CONFIG_PRE_CONSOLE_BUFFER
+	unsigned long	precon_buf_idx;	/* Pre-Console buffer index */
+#endif
+	unsigned long	env_addr;	/* Address  of Environment struct */
+	unsigned long	env_valid;	/* Checksum of Environment valid? */
+	unsigned long	fb_base;	/* base address of frame buffer */
+#ifdef CONFIG_FSL_ESDHC
+	unsigned long	sdhc_clk;
+#endif
+	/* Here begins ARM-specific things. Needs discussion */
+#ifdef CONFIG_AT91FAMILY
+	/* "static data" needed by at91's clock.c */
+	unsigned long	cpu_clk_rate_hz;
+	unsigned long	main_clk_rate_hz;
+	unsigned long	mck_rate_hz;
+	unsigned long	plla_rate_hz;
+	unsigned long	pllb_rate_hz;
+	unsigned long	at91_pllb_usb_init;
+#endif
+#ifdef CONFIG_ARM
+	/* "static data" needed by most of timer.c on ARM platforms */
+	unsigned long	timer_rate_hz;
+	unsigned long	tbl;
+	unsigned long	tbu;
+	unsigned long long	timer_reset_value;
+	unsigned long	lastinc;
+#endif
+#ifdef CONFIG_IXP425
+	unsigned long	timestamp;
+#endif
+	/* TODO: is this the same as relocaddr, or something else? */
+	unsigned long	dest_addr;	/* Post-relocation address of U-Boot */
+	unsigned long	dest_addr_sp;
+
+	unsigned long	relocaddr;	/* Start address of U-Boot in RAM */
+	phys_size_t	ram_size;	/* RAM size */
+	unsigned long	mon_len;	/* monitor len */
+	unsigned long	irq_sp;		/* irq stack pointer */
+	unsigned long	start_addr_sp;	/* start_addr_stackpointer */
+	unsigned long	reloc_off;
+#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
+	unsigned long	tlb_addr;
+#endif
+	struct global_data *new_gd;	/* relocated global data */
+	const void	*fdt_blob;	/* Our device tree, NULL if none */
+	void		**jt;		/* jump table */
+	char		env_buf[32];	/* buffer for getenv() before reloc. */
+#if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
+	unsigned long	post_log_word; /* Record POST activities */
+	unsigned long	post_log_res; /* success of POST test */
+	unsigned long	post_init_f_time; /* When post_init_f started */
+#endif
+} gd_t;
+#endif
+
+/*
+ * Global Data Flags
+ */
+#define	GD_FLG_RELOC		0x00001	/* Code was relocated to RAM	   */
+#define	GD_FLG_DEVINIT		0x00002	/* Devices have been initialized   */
+#define	GD_FLG_SILENT		0x00004	/* Silent mode			   */
+#define	GD_FLG_POSTFAIL		0x00008	/* Critical POST test failed	   */
+#define	GD_FLG_POSTSTOP		0x00010	/* POST seqeunce aborted	   */
+#define	GD_FLG_LOGINIT		0x00020	/* Log Buffer has been initialized */
+#define GD_FLG_DISABLE_CONSOLE	0x00040	/* Disable console (in & out)	   */
+#define GD_FLG_ENV_READY	0x00080	/* Env. imported into hash table   */
+
+/* ARM uses r8 to hold the global data pointer */
+#ifdef CONFIG_ARM
+#define DECLARE_GLOBAL_DATA_PTR     register volatile gd_t *gd asm ("r8")
+
+#else /* All other architectures */
+
+#define XTRN_DECLARE_GLOBAL_DATA_PTR    extern
+#define DECLARE_GLOBAL_DATA_PTR     XTRN_DECLARE_GLOBAL_DATA_PTR gd_t *gd
+#endif
+
+#endif /* __ASM_GENERIC_GBL_DATA_H */
Signature · 1 line
1.7.3.1
#2 lore raw

RFC PATCH 1/19 Introduce generic global_data

Dear Simon,

Quoted 3 lines · Simon Glass

We want to unify the global_data structure. Most fields are common across architectures, but there are a fair number of SOC-specific additions. It isn't clear how best to deal with these, but for now we just use #ifdef.

I would like to see some more 'clustering' here. Especially the timer stuff is implementation specific and should therefore not coded directly but with some pointer to the specific stuff i.e. introduce some timer_t which is specific for arm in general and maybe has some more specialization for atmel devices or what else and just save a pointer to that struct in gd_t like it is done with bd_t.
Well maybe having a pointer here is stated critical so we could just insert the struct directly and let the compiler decide about the size (BTW this could be done with bd_t now too cause we have a pre-calculated size of gd_t since some time, saves some little steps when instantiating gd_t when running).
Beside that we could also introduce some more structs holding specific stuff i.e. console_t, reloc_t, ...
(but yes, it should be done in a second step ...)

What do you think about that?

best regards

Andreas Bie?mann

#3 lore raw

RFC PATCH 1/19 Introduce generic global_data

Hi Andreas,

Quoted 7 lines · Andreas Bie?mann

Dear Simon,

Quoted 3 lines · Simon Glass

We want to unify the global_data structure. Most fields are common across architectures, but there are a fair number of SOC-specific additions. It isn't clear how best to deal with these, but for now we just use #ifdef.

Sorry your email got a little buried this week.

Quoted 6 lines

I would like to see some more 'clustering' here. Especially the timer stuff is implementation specific and should therefore not coded directly but with some pointer to the specific stuff i.e. introduce some timer_t which is specific for arm in general and maybe has some more specialization for atmel devices or what else and just save a pointer to that struct in gd_t like it is done with bd_t.

Actually I wonder if we should an architecture-specific structure, something like

struct global_data {
/* generic things first */
ulong baud_rate;
ulong ram_size;
/* hopefully lots of other things that are mostly common */

/* architecture-specific things */
struct arch_global_data arch;
};

struct arch_global_data can be defined in include/asm/global_data.h before it includes include/asm-generic/global_data.h, or the other way around might be better.

One thing I notice is that some architectures share some fields, and others omit them.I feel we should include them at the global level if at least 2 architectures need them. This means that the 'minimal' architectures with hardly any fields will have quite a few unused fields in global_data. I don't think that matters, and the use will increase as that arch gets more functionality.

Quoted 5 lines

Well maybe having a pointer here is stated critical so we could just insert the struct directly and let the compiler decide about the size (BTW this could be done with bd_t now too cause we have a pre-calculated size of gd_t since some time, saves some little steps when instantiating gd_t when running).

Yes I agree that just including the structure seems better. A pointer is slower and we just point to a place very close anyway.

It would be nice to subsume bd_t into global_data.

Quoted 5 lines

Beside that we could also introduce some more structs holding specific stuff i.e. console_t, reloc_t, ...
(but yes, it should be done in a second step ...)

What do you think about that?

Certainly agree for reloc and perhaps there are other cases too. It is far too long at present. Something to think about.

For now I would prefer to do nothing on either point, since bringing everything into one place shows up the conflicts and similarities. Part of the purpose of the generic board effort is to minimise these, and they are hard to spot if they are all in separate files.

But when we get through this, and find that there are things which genuinely are specific to a single arch, then I think breaking them out is reasonable, hopefully combined with joining global_data and bd_t.

Regards,
Simon

Quoted 4 lines

best regards

Andreas Bie?mann

#4 lore raw

RFC PATCH 1/19 Introduce generic global_data

Hi Simon,

Quoted 24 lines · Simon Glass

Hi Andreas,

Quoted 7 lines · Andreas Bie?mann

Dear Simon,

Quoted 3 lines · Simon Glass

We want to unify the global_data structure. Most fields are common across architectures, but there are a fair number of SOC-specific additions. It isn't clear how best to deal with these, but for now we just use #ifdef.

Sorry your email got a little buried this week.

Quoted 6 lines

I would like to see some more 'clustering' here. Especially the timer stuff is implementation specific and should therefore not coded directly but with some pointer to the specific stuff i.e. introduce some timer_t which is specific for arm in general and maybe has some more specialization for atmel devices or what else and just save a pointer to that struct in gd_t like it is done with bd_t.

Actually I wonder if we should an architecture-specific structure, something like

Quoted 9 lines
struct global_data {
   /* generic things first */
   ulong baud_rate;
   ulong ram_size;
   /* hopefully lots of other things that are mostly common */

   /* architecture-specific things */
   struct arch_global_data arch;
};

This makes auto-generated asm offsets a little trickier I think

Quoted 3 lines

struct arch_global_data can be defined in include/asm/global_data.h before it includes include/asm-generic/global_data.h, or the other way around might be better.

include/asm-generic/global_data.h would include include/asm/global_data.h

But what of the corner case that an arch has no specific global data?

Quoted 6 lines

One thing I notice is that some architectures share some fields, and others omit them.I feel we should include them at the global level if at least 2 architectures need them. This means that the 'minimal' architectures with hardly any fields will have quite a few unused fields in global_data. I don't think that matters, and the use will

I would not bank on that, and I think you will get strong objection from Wolfgang if you try to litter global data with members that are not strictly necessary

Quoted 10 lines

increase as that arch gets more functionality.

Quoted 5 lines

Well maybe having a pointer here is stated critical so we could just insert the struct directly and let the compiler decide about the size (BTW this could be done with bd_t now too cause we have a pre-calculated size of gd_t since some time, saves some little steps when instantiating gd_t when running).

Yes I agree that just including the structure seems better. A pointer is slower and we just point to a place very close anyway.

Not so fast - The idea is that gd is writeable pre-relocation and therefore can be instantiated in the very limit pre-SDRAM environment such as the CPU cache. bd is not needed until after SDRAM has been initialised, so it's size constraints aren't so bad.

Quoted 2 lines

It would be nice to subsume bd_t into global_data.

NAK

Quoted 8 lines
Quoted 5 lines

Beside that we could also introduce some more structs holding specific stuff i.e. console_t, reloc_t, ...
(but yes, it should be done in a second step ...)

What do you think about that?

Certainly agree for reloc and perhaps there are other cases too. It is far too long at present. Something to think about.

I agree that gd could be cleaned up - particularly the types - sub-structuring it is probably a bit over the top though (as I mentioned, how will this impact asm-offsets?

Quoted 5 lines

For now I would prefer to do nothing on either point, since bringing everything into one place shows up the conflicts and similarities. Part of the purpose of the generic board effort is to minimise these, and they are hard to spot if they are all in separate files.

Hmm, I'm starting to wonder if we should instead have:

struct gd_generic {
	/* Relocation stuff */

	/* pre-console stuff */

	/* Jump table stuff */
}
struct gd {
	struct gd_generic common;

	/* Arch specific stuff */
}

This eliminates the 'no arch specific global data' corner case

Quoted 5 lines

But when we get through this, and find that there are things which genuinely are specific to a single arch, then I think breaking them out is reasonable, hopefully combined with joining global_data and bd_t.

Regards,

Graeme

#5 lore raw

RFC PATCH 1/19 Introduce generic global_data

Hi Graeme,

Quoted 33 lines · Graeme Russ

Hi Simon,

Quoted 30 lines · Simon Glass

Hi Andreas,

Quoted 7 lines · Andreas Bie?mann

Dear Simon,

Quoted 3 lines · Simon Glass

We want to unify the global_data structure. Most fields are common across architectures, but there are a fair number of SOC-specific additions. It isn't clear how best to deal with these, but for now we just use #ifdef.

Sorry your email got a little buried this week.

Quoted 6 lines

I would like to see some more 'clustering' here. Especially the timer stuff is implementation specific and should therefore not coded directly but with some pointer to the specific stuff i.e. introduce some timer_t which is specific for arm in general and maybe has some more specialization for atmel devices or what else and just save a pointer to that struct in gd_t like it is done with bd_t.

Actually I wonder if we should an architecture-specific structure, something like

struct global_data {
? ?/* generic things first */
? ?ulong baud_rate;
? ?ulong ram_size;
? ?/* hopefully lots of other things that are mostly common */

Quoted 6 lines
Quoted 3 lines

? ?/* architecture-specific things */
? ?struct arch_global_data arch;
};

This makes auto-generated asm offsets a little trickier I think

Yes, not impossible though.

Quoted 8 lines
Quoted 3 lines

struct arch_global_data ?can be defined in include/asm/global_data.h before it includes include/asm-generic/global_data.h, or the other way around might be better.

include/asm-generic/global_data.h would include include/asm/global_data.h

But what of the corner case that an arch has no specific global data?

Define an empty struct? I would prefer not to do any of this yet anyway, until we know that there are plenty of arch-specific things needed.

Quoted 10 lines
Quoted 6 lines

One thing I notice is that some architectures share some fields, and others omit them.I feel we should include them at the global level if at least 2 architectures need them. This means that the 'minimal' architectures with hardly any fields will have quite a few unused fields in global_data. I don't think that matters, and the use will

I would not bank on that, and I think you will get strong objection from Wolfgang if you try to litter global data with members that are not strictly necessary

Well we have two solutions: #ifdefs and the arch-specific struct. But the purpose of this series is rather to try to bring everything out so we can see the commonality and check that it is correct before we start changing it further.

Quoted 9 lines
Quoted 9 lines

increase as that arch gets more functionality.

Quoted 5 lines

Well maybe having a pointer here is stated critical so we could just insert the struct directly and let the compiler decide about the size (BTW this could be done with bd_t now too cause we have a pre-calculated size of gd_t since some time, saves some little steps when instantiating gd_t when running).

Quoted 7 lines
Quoted 2 lines

Yes I agree that just including the structure seems better. A pointer is slower and we just point to a place very close anyway.

Not so fast - The idea is that gd is writeable pre-relocation and therefore can be instantiated in the very limit pre-SDRAM environment such as the CPU cache. bd is not needed until after SDRAM has been initialised, so it's size constraints aren't so bad.

I didn't realise this distinction. Most of the bd_info stuff seems to be things that could just be written into the structure on demand anyway (sort of like a call to arch_get_board_info() or similar) rather than set up at start of day. Perhaps the heavily-used stuff belongs in global_data. Anyway, a discussion for another day.

What is the limit on CPU cache size for SRAM in these architectures? I assume it includes code and data, and is something like 4KB or 8KB at worst?

Quoted 5 lines
Quoted 3 lines

It would be nice to subsume bd_t into global_data.

NAK

For the above reason? Well for now it is a pointer anyway.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Beside that we could also introduce some more structs holding specific stuff i.e. console_t, reloc_t, ...
(but yes, it should be done in a second step ...)

Quoted 9 lines
Quoted 4 lines
Quoted 1 line

What do you think about that?

Certainly agree for reloc and perhaps there are other cases too. It is far too long at present. Something to think about.

I agree that gd could be cleaned up - particularly the types - sub-structuring it is probably a bit over the top though (as I mentioned, how will this impact asm-offsets?

We can deal with this if we need to, but first we need to see what assembler code actually accesses it. With the effort to move relocation etc. into C from assembler, this may reduce.

Quoted 16 lines
Quoted 5 lines

For now I would prefer to do nothing on either point, since bringing everything into one place shows up the conflicts and similarities. Part of the purpose of the generic board effort is to minimise these, and they are hard to spot if they are all in separate files.

Hmm, I'm starting to wonder if we should instead have:

struct gd_generic {
? ? ? ?/* Relocation stuff */

? ? ? ?/* pre-console stuff */

? ? ? ?/* Jump table stuff */
}

Quoted 8 lines

struct gd {
? ? ? ?struct gd_generic common;

? ? ? ?/* Arch specific stuff */
}

This eliminates the 'no arch specific global data' corner case

Maybe. Is it best to #include <asm-generic/global_data.h> instead of <asm/global_data.h> from U-Boot files?

Quoted 9 lines
Quoted 5 lines

But when we get through this, and find that there are things which genuinely are specific to a single arch, then I think breaking them out is reasonable, hopefully combined with joining global_data and bd_t.

Regards,

Graeme

Regards,
Simon

#6 lore raw

RFC PATCH 1/19 Introduce generic global_data

Hi Simon and Graeme,

Quoted 13 lines · Simon Glass

Hi Graeme,

Quoted 10 lines · Graeme Russ

Hi Simon,

Quoted 7 lines · Simon Glass

Hi Andreas,

Quoted 3 lines · Andreas Bie?mann

Dear Simon,

On 28.12.11 07:35, Simon Glass wrote:

<snip discussion about 'how to restructure gd_t' ... should be done later>

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

For now I would prefer to do nothing on either point, since bringing everything into one place shows up the conflicts and similarities. Part of the purpose of the generic board effort is to minimise these, and they are hard to spot if they are all in separate files.

Currently I agree with you both. It would be best to just move all the specific stuff into one file but let the structure as is (from view of SoC/arch). Later on we could shrink it down by one of the mentioned possibilities.

Quoted 10 lines
Quoted 10 lines

Hmm, I'm starting to wonder if we should instead have:

struct gd_generic {
       /* Relocation stuff */

       /* pre-console stuff */

       /* Jump table stuff */
}
Quoted 7 lines
Quoted 7 lines
struct gd {
       struct gd_generic common;

       /* Arch specific stuff */
}

This eliminates the 'no arch specific global data' corner case

Sounds good to me, but if we restructure gd_t in any way we should introduce some ability to version the struct for future changes (keep stand alone apps in mind!).

best regards

Andreas Bie?mann

#7 lore raw

RFC PATCH 1/19 Introduce generic global_data

Hi Andreas,

Quoted 24 lines · Andreas Bie?mann

Hi Simon and Graeme,

Quoted 13 lines · Simon Glass

Hi Graeme,

Quoted 10 lines · Graeme Russ

Hi Simon,

Quoted 7 lines · Simon Glass

Hi Andreas,

Quoted 3 lines · Andreas Bie?mann

Dear Simon,

On 28.12.11 07:35, Simon Glass wrote:

<snip discussion about 'how to restructure gd_t' ... should be done later>

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

For now I would prefer to do nothing on either point, since bringing everything into one place shows up the conflicts and similarities. Part of the purpose of the generic board effort is to minimise these, and they are hard to spot if they are all in separate files.

Quoted 4 lines

Currently I agree with you both. It would be best to just move all the specific stuff into one file but let the structure as is (from view of SoC/arch). Later on we could shrink it down by one of the mentioned possibilities.

OK good.

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

Hmm, I'm starting to wonder if we should instead have:

struct gd_generic {
? ? ? ?/* Relocation stuff */

? ? ? ?/* pre-console stuff */

? ? ? ?/* Jump table stuff */
}

struct gd {
? ? ? ?struct gd_generic common;

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

? ? ? ?/* Arch specific stuff */
}

This eliminates the 'no arch specific global data' corner case

Sounds good to me, but if we restructure gd_t in any way we should introduce some ability to version the struct for future changes (keep stand alone apps in mind!).

Yes - in fact just moving to generic board makes the API incompatible. I suspect I should increment something somewhere - will take a look.

Regards,
Simon

Quoted 4 lines

best regards

Andreas Bie?mann

#8 lore raw

RFC PATCH 2/19 Make relocation functions global

In reply to Simon Glass

We want to be able to call relocations functions from our new board code, so make them global and add to the header.

---
 common/reloc.c  |   29 ++++++++++++++++++++++++++---
 include/reloc.h |   16 ++++++++++++++++
 2 files changed, 42 insertions(+), 3 deletions(-)
common/reloc.c +26 -3
index 2344e98..ec0d72f 100644
@@ -28,7 +28,15 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static int reloc_make_copy(void)
+int reloc_calculate_dest(void)
+{
+	gd->relocaddr = gd->dest_addr;
+	gd->reloc_off = gd->dest_addr - CONFIG_SYS_TEXT_BASE;
+	debug("relocation Offset is: %08lx\n", gd->reloc_off);
+	return 0;
+}
+
+int reloc_make_copy(void)
 {
 	char *dst_addr = (char *)gd->relocaddr;
 
@@ -51,7 +59,7 @@ static int reloc_make_copy(void)
 	return 0;
 }
 
-static int reloc_elf(void)
+int reloc_elf(void)
 {
 #ifndef CONFIG_SPL_BUILD
 	const Elf32_Rel *ptr, *end;
@@ -76,7 +84,7 @@ static int reloc_elf(void)
 	return 0;
 }
 
-static int reloc_clear_bss(void)
+int reloc_clear_bss(void)
 {
 	char *dst_addr = (char *)_start + _bss_start_ofs;
 	size_t size = _bss_end_ofs - _bss_start_ofs;
@@ -93,6 +101,20 @@ static int reloc_clear_bss(void)
 	return 0;
 }
 
+#ifndef CONFIG_SYS_LEGACY_BOARD
+int reloc_jump_to_copy(void)
+{
+	/* TODO: tidy this up since we don't want a separate nand_boot() */
+#ifdef CONFIG_NAND_SPL
+	nand_boot();
+#else
+	proc_call_board_init_r(gd->new_gd, gd->dest_addr,
+			       (board_init_r_func)board_init_r,
+			       gd->dest_addr_sp);
+#endif
+}
+#endif
+
 void __relocate_code(ulong dest_addr_sp, gd_t *new_gd, ulong dest_addr)
 {
 	ulong new_board_init_r = (uintptr_t)board_init_r + gd->reloc_off;
@@ -106,6 +128,7 @@ void __relocate_code(ulong dest_addr_sp, gd_t *new_gd, ulong dest_addr)
 
 	debug("relocation complete: starting from board_init_r() at %lx\n",
 	      new_board_init_r);
+
 	/* TODO: tidy this up since we don't want a separate nand_boot() */
 #ifdef CONFIG_NAND_SPL
 	nand_boot();
include/reloc.h +16 -0
index 79c0a24..adaa3bc 100644
@@ -51,4 +51,20 @@ void proc_call_board_init_r(gd_t *new_gd, ulong dest_addr,
  */
 void relocate_code(ulong dest_sp, gd_t *new_gd, ulong dest_addr)
 		__attribute__ ((noreturn));
+
+/* Work out the destination code address */
+int reloc_calculate_dest(void);
+
+/* Make a copy of the U-Boot code in the new location */
+int reloc_make_copy(void);
+
+/* Fixup relocations in the new code */
+int reloc_elf(void);
+
+/* Clear the new BSS region */
+int reloc_clear_bss(void);
+
+/* Jump to the new relocated U-Boot code */
+int reloc_jump_to_copy(void);
+
 #endif
Signature · 1 line
1.7.3.1
#9 lore raw

RFC PATCH 3/19 Add basic initcall implementation

In reply to Simon Glass
---
 include/initcall.h |   25 +++++++++++++++++++++++++
 lib/Makefile       |    1 +
 lib/initcall.c     |   41 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+), 0 deletions(-)
 create mode 100644 include/initcall.h
 create mode 100644 lib/initcall.c
include/initcall.h new file +25 -0
new file mode 100644
index 0000000..9e54fa5
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2011 The Chromium OS Authors.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+typedef int (*init_fnc_t)(void);
+
+int initcall_run_list(init_fnc_t init_sequence[]);
lib/Makefile +1 -0
index 54708c2..89ddeda 100644
@@ -40,6 +40,7 @@ COBJS-y += display_options.o
 COBJS-y += errno.o
 COBJS-$(CONFIG_OF_CONTROL) += fdtdec.o
 COBJS-$(CONFIG_GZIP) += gunzip.o
+COBJS-y += initcall.o
 COBJS-y += hashtable.o
 COBJS-$(CONFIG_LMB) += lmb.o
 COBJS-y += ldiv.o
lib/initcall.c new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
1.7.3.1
#10 lore raw

RFC PATCH 4/19 define CONFIG_SYS_LEGACY_BOARD everywhere

In reply to Simon Glass

We are introducing a new unified board setup and we want this to be the default. So we need to opt all architectures out first.

---
 README                    |    5 +++++
 arch/arm/config.mk        |    3 +++
 arch/avr32/config.mk      |    3 +++
 arch/blackfin/config.mk   |    3 +++
 arch/m68k/config.mk       |    3 +++
 arch/microblaze/config.mk |    3 +++
 arch/mips/config.mk       |    3 +++
 arch/nds32/config.mk      |    3 +++
 arch/nios2/config.mk      |    3 +++
 arch/powerpc/config.mk    |    3 +++
 arch/sandbox/config.mk    |    3 +++
 arch/sh/config.mk         |    3 +++
 arch/sparc/config.mk      |    3 +++
 arch/x86/config.mk        |    3 +++
 config.mk                 |    4 ++++
 15 files changed, 48 insertions(+), 0 deletions(-)
README +5 -0
index a076dbf..bf56318 100644
@@ -2745,6 +2745,11 @@ Configuration Settings:
 	This makes U-Boot skip relocation for those architectures which
 	don't support it. It is normally defined in arch/xxx/config.mk
 
+- CONFIG_SYS_LEGACY_BOARD
+	This selects the legacy architecture-specific board system
+	instead of the cross-architecture board. It is intended to move
+	away from this over time.
+
 The following definitions that deal with the placement and management
 of environment data (variable area); in general, we support the
 following configurations:
arch/arm/config.mk +3 -0
index 45f9dca..31e9ef9 100644
@@ -33,6 +33,9 @@ endif
 
 PLATFORM_CPPFLAGS += -DCONFIG_ARM -D__ARM__
 
+# Move to unified board system later
+CONFIG_SYS_LEGACY_BOARD := y
+
 # Explicitly specifiy 32-bit ARM ISA since toolchain default can be -mthumb:
 PF_CPPFLAGS_ARM := $(call cc-option,-marm,)
 
arch/avr32/config.mk +3 -0
index 1995983..07d8a6f 100644
@@ -34,3 +34,6 @@ LDSCRIPT			= $(SRCTREE)/$(CPUDIR)/u-boot.lds
 
 # We use legacy relocation for now
 CONFIG_SYS_SKIP_RELOC := y
+
+# Move to unified board system later
+CONFIG_SYS_LEGACY_BOARD := y
arch/blackfin/config.mk +3 -0
index 56047c8..ec7ae4a 100644
@@ -40,6 +40,9 @@ PLATFORM_CPPFLAGS += -DCONFIG_BLACKFIN
 # Blackfin does not do relocation
 CONFIG_SYS_SKIP_RELOC := y
 
+# Move to unified board system later
+CONFIG_SYS_LEGACY_BOARD := y
+
 LDFLAGS_FINAL += --gc-sections
 LDFLAGS += -m elf32bfin
 PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections
arch/m68k/config.mk +3 -0
index 52bfc81..b5819f1 100644
@@ -32,3 +32,6 @@ LDFLAGS_FINAL                  += --gc-sections
 
 # We use legacy relocation for now
 CONFIG_SYS_SKIP_RELOC := y
+
+# Move to unified board system later
+CONFIG_SYS_LEGACY_BOARD := y
arch/microblaze/config.mk +3 -0
index 7645f2e..148107d 100644
@@ -32,3 +32,6 @@ PLATFORM_CPPFLAGS += -ffixed-r31 -D__microblaze__
 
 # Microblaze does not do relocation
 CONFIG_SYS_SKIP_RELOC := y
+
+# Move to unified board system later
+CONFIG_SYS_LEGACY_BOARD := y
arch/mips/config.mk +3 -0
index 832b93f..0c7cbd7 100644
@@ -27,6 +27,9 @@ CONFIG_STANDALONE_LOAD_ADDR ?= 0x80200000 -T mips.lds
 
 PLATFORM_CPPFLAGS += -DCONFIG_MIPS -D__MIPS__
 
+# Move to unified board system later
+CONFIG_SYS_LEGACY_BOARD := y
+
 #
 # From Linux arch/mips/Makefile
 #
arch/nds32/config.mk +3 -0
index 4a4499b..0c18d5b 100644
@@ -36,3 +36,6 @@ LDFLAGS_u-boot		= --gc-sections --relax
 
 # We use legacy relocation for now
 CONFIG_SYS_SKIP_RELOC := y
+
+# Move to unified board system later
+CONFIG_SYS_LEGACY_BOARD := y
arch/nios2/config.mk +3 -0
index cde7f82..240a4f8 100644
@@ -34,3 +34,6 @@ PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections
 
 # NIOS2 does not do relocation
 CONFIG_SYS_SKIP_RELOC := y
+
+# Move to unified board system later
+CONFIG_SYS_LEGACY_BOARD := y
arch/powerpc/config.mk +3 -0
index eba562f..6a4f59e 100644
@@ -29,6 +29,9 @@ PLATFORM_RELFLAGS += -fpic -mrelocatable -ffunction-sections -fdata-sections
 PLATFORM_CPPFLAGS += -DCONFIG_PPC -D__powerpc__
 PLATFORM_LDFLAGS  += -n
 
+# Move to unified board system later
+CONFIG_SYS_LEGACY_BOARD := y
+
 #
 # When cross-compiling on NetBSD, we have to define __PPC__ or else we
 # will pick up a va_list declaration that is incompatible with the
arch/sandbox/config.mk +3 -0
index d71326f..a355f84 100644
@@ -22,3 +22,6 @@ PLATFORM_LIBS += -lrt
 
 # Sandbox does not do relocation
 CONFIG_SYS_SKIP_RELOC := y
+
+# Move to unified board system later
+CONFIG_SYS_LEGACY_BOARD := y
arch/sh/config.mk +3 -0
index 48a7b37..875ad84 100644
@@ -34,3 +34,6 @@ LDFLAGS_FINAL = --gc-sections
 
 # SH does not do relocation
 CONFIG_SYS_SKIP_RELOC := y
+
+# Move to unified board system later
+CONFIG_SYS_LEGACY_BOARD := y
arch/sparc/config.mk +3 -0
index 032659c..8955ba6 100644
@@ -29,3 +29,6 @@ PLATFORM_CPPFLAGS += -DCONFIG_SPARC -D__sparc__
 
 # Sparc does not do relocation
 CONFIG_SYS_SKIP_RELOC := y
+
+# Move to unified board system later
+CONFIG_SYS_LEGACY_BOARD := y
arch/x86/config.mk +3 -0
index 11f3d18..cb8865a 100644
@@ -51,3 +51,6 @@ export USE_PRIVATE_LIBGCC=$(shell dirname $(PREFIXED_LIBGCC))
 
 # We use legacy relocation for now
 CONFIG_SYS_SKIP_RELOC := y
+
+# Move to unified board system later
+CONFIG_SYS_LEGACY_BOARD := y
config.mk +4 -0
index ddaa477..db5b909 100644
@@ -206,6 +206,10 @@ ifeq ($(CONFIG_SPL_BUILD),y)
 CPPFLAGS += -DCONFIG_SPL_BUILD
 endif
 
+ifeq ($(CONFIG_SYS_LEGACY_BOARD),y)
+CPPFLAGS += -DCONFIG_SYS_LEGACY_BOARD
+endif
+
 ifneq ($(RESET_VECTOR_ADDRESS),)
 CPPFLAGS += -DRESET_VECTOR_ADDRESS=$(RESET_VECTOR_ADDRESS)
 endif
Signature · 1 line
1.7.3.1
#11 lore raw

RFC PATCH 5/19 Add generic post-relocation board_r.c

In reply to Simon Glass

This file handles common post-relocation init for boards which use the generic framework.

---
 board/freescale/p2020come/Makefile |    4 +
 common/Makefile                    |    6 +-
 common/board_r.c                   |  382 ++++++++++++++++++++++++++++++++++++
 3 files changed, 391 insertions(+), 1 deletions(-)
 create mode 100644 common/board_r.c
board/freescale/p2020come/Makefile +4 -0
index ba87904..d0e1997 100644
@@ -29,6 +29,10 @@ COBJS-y			+= ddr.o
 COBJS-y			+= law.o
 COBJS-y			+= tlb.o
 
+ifndef CONFIG_SYS_LEGACY_BOARD
+COBJS	+= board_r.o
+endif
+
 SRCS	:= $(SOBJS:.o=.S) $(COBJS-y:.o=.c)
 OBJS	:= $(addprefix $(obj),$(COBJS-y))
 SOBJS	:= $(addprefix $(obj),$(SOBJS))
common/Makefile +5 -1
index 3801c28..90601e6 100644
@@ -36,6 +36,11 @@ COBJS-y += s_record.o
 COBJS-$(CONFIG_SERIAL_MULTI) += serial.o
 COBJS-y += xyzModem.o
 
+# boards
+ifeq ($(CONFIG_SYS_LEGACY_BOARD),)
+COBJS-y += board_r.o
+endif
+
 # core command
 COBJS-y += cmd_boot.o
 COBJS-$(CONFIG_CMD_BOOTM) += cmd_bootm.o
@@ -193,7 +198,6 @@ ifndef CONFIG_SYS_SKIP_RELOC
 COBJS-y += reloc.o
 endif
 
-
 COBJS	:= $(sort $(COBJS-y))
 XCOBJS	:= $(sort $(XCOBJS-y))
 SRCS	:= $(COBJS:.o=.c) $(XCOBJS:.o=.c)
common/board_r.c new file +382 -0

382 lines not on this page · raw message

Signature · 1 line
1.7.3.1
#12 lore raw

RFC PATCH 6/19 Add generic pre-relocation board_f.c

In reply to Simon Glass

This file handles common pre-relocation init for boards which use the generic framework.

It starts up the console, DRAM, performs relocation and then jumps to post-relocation init.

---
 board/freescale/p2020come/Makefile |    2 +
 common/Makefile                    |    1 +
 common/board_f.c                   |  430 ++++++++++++++++++++++++++++++++++++
 3 files changed, 433 insertions(+), 0 deletions(-)
 create mode 100644 common/board_f.c
board/freescale/p2020come/Makefile +2 -0
index d0e1997..52538fd 100644
@@ -31,6 +31,8 @@ COBJS-y			+= tlb.o
 
 ifndef CONFIG_SYS_LEGACY_BOARD
 COBJS	+= board_r.o
+COBJS	+= board_f.o
+COBJS	+= reloc.o
 endif
 
 SRCS	:= $(SOBJS:.o=.S) $(COBJS-y:.o=.c)
common/Makefile +1 -0
index 90601e6..008f131 100644
@@ -38,6 +38,7 @@ COBJS-y += xyzModem.o
 
 # boards
 ifeq ($(CONFIG_SYS_LEGACY_BOARD),)
+COBJS-y += board_f.o
 COBJS-y += board_r.o
 endif
 
common/board_f.c new file +430 -0

430 lines not on this page · raw message

Signature · 1 line
1.7.3.1
#13 lore raw

RFC PATCH 7/19 Add spl load feature

In reply to Simon Glass
---
 common/board_f.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
common/board_f.c +22 -0
index f9eb4ca..06317ed 100644
@@ -277,6 +277,7 @@ static int reserve_uboot(void)
 	return 0;
 }
 
+#ifndef CONFIG_SPL_BUILD
 /* reserve memory for malloc() area */
 static int reserve_malloc(void)
 {
@@ -295,6 +296,7 @@ static int reserve_board(void)
 			sizeof(bd_t), gd->dest_addr_sp);
 	return 0;
 }
+#endif
 
 static int setup_machine(void)
 {
@@ -313,6 +315,7 @@ static int reserve_global_data(void)
 	return 0;
 }
 
+#ifndef CONFIG_SPL_BUILD
 static int reserve_stacks(void)
 {
 	/* setup stackpointer for exeptions */
@@ -329,6 +332,17 @@ static int reserve_stacks(void)
 	gd->dest_addr_sp &= ~0x07;
 	return 0;
 }
+#endif
+
+#ifdef CONFIG_SPL_BUILD
+static int reserve_stacks_spl(void)
+{
+	/* Why not -= ? */
+	gd->dest_addr_sp += 128;	/* leave 32 words for abort-stack   */
+	gd->irq_sp = gd->dest_addr_sp;
+	return 0;
+}
+#endif
 
 #ifdef CONFIG_POST
 static int init_post(void)
@@ -392,18 +406,26 @@ static init_fnc_t init_sequence_f[] = {
 	reserve_lcd,
 #endif
 	reserve_uboot,
+#ifndef CONFIG_SPL_BUILD
 	reserve_malloc,
 	reserve_board,
+#endif
 	setup_machine,
 	reserve_global_data,
+#ifdef CONFIG_SPL_BUILD
+	reserve_stacks_spl,
+#else
 	reserve_stacks,
+#endif
 #ifdef CONFIG_POST
 	init_post,
 #endif
 	report_dram_config,
 	reloc_calculate_dest,
 	reloc_make_copy,
+#ifndef CONFIG_SPL_BUILD
 	reloc_elf,
+#endif
 	reloc_clear_bss,
 	reloc_jump_to_copy,
 	NULL,
Signature · 1 line
1.7.3.1
#14 lore raw

RFC PATCH 8/19 switch ARM over to generic board

In reply to Simon Glass
---
 arch/arm/config.mk                 |    3 ---
 arch/arm/include/asm/global_data.h |    8 ++++++++
 arch/arm/lib/Makefile              |    2 ++
 3 files changed, 10 insertions(+), 3 deletions(-)
arch/arm/config.mk +0 -3
index 31e9ef9..45f9dca 100644
@@ -33,9 +33,6 @@ endif
 
 PLATFORM_CPPFLAGS += -DCONFIG_ARM -D__ARM__
 
-# Move to unified board system later
-CONFIG_SYS_LEGACY_BOARD := y
-
 # Explicitly specifiy 32-bit ARM ISA since toolchain default can be -mthumb:
 PF_CPPFLAGS_ARM := $(call cc-option,-marm,)
 
arch/arm/include/asm/global_data.h +8 -0
index c3ff789..e31e06a 100644
@@ -23,6 +23,13 @@
 
 #ifndef	__ASM_GBL_DATA_H
 #define __ASM_GBL_DATA_H
+
+#ifndef CONFIG_SYS_LEGACY_BOARD
+
+/* Use the generic board which requires a unified global_data */
+#include <asm-generic/global_data.h>
+
+#else
 /*
  * The following data structure is placed in some memory which is
  * available very early after boot (like DPRAM on MPC8xx/MPC82xx, or
@@ -99,5 +106,6 @@ typedef	struct	global_data {
 #define GD_FLG_ENV_READY	0x00080	/* Environment imported into hash table	*/
 
 #define DECLARE_GLOBAL_DATA_PTR     register volatile gd_t *gd asm ("r8")
+#endif /* CONFIG_SYS_LEGACY_BOARD */
 
 #endif /* __ASM_GBL_DATA_H */
arch/arm/lib/Makefile +2 -0
index 213c76f..fd3b331 100644
@@ -37,7 +37,9 @@ GLSOBJS	+= _umodsi3.o
 
 GLCOBJS	+= div0.o
 
+ifeq ($(CONFIG_SYS_LEGACY_BOARD),y)
 COBJS-y	+= board.o
+endif
 COBJS-y	+= bootm.o
 COBJS-y	+= cache.o
 COBJS-y	+= cache-cp15.o
Signature · 1 line
1.7.3.1
#15 lore raw

RFC PATCH 9/19 arm: Remove unused code in board.c, global_data.h

In reply to Simon Glass

Now that ARM uses the generic board, we don't need this code.

---
 arch/arm/include/asm/global_data.h |   81 -----
 arch/arm/lib/Makefile              |    2 -
 arch/arm/lib/board.c               |  622 +-----------------------------------
 3 files changed, 9 insertions(+), 696 deletions(-)
arch/arm/include/asm/global_data.h +0 -81
index e31e06a..0251aad 100644
@@ -24,88 +24,7 @@
 #ifndef	__ASM_GBL_DATA_H
 #define __ASM_GBL_DATA_H
 
-#ifndef CONFIG_SYS_LEGACY_BOARD
-
 /* Use the generic board which requires a unified global_data */
 #include <asm-generic/global_data.h>
 
-#else
-/*
- * The following data structure is placed in some memory which is
- * available very early after boot (like DPRAM on MPC8xx/MPC82xx, or
- * some locked parts of the data cache) to allow for a minimum set of
- * global variables during system initialization (until we have set
- * up the memory controller so that we can use RAM).
- *
- * Keep it *SMALL* and remember to set GENERATED_GBL_DATA_SIZE > sizeof(gd_t)
- */
-
-typedef	struct	global_data {
-	bd_t		*bd;
-	unsigned long	flags;
-	unsigned long	baudrate;
-	unsigned long	have_console;	/* serial_init() was called */
-#ifdef CONFIG_PRE_CONSOLE_BUFFER
-	unsigned long	precon_buf_idx;	/* Pre-Console buffer index */
-#endif
-	unsigned long	env_addr;	/* Address  of Environment struct */
-	unsigned long	env_valid;	/* Checksum of Environment valid? */
-	unsigned long	fb_base;	/* base address of frame buffer */
-#ifdef CONFIG_FSL_ESDHC
-	unsigned long	sdhc_clk;
-#endif
-#ifdef CONFIG_AT91FAMILY
-	/* "static data" needed by at91's clock.c */
-	unsigned long	cpu_clk_rate_hz;
-	unsigned long	main_clk_rate_hz;
-	unsigned long	mck_rate_hz;
-	unsigned long	plla_rate_hz;
-	unsigned long	pllb_rate_hz;
-	unsigned long	at91_pllb_usb_init;
-#endif
-#ifdef CONFIG_ARM
-	/* "static data" needed by most of timer.c on ARM platforms */
-	unsigned long	timer_rate_hz;
-	unsigned long	tbl;
-	unsigned long	tbu;
-	unsigned long long	timer_reset_value;
-	unsigned long	lastinc;
-#endif
-#ifdef CONFIG_IXP425
-	unsigned long	timestamp;
-#endif
-	unsigned long	relocaddr;	/* Start address of U-Boot in RAM */
-	phys_size_t	ram_size;	/* RAM size */
-	unsigned long	mon_len;	/* monitor len */
-	unsigned long	irq_sp;		/* irq stack pointer */
-	unsigned long	start_addr_sp;	/* start_addr_stackpointer */
-	unsigned long	reloc_off;
-#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
-	unsigned long	tlb_addr;
-#endif
-	const void	*fdt_blob;	/* Our device tree, NULL if none */
-	void		**jt;		/* jump table */
-	char		env_buf[32];	/* buffer for getenv() before reloc. */
-#if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
-	unsigned long	post_log_word; /* Record POST activities */
-	unsigned long	post_log_res; /* success of POST test */
-	unsigned long	post_init_f_time; /* When post_init_f started */
-#endif
-} gd_t;
-
-/*
- * Global Data Flags
- */
-#define	GD_FLG_RELOC		0x00001	/* Code was relocated to RAM		*/
-#define	GD_FLG_DEVINIT		0x00002	/* Devices have been initialized	*/
-#define	GD_FLG_SILENT		0x00004	/* Silent mode				*/
-#define	GD_FLG_POSTFAIL		0x00008	/* Critical POST test failed		*/
-#define	GD_FLG_POSTSTOP		0x00010	/* POST seqeunce aborted		*/
-#define	GD_FLG_LOGINIT		0x00020	/* Log Buffer has been initialized	*/
-#define GD_FLG_DISABLE_CONSOLE	0x00040	/* Disable console (in & out)		*/
-#define GD_FLG_ENV_READY	0x00080	/* Environment imported into hash table	*/
-
-#define DECLARE_GLOBAL_DATA_PTR     register volatile gd_t *gd asm ("r8")
-#endif /* CONFIG_SYS_LEGACY_BOARD */
-
 #endif /* __ASM_GBL_DATA_H */
arch/arm/lib/Makefile +0 -2
index fd3b331..213c76f 100644
@@ -37,9 +37,7 @@ GLSOBJS	+= _umodsi3.o
 
 GLCOBJS	+= div0.o
 
-ifeq ($(CONFIG_SYS_LEGACY_BOARD),y)
 COBJS-y	+= board.o
-endif
 COBJS-y	+= bootm.o
 COBJS-y	+= cache.o
 COBJS-y	+= cache-cp15.o
arch/arm/lib/board.c +9 -613

632 lines not on this page · raw message

Signature · 1 line
1.7.3.1
#16 lore raw

RFC PATCH 10/19 Add CONFIG_SYS_SYM_OFFSETS to support offset symbols

In reply to Simon Glass

Link symbols as created by the link script can either be absolute or relative to the text start. This option switches between the two options so that we can support both.

As we convert architectures over to generic board, we can see if this option is actually needed, or whether it is possible to unify this feature also.

---
 common/board_f.c               |    9 +++++++++
 common/reloc.c                 |   17 ++++++++++++++++-
 include/asm-generic/sections.h |   11 +++++++++++
 3 files changed, 36 insertions(+), 1 deletions(-)
common/board_f.c +9 -0
index 06317ed..17fcf08 100644
@@ -107,8 +107,13 @@ static int display_banner(void)
 {
 	ulong bss_start, bss_end;
 
+#ifdef CONFIG_SYS_SYM_OFFSETS
 	bss_start = _bss_start_ofs + _TEXT_BASE;
 	bss_end = _bss_end_ofs + _TEXT_BASE;
+#else
+	bss_start = (ulong)&__bss_start;
+	bss_end = (ulong)&__bss_end;
+#endif
 	printf("\n\n%s\n\n", version_string);
 	debug("U-Boot code: %08lX -> %08lX  BSS: -> %08lX\n",
 	      _TEXT_BASE, bss_start, bss_end);
@@ -165,7 +170,11 @@ static int setup_global_data(void)
 	dmb();
 	memset((void *)gd, '\0', sizeof(gd_t));
 
+#ifdef CONFIG_SYS_SYM_OFFSETS
 	gd->mon_len = _bss_end_ofs;
+#else
+	gd->mon_len = (ulong)&__bss_end - (ulong)&__text_start;
+#endif
 	return 0;
 }
 
common/reloc.c +16 -1
index ec0d72f..564cc67 100644
@@ -43,11 +43,15 @@ int reloc_make_copy(void)
 	/* TODO: __text_start would be better when we have it */
 	char *src_addr = (char *)_start;
 	/* TODO: switch over to __image_copy_end when we can */
+#ifdef CONFIG_SYS_SYM_OFFSETS
 #ifdef CONFIG_SPL_BUILD
 	char *end_addr = src_addr + _image_copy_end_ofs;
 #else
 	char *end_addr = src_addr + _rel_dyn_start_ofs;
 #endif
+#else
+	char *end_addr = (char *)&__data_end;
+#endif
 
 	if (dst_addr != src_addr) {
 		size_t size = end_addr - src_addr;
@@ -64,14 +68,20 @@ int reloc_elf(void)
 #ifndef CONFIG_SPL_BUILD
 	const Elf32_Rel *ptr, *end;
 	Elf32_Addr *addr;
-	char *src_addr = (char *)_start;
 	Elf32_Sym *dynsym;
 	ulong reloc_ofs = gd->reloc_off;
 
 	/* scan the relocation table for relevant entries */
+#ifdef CONFIG_SYS_SYM_OFFSETS
+	char *src_addr = (char *)_start;
+
 	ptr = (Elf32_Rel *)(src_addr + _rel_dyn_start_ofs);
 	end = (Elf32_Rel *)(src_addr + _rel_dyn_end_ofs);
 	dynsym = (Elf32_Sym *)(src_addr + _dynsym_start_ofs);
+#else
+	ptr = (Elf32_Rel *)(&__rel_dyn_start);
+	end = (Elf32_Rel *)(&__rel_dyn_end);
+#endif
 	debug("%s: process reloc entries %p-%p, dynsym at %p\n", __func__,
 	      ptr, end, dynsym);
 	for (; ptr < end; ptr++) {
@@ -86,8 +96,13 @@ int reloc_elf(void)
 
 int reloc_clear_bss(void)
 {
+#ifdef CONFIG_SYS_SYM_OFFSETS
 	char *dst_addr = (char *)_start + _bss_start_ofs;
 	size_t size = _bss_end_ofs - _bss_start_ofs;
+#else
+	ulong *dst_addr = (ulong *)((ulong)&__bss_start + gd->reloc_off);
+	size_t size = (size_t)&__bss_end - (size_t)&__bss_start;
+#endif
 
 #ifndef CONFIG_SPL_BUILD
 	/* No relocation for SPL (TBD: better to set reloc_off to zero) */
include/asm-generic/sections.h +11 -0
index 2935dc1..0dac424 100644
@@ -79,6 +79,17 @@ extern char __image_copy_end[];
  */
 extern void _start(void);
 
+/*
+ * ARM needs to use offsets for symbols, since the values of some symbols
+ * are not resolved prior to relocation (and are just 0). Maybe this can be
+ * resolved, or maybe other architectures are similar, iwc this should be
+ * promoted to an architecture option.
+ */
+#ifdef CONFIG_ARM
+#define CONFIG_SYS_SYM_OFFSETS
+#endif
+
+#ifdef CONFIG_SYS_SYM_OFFSETS
 /* Start/end of the relocation entries, as an offset from _start */
 extern ulong _rel_dyn_start_ofs;
 extern ulong _rel_dyn_end_ofs;
Signature · 1 line
1.7.3.1
#17 lore raw

RFC PATCH 11/19 x86: Remove compiler warning in sc520_timer.c

In reply to Simon Glass

Removes 'set but not used' warning.

---
 arch/x86/cpu/sc520/sc520_timer.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/cpu/sc520/sc520_timer.c +1 -1
index 495a694..7f812dc 100644
@@ -81,7 +81,7 @@ void sc520_udelay(unsigned long usec)
 	long temp;
 
 	temp = readw(&sc520_mmcr->swtmrmilli);
-	temp = readw(&sc520_mmcr->swtmrmicro);
+	temp += readw(&sc520_mmcr->swtmrmicro);
 
 	do {
 		m += readw(&sc520_mmcr->swtmrmilli);
Signature · 1 line
1.7.3.1
#18 lore raw

RFC PATCH 12/19 x86: Remove dead code in eNET

In reply to Simon Glass

This avoids a compiler warning about unused variables.

---
 board/eNET/eNET.c |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)
board/eNET/eNET.c +0 -5
index 429fe1b..2f26470 100644
@@ -178,11 +178,6 @@ void show_boot_progress(int val)
 
 int last_stage_init(void)
 {
-	int minor;
-	int major;
-
-	major = minor = 0;
-
 	outb(0x00, LED_LATCH_ADDRESS);
 
 	register_timer_isr(enet_timer_isr);
Signature · 1 line
1.7.3.1
#19 lore raw

RFC PATCH 13/19 x86: Add processor library and relocation functions

In reply to Simon Glass

These are needed for generic relocation to function correctly.

---
 arch/x86/include/asm/reloc.h |   32 ++++++++++++++++++++
 arch/x86/lib/Makefile        |    1 +
 arch/x86/lib/proc.S          |   67 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 100 insertions(+), 0 deletions(-)
 create mode 100644 arch/x86/include/asm/reloc.h
 create mode 100644 arch/x86/lib/proc.S
arch/x86/include/asm/reloc.h new file +32 -0
new file mode 100644
index 0000000..61e0887
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2011 The Chromium OS Authors.
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <elf.h>
+
+int arch_elf_relocate_entry(Elf32_Addr *addr, Elf32_Word info,
+			    Elf32_Sym *symtab,  ulong reloc_off)
+{
+	/* TODO: if(ELF32_R_TYPE(ptr->r_info) != ... return -1 */
+	if (*addr >= CONFIG_SYS_TEXT_BASE)
+		*addr += reloc_off;
+
+	return 0;
+}
arch/x86/lib/Makefile +1 -0
index d584aa4..ff5a864 100644
@@ -27,6 +27,7 @@ LIB	= $(obj)lib$(ARCH).o
 
 SOBJS-$(CONFIG_SYS_PC_BIOS)	+= bios.o
 SOBJS-$(CONFIG_SYS_PCI_BIOS)	+= bios_pci.o
+SOBJS-y += proc.o
 SOBJS-$(CONFIG_SYS_X86_REALMODE)	+= realmode_switch.o
 
 COBJS-$(CONFIG_SYS_PC_BIOS)	+= bios_setup.o
arch/x86/lib/proc.S new file +67 -0

67 lines not on this page · raw message

Signature · 1 line
1.7.3.1
#20 lore raw

RFC PATCH 14/19 Tidy up asm/generic sections.h to include x86 symbols

In reply to Simon Glass

Include some symbols used by x86 and other architectures, then move x86 over to using this header file.

---
 arch/arm/include/asm/u-boot-arm.h |    4 ----
 arch/x86/include/asm/u-boot-x86.h |    8 --------
 arch/x86/lib/board.c              |    1 +
 include/asm-generic/sections.h    |   18 ++++++++++++++++++
 4 files changed, 19 insertions(+), 12 deletions(-)
arch/arm/include/asm/u-boot-arm.h +0 -4
index 4ca75f9..7cfae9b 100644
@@ -30,12 +30,8 @@
 #define _U_BOOT_ARM_H_	1
 
 /* for the following variables, see start.S */
-extern ulong _bss_start_ofs;	/* BSS start relative to _start */
-extern ulong _bss_end_ofs;		/* BSS end relative to _start */
-extern ulong _end_ofs;		/* end of image relative to _start */
 extern ulong IRQ_STACK_START;	/* top of IRQ stack */
 extern ulong FIQ_STACK_START;	/* top of FIQ stack */
-extern ulong _TEXT_BASE;	/* code start */
 extern ulong _datarel_start_ofs;
 extern ulong _datarelrolocal_start_ofs;
 extern ulong _datarellocal_start_ofs;
arch/x86/include/asm/u-boot-x86.h +0 -8
index 755f88a..d3e2f4c 100644
@@ -24,14 +24,6 @@
 #ifndef _U_BOOT_I386_H_
 #define _U_BOOT_I386_H_	1
 
-/* Exports from the Linker Script */
-extern ulong __text_start;
-extern ulong __data_end;
-extern ulong __rel_dyn_start;
-extern ulong __rel_dyn_end;
-extern ulong __bss_start;
-extern ulong __bss_end;
-
 /* cpu/.../cpu.c */
 int x86_cpu_init_r(void);
 int cpu_init_r(void);
arch/x86/lib/board.c +1 -0
index 3d00f20..d4bfe88 100644
@@ -42,6 +42,7 @@
 #include <ide.h>
 #include <serial.h>
 #include <asm/u-boot-x86.h>
+#include <asm-generic/sections.h>
 #include <elf.h>
 
 #ifdef CONFIG_BITBANGMII
include/asm-generic/sections.h +18 -0
index 0dac424..f273a30 100644
@@ -100,4 +100,22 @@ extern ulong _dynsym_start_ofs;
 /* End of the region to be relocated, as an offset form _start */
 extern ulong _image_copy_end_ofs;
 
+extern ulong _bss_start_ofs;	/* BSS start relative to _start */
+extern ulong _bss_end_ofs;		/* BSS end relative to _start */
+extern ulong _end_ofs;		/* end of image relative to _start */
+
+extern ulong _TEXT_BASE;	/* code start */
+
+#else /* don't use offsets: */
+
+/* Exports from the Linker Script */
+extern ulong __data_end;
+extern ulong __rel_dyn_start;
+extern ulong __rel_dyn_end;
+extern ulong __bss_end;
+
+extern ulong _TEXT_BASE;	/* code start */
+
+#endif
+
 #endif /* _ASM_GENERIC_SECTIONS_H_ */
Signature · 1 line
1.7.3.1
#21 lore raw

RFC PATCH 15/19 Add fields required by x86 to global_data

In reply to Simon Glass

These two fields are needed for x86.

---
 include/asm-generic/global_data.h |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
include/asm-generic/global_data.h +4 -0
index 16fee5a..99750a8 100644
@@ -50,6 +50,10 @@ typedef struct global_data {
 #endif
 	unsigned long	env_addr;	/* Address  of Environment struct */
 	unsigned long	env_valid;	/* Checksum of Environment valid? */
+#ifdef CONFIG_X86
+	unsigned long	cpu_clk;	/* CPU clock in Hz!		*/
+	unsigned long	bus_clk;
+#endif
 	unsigned long	fb_base;	/* base address of frame buffer */
 #ifdef CONFIG_FSL_ESDHC
 	unsigned long	sdhc_clk;
Signature · 1 line
1.7.3.1
#22 lore raw

RFC PATCH 16/19 x86: Change stub example to use asm-generic/sections.h

In reply to Simon Glass

We can use the declarations of __bss_start and _end from this header instead of declaring them locally.

---
 examples/standalone/stubs.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
examples/standalone/stubs.c +3 -4
index a6add6a..83454e3 100644
@@ -203,16 +203,15 @@ void __attribute__((unused)) dummy(void)
 #include <_exports.h>
 }
 
-extern unsigned long __bss_start, _end;
+#include <asm-generic/sections.h>
 
 void app_startup(char * const *argv)
 {
-	unsigned char * cp = (unsigned char *) &__bss_start;
+	unsigned char *cp = &__bss_start;
 
 	/* Zero out BSS */
-	while (cp < (unsigned char *)&_end) {
+	while (cp < &_end)
 		*cp++ = 0;
-	}
 
 #if defined(CONFIG_X86)
 	/* x86 does not have a dedicated register for passing global_data */
Signature · 1 line
1.7.3.1
#23 lore raw

RFC PATCH 17/19 x86: Add initial memory barrier macros

In reply to Simon Glass

These are available on other architecures, so add them on x86.

---
 arch/x86/include/asm/io.h |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
arch/x86/include/asm/io.h +8 -0
index 9b757d4..b12bdd8 100644
@@ -234,4 +234,12 @@ static inline phys_addr_t virt_to_phys(void * vaddr)
 	return (phys_addr_t)(vaddr);
 }
 
+/*
+ * TODO: The kernel offers some more advanced versions of barriers, it might
+ * have some advantages to use them instead of the simple one here.
+ */
+#define dmb()		__asm__ __volatile__ ("" : : : "memory")
+#define __iormb()	dmb()
+#define __iowmb()	dmb()
+
 #endif
Signature · 1 line
1.7.3.1
#24 lore raw

RFC PATCH 18/19 Bring in x86 to unified board architecture

In reply to Simon Glass
---
 arch/x86/config.mk                 |    6 ------
 arch/x86/include/asm/global_data.h |    6 ++++++
 arch/x86/lib/Makefile              |    2 ++
 common/board_r.c                   |    3 +++
 4 files changed, 11 insertions(+), 6 deletions(-)
arch/x86/config.mk +0 -6
index cb8865a..23cacff 100644
@@ -48,9 +48,3 @@ NORMAL_LIBGCC = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
 PREFIXED_LIBGCC = $(OBJTREE)/arch/$(ARCH)/lib/$(shell basename $(NORMAL_LIBGCC))
 
 export USE_PRIVATE_LIBGCC=$(shell dirname $(PREFIXED_LIBGCC))
-
-# We use legacy relocation for now
-CONFIG_SYS_SKIP_RELOC := y
-
-# Move to unified board system later
-CONFIG_SYS_LEGACY_BOARD := y
arch/x86/include/asm/global_data.h +6 -0
index 05a2139..d68447a 100644
@@ -23,6 +23,8 @@
 
 #ifndef	__ASM_GBL_DATA_H
 #define __ASM_GBL_DATA_H
+
+#ifdef CONFIG_LEGACY_BOARD
 /*
  * The following data structure is placed in some memory wich is
  * available very early after boot (like DPRAM on MPC8xx/MPC82xx, or
@@ -81,4 +83,8 @@ extern gd_t *gd;
 gd_t *gd
 #endif
 
+#else /* CONFIG_SYS_LEGACY_BOARD */
+#include <asm-generic/global_data.h>
+#endif
+
 #endif /* __ASM_GBL_DATA_H */
arch/x86/lib/Makefile +2 -0
index ff5a864..6c1cd64 100644
@@ -31,7 +31,9 @@ SOBJS-y += proc.o
 SOBJS-$(CONFIG_SYS_X86_REALMODE)	+= realmode_switch.o
 
 COBJS-$(CONFIG_SYS_PC_BIOS)	+= bios_setup.o
+ifeq ($(CONFIG_SYS_LEGACY_BOARD),y)
 COBJS-y	+= board.o
+endif
 COBJS-y	+= bootm.o
 COBJS-y	+= gcc.o
 COBJS-y	+= interrupts.o
common/board_r.c +3 -0
index bd656bd..2a01c3a 100644
@@ -54,8 +54,11 @@ static int initr_reloc(void)
  */
 static int initr_caches(void)
 {
+	/* TODO: sort out x86 code here */
+#ifndef CONFIG_X86
 	/* Enable caches */
 	enable_caches();
+#endif
 	return 0;
 }
 
Signature · 1 line
1.7.3.1
#25 lore raw

RFC PATCH 19/19 x86: Remove unused board/global_data code

In reply to Simon Glass

Now that x86 uses generic board, this code is not needed.

---
 arch/x86/include/asm/global_data.h |   61 -----
 arch/x86/lib/Makefile              |    2 -
 arch/x86/lib/board.c               |  453 +-----------------------------------
 3 files changed, 1 insertions(+), 515 deletions(-)
arch/x86/include/asm/global_data.h +0 -61
index d68447a..2cd00b8 100644
@@ -24,67 +24,6 @@
 #ifndef	__ASM_GBL_DATA_H
 #define __ASM_GBL_DATA_H
 
-#ifdef CONFIG_LEGACY_BOARD
-/*
- * The following data structure is placed in some memory wich is
- * available very early after boot (like DPRAM on MPC8xx/MPC82xx, or
- * some locked parts of the data cache) to allow for a minimum set of
- * global variables during system initialization (until we have set
- * up the memory controller so that we can use RAM).
- *
- * Keep it *SMALL* and remember to set GENERATED_GBL_DATA_SIZE > sizeof(gd_t)
- */
-
-#ifndef __ASSEMBLY__
-
-typedef	struct global_data {
-	bd_t		*bd;
-	unsigned long	flags;
-	unsigned long	baudrate;
-	unsigned long	have_console;	/* serial_init() was called */
-#ifdef CONFIG_PRE_CONSOLE_BUFFER
-	unsigned long	precon_buf_idx;	/* Pre-Console buffer index */
-#endif
-	unsigned long	reloc_off;	/* Relocation Offset */
-	unsigned long	load_off;	/* Load Offset */
-	unsigned long	env_addr;	/* Address  of Environment struct */
-	unsigned long	env_valid;	/* Checksum of Environment valid? */
-	unsigned long	cpu_clk;	/* CPU clock in Hz!		*/
-	unsigned long	bus_clk;
-	unsigned long	relocaddr;	/* Start address of U-Boot in RAM */
-	unsigned long	start_addr_sp;	/* start_addr_stackpointer */
-	phys_size_t	ram_size;	/* RAM size */
-	unsigned long	reset_status;	/* reset status register at boot */
-	void		**jt;		/* jump table */
-	char		env_buf[32];	/* buffer for getenv() before reloc. */
-} gd_t;
-
-extern gd_t *gd;
-
-#endif
-
-/*
- * Global Data Flags
- */
-#define	GD_FLG_RELOC		0x00001	/* Code was relocated to RAM		*/
-#define	GD_FLG_DEVINIT		0x00002	/* Devices have been initialized	*/
-#define	GD_FLG_SILENT		0x00004	/* Silent mode				*/
-#define	GD_FLG_POSTFAIL		0x00008	/* Critical POST test failed		*/
-#define	GD_FLG_POSTSTOP		0x00010	/* POST seqeunce aborted		*/
-#define	GD_FLG_LOGINIT		0x00020	/* Log Buffer has been initialized	*/
-#define GD_FLG_DISABLE_CONSOLE	0x00040	/* Disable console (in & out)		*/
-#define GD_FLG_ENV_READY	0x00080	/* Environment imported into hash table	*/
-
-#if 0
-#define DECLARE_GLOBAL_DATA_PTR
-#else
-#define XTRN_DECLARE_GLOBAL_DATA_PTR    extern
-#define DECLARE_GLOBAL_DATA_PTR     XTRN_DECLARE_GLOBAL_DATA_PTR \
-gd_t *gd
-#endif
-
-#else /* CONFIG_SYS_LEGACY_BOARD */
 #include <asm-generic/global_data.h>
-#endif
 
 #endif /* __ASM_GBL_DATA_H */
arch/x86/lib/Makefile +0 -2
index 6c1cd64..ff5a864 100644
@@ -31,9 +31,7 @@ SOBJS-y += proc.o
 SOBJS-$(CONFIG_SYS_X86_REALMODE)	+= realmode_switch.o
 
 COBJS-$(CONFIG_SYS_PC_BIOS)	+= bios_setup.o
-ifeq ($(CONFIG_SYS_LEGACY_BOARD),y)
 COBJS-y	+= board.o
-endif
 COBJS-y	+= bootm.o
 COBJS-y	+= gcc.o
 COBJS-y	+= interrupts.o
arch/x86/lib/board.c +1 -452

456 lines not on this page · raw message

Signature · 1 line
1.7.3.1
#26 lore raw

cover Create generic board init and move ARM and x86 to it

In reply to Simon Glass

Dear Simon,

Quoted 2 lines · In message <[email protected]> you wrote:

This series creates a generic board.c implementation which contains the essential functions of the various arch/xxx/lib/board.c files.

I'll be loking into this deeper when I'm back at work (i. e. starting with week 2 next year), but I'd like to make this comment as early as possible:

When making such changes, I _strongly_ recommend to use the Power architecture implementation as reference. There are a number of reasons for this, which I don't intend to explain in detail here and now (lack of time). But PPC is the most complete, longest living and most thoroughly designed architecture. Things that other architectures aquire only over time (relocation, cache support, FDT support, multiple busses [I2C, PCI, ...]) have "always" been supported by PPC.

I fear that unifying any architectures and not including PPC rightr from the beginning will result in additional efforts later, so please have a look is this can be changed.

Thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Cigarette, n.: A fire at one end, a fool at the other, and a  bit  of
tobacco in between.
#27 lore raw

cover Create generic board init and move ARM and x86 to it

Hi Wolfgang,

Quoted 20 lines · Wolfgang Denk

Dear Simon,

Quoted 2 lines · In message <[email protected]> you wrote:

This series creates a generic board.c implementation which contains the essential functions of the various arch/xxx/lib/board.c files.

I'll be loking into this deeper when I'm back at work (i. e. starting with week 2 next year), but I'd like to make this comment as early as possible:

When making such changes, I _strongly_ recommend to use the Power architecture implementation as reference. ?There are a number of reasons for this, which I don't intend to explain in detail here and now (lack of time). ?But PPC is the most complete, longest living and most thoroughly designed architecture. ?Things that other architectures aquire only over time (relocation, cache support, FDT support, multiple busses [I2C, PCI, ...]) have "always" been supported by PPC.

Quoted 5 lines

I fear that unifying any architectures and not including PPC rightr from the beginning will result in additional efforts later, so please have a look is this can be changed.

Thanks.

Yes that has been in the back of my mind. I have had a look through this but have not started a serious effort on it. There are quite a few extra bits. My main concern is that I cannot test PPC, but I will see if I can put together a patch in any case.

Regards,
Simon

Quoted 11 lines

Best regards,

Wolfgang Denk

--
DENX Software Engineering GmbH, ? ? MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Cigarette, n.: A fire at one end, a fool at the other, and a ?bit ?of tobacco in between.

#28 lore raw

cover Create generic board init and move ARM and x86 to it

In reply to Simon Glass

Hi Simon,

Sorry for the delay in reviewing this - I've been doing a lot of work on the x86 side of things. I now have a working solution to the board_init_f_r() / global data clobbering problem which involves having the gd 'variable' as a register like all other arch's. The solution is non-trivial and gd access is slightly more expensive than the vanilla variable approach, but it makes this a lot cleaner cross-arch wise...

Here's a hint ;)

static inline gd_t *get_fs_gd_ptr(void)

{
       gd_t *gd_ptr;

       asm volatile("fs movl 0, %0\n" : "=r" (gd_ptr));

       return gd_ptr;
}

#define gd get_fs_gd_ptr()

Quoted 4 lines · Simon Glass

This series creates a generic board.c implementation which contains the essential functions of the various arch/xxx/lib/board.c files.

What is the motivation for this change?

[snip]

I think that we can all agree that there is strong motivation for change.

However, I think this approach is not the right one - and I think the CFI driver backs me up. Your plan is to create generic code which you want ALL arches to cross over to, but you only look to migrate two initially and migrate the rest 'later'. This is similar to what happened with the CFI driver, and there are still boards with custom flash.c files which are completely redundant.

But, creating a single patch-set to migrate everyone in one go is going to be too massive a job to do in one go, and too prone to introducing breakage.

Quoted 4 lines

All the functions of board_init_f() and board_init_r() are broken into separate function calls so that they can easily be included or excluded for a particular architecture. It also makes it easier to adopt Graeme's initcall proposal later if desired.

I think we should look at this sooner rather than later. I've shown with x86 that the init sequence has three distinct phases:

1) Execute in flash using temporary RAM
2) Copy U-Boot from flash to RAM
3) Execute in RAM

My latest work now has all init functions having the same signature (i.e. void parameter returning int). For x86, there is a little 'magic' that needs to be done as gd is copied from temporary RAM to SDRAM, but for other arches using a dedicated register, this is otherwise trivial.

So instead of trying to pluck out something (relocation in this case) from the molasses of ten different board.c files and having to perform open-heart surgery on them all to get the code grafted in, I think we should approach it from the generic init sequence angle.

If we work each individual arch to use a generic init sequence (like the proposed x86 code) then the init processing naturally falls out as common code and the patch to realise this is trivial. From there, we can start to pull out common init code like init_baudrate() and hang() and change the function signatures of the functions that require wrappers and move some #ifdef's into more appropriate locations - One example in board.c:

#ifdef CONFIG_BITBANGMII
int bb_miiphy_init_r(void)

{
	bb_miiphy_init();

	return 0;
}

#endif

Ouch!

The other big benefit is that you only touch one architecture at a time up until you 'pull the switch'. And when you do pull the switch, you should be factoring out identical code so the chances of breaking something should be vastly reduced. Take a look at the history of ARM relocation for example - that was constrained to one arch but still the amount of breakage was massive.

Quoted 4 lines

Generic relocation is used (see previous series) but now rather than calling relocate_code() to do everything, we call the individual relocation steps one by one. Again this makes it easier to leave things out, particularly for SPL.

Note that not all arches need and/or use ELF relocation - Attacking this first does not move towards unity of board.c

Quoted 21 lines

ARM is a relatively large board.c file and one which I can test, therefore I think it is a good target for this series. On the other hand, x86 is relatively small and simple, but different enough that it introduces a few issues to be solved. So I have chosen both ARM and x86 for this series.

The next target should probably be PowerPC, since it is large and has some additional features. I suspect we may want to leave some of these very architecture-specific functions in arch/powerpc/lib/board.c, taking out only the generic code. I haven't felt a strong need to do this for ARM/x86, but we could even go as far as putting the initcall list into the architecture-specific board file if the architecture adds a lot of unusual calls.

A generic global_data structure is also required. This might upset a few people. Here is my basic reasoning: most fields are the same, all architectures include and need it, most global_data.h files already have
#ifdefs to select fields for a particular SOC, so it is hard to
see why architecures are different in this area. We can perhaps add a way to put architecture-specific fields into a separate header file, but for now I have judged that to be counter-productive.

Quoted 3 lines

There was dicussion on the list about passing gd_t around as a parameter to pre-relocation init functions. I think this makes sense, but it can be done as a separate change, and this series does not require it.

This has been raised quite some time ago - The resulting code size increase is not worth it. x86 can now emulate the 'gd is a register' so gd is now available and writtable always on every arch. As I said before, gd access is slightly more expensive (one instruction) and initialising the gd pointer is _very_ expensive (rebuilding the Global Descriptor Table) but this only happens three times in total, so I am happy to accept the penalty for a unified architecture.

Quoted 8 lines

While this series needs to stand on its own (as with the link script cleanup series and the generic relocation series) the goal is the unification of the board init code. So I hope we can address issues with this in mind, rather than focusing too narrowly on particular ARM or x86 issues.

Comments welcome. Note that the x86 side of this still needs a fair bit of work, sorry.

The big issue I have is that we now have two RFC's which have major impacts on x86 and one of us is going to have to give way to the other :)

My patch set is mostly re-factoring and has no impact on anybody else and is practically complete - I'll do one last RFC, but I think it's already close to 'PATCH' status

Quoted 12 lines

Simon Glass (19):
Introduce generic global_data
Make relocation functions global
Add basic initcall implementation
define CONFIG_SYS_LEGACY_BOARD everywhere Add generic post-relocation board_r.c
Add generic pre-relocation board_f.c
Add spl load feature
switch ARM over to generic board
arm: Remove unused code in board.c, global_data.h Add CONFIG_SYS_SYM_OFFSETS to support offset symbols
x86: Remove compiler warning in sc520_timer.c

Quoted 8 lines

x86: Remove dead code in eNET
x86: Add processor library and relocation functions Tidy up asm/generic sections.h to include x86 symbols Add fields required by x86 to global_data
x86: Change stub example to use asm-generic/sections.h
x86: Add initial memory barrier macros
Bring in x86 to unified board architecture
x86: Remove unused board/global_data code

There are several x86 patches which simply do not belong in this series (and some of which already have non-RFC patches submitted)

I honestly think we should get the x86 init sequence patches finalised first for several reasons:

- Because x86 is so small, it provides a good test-bed - ELF relocation was first finalised on x86 (it came and went with varying levels of success previously)
- They bring x86 in line with other arches re: global data
- They are now fully run-tested

Regards,

Graeme

#29 lore raw

cover Create generic board init and move ARM and x86 to it

Dear Graeme Russ,

Quoted 9 lines · In message <[email protected]> you wrote:

I honestly think we should get the x86 init sequence patches finalised first for several reasons:

- Because x86 is so small, it provides a good test-bed - ELF relocation was first finalised on x86 (it came and went with varying levels of success previously)
- They bring x86 in line with other arches re: global data
- They are now fully run-tested

I agree with that.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The game of life is a game of boomerangs.  Our  thoughts,  deeds  and
words return to us sooner or later with astounding accuracy.
#30 lore raw

cover Create generic board init and move ARM and x86 to it

In reply to Graeme Russ

Hi Graeme,

Quoted 39 lines · Graeme Russ

Hi Simon,

Sorry for the delay in reviewing this - I've been doing a lot of work on the x86 side of things. I now have a working solution to the board_init_f_r() / global data clobbering problem which involves having the gd 'variable' as a register like all other arch's. The solution is non-trivial and gd access is slightly more expensive than the vanilla variable approach, but it makes this a lot cleaner cross-arch wise...

Here's a hint ;)

static inline gd_t *get_fs_gd_ptr(void)
{
? ? ? gd_t *gd_ptr;

? ? ? asm volatile("fs movl 0, %0\n" : "=r" (gd_ptr));

? ? ? return gd_ptr;
}

#define gd ? ? ?get_fs_gd_ptr()

Quoted 4 lines · Simon Glass

This series creates a generic board.c implementation which contains the essential functions of the various arch/xxx/lib/board.c files.

What is the motivation for this change?

[snip]

I think that we can all agree that there is strong motivation for change.

However, I think this approach is not the right one - and I think the CFI driver backs me up. Your plan is to create generic code which you want ALL arches to cross over to, but you only look to migrate two initially and migrate the rest 'later'. This is similar to what happened with the CFI driver, and there are still boards with custom flash.c files which are completely redundant.

Quoted 2 lines

But, creating a single patch-set to migrate everyone in one go is going to be too massive a job to do in one go, and too prone to introducing breakage.

Yes to some extent. However, my patch basically splits the two board_init_x() functions into parts, and puts them in a function table.

I don't think it is a huge job to do this for PowerPC also, and that seems to be the most feature-full architecture.

Also it does depend on expectations. I would hope that moving an architecture over would be a fairly small task:

- getting generic relocation working
- adding functions for anything that is missing from board init code
- removing things which don't work on the architecture?
- worrying about differences in ordering between functions

Quoted 23 lines
Quoted 5 lines

All the functions of board_init_f() and board_init_r() are broken into separate function calls so that they can easily be included or excluded for a particular architecture. It also makes it easier to adopt Graeme's initcall proposal later if desired.

I think we should look at this sooner rather than later. I've shown with x86 that the init sequence has three distinct phases:

?1) Execute in flash using temporary RAM
?2) Copy U-Boot from flash to RAM
?3) Execute in RAM

My latest work now has all init functions having the same signature (i.e. void parameter returning int). For x86, there is a little 'magic' that needs to be done as gd is copied from temporary RAM to SDRAM, but for other arches using a dedicated register, this is otherwise trivial.

So instead of trying to pluck out something (relocation in this case) from the molasses of ten different board.c files and having to perform open-heart surgery on them all to get the code grafted in, I think we should approach it from the generic init sequence angle.

Quoted 6 lines

If we work each individual arch to use a generic init sequence (like the proposed x86 code) then the init processing naturally falls out as common code and the patch to realise this is trivial. From there, we can start to pull out common init code like init_baudrate() and hang() and change the function signatures of the functions that require wrappers and move some #ifdef's into more appropriate locations - One example in board.c:

Well it seems like a lot of work to refactor each arch/xxx/board.c file into functions with a function pointer list, then later remove this code function by function.

My feeling is that with a generic board, it should hopefully be a fairly small amount of work for someone familiar with an architecture to find the bugs and patch the generic code to suit their architecture. It is something that needs to be done once, not every time there is a new patch removing (almost) common code.

Quoted 17 lines

#ifdef CONFIG_BITBANGMII
int bb_miiphy_init_r(void)
{
? ? ? ?bb_miiphy_init();

? ? ? ?return 0;
}
#endif

Ouch!

The other big benefit is that you only touch one architecture at a time up until you 'pull the switch'. And when you do pull the switch, you should be factoring out identical code so the chances of breaking something should be vastly reduced. Take a look at the history of ARM relocation for example - that was constrained to one arch but still the amount of breakage was massive.

#31 lore raw

cover Create generic board init and move ARM and x86 to it

Hi Simon,

Quoted 5 lines · Simon Glass

Hi Graeme,

Quoted 2 lines · Graeme Russ

Hi Simon,

[snip]

Quoted 7 lines
Quoted 7 lines

However, I think this approach is not the right one - and I think the CFI driver backs me up. Your plan is to create generic code which you want ALL arches to cross over to, but you only look to migrate two initially and migrate the rest 'later'. This is similar to what happened with the CFI driver, and there are still boards with custom flash.c files which are completely redundant.

Quoted 6 lines
Quoted 2 lines

But, creating a single patch-set to migrate everyone in one go is going to be too massive a job to do in one go, and too prone to introducing breakage.

Yes to some extent. However, my patch basically splits the two board_init_x() functions into parts, and puts them in a function table.

Ah yes, looking a bit closer I see this now in patches 5 & 6. However, I think if you look at my patches 9, 10, 12 and 13 I'm doing essentially the same thing for x86. The difference is, I'm moving live code, rather than creating dead code then switching over. I personally do not think your approach is very safe - If there is a breakage, it is spread over multiple patches - With the 'move code around' approach, all breakages are confined to a single patch

Quoted 2 lines

I don't think it is a huge job to do this for PowerPC also, and that seems to be the most feature-full architecture.

I agree - The init architecture is the same, but the sequence is bigger (and not in the same order)

Quoted 7 lines

Also it does depend on expectations. I would hope that moving an architecture over would be a fairly small task:

- getting generic relocation working
- adding functions for anything that is missing from board init code
- removing things which don't work on the architecture?
- worrying about differences in ordering between functions

I see it as:
1) Rework the arch init sequence to be a pure list of 'int foo(void)' functions, adding helpers and wrappers where necessary
2) Switch over to use the generic init processing loop
3) Factor out common helpers and wrappers across all arches
4) Factor out common functionality (e.g. relocation)
5) After all arches are switched, remove wrappers by changing the function signature of the wrapped function
6) Move helpers into relevant driver/common source file

I think 1 & 2 need to be done for at least ARM, x86 and PPC before starting 3 & 4 and 1-4 needs to be done for all arches before doing 5 & 6

[snip]

Quoted 10 lines
Quoted 6 lines

If we work each individual arch to use a generic init sequence (like the proposed x86 code) then the init processing naturally falls out as common code and the patch to realise this is trivial. From there, we can start to pull out common init code like init_baudrate() and hang() and change the function signatures of the functions that require wrappers and move some #ifdef's into more appropriate locations - One example in board.c:

Well it seems like a lot of work to refactor each arch/xxx/board.c file into functions with a function pointer list, then later remove this code function by function.

Yes, it is more work, but it is intrinsically safer (and git bisect-able)

Quoted 3 lines

My feeling is that with a generic board, it should hopefully be a fairly small amount of work for someone familiar with an architecture to find the bugs and patch the generic code to suit their

You seem to admit that your approach can introduce bugs

Quoted 2 lines

architecture. It is something that needs to be done once, not every time there is a new patch removing (almost) common code.

The safer approach is to tackle each arch independently - Convert each board.c to something similar to what I have shown with x86 and test those arch-specific changes to make sure nothing has been broken. Then it is a trivial matter of checking that there are no incompatibilities between the arch and the common case (and adjusting as required) and switching over to the common case

[snip]

Quoted 10 lines
Quoted 7 lines

The other big benefit is that you only touch one architecture at a time up until you 'pull the switch'. And when you do pull the switch, you should be factoring out identical code so the chances of breaking something should be vastly reduced. Take a look at the history of ARM relocation for example - that was constrained to one arch but still the amount of breakage was massive.

From previous discussions, if something is optional then the switch

will never happen. The code you are talking about is sometimes identical, sometimes slightly different. In some cases the order is different. I see many ways of introducing breakages. I do agree that

The init sequence order is dictated arch-specifically through the init arrays which will (for the time being) remain in the arch specific board.c. But that is all arch/foo/lib/board.c will contain - init sequence arrays, no 'code'

Quoted 4 lines

doing one architecture at a time is best - with the proviso that we need to pick archs that have the most features (so ARM and PowerPC I suppose) to make sure we are not deluding ourselves as to the simplicity of the task.

ARM + PPC + x86 = 95% of the complexity. If we pull them off, the others are trivial cases.

Quoted 11 lines

So perhaps a generic board init that is the default can be switched off on board-by-board basic would be the right approach. Then we can flick the switch while providing for those affected to still get work done until bugs are reported and found?

Quoted 6 lines
Quoted 5 lines

Generic relocation is used (see previous series) but now rather than calling relocate_code() to do everything, we call the individual relocation steps one by one. Again this makes it easier to leave things out, particularly for SPL.

Quoted 6 lines
Quoted 2 lines

Note that not all arches need and/or use ELF relocation - Attacking this first does not move towards unity of board.c

It is a feature used by about half, and it does include the complexity of jumping from pre-reloc to post-reloc init. I think it was a reasonable first target.

It is an excellent first target after making the init sequence generic - skipping relocation is then trivial (you just don't include it in the init sequence)

[snip]

Quoted 6 lines
Quoted 2 lines

The big issue I have is that we now have two RFC's which have major impacts on x86 and one of us is going to have to give way to the other :)

Well I posted my x86 patches so they are not just sitting in the long grass on my machine. They are not complete, and I would likely need your input on these anyway.

Most of your patches are a subset of my complete init re-write (and credit where it is due, you initial relocation RFC was the catalyst - I wanted to make your life a little easier by simplifying things in x86-land)

Quoted 7 lines
Quoted 3 lines

My patch set is mostly re-factoring and has no impact on anybody else and is practically complete - I'll do one last RFC, but I think it's already close to 'PATCH' status

That's a separate series from my point of view. I can't comment on the wierd x96-isms in the series, but I did read through each patch and it all seems sensible to me.

Thanks, that is enough for me for now. I'll request a proper review when I submit the [PATCH] series

[snip]

Quoted 5 lines
Quoted 2 lines

There are several x86 patches which simply do not belong in this series (and some of which already have non-RFC patches submitted)

OK, these are the warnings I think. Probably I should build without -Werrors and try to ignore them!

Propagate them to the top of your list to get them out of the way. I need to add them to my series (with original attribution of course) or commit them as is (some need tweaking)

Quoted 9 lines
Quoted 8 lines

I honestly think we should get the x86 init sequence patches finalised first for several reasons:

- Because x86 is so small, it provides a good test-bed - ELF relocation was first finalised on x86 (it came and went with varying levels of success previously)
- They bring x86 in line with other arches re: global data
- They are now fully run-tested

Quoted 5 lines

No disagreement there, and anyway as you can see the relocation stuff mostly came from your x86 code. It will provide a good template for getting x86 working properly with the generic board init.

What do you need from me to get that through?

Patience :) - I'll try to get a final series up this week

Quoted 3 lines

Per Wolfgang's request to go with PPC as an early-adopter, this is somewhat in conflict, since as you say, x86 is less feature-full than ARM and much less than PowerPC.

We need to get the PPC (plus ARM and x86) init sequence distilled to pure init loops before moving forward.

Quoted 2 lines

Can anyone recommend a PowerPC board with a quick U-Boot program-run cycle that I can easily get that will let me try out things there?

If all we are doing is moving and wrapping code, the review and test should be fairly straighfoward

Regards,

Graeme

#32 lore raw

cover Create generic board init and move ARM and x86 to it

Hi Graeme,

Quoted 25 lines · Graeme Russ

Hi Simon,

Quoted 5 lines · Simon Glass

Hi Graeme,

Quoted 2 lines · Graeme Russ

Hi Simon,

[snip]

Quoted 7 lines
Quoted 7 lines

However, I think this approach is not the right one - and I think the CFI driver backs me up. Your plan is to create generic code which you want ALL arches to cross over to, but you only look to migrate two initially and migrate the rest 'later'. This is similar to what happened with the CFI driver, and there are still boards with custom flash.c files which are completely redundant.

Quoted 6 lines
Quoted 2 lines

But, creating a single patch-set to migrate everyone in one go is going to be too massive a job to do in one go, and too prone to introducing breakage.

Yes to some extent. However, my patch basically splits the two board_init_x() functions into parts, and puts them in a function table.

Quoted 7 lines

Ah yes, looking a bit closer I see this now in patches 5 & 6. However, I think if you look at my patches 9, 10, 12 and 13 I'm doing essentially the same thing for x86. The difference is, I'm moving live code, rather than creating dead code then switching over. I personally do not think your approach is very safe - If there is a breakage, it is spread over multiple patches - With the 'move code around' approach, all breakages are confined to a single patch

See my other email on this topic though - I feel that one test/fix cycle is better than testing every board for every little patch over an extended period.

Quoted 6 lines
Quoted 3 lines

I don't think it is a huge job to do this for PowerPC also, and that seems to be the most feature-full architecture.

I agree - The init architecture is the same, but the sequence is bigger (and not in the same order)

Yes that's what I'm finding.

Quoted 19 lines
Quoted 8 lines

Also it does depend on expectations. I would hope that moving an architecture over would be a fairly small task:

- getting generic relocation working
- adding functions for anything that is missing from board init code
- removing things which don't work on the architecture?
- worrying about differences in ordering between functions

I see it as:
?1) Rework the arch init sequence to be a pure list of 'int foo(void)' ? ?functions, adding helpers and wrappers where necessary ?2) Switch over to use the generic init processing loop
?3) Factor out common helpers and wrappers across all arches ?4) Factor out common functionality (e.g. relocation)
?5) After all arches are switched, remove wrappers by changing the ? ?function signature of the wrapped function
?6) Move helpers into relevant driver/common source file

Quoted 2 lines

I think 1 & 2 need to be done for at least ARM, x86 and PPC before starting 3 & 4 and 1-4 needs to be done for all arches before doing 5 & 6

OK yes we could do this. But I think the end result is different.

I am keen to create a single common/board_f.c implementation for pre-reloc init and common/board_r.c for post-reloc init. I believe where your approach ends up with with separate arch/xxx/board.c files still, with their own initcall list, and a number of private functions. Now this is better than where we are now, but my original complaint was that I want to be able to add features to a single place and have them work across all architectures. With your end-result I still need to figure out where to put the new feature in each initcall list and create 10 patches, one for each arch, to plumb it in.

IMO the ordering differences between architectures are mostly unnecessary - an artifact of forking the code - and we should aim to minimise these differences.

Putting everything in one file helps to clarify exactly what the differences are between archs, and discussions can take place as to why and whether this differences can be removed. If we accept that PPC is the one true way (in terms of U-Boot code base), then the job is to make other arch's code more like PPC. This is best done in one place I think.

After a bit of thought, I worry also that your approach will create an extended period of time where U-Boot is unstable, as patch are patch is added to refactor the code. Granted, many of these patches are small and the risk is small. But why bother? At the end we still have 10 different board files, lots of differences and no one willing to change anything because it requires an entire test cycle again.

Maybe I am being too ambitious here, but since everything started with PPC's board.c, I don't see why we shouldn't head back in that direction and just create a single file again. It does create a big test problem, but only once :-)

Anyway if we do go with what you propose I still think it is better than what we have.

Quoted 10 lines

[snip]

Quoted 7 lines
Quoted 6 lines

If we work each individual arch to use a generic init sequence (like the proposed x86 code) then the init processing naturally falls out as common code and the patch to realise this is trivial. From there, we can start to pull out common init code like init_baudrate() and hang() and change the function signatures of the functions that require wrappers and move some #ifdef's into more appropriate locations - One example in board.c:

Quoted 5 lines
Quoted 3 lines

Well it seems like a lot of work to refactor each arch/xxx/board.c file into functions with a function pointer list, then later remove this code function by function.

Yes, it is more work, but it is intrinsically safer (and git bisect-able)

Well I don't propose to create things which are not bisect-able. I think what you mean is that there will be a commit which switches over to generic board for an architecture, and board init before that patch is quite different from board init afterwards. Yes that's right. Once the patch is reviewed, testing and committed, presumably most boards will work fine. The exception will be the boards which have unique features and no one had time to check them. That problem is not unique to either approach. Future patches welcome :-)

Quoted 6 lines
Quoted 4 lines

My feeling is that with a generic board, it should hopefully be a fairly small amount of work for someone familiar with an architecture to find the bugs and patch the generic code to suit their

You seem to admit that your approach can introduce bugs

Yes I do. Both approaches introduce bugs. I think that is unavoidable so we should try to do this once and get the best result out of it that we can.

Quoted 10 lines
Quoted 3 lines

architecture. It is something that needs to be done once, not every time there is a new patch removing (almost) common code.

The safer approach is to tackle each arch independently - Convert each board.c to something similar to what I have shown with x86 and test those arch-specific changes to make sure nothing has been broken. Then it is a trivial matter of checking that there are no incompatibilities between the arch and the common case (and adjusting as required) and switching over to the common case

This switch-over is really no different from what I propose (except that I want to go further and have a single board file). It introduces the same bisect issue you mentioned, and I feel it doesn't really improve the situation. We have instability with each patch as we refactor the board init code on each arch, then instability when we switch over. Why not just have this pain once?

Quoted 10 lines

[snip]

Quoted 7 lines
Quoted 7 lines

The other big benefit is that you only touch one architecture at a time up until you 'pull the switch'. And when you do pull the switch, you should be factoring out identical code so the chances of breaking something should be vastly reduced. Take a look at the history of ARM relocation for example - that was constrained to one arch but still the amount of breakage was massive.

From previous discussions, if something is optional then the switch

Quoted 8 lines
Quoted 3 lines

will never happen. The code you are talking about is sometimes identical, sometimes slightly different. In some cases the order is different. I see many ways of introducing breakages. I do agree that

The init sequence order is dictated arch-specifically through the init arrays which will (for the time being) remain in the arch specific board.c. But that is all arch/foo/lib/board.c will contain - init sequence arrays, no 'code'

OK, see above. Better than what we have, for sure. I am hoping we can go further.

Quoted 8 lines
Quoted 5 lines

doing one architecture at a time is best - with the proviso that we need to pick archs that have the most features (so ARM and PowerPC I suppose) to make sure we are not deluding ourselves as to the simplicity of the task.

ARM + PPC + x86 = 95% of the complexity. If we pull them off, the others are trivial cases.

OK good.

Quoted 15 lines
Quoted 15 lines

So perhaps a generic board init that is the default can be switched off on board-by-board basic would be the right approach. Then we can flick the switch while providing for those affected to still get work done until bugs are reported and found?

Quoted 8 lines
Quoted 5 lines

Generic relocation is used (see previous series) but now rather than calling relocate_code() to do everything, we call the individual relocation steps one by one. Again this makes it easier to leave things out, particularly for SPL.

Note that not all arches need and/or use ELF relocation - Attacking this first does not move towards unity of board.c

Quoted 7 lines
Quoted 3 lines

It is a feature used by about half, and it does include the complexity of jumping from pre-reloc to post-reloc init. I think it was a reasonable first target.

It is an excellent first target after making the init sequence generic - skipping relocation is then trivial (you just don't include it in the init sequence)

Yes

Quoted 6 lines

[snip]

Quoted 3 lines
Quoted 2 lines

The big issue I have is that we now have two RFC's which have major impacts on x86 and one of us is going to have to give way to the other :)

Quoted 7 lines
Quoted 3 lines

Well I posted my x86 patches so they are not just sitting in the long grass on my machine. They are not complete, and I would likely need your input on these anyway.

Most of your patches are a subset of my complete init re-write (and credit where it is due, you initial relocation RFC was the catalyst - I wanted to make your life a little easier by simplifying things in x86-land)

Yes, they are a subset - but hopefully generic enough to work for any arch.

Quoted 11 lines
Quoted 8 lines
Quoted 4 lines

My patch set is mostly re-factoring and has no impact on anybody else and is practically complete - I'll do one last RFC, but I think it's already close to 'PATCH' status

That's a separate series from my point of view. I can't comment on the wierd x96-isms in the series, but I did read through each patch and it all seems sensible to me.

Thanks, that is enough for me for now. I'll request a proper review when I submit the [PATCH] series

OK

Quoted 6 lines

[snip]

Quoted 3 lines
Quoted 2 lines

There are several x86 patches which simply do not belong in this series (and some of which already have non-RFC patches submitted)

Quoted 6 lines
Quoted 2 lines

OK, these are the warnings I think. Probably I should build without -Werrors and try to ignore them!

Propagate them to the top of your list to get them out of the way. I need to add them to my series (with original attribution of course) or commit them as is (some need tweaking)

OK

Quoted 16 lines
Quoted 10 lines
Quoted 9 lines

I honestly think we should get the x86 init sequence patches finalised first for several reasons:

?- Because x86 is so small, it provides a good test-bed - ELF relocation ? was first finalised on x86 (it came and went with varying levels of ? success previously)
?- They bring x86 in line with other arches re: global data ?- They are now fully run-tested

Quoted 5 lines

No disagreement there, and anyway as you can see the relocation stuff mostly came from your x86 code. It will provide a good template for getting x86 working properly with the generic board init.

What do you need from me to get that through?

Quoted 8 lines

Patience :) - I'll try to get a final series up this week

Quoted 3 lines

Per Wolfgang's request to go with PPC as an early-adopter, this is somewhat in conflict, since as you say, x86 is less feature-full than ARM and much less than PowerPC.

We need to get the PPC (plus ARM and x86) init sequence distilled to pure init loops before moving forward.

Well for now I'm going to continue looking at PPC init and seeing if I can roll into into the series. Whichever way we go it is a useful resource.

Quoted 6 lines
Quoted 3 lines

Can anyone recommend a PowerPC board with a quick U-Boot program-run cycle that I can easily get that will let me try out things there?

If all we are doing is moving and wrapping code, the review and test should be fairly straighfoward

Hmmm that's mostly what I am doing too, with the addition that I am trying to reason about the ordering of the code.

Regards,
Simon

Quoted 4 lines

Regards,

Graeme

#33 lore raw

cover Create generic board init and move ARM and x86 to it

Hi Simon,

In case you haven't noticed (I did not Cc you or Wolfgang, sorry 'bout that) I've posted the cleaned up version of my x86 init refactoring...

Quoted 11 lines · Simon Glass

Hi Graeme,

Quoted 8 lines · Graeme Russ

Hi Simon,

Quoted 5 lines · Simon Glass

Hi Graeme,

Quoted 2 lines · Graeme Russ

Hi Simon,

[snip]

Quoted 9 lines
Quoted 8 lines

Ah yes, looking a bit closer I see this now in patches 5 & 6. However, I think if you look at my patches 9, 10, 12 and 13 I'm doing essentially the same thing for x86. The difference is, I'm moving live code, rather than creating dead code then switching over. I personally do not think your approach is very safe - If there is a breakage, it is spread over multiple patches - With the 'move code around' approach, all breakages are confined to a single patch

Quoted 3 lines

See my other email on this topic though - I feel that one test/fix cycle is better than testing every board for every little patch over an extended period.

The problem is not one of how sparsely the test/fix cycles are spread over time, it is one of spreading the breakage over multiple patches - If you are replacing functionality then add the new functionality, add the hooks to use it and delete the old in a single patch. That way, if you change breaks something, the revert is trivial. If you multi-patch approach breaks something, the revert becomes more difficult.

Quoted 30 lines
Quoted 5 lines
Quoted 2 lines

I don't think it is a huge job to do this for PowerPC also, and that seems to be the most feature-full architecture.

I agree - The init architecture is the same, but the sequence is bigger (and not in the same order)

Yes that's what I'm finding.

Quoted 19 lines
Quoted 8 lines

Also it does depend on expectations. I would hope that moving an architecture over would be a fairly small task:

- getting generic relocation working
- adding functions for anything that is missing from board init code
- removing things which don't work on the architecture?
- worrying about differences in ordering between functions

I see it as:
1) Rework the arch init sequence to be a pure list of 'int foo(void)' functions, adding helpers and wrappers where necessary
2) Switch over to use the generic init processing loop
3) Factor out common helpers and wrappers across all arches
4) Factor out common functionality (e.g. relocation)
5) After all arches are switched, remove wrappers by changing the function signature of the wrapped function
6) Move helpers into relevant driver/common source file

Quoted 2 lines

I think 1 & 2 need to be done for at least ARM, x86 and PPC before starting 3 & 4 and 1-4 needs to be done for all arches before doing 5 & 6

Quoted 6 lines

OK yes we could do this. But I think the end result is different.

I am keen to create a single common/board_f.c implementation for pre-reloc init and common/board_r.c for post-reloc init. I believe where your approach ends up with with separate arch/xxx/board.c files still, with their own initcall list, and a number of private

Correct, but as a first step, the processing loop code is made common, leaving only the init arrays per-arch

Quoted 5 lines

functions. Now this is better than where we are now, but my original complaint was that I want to be able to add features to a single place and have them work across all architectures. With your end-result I still need to figure out where to put the new feature in each initcall list and create 10 patches, one for each arch, to plumb it in.

Agree, and my ultimate end goal (as per my previous initcall patch series) is to remove the per-arch init list as well...

Quoted 10 lines

IMO the ordering differences between architectures are mostly unnecessary - an artifact of forking the code - and we should aim to minimise these differences.

Putting everything in one file helps to clarify exactly what the differences are between archs, and discussions can take place as to why and whether this differences can be removed. If we accept that PPC is the one true way (in terms of U-Boot code base), then the job is to make other arch's code more like PPC. This is best done in one place I think.

I see two issues with your approach:
1) You want to take a 'big bang' approach and change every arch over in one set of patches. I admire your vision, but question you realism ;) I took one look across all the init sequences and fled in horror. Such a big-bang approach is sure to cause some _major_ board breakage
2) As Wolfgang has eluded to, a unified set of init arrays will be more

     #ifdef than code
Quoted 2 lines

After a bit of thought, I worry also that your approach will create an extended period of time where U-Boot is unstable, as patch are patch

How so - Take a look at my x86 patch series. It only impacts x86 and it can be easily tested. Other arches are going to be even easier as the most delicate part of my series was getting global data to behave properly. For the other arches, it will be a simple matter of moving code around. What I did for x86 was fold a single init function which was outside the init array into the array (and creating a helper or wrapper as needed) at a time in a series of small patches. I then squashed them all together

Quoted 4 lines

is added to refactor the code. Granted, many of these patches are small and the risk is small. But why bother? At the end we still have 10 different board files, lots of differences and no one willing to change anything because it requires an entire test cycle again.

Because what we end up with is 10 sets of init_f, init_f_r and init_r arrays - All the processing loop and entry points are common and all the helpers and wrappers have been factored out as far as possible.

So we have 10 sets of very clean code (statically initialised arrays) which we can look at side-by-side and decide what to do. This may be either:
- Decide it's all too hard and keep them arch specific (but at least the processing code is now common)
- Create unified arrays using #ifdefs
- Distil them into a set of 'common for most' which we use as the default and have separate ones for the corner cases
- Change the way we do things entirely

Your approach immediately goes for option #2 or #3 on the assumption that it is possible to do so - My approach may end up in exactly the same place, but if not, it's not a wasted effort

Quoted 4 lines

Maybe I am being too ambitious here, but since everything started with PPC's board.c, I don't see why we shouldn't head back in that direction and just create a single file again. It does create a big test problem, but only once :-)

No, it creates a _HUGE_ test problem - And what do we do with the corner cases that fail in weird and wonderful ways...

Quoted 13 lines

Anyway if we do go with what you propose I still think it is better than what we have.

Quoted 10 lines

[snip]

Quoted 7 lines
Quoted 6 lines

If we work each individual arch to use a generic init sequence (like the proposed x86 code) then the init processing naturally falls out as common code and the patch to realise this is trivial. From there, we can start to pull out common init code like init_baudrate() and hang() and change the function signatures of the functions that require wrappers and move some #ifdef's into more appropriate locations - One example in board.c:

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Well it seems like a lot of work to refactor each arch/xxx/board.c file into functions with a function pointer list, then later remove this code function by function.

Yes, it is more work, but it is intrinsically safer (and git bisect-able)

Well I don't propose to create things which are not bisect-able. I

But you have - You create new functionality in one patch, add a number of patches, then finally use that new functionality in a later patch.

Quoted 7 lines

think what you mean is that there will be a commit which switches over to generic board for an architecture, and board init before that patch is quite different from board init afterwards. Yes that's right. Once the patch is reviewed, testing and committed, presumably most boards will work fine. The exception will be the boards which have unique features and no one had time to check them. That problem is not unique to either approach. Future patches welcome :-)

With my latest series, each patch made a functional change that was manifest _in that patch_ so I was able to step through each and every patch, building and running each one as I went (and just for the record, the first run through was a dead-set shocker - the gd patches had a fair bit more work to do)

You series does not do this - You can apply one patch, build, load and run and say 'yep, it still runs' but when you apply the next patch (or the next, or the next etc) and something breaks, it might not have been the last patch you applied that broke it. Specifically, patches 5 & 6 and then leap to patch 18 before we use that code in x86

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

My feeling is that with a generic board, it should hopefully be a fairly small amount of work for someone familiar with an architecture to find the bugs and patch the generic code to suit their

You seem to admit that your approach can introduce bugs

Yes I do. Both approaches introduce bugs. I think that is unavoidable so we should try to do this once and get the best result out of it that we can.

I comes down to identifying the exact patch that introduced the bug

Quoted 10 lines
Quoted 9 lines
Quoted 2 lines

architecture. It is something that needs to be done once, not every time there is a new patch removing (almost) common code.

The safer approach is to tackle each arch independently - Convert each board.c to something similar to what I have shown with x86 and test those arch-specific changes to make sure nothing has been broken. Then it is a trivial matter of checking that there are no incompatibilities between the arch and the common case (and adjusting as required) and switching over to the common case

Quoted 3 lines

This switch-over is really no different from what I propose (except that I want to go further and have a single board file). It introduces the same bisect issue you mentioned, and I feel it doesn't really

No it does not - each arch is migrated independently towards a common implementation (but that implementation is replicated in each arch) - So for each arch, up until the point were we say 'they are now the same' we can bisect a bug to a single patch in that arches migration path. Then we look at the code and say 'yep, they are all the same' and create the common code and switch them _all_ over in a single patch. This is bisectable at every step.

Quoted 3 lines

improve the situation. We have instability with each patch as we refactor the board init code on each arch, then instability when we switch over. Why not just have this pain once?

Because as soon as you break bisectability (is that even a word) your 'pain' is several orders of magnitude worse. A bisectable bug can be a simple revert. A non-bisectable bug requires a new patch which may introduce even more bugs

Quoted 13 lines
Quoted 13 lines

[snip]

Quoted 10 lines
Quoted 7 lines

The other big benefit is that you only touch one architecture at a time up until you 'pull the switch'. And when you do pull the switch, you should be factoring out identical code so the chances of breaking something should be vastly reduced. Take a look at the history of ARM relocation for example - that was constrained to one arch but still the amount of breakage was massive.

From previous discussions, if something is optional then the switch

will never happen. The code you are talking about is sometimes identical, sometimes slightly different. In some cases the order is different. I see many ways of introducing breakages. I do agree that

Quoted 7 lines
Quoted 4 lines

The init sequence order is dictated arch-specifically through the init arrays which will (for the time being) remain in the arch specific board.c. But that is all arch/foo/lib/board.c will contain - init sequence arrays, no 'code'

OK, see above. Better than what we have, for sure. I am hoping we can go further.

And so am I - I have not given up on initcall yet ;) (actually, I have an idea but I'll start a new thread to discuss)

[snip]

Regards,

Graeme

#34 lore raw

cover Create generic board init and move ARM and x86 to it

Dear Graeme Russ,

Quoted 7 lines · In message <[email protected]> you wrote:

The problem is not one of how sparsely the test/fix cycles are spread over time, it is one of spreading the breakage over multiple patches - If you are replacing functionality then add the new functionality, add the hooks to use it and delete the old in a single patch. That way, if you change breaks something, the revert is trivial. If you multi-patch approach breaks something, the revert becomes more difficult.

True. Especially as it's likely that different patches will break different boards, so there will not even be a chance so revert.

Quoted 4 lines
Quoted 1 line

Well I don't propose to create things which are not bisect-able. I

But you have - You create new functionality in one patch, add a number of patches, then finally use that new functionality in a later patch.

This is what I fear as well.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Disc space - the final frontier!
#35 lore raw

cover Create generic board init and move ARM and x86 to it

Hi Wolfgang,

Quoted 11 lines · Wolfgang Denk

Dear Graeme Russ,

Quoted 7 lines · In message <[email protected]> you wrote:

The problem is not one of how sparsely the test/fix cycles are spread over time, it is one of spreading the breakage over multiple patches - If you are replacing functionality then add the new functionality, add the hooks to use it and delete the old in a single patch. That way, if you change breaks something, the revert is trivial. If you multi-patch approach breaks something, the revert becomes more difficult.

Quoted 2 lines

True. ?Especially as it's likely that different patches will break different boards, so there will not even be a chance so revert.

The only option would be to have a way to use the legacy code for particular boards (say a CONFIG option) until they are fixed. Not entirely satisfactory. Of course this could happen with either approach, and reverts become impossible when further patches are layered on top.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Well I don't propose to create things which are not bisect-able. I

But you have - You create new functionality in one patch, add a number of patches, then finally use that new functionality in a later patch.

This is what I fear as well.

Well let's see how we go with the incremental approach - hopefully we can get the same result with less pain and risk, and not too much work.

Regards,
Simon

Quoted 10 lines

Best regards,

Wolfgang Denk

--
DENX Software Engineering GmbH, ? ? MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Disc space - the final frontier!

#36 lore raw

cover Create generic board init and move ARM and x86 to it

Dear Simon Glass,

Quoted 4 lines · In message <CAPnjgZ2jS8kzCt06LbYnXSyEKm6ck8apm=P1YqqDtnZ0+q9dhw@mail.gmail.com>…

Well let's see how we go with the incremental approach - hopefully we can get the same result with less pain and risk, and not too much work.

Did you miss my proposal not to change the existing coe for all boards, but to provide anew implementation and convert boards one by one? What do you think about such an approach?

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"The X11 source code style is ATROCIOUS and should not be used  as  a
model."                                                   - Doug Gwyn
#37 lore raw

cover Create generic board init and move ARM and x86 to it

Hi Wolfgang,

Quoted 11 lines · Wolfgang Denk

Dear Simon Glass,

Quoted 4 lines · In message <CAPnjgZ2jS8kzCt06LbYnXSyEKm6ck8apm=P1YqqDtnZ0+q9dhw@mail.gmail.com>…

Well let's see how we go with the incremental approach - hopefully we can get the same result with less pain and risk, and not too much work.

Did you miss my proposal not to change the existing coe for all boards, but to provide anew implementation and convert boards one by one? What do you think about such an approach?

My idea was to migrate each arch to the 'pure processing loops' implementation I have just posted for x86. We can then factor out the processing loop code into common code leaving just the init function arrays in arch/foo/lib/board.c

We can then look at how to deal with the disparate init sequences - I'm going to have a look at my new 'initcall' proposal to see if that is viable
- If so, we auto generate init_sequence.c

Regards,

Graeme

#38 lore raw

cover Create generic board init and move ARM and x86 to it

In reply to Wolfgang Denk

Hi Wolfgang,

Quoted 4 lines · Wolfgang Denk

Dear Simon Glass,

Quoted 1 line · In message <CAPnjgZ2jS8kzCt06LbYnXSyEKm6ck8apm=P1YqqDtnZ0+q9dhw@mail.gmail.com>…
Quoted 8 lines
Quoted 3 lines

Well let's see how we go with the incremental approach - hopefully we can get the same result with less pain and risk, and not too much work.

Did you miss my proposal not to change the existing coe for all boards, but to provide anew implementation and convert boards one by one? ?What do you think about such an approach?

Sorry I must have misread this as 'architecture' instead of 'board'. I suppose this would work since there is a simple CONFIG switch to move over.

The concern with doing this for a whole architecture was the board breakages, and this idea would avoid that. I wonder what would be the incentive for boards to move over? Perhaps eventually it could be the default, or we could discourage patches to the old code.

I have brought in PPC to board_f.c and board_r.c but not dealt with relocation. Once I have done that, gone through the new x86 series again and MAKEALL doesn't scream too loudly I'll do another RFC along these lines.

If Graham can move his initcall stuff along too then we can also get rid of the #ifdefs, which it IMO the main ugliness with my RFC.

Regards,
Simon

Quoted 10 lines

Best regards,

Wolfgang Denk

--
DENX Software Engineering GmbH, ? ? MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de "The X11 source code style is ATROCIOUS and should not be used ?as ?a model." ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? - Doug Gwyn

#39 lore raw

cover Create generic board init and move ARM and x86 to it

Dear Simon Glass,

Quoted 5 lines · In message <CAPnjgZ3592m_m=TMaFptwzO+_O94veYkVRFFdGPP599igefNyg@mail.gmail.com>…

I have brought in PPC to board_f.c and board_r.c but not dealt with relocation. Once I have done that, gone through the new x86 series again and MAKEALL doesn't scream too loudly I'll do another RFC along these lines.

I'm seriously concerned about you insisting to include relocation here. This has nothign to do with it. Leave that out.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"When the only  tool  you  have  is  a  hammer,  you  tend  to  treat
everything as if it were a nail."                    - Abraham Maslow
#40 lore raw

cover Create generic board init and move ARM and x86 to it

Hi Wolfgang,

Quoted 11 lines · Wolfgang Denk

Dear Simon Glass,

Quoted 5 lines · In message <CAPnjgZ3592m_m=TMaFptwzO+_O94veYkVRFFdGPP599igefNyg@mail.gmail.com>…

I have brought in PPC to board_f.c and board_r.c but not dealt with relocation. Once I have done that, gone through the new x86 series again and MAKEALL doesn't scream too loudly I'll do another RFC along these lines.

I'm seriously concerned about you insisting to include relocation here. ?This has nothign to do with it. ?Leave that out.

I'm not insisting, only that I have already done a series for generic relocation so figured this new series would come second. I did signal this right at the beginning when suggesting the approach:

http://lists.denx.de/pipermail/u-boot/2011-November/109987.html

Anyway, leaving out relocation is easier so I will rebase this series on top of master instead.

Regards,
Simon

Quoted 11 lines

Best regards,

Wolfgang Denk

--
DENX Software Engineering GmbH, ? ? MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de "When the only ?tool ?you ?have ?is ?a ?hammer, ?you ?tend ?to ?treat everything as if it were a nail." ? ? ? ? ? ? ? ? ? ?- Abraham Maslow

#41 lore raw

cover Create generic board init and move ARM and x86 to it

In reply to Graeme Russ

Hi Graham,

Quoted 4 lines · Graeme Russ

Hi Simon,

In case you haven't noticed (I did not Cc you or Wolfgang, sorry 'bout that) I've posted the cleaned up version of my x86 init refactoring...

Yes I see it - thats great thanks. I will go through it and compare.

[big snip]

Quoted 9 lines
Quoted 6 lines

functions. Now this is better than where we are now, but my original complaint was that I want to be able to add features to a single place and have them work across all architectures. With your end-result I still need to figure out where to put the new feature in each initcall list and create 10 patches, one for each arch, to plumb it in.

Agree, and my ultimate end goal (as per my previous initcall patch series) is to remove the per-arch init list as well...

Well since it seems we are going for the same goal, and you are actively submitting patches towards it, I'm very happy. I mostly agree with your points, so will not respond bit by bit. The easiest route to the goal is the right one, so let's run with what you propose and see how we go. Thanks for taking it up.

[another big snip]

I had a go at bringing PPC into the generic board patches. Apart from the cloud of #ifdefs as expected it is not too bad. And those can be dealt with by initcalls.

Am hoping we can get there soon!

Regards,
Simon

Quoted 3 lines

Regards,

Graeme

#42 lore raw

cover Create generic board init and move ARM and x86 to it

In reply to Simon Glass

Dear Simon Glass,

Quoted 5 lines · In message <CAPnjgZ1Zim6=u3rLcnAKE-0Bw3sO_hRY+U67jkpkNoNi8g7ctw@mail.gmail.com>…

Also it does depend on expectations. I would hope that moving an architecture over would be a fairly small task:

- getting generic relocation working

I don;t see why this would be a direct prerequisite here. We want to have that, no boubt about that. But it appears to be an unrelated change to me.

Quoted 1 line

- adding functions for anything that is missing from board init code

"anything that is missing from board init code" ?

Quoted 1 line

- removing things which don't work on the architecture?

That would probably reander systems broken that need these things?

Quoted 1 line

- worrying about differences in ordering between functions

This is indeed the biggest issue.

Keep in mind that my original ida of providing a function call table was to allow to define this table in a board specific way (i. e. in the board config file).

[Not that this idea found many friends...]

Quoted 7 lines
Quoted 3 lines

pull out common init code like init_baudrate() and hang() and change the function signatures of the functions that require wrappers and move some #ifdef's into more appropriate locations - One example in board.c:

Well it seems like a lot of work to refactor each arch/xxx/board.c file into functions with a function pointer list, then later remove this code function by function.

Would that really be a clever approach?

Quoted 5 lines

My feeling is that with a generic board, it should hopefully be a fairly small amount of work for someone familiar with an architecture to find the bugs and patch the generic code to suit their architecture. It is something that needs to be done once, not every time there is a new patch removing (almost) common code.

It is definitely not that easy. You fix one thing here, and break another board there. Ideally you would have to re-test any change on _all_ boards.

Quoted 4 lines

From previous discussions, if something is optional then the switch will never happen. The code you are talking about is sometimes identical, sometimes slightly different. In some cases the order is different. I see many ways of introducing breakages. I do agree that

And I bet most of them _will_ introduce breakages.

Quoted 4 lines

doing one architecture at a time is best - with the proviso that we need to pick archs that have the most features (so ARM and PowerPC I suppose) to make sure we are not deluding ourselves as to the simplicity of the task.

I would suggest to attempt to merge ARM into PPC.

Quoted 4 lines

So perhaps a generic board init that is the default can be switched off on board-by-board basic would be the right approach. Then we can flick the switch while providing for those affected to still get work done until bugs are reported and found?

Heh! Board specific init tables!

Quoted 6 lines
Quoted 2 lines

Note that not all arches need and/or use ELF relocation - Attacking this first does not move towards unity of board.c

It is a feature used by about half, and it does include the complexity of jumping from pre-reloc to post-reloc init. I think it was a reasonable first target.

What exactly is the problem here?

Quoted 1 line

Per Wolfgang's request to go with PPC as an early-adopter, this is

No. It's the other way round. PPC is what should be adopted to.

Quoted 2 lines

Can anyone recommend a PowerPC board with a quick U-Boot program-run cycle that I can easily get that will let me try out things there?

Define "get easily".

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
People have one thing in common: they are all different.
#43 lore raw

cover Create generic board init and move ARM and x86 to it

Hi Wolfgang,

Quoted 4 lines · Wolfgang Denk

Dear Simon Glass,

Quoted 1 line · In message <CAPnjgZ1Zim6=u3rLcnAKE-0Bw3sO_hRY+U67jkpkNoNi8g7ctw@mail.gmail.com>…
Quoted 8 lines
Quoted 4 lines

Also it does depend on expectations. I would hope that moving an architecture over would be a fairly small task:

- getting generic relocation working

I don;t see why this would be a direct prerequisite here. ?We want to have that, no boubt about that. ?But it appears to be an unrelated change to me.

I don't think it's essential, but it is desirable, which I why it is on the list.

Quoted 4 lines
Quoted 2 lines

- adding functions for anything that is missing from board init code

"anything that is missing from board init code" ?

By that I mean that if the architecture has its own little things which aren't supported by generic board init, then these would need to be worked into the generic board init somehow, perhaps initially with a new function in the initcall list.

Quoted 4 lines
Quoted 2 lines

- removing things which don't work on the architecture?

That would probably reander systems broken that need these things?

Sorry for being so vague. What I mean is that if an arch does not support a feature, then we don't want to call the init functions for it on that architecture. Sometimes this is handled automatically - e.g. if an arch does not support CONFIG_POST then the generic board init code will skip this anyway. But there may be other cases where features available in the generic board init cannot be supported in all archs.

Quoted 10 lines
Quoted 2 lines

- worrying about differences in ordering between functions

This is indeed the biggest issue.

Keep in mind that my original ida of providing a function call table was to allow to define this table in a board specific way (i. e. in the board config file).

[Not that this idea found many friends...]

With this series I have moved over to purely having a function call table, with no actual init code in board_init_f() and board_init_r().

Having done this, I have found that the list of functions is very long, So we probably don't want boards to duplicate this list and #ifdefs may be the lesser of two evils. If we can move to Graham' initcall idea (basically using the linker to create the list of initcalls for pre- and post-reloc) then it becomes possible to boards to insert things in the init sequence without #ifdefs in commong/board.f/r.c.

For now I have tried to simply move the code into separate functions, since this makes it easier to compare against the original code in the arch/xxx/lib/board.c files, to make sure nothing is left out and the ordering is OK.

Quoted 10 lines
Quoted 8 lines
Quoted 4 lines

pull out common init code like init_baudrate() and hang() and change the function signatures of the functions that require wrappers and move some #ifdef's into more appropriate locations - One example in board.c:

Well it seems like a lot of work to refactor each arch/xxx/board.c file into functions with a function pointer list, then later remove this code function by function.

Would that really be a clever approach?

I'm not convinced it is the best idea. A trivial change of just removing duplicated code from all the archs and inserting it into generic board should be safe enough. But is that really a common case? I have found lots of subtle differences that need to be worked out, and there is the ordering to worry about. Every time there is a patch we need to re-test all boards. It might be easier to just create a generic board implementation one, and then test it once on each board, rather than testing on each board with every patch. Of course every time you patch generic board you might introduce a breakage in an existing (previously working) board, but that is the normal situation with development so I don't see a problem there.

Perhaps the biggest problem is the difficulty of testing, and if we can avoid months of little patches (each one potentially breaking lots of boards at run-time) then I would prefer that.

Quoted 10 lines
Quoted 6 lines

My feeling is that with a generic board, it should hopefully be a fairly small amount of work for someone familiar with an architecture to find the bugs and patch the generic code to suit their architecture. It is something that needs to be done once, not every time there is a new patch removing (almost) common code.

It is definitely not that easy. ?You fix one thing here, and break another board there. ?Ideally you would have to re-test any change on _all_ boards.

Well I suppose that's what I'm saying. Doing this once, accepting that some boards will thereby be broken, and then accepting patches to fix them feels easier than trying to keep everything working through a long series of little changes.

Quoted 6 lines
Quoted 5 lines

From previous discussions, if something is optional then the switch will never happen. The code you are talking about is sometimes identical, sometimes slightly different. In some cases the order is different. I see many ways of introducing breakages. I do agree that

Quoted 8 lines

And I bet most of them _will_ introduce breakages.

Quoted 4 lines

doing one architecture at a time is best - with the proviso that we need to pick archs that have the most features (so ARM and PowerPC I suppose) to make sure we are not deluding ourselves as to the simplicity of the task.

I would suggest to attempt to merge ARM into PPC.

Yes I hear you. I have had a crack at that with pre-reloc init. It's not exactly a thing of beauty but it isn't too bad. What I really like about having everything in one file (#ifdefs and all) is that you can quickly see where there are unnecessary arch differences, and refactor them.

Quoted 7 lines
Quoted 5 lines

So perhaps a generic board init that is the default can be switched off on board-by-board basic would be the right approach. Then we can flick the switch while providing for those affected to still get work done until bugs are reported and found?

Heh! ?Board specific init tables!

See above - I vote for Graham's initcall stuff - I believe the main concern was figuring out the init order and perhaps a little objdump | grep | awk System.map script would do the job here.

Quoted 9 lines
Quoted 7 lines
Quoted 3 lines

Note that not all arches need and/or use ELF relocation - Attacking this first does not move towards unity of board.c

It is a feature used by about half, and it does include the complexity of jumping from pre-reloc to post-reloc init. I think it was a reasonable first target.

What exactly is the problem here?

The problem is the code duplication inherent in relocation - each architecture has its own way of doing it, but really it can mostly be written generically in C. ARM is even worse with each CPU implementing essentially the same code!

Quoted 4 lines
Quoted 2 lines

Per Wolfgang's request to go with PPC as an early-adopter, this is

No. ?It's the other way round. ?PPC is what should be adopted to.

Yes I can see that PPC is a superset, or at least contains the most features. I will continue to look at this.

Quoted 5 lines
Quoted 3 lines

Can anyone recommend a PowerPC board with a quick U-Boot program-run cycle that I can easily get that will let me try out things there?

Define "get easily".

Well, perhaps buy for around $500 or so and get it shipped to California to arrive this week/early next?

Regards,
Simon

Quoted 10 lines

Best regards,

Wolfgang Denk

--
DENX Software Engineering GmbH, ? ? MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de People have one thing in common: they are all different.

#44 lore raw

cover Create generic board init and move ARM and x86 to it

Dear Simon Glass,

Quoted 9 lines · In message <CAPnjgZ1eutEboyvEtYcxcZcv=1Z_3tKq_45wBrgNdPsnxRth3A@mail.gmail.com>…
Quoted 6 lines
Quoted 2 lines

- getting generic relocation working

I don;t see why this would be a direct prerequisite here. =A0We want to have that, no boubt about that. =A0But it appears to be an unrelated change to me.

I don't think it's essential, but it is desirable, which I why it is on the list.

I recommend to put this on a different list. Please keep changes orthogonal and restict this discussion and patch series to things dealing with the normalization of the board init code.

This is complicated enough, and it does not good to include additional, unrelated tasks.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

- adding functions for anything that is missing from board init code

"anything that is missing from board init code" ?

By that I mean that if the architecture has its own little things which aren't supported by generic board init, then these would need to be worked into the generic board init somehow, perhaps initially with a new function in the initcall list.

Such an approach will most probable result in a mess of code that is even more dificult to maintain than the current split we have now.

Quoted 11 lines
Quoted 3 lines
Quoted 1 line

- removing things which don't work on the architecture?

That would probably reander systems broken that need these things?

Sorry for being so vague. What I mean is that if an arch does not support a feature, then we don't want to call the init functions for it on that architecture. Sometimes this is handled automatically - e.g. if an arch does not support CONFIG_POST then the generic board init code will skip this anyway. But there may be other cases where features available in the generic board init cannot be supported in all archs.

This is the same problem as above, right? Each architecture, and actually each board may or may not require certain initializations, and actually may require them to happen in a certain order (which may be different from other boards).

Quoted 8 lines
Quoted 5 lines

Keep in mind that my original ida of providing a function call table was to allow to define this table in a board specific way (i. e. in the board config file).

[Not that this idea found many friends...]

With this series I have moved over to purely having a function call table, with no actual init code in board_init_f() and board_init_r().

This was the original plan.

Quoted 3 lines

Having done this, I have found that the list of functions is very long, So we probably don't want boards to duplicate this list and #ifdefs may be the lesser of two evils. If we can move to Graham'

I don't really see this as an practical approach. Did you look at the PPC code? init_sequence[] has a total of 29 entries, "decorated" with 21 conditionals. If we merge in ARM and x86, we will have a mess nobody is able to understand.

Quoted 4 lines

For now I have tried to simply move the code into separate functions, since this makes it easier to compare against the original code in the arch/xxx/lib/board.c files, to make sure nothing is left out and the ordering is OK.

Agreed.

Quoted 12 lines

I'm not convinced it is the best idea. A trivial change of just removing duplicated code from all the archs and inserting it into generic board should be safe enough. But is that really a common case? I have found lots of subtle differences that need to be worked out, and there is the ordering to worry about. Every time there is a patch we need to re-test all boards. It might be easier to just create a generic board implementation one, and then test it once on each board, rather than testing on each board with every patch. Of course every time you patch generic board you might introduce a breakage in an existing (previously working) board, but that is the normal situation with development so I don't see a problem there.

Quoted 3 lines

Perhaps the biggest problem is the difficulty of testing, and if we can avoid months of little patches (each one potentially breaking lots of boards at run-time) then I would prefer that.

I am not sure that the whole approach makes sense. The resulkting mess of #ifdef's is not there because people didn't care, but because of very specific requirements of specific hardware, that - at least given the tools of the respective point of time - could not be solved more efficiently.

I see two options here:

- We can take the existing code and try to unify it, and make all boards (including a large number of EOLed and unmaintained ones) to that new code base.

This will be a lot of work, and the resulting code will probably messy again.

- We could as well try to come up with a new, cleaned up implementa- tion that maybe doesn't fit all, but only 80 or 90% of the existing boards. We could then (1) convert existing code step by step to the new implementation and (2) accept new submissions only when using the new code.

There may be a number of boards where conversion is non trivial, or where nobody is willing or able to perform the changes and / or the testing. My gut feeling tis that this would be a relatively small number of boards, and mostly old and unmaintained ones. We might give them some grace period and then remove them.

Quoted 4 lines

Well I suppose that's what I'm saying. Doing this once, accepting that some boards will thereby be broken, and then accepting patches to fix them feels easier than trying to keep everything working through a long series of little changes.

You appear to assume that onlly a small percentage of boards would be broken. My expectations are different. Intentionally causing breakage may be useful here and there, but I don;t think it;s the right thing here.

Quoted 10 lines
Quoted 5 lines
Quoted 3 lines

It is a feature used by about half, and it does include the complexity of jumping from pre-reloc to post-reloc init. I think it was a reasonable first target.

What exactly is the problem here?

The problem is the code duplication inherent in relocation - each architecture has its own way of doing it, but really it can mostly be written generically in C. ARM is even worse with each CPU implementing essentially the same code!

I suggect we leave relocation out of this discussion here. It is an area that needs to be cleaned up, definitely. But it is another, unrelated topic.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"No problem is so formidable that you can't walk away from it."
- C. Schulz