diff mbox

[U-Boot,v3,8/9] sunxi: non-FEL SPL boot support for sun7i

Message ID 1397844350-7341-8-git-send-email-ijc@hellion.org.uk
State Superseded
Delegated to: Albert ARIBAUD
Headers show

Commit Message

Ian Campbell April 18, 2014, 6:05 p.m. UTC
Add support for booting from an MMC card.

Signed-off-by: Stefan Roese <sr@denx.de>
Signed-off-by: Henrik Nordström <henrik@henriknordstrom.net>
Signed-off-by: Ian Campbell <ijc@hellion.org.uk>
Cc: Tom Cubie <Mr.hipboi@gmail.com>
---
v3: Based on c89867dca2e9 "sunxi: clocks: clock_get_pll5
prototype and coding style".

v2: Based on u-boot-sunxi.git#sunxi d9aa5dd3d15c "sunxi: mmc:
checkpatch whitespace fixes" with v2014.04-rc2 merged in:
   - mksunxiboot cleanups
   - rebase on Kbuild stuff

v1: Based on u-boot-sunxi.git#sunxi commit d854c4de2f57 "arm: Handle .gnu.hash
section in ldscripts" vs v2014.01.
---
 Makefile                                |  10 +++
 arch/arm/cpu/armv7/sunxi/config.mk      |   8 ++
 arch/arm/cpu/armv7/sunxi/u-boot-spl.lds |  52 +++++++++++
 boards.cfg                              |   1 +
 include/configs/sunxi-common.h          |  26 ++++++
 spl/Makefile                            |  13 +++
 tools/.gitignore                        |   1 +
 tools/Makefile                          |   2 +
 tools/mksunxiboot.c                     | 154 ++++++++++++++++++++++++++++++++
 9 files changed, 267 insertions(+)
 create mode 100644 arch/arm/cpu/armv7/sunxi/config.mk
 create mode 100644 arch/arm/cpu/armv7/sunxi/u-boot-spl.lds
 create mode 100644 tools/mksunxiboot.c

Comments

Marek Vasut April 26, 2014, 6:46 p.m. UTC | #1
On Friday, April 18, 2014 at 08:05:49 PM, Ian Campbell wrote:
> Add support for booting from an MMC card.
> 
> Signed-off-by: Stefan Roese <sr@denx.de>
> Signed-off-by: Henrik Nordström <henrik@henriknordstrom.net>
> Signed-off-by: Ian Campbell <ijc@hellion.org.uk>
> Cc: Tom Cubie <Mr.hipboi@gmail.com>
[...]

> +typedef unsigned char u8;
> +typedef unsigned int u32;

Uh, really ? Just use uint8_t or uint32_t ...

> +/* boot head definition from sun4i boot code */
> +struct boot_file_head {
> +	u32 jump_instruction;	/* one intruction jumping to real code */
> +	u8 magic[8];		/* ="eGON.BT0" or "eGON.BT1", not C-style str */
> +	u32 check_sum;		/* generated by PC */
> +	u32 length;		/* generated by PC */
> +#if 1
> +	/* We use a simplified header, only filling in what is needed by the
> +	 * boot ROM. To be compatible with Allwinner tools the larger header
> +	 * below should be used, followed by a custom header if desired. */
> +	u8 pad[12];		/* align to 32 bytes */
> +#else

Please fix or remove dead code.

> +	u32 pub_head_size;	/* the size of boot_file_head */
> +	u8 pub_head_vsn[4];	/* the version of boot_file_head */
> +	u8 file_head_vsn[4];	/* the version of boot0_file_head or
> +				   boot1_file_head */
> +	u8 Boot_vsn[4];		/* Boot version */
> +	u8 eGON_vsn[4];		/* eGON version */
> +	u8 platform[8];		/* platform information */
> +#endif
> +};
> +
> +#define BOOT0_MAGIC                     "eGON.BT0"
> +#define STAMP_VALUE                     0x5F0A6C39
> +
> +/* check sum functon from sun4i boot code */
> +int gen_check_sum(void *boot_buf)
> +{
> +	struct boot_file_head *head_p;
> +	u32 length;
> +	u32 *buf;
> +	u32 loop;
> +	u32 i;
> +	u32 sum;
> +
> +	head_p = (struct boot_file_head *)boot_buf;
> +	length = head_p->length;
> +	if ((length & 0x3) != 0)	/* must 4-byte-aligned */
> +		return -1;
> +	buf = (u32 *)boot_buf;

This will cause unaligned access if ran on ARM and boot_buf is not aligned.

> +	head_p->check_sum = STAMP_VALUE;	/* fill stamp */
> +	loop = length >> 2;
> +
> +	/* calculate the sum */
> +	for (i = 0, sum = 0; i < loop; i++)
> +		sum += buf[i];
> +
> +	/* write back check sum */
> +	head_p->check_sum = sum;
> +
> +	return 0;
> +}
> +
> +#define ALIGN(x, a) __ALIGN_MASK((x), (typeof(x))(a)-1)
> +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))

Isn't this already defined in include/common.h ?

Looks like this tool might as well be wrapped into the mkimage toolset ...
Ian Campbell April 27, 2014, 5 p.m. UTC | #2
On Sat, 2014-04-26 at 20:46 +0200, Marek Vasut wrote:

> > +#define ALIGN(x, a) __ALIGN_MASK((x), (typeof(x))(a)-1)
> > +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
> 
> Isn't this already defined in include/common.h ?

Yes but it seems that header isn't usable by tools/* AFAICT. I get a
boatload of compiler errors when I try...

Ian.
Marek Vasut April 27, 2014, 6:07 p.m. UTC | #3
On Sunday, April 27, 2014 at 07:00:34 PM, Ian Campbell wrote:
> On Sat, 2014-04-26 at 20:46 +0200, Marek Vasut wrote:
> > > +#define ALIGN(x, a) __ALIGN_MASK((x), (typeof(x))(a)-1)
> > > +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
> > 
> > Isn't this already defined in include/common.h ?
> 
> Yes but it seems that header isn't usable by tools/* AFAICT. I get a
> boatload of compiler errors when I try...

There are a couple of things which include it even in tools/ :

# git grep common.h tools/
tools/patman/test.py: include/common.h    |    8 ++++++
tools/patman/test.py:+#include <common.h>
tools/scripts/define2mk.sed:# which preprocesses the common.h header files and 
outputs the final
tools/updater/cmd_flash.c:#include <common.h>
tools/updater/flash.c:#include <common.h>
tools/updater/flash_hw.c:#include <common.h>
tools/updater/update.c:#include <common.h>
tools/updater/utils.c:#include <common.h>

btw. I should have escaped the dot in common.h pattern, but whatever ...

Best regards,
Marek Vasut
Ian Campbell April 27, 2014, 6:38 p.m. UTC | #4
On Sun, 2014-04-27 at 20:07 +0200, Marek Vasut wrote:

> # git grep common.h tools/
> tools/patman/test.py: include/common.h    |    8 ++++++
> tools/patman/test.py:+#include <common.h>
> tools/scripts/define2mk.sed:# which preprocesses the common.h header files and 
> outputs the final

I only got these three when I looked. I'm on v2014.04, but even with
current trunk I only see fit_common.h not the ones which you show below
(tools/updater isn't even in trunk). Perhaps this is some newer stuff
not yet in trunk?

> tools/updater/cmd_flash.c:#include <common.h>
> tools/updater/flash.c:#include <common.h>
> tools/updater/flash_hw.c:#include <common.h>
> tools/updater/update.c:#include <common.h>
> tools/updater/utils.c:#include <common.h>
> 
> btw. I should have escaped the dot in common.h pattern, but whatever ...
> 
> Best regards,
> Marek Vasut
>
Marek Vasut April 27, 2014, 7:15 p.m. UTC | #5
On Sunday, April 27, 2014 at 08:38:52 PM, Ian Campbell wrote:
> On Sun, 2014-04-27 at 20:07 +0200, Marek Vasut wrote:
> > # git grep common.h tools/
> > tools/patman/test.py: include/common.h    |    8 ++++++
> > tools/patman/test.py:+#include <common.h>
> > tools/scripts/define2mk.sed:# which preprocesses the common.h header
> > files and outputs the final
> 
> I only got these three when I looked. I'm on v2014.04, but even with
> current trunk I only see fit_common.h not the ones which you show below
> (tools/updater isn't even in trunk). Perhaps this is some newer stuff
> not yet in trunk?

Ah, darn. What errors do you get ?

Best regards,
Marek Vasut
Ian Campbell April 27, 2014, 7:29 p.m. UTC | #6
On Sun, 2014-04-27 at 21:15 +0200, Marek Vasut wrote:
> On Sunday, April 27, 2014 at 08:38:52 PM, Ian Campbell wrote:
> > On Sun, 2014-04-27 at 20:07 +0200, Marek Vasut wrote:
> > > # git grep common.h tools/
> > > tools/patman/test.py: include/common.h    |    8 ++++++
> > > tools/patman/test.py:+#include <common.h>
> > > tools/scripts/define2mk.sed:# which preprocesses the common.h header
> > > files and outputs the final
> > 
> > I only got these three when I looked. I'm on v2014.04, but even with
> > current trunk I only see fit_common.h not the ones which you show below
> > (tools/updater isn't even in trunk). Perhaps this is some newer stuff
> > not yet in trunk?
> 
> Ah, darn. What errors do you get ?

All sorts...

  HOSTCC  tools/mksunxiboot
In file included from include/common.h:20:0,
                 from tools/mksunxiboot.c:18:
include/linux/bitops.h: In function ‘generic_set_bit’:
include/linux/bitops.h:141:23: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
  unsigned long mask = BIT_MASK(nr);
                       ^
include/linux/bitops.h:141:23: note: each undeclared identifier is reported only once for each function it appears in
include/linux/bitops.h: In function ‘generic_clear_bit’:
include/linux/bitops.h:149:23: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
  unsigned long mask = BIT_MASK(nr);
                       ^
In file included from include/part.h:177:0,
                 from include/common.h:92,
                 from tools/mksunxiboot.c:18:
include/part_efi.h: At top level:
include/part_efi.h:62:1: error: unknown type name ‘u16’
 typedef u16 efi_char16_t;
 ^
include/part_efi.h:65:2: error: unknown type name ‘u8’
  u8 b[16];
  ^
include/part_efi.h:70:2: error: unknown type name ‘u8’
  u8 boot_ind;  /* 0x80 - active */
  ^
include/part_efi.h:71:2: error: unknown type name ‘u8’
  u8 head;  /* starting head */
  ^
include/part_efi.h:72:2: error: unknown type name ‘u8’
  u8 sector;  /* starting sector */
  ^
include/part_efi.h:73:2: error: unknown type name ‘u8’
  u8 cyl;   /* starting cylinder */
  ^
include/part_efi.h:74:2: error: unknown type name ‘u8’
  u8 sys_ind;  /* What partition type */
  ^
include/part_efi.h:75:2: error: unknown type name ‘u8’
  u8 end_head;  /* end head */
  ^
include/part_efi.h:76:2: error: unknown type name ‘u8’
  u8 end_sector;  /* end sector */
  ^
include/part_efi.h:77:2: error: unknown type name ‘u8’
  u8 end_cyl;  /* end cylinder */
  ^
include/part_efi.h:98:12: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘gpt_header’
 } __packed gpt_header;
            ^
include/part_efi.h:102:3: error: unknown type name ‘u64’
   u64 required_to_function:1;
   ^
include/part_efi.h:103:3: error: unknown type name ‘u64’
   u64 no_block_io_protocol:1;
   ^
include/part_efi.h:104:3: error: unknown type name ‘u64’
   u64 legacy_bios_bootable:1;
   ^
include/part_efi.h:105:3: error: unknown type name ‘u64’
   u64 reserved:45;
   ^
include/part_efi.h:105:3: error: width of ‘reserved’ exceeds its type
include/part_efi.h:106:3: error: unknown type name ‘u64’
   u64 type_guid_specific:16;
   ^
include/part_efi.h:109:12: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘gpt_entry_attributes’
 } __packed gpt_entry_attributes;
            ^
include/part_efi.h:117:2: error: unknown type name ‘gpt_entry_attributes’
  gpt_entry_attributes attributes;
  ^
include/part_efi.h:119:12: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘gpt_entry’
 } __packed gpt_entry;
            ^
include/part_efi.h:122:2: error: unknown type name ‘u8’
  u8 boot_code[440];
  ^
include/part_efi.h:127:12: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘legacy_mbr’
 } __packed legacy_mbr;
            ^
In file included from include/common.h:92:0,
                 from tools/mksunxiboot.c:18:
include/part.h:193:5: error: unknown type name ‘gpt_header’
     gpt_header *gpt_h, gpt_entry *gpt_e);
     ^
include/part.h:193:24: error: unknown type name ‘gpt_entry’
     gpt_header *gpt_h, gpt_entry *gpt_e);
                        ^
include/part.h:205:18: error: unknown type name ‘gpt_header’
 int gpt_fill_pte(gpt_header *gpt_h, gpt_entry *gpt_e,
                  ^
include/part.h:205:37: error: unknown type name ‘gpt_entry’
 int gpt_fill_pte(gpt_header *gpt_h, gpt_entry *gpt_e,
                                     ^
include/part.h:218:49: error: unknown type name ‘gpt_header’
 int gpt_fill_header(block_dev_desc_t *dev_desc, gpt_header *gpt_h,
                                                 ^
In file included from include/image.h:49:0,
                 from include/common.h:94,
                 from tools/mksunxiboot.c:18:
include/fdt_support.h:15:1: error: unknown type name ‘u32’
 u32 fdt_getprop_u32_default(const void *fdt, const char *path,
 ^
include/fdt_support.h:16:5: error: unknown type name ‘u32’
     const char *prop, const u32 dflt);
     ^
include/fdt_support.h:22:6: error: unknown type name ‘u32’
      u32 val, int create);
      ^
include/fdt_support.h:36:24: error: unknown type name ‘u32’
      const char *prop, u32 val, int create);
                        ^
include/fdt_support.h:40:26: error: unknown type name ‘u32’
        const char *prop, u32 val, int create);
                          ^
include/fdt_support.h:41:34: error: unknown type name ‘u64’
 int fdt_fixup_memory(void *blob, u64 start, u64 size);
                                  ^
include/fdt_support.h:41:45: error: unknown type name ‘u64’
 int fdt_fixup_memory(void *blob, u64 start, u64 size);
                                             ^
include/fdt_support.h:42:40: error: unknown type name ‘u64’
 int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks);
                                        ^
include/fdt_support.h:42:53: error: unknown type name ‘u64’
 int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks);
                                                     ^
include/fdt_support.h:51:49: error: unknown type name ‘bd_t’
 static inline void fdt_fixup_dr_usb(void *blob, bd_t *bd) {}
                                                 ^
include/fdt_support.h:65:33: error: unknown type name ‘bd_t’
 void ft_board_setup(void *blob, bd_t *bd);
                                 ^
include/fdt_support.h:66:31: error: unknown type name ‘bd_t’
 void ft_cpu_setup(void *blob, bd_t *bd);
                               ^
include/fdt_support.h:67:31: error: unknown type name ‘bd_t’
 void ft_pci_setup(void *blob, bd_t *bd);
                               ^
include/fdt_support.h:77:1: error: unknown type name ‘u64’
 u64 fdt_translate_address(void *blob, int node_offset, const __be32 *in_addr);
 ^
include/fdt_support.h:79:6: error: unknown type name ‘phys_addr_t’
      phys_addr_t compat_off);
      ^
include/fdt_support.h:86:10: error: unknown type name ‘u64’
          u64 addr);
          ^
include/fdt_support.h:87:1: error: unknown type name ‘u64’
 u64 fdt_get_base_address(void *fdt, int node);
 ^
In file included from include/common.h:94:0,
                 from tools/mksunxiboot.c:18:
include/image.h:322:13: error: field ‘lmb’ has incomplete type
  struct lmb lmb;  /* for memory mgmt */
             ^
include/image.h: In function ‘fit_image_check_target_arch’:
include/image.h:981:41: error: ‘IH_ARCH_DEFAULT’ undeclared (first use in this function)
  return fit_image_check_arch(fdt, node, IH_ARCH_DEFAULT);
                                         ^
In file included from /home/ijc/devel/u-boot.git/arch/arm/include/asm/u-boot.h:25:0,
                 from include/common.h:153,
                 from tools/mksunxiboot.c:18:
include/asm-generic/u-boot.h: At top level:
include/asm-generic/u-boot.h:29:2: error: unknown type name ‘phys_size_t’
  phys_size_t bi_memsize; /* size  of DRAM memory in bytes */
  ^
In file included from /home/ijc/devel/u-boot.git/arch/arm/include/asm/global_data.h:45:0,
                 from include/common.h:154,
                 from tools/mksunxiboot.c:18:
include/asm-generic/global_data.h:60:2: error: unknown type name ‘phys_size_t’
  phys_size_t ram_size; /* RAM size */
  ^
In file included from tools/mksunxiboot.c:18:0:
include/common.h:267:1: error: unknown type name ‘phys_size_t’
 phys_size_t initdram (int);
 ^
include/common.h:306:1: error: unknown type name ‘u8’
 extern u8 __dtb_dt_begin[]; /* embedded device tree blob */
 ^
include/common.h:352:14: error: unknown type name ‘cmd_tbl_t’
 int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
              ^
include/common.h:355:19: error: unknown type name ‘cmd_tbl_t’
 int do_fat_fsload(cmd_tbl_t *, int, int, char * const []);
                   ^
include/common.h:358:17: error: unknown type name ‘cmd_tbl_t’
 int do_ext2load(cmd_tbl_t *, int, int, char * const []);
                 ^
include/common.h:391:5: error: conflicting types for ‘setenv’
 int setenv      (const char *, const char *);
     ^
In file included from /home/ijc/devel/u-boot.git/include/compiler.h:23:0,
                 from /home/ijc/devel/u-boot.git/include/libfdt_env.h:12,
                 from <command-line>:0:
/usr/include/stdlib.h:584:12: note: previous declaration of ‘setenv’ was here
 extern int setenv (const char *__name, const char *__value, int __replace)
            ^
In file included from tools/mksunxiboot.c:18:0:
include/common.h:471:1: error: unknown type name ‘phys_size_t’
 phys_size_t get_effective_memsize(void);
 ^
include/common.h:635:1: error: unknown type name ‘u32’
 u32 cpu_mask      (void);
 ^
In file included from include/common.h:825:0,
                 from tools/mksunxiboot.c:18:
include/uuid.h:18:3: error: conflicting types for ‘__packed’
 } __packed;
   ^
In file included from include/part.h:177:0,
                 from include/common.h:92,
                 from tools/mksunxiboot.c:18:
include/part_efi.h:80:3: note: previous declaration of ‘__packed’ was here
 } __packed;
   ^
In file included from /home/ijc/devel/u-boot.git/include/compiler.h:25:0,
                 from /home/ijc/devel/u-boot.git/include/libfdt_env.h:12,
                 from <command-line>:0:
include/common.h:860:5: error: conflicting types for ‘_IO_getc’
 int getc(void);
     ^
In file included from /usr/include/stdio.h:74:0,
                 from /home/ijc/devel/u-boot.git/include/compiler.h:25,
                 from /home/ijc/devel/u-boot.git/include/libfdt_env.h:12,
                 from <command-line>:0:
/usr/include/libio.h:434:12: note: previous declaration of ‘_IO_getc’ was here
 extern int _IO_getc (_IO_FILE *__fp);
            ^
In file included from tools/mksunxiboot.c:18:0:
include/common.h:864:23: error: macro "putc" requires 2 arguments, but only 1 given
 void putc(const char c);
                       ^
include/common.h:864:6: error: ‘putc’ redeclared as different kind of symbol
 void putc(const char c);
      ^
include/common.h:865:6: error: conflicting types for ‘puts’
 void puts(const char *s);
      ^
include/common.h:883:5: error: conflicting types for ‘fprintf’
 int fprintf(int file, const char *fmt, ...)
     ^
include/common.h:885:6: error: conflicting types for ‘fputs’
 void fputs(int file, const char *s);
      ^
include/common.h:886:6: error: conflicting types for ‘fputc’
 void fputc(int file, const char c);
      ^
include/common.h:888:5: error: conflicting types for ‘fgetc’
 int fgetc(int file);
     ^
In file included from /home/ijc/devel/u-boot.git/include/compiler.h:25:0,
                 from /home/ijc/devel/u-boot.git/include/libfdt_env.h:12,
                 from <command-line>:0:
/usr/include/stdio.h:531:12: note: previous declaration of ‘fgetc’ was here
 extern int fgetc (FILE *__stream);
            ^
In file included from include/common.h:898:0,
                 from tools/mksunxiboot.c:18:
include/net.h:632:1: error: unknown type name ‘u8’
 static inline int is_zero_ether_addr(const u8 *addr)
 ^
include/net.h:644:1: error: unknown type name ‘u8’
 static inline int is_multicast_ether_addr(const u8 *addr)
 ^
include/net.h:655:1: error: unknown type name ‘u8’
 static inline int is_broadcast_ether_addr(const u8 *addr)
 ^
include/net.h:670:1: error: unknown type name ‘u8’
 static inline int is_valid_ether_addr(const u8 *addr)
 ^
In file included from tools/mksunxiboot.c:18:0:
include/common.h:933:32: error: unknown type name ‘phys_addr_t’
 static inline void *map_sysmem(phys_addr_t paddr, unsigned long len)
                                ^
include/common.h:942:1: error: unknown type name ‘phys_addr_t’
 static inline phys_addr_t map_to_sysmem(const void *ptr)
 ^
include/common.h: In function ‘map_to_sysmem’:
include/common.h:944:10: error: ‘phys_addr_t’ undeclared (first use in this function)
  return (phys_addr_t)(uintptr_t)ptr;
          ^
include/common.h:944:23: error: expected expression before ‘uintptr_t’
  return (phys_addr_t)(uintptr_t)ptr;
                       ^
include/common.h:944:33: error: expected ‘;’ before ‘ptr’
  return (phys_addr_t)(uintptr_t)ptr;
                                 ^
make[1]: *** [tools/mksunxiboot] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [tools] Error 2
Marek Vasut April 27, 2014, 11:58 p.m. UTC | #7
On Sunday, April 27, 2014 at 09:29:02 PM, Ian Campbell wrote:
> On Sun, 2014-04-27 at 21:15 +0200, Marek Vasut wrote:
> > On Sunday, April 27, 2014 at 08:38:52 PM, Ian Campbell wrote:
> > > On Sun, 2014-04-27 at 20:07 +0200, Marek Vasut wrote:
> > > > # git grep common.h tools/
> > > > tools/patman/test.py: include/common.h    |    8 ++++++
> > > > tools/patman/test.py:+#include <common.h>
> > > > tools/scripts/define2mk.sed:# which preprocesses the common.h header
> > > > files and outputs the final
> > > 
> > > I only got these three when I looked. I'm on v2014.04, but even with
> > > current trunk I only see fit_common.h not the ones which you show below
> > > (tools/updater isn't even in trunk). Perhaps this is some newer stuff
> > > not yet in trunk?
> > 
> > Ah, darn. What errors do you get ?
> 
> All sorts...

Ouch, ok. How come the other files can include this stuff without errors ?

Best regards,
Marek Vasut
Ian Campbell April 28, 2014, 9:06 a.m. UTC | #8
On Mon, 2014-04-28 at 01:58 +0200, Marek Vasut wrote:
> On Sunday, April 27, 2014 at 09:29:02 PM, Ian Campbell wrote:
> > On Sun, 2014-04-27 at 21:15 +0200, Marek Vasut wrote:
> > > On Sunday, April 27, 2014 at 08:38:52 PM, Ian Campbell wrote:
> > > > On Sun, 2014-04-27 at 20:07 +0200, Marek Vasut wrote:
> > > > > # git grep common.h tools/
> > > > > tools/patman/test.py: include/common.h    |    8 ++++++
> > > > > tools/patman/test.py:+#include <common.h>
> > > > > tools/scripts/define2mk.sed:# which preprocesses the common.h header
> > > > > files and outputs the final
> > > > 
> > > > I only got these three when I looked. I'm on v2014.04, but even with
> > > > current trunk I only see fit_common.h not the ones which you show below
> > > > (tools/updater isn't even in trunk). Perhaps this is some newer stuff
> > > > not yet in trunk?
> > > 
> > > Ah, darn. What errors do you get ?
> > 
> > All sorts...
> 
> Ouch, ok. How come the other files can include this stuff without errors ?

AFAIK nothing in the current mainline master does, I think you must have
some other branch merged.

Ian.
diff mbox

Patch

diff --git a/Makefile b/Makefile
index c91c10e..379731c 100644
--- a/Makefile
+++ b/Makefile
@@ -870,6 +870,13 @@  OBJCOPYFLAGS_u-boot.spr = -I binary -O binary --pad-to=$(CONFIG_SPL_PAD_TO) \
 u-boot.spr: spl/u-boot-spl.img u-boot.img FORCE
 	$(call if_changed,pad_cat)
 
+ifneq ($(CONFIG_SUNXI),)
+OBJCOPYFLAGS_u-boot-sunxi-with-spl.bin = -I binary -O binary \
+				   --pad-to=$(CONFIG_SPL_PAD_TO) --gap-fill=0xff
+u-boot-sunxi-with-spl.bin: spl/sunxi-spl.bin u-boot.img FORCE
+	$(call if_changed,pad_cat)
+endif
+
 ifneq ($(CONFIG_TEGRA),)
 OBJCOPYFLAGS_u-boot-nodtb-tegra.bin = -O binary --pad-to=$(CONFIG_SYS_TEXT_BASE)
 u-boot-nodtb-tegra.bin: spl/u-boot-spl u-boot.bin FORCE
@@ -1081,6 +1088,9 @@  spl/u-boot-spl.bin: spl/u-boot-spl
 spl/u-boot-spl: tools prepare
 	$(Q)$(MAKE) obj=spl -f $(srctree)/spl/Makefile all
 
+spl/sunxi-spl.bin: spl/u-boot-spl
+	@:
+
 tpl/u-boot-tpl.bin: tools prepare
 	$(Q)$(MAKE) obj=tpl -f $(srctree)/spl/Makefile all CONFIG_TPL_BUILD=y
 
diff --git a/arch/arm/cpu/armv7/sunxi/config.mk b/arch/arm/cpu/armv7/sunxi/config.mk
new file mode 100644
index 0000000..00f5ffc
--- /dev/null
+++ b/arch/arm/cpu/armv7/sunxi/config.mk
@@ -0,0 +1,8 @@ 
+# Build a combined spl + u-boot image
+ifdef CONFIG_SPL
+ifndef CONFIG_SPL_BUILD
+ifndef CONFIG_SPL_FEL
+ALL-y += u-boot-sunxi-with-spl.bin
+endif
+endif
+endif
diff --git a/arch/arm/cpu/armv7/sunxi/u-boot-spl.lds b/arch/arm/cpu/armv7/sunxi/u-boot-spl.lds
new file mode 100644
index 0000000..5008028
--- /dev/null
+++ b/arch/arm/cpu/armv7/sunxi/u-boot-spl.lds
@@ -0,0 +1,52 @@ 
+/*
+ * (C) Copyright 2012
+ * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
+ * Tom Cubie <tangliang@allwinnertech.com>
+ *
+ * Based on omap-common/u-boot-spl.lds:
+ *
+ * (C) Copyright 2002
+ * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
+ *
+ * (C) Copyright 2010
+ * Texas Instruments, <www.ti.com>
+ *	Aneesh V <aneesh@ti.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+MEMORY { .sram : ORIGIN = CONFIG_SPL_TEXT_BASE,\
+		LENGTH = CONFIG_SPL_MAX_SIZE }
+MEMORY { .sdram : ORIGIN = CONFIG_SPL_BSS_START_ADDR, \
+		LENGTH = CONFIG_SPL_BSS_MAX_SIZE }
+
+OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
+OUTPUT_ARCH(arm)
+ENTRY(_start)
+SECTIONS
+{
+	.text      :
+	{
+		__start = .;
+		arch/arm/cpu/armv7/start.o	(.text)
+		*(.text*)
+	} > .sram
+
+	. = ALIGN(4);
+	.rodata : { *(SORT_BY_ALIGNMENT(.rodata*)) } >.sram
+
+	. = ALIGN(4);
+	.data : { *(SORT_BY_ALIGNMENT(.data*)) } >.sram
+
+	. = ALIGN(4);
+	__image_copy_end = .;
+	_end = .;
+
+	.bss :
+	{
+		. = ALIGN(4);
+		__bss_start = .;
+		*(.bss*)
+		. = ALIGN(4);
+		__bss_end = .;
+	} > .sdram
+}
diff --git a/boards.cfg b/boards.cfg
index b74f8c8..b6e20ae 100644
--- a/boards.cfg
+++ b/boards.cfg
@@ -371,6 +371,7 @@  Active  arm         armv7          rmobile     renesas         lager
 Active  arm         armv7          s5pc1xx     samsung         goni                s5p_goni                             -                                                                                                                                 Mateusz Zalega <m.zalega@samsung.com>
 Active  arm         armv7          s5pc1xx     samsung         smdkc100            smdkc100                             -                                                                                                                                 Minkyu Kang <mk7.kang@samsung.com>
 Active  arm         armv7          socfpga     altera          socfpga             socfpga_cyclone5                     -                                                                                                                                 -
+Active  arm         armv7          sunxi       -               sunxi               Cubietruck                           sun7i:CUBIETRUCK,SPL,SUNXI_GMAC,RGMII                                                                                             -
 Active  arm         armv7          sunxi       -               sunxi               Cubietruck_FEL                       sun7i:CUBIETRUCK,SPL_FEL,SUNXI_GMAC,RGMII                                                                                         -
 Active  arm         armv7          u8500       st-ericsson     snowball            snowball                             -                                                                                                                                 Mathieu Poirier <mathieu.poirier@linaro.org>
 Active  arm         armv7          u8500       st-ericsson     u8500               u8500_href                           -                                                                                                                                 -
diff --git a/include/configs/sunxi-common.h b/include/configs/sunxi-common.h
index ede3d50..56a89b9 100644
--- a/include/configs/sunxi-common.h
+++ b/include/configs/sunxi-common.h
@@ -17,6 +17,11 @@ 
  * High Level Configuration Options
  */
 #define CONFIG_SUNXI		/* sunxi family */
+#ifdef CONFIG_SPL_BUILD
+#ifndef CONFIG_SPL_FEL
+#define CONFIG_SYS_THUMB_BUILD	/* Thumbs mode to save space in SPL */
+#endif
+#endif
 
 #include <asm/arch/cpu.h>	/* get chip and board defs */
 
@@ -121,11 +126,32 @@ 
 #define CONFIG_SPL_SERIAL_SUPPORT
 #define CONFIG_SPL_LIBGENERIC_SUPPORT
 
+#ifdef CONFIG_SPL_FEL
+
 #define CONFIG_SPL
 #define CONFIG_SPL_LDSCRIPT "arch/arm/cpu/armv7/sunxi/u-boot-spl-fel.lds"
 #define CONFIG_SPL_START_S_PATH "arch/arm/cpu/armv7/sunxi"
 #define CONFIG_SPL_TEXT_BASE		0x2000
 #define CONFIG_SPL_MAX_SIZE		0x4000		/* 16 KiB */
+
+#else /* CONFIG_SPL */
+
+#define CONFIG_SPL_BSS_START_ADDR	0x4ff80000
+#define CONFIG_SPL_BSS_MAX_SIZE		0x80000		/* 512 KiB */
+
+#define CONFIG_SPL_TEXT_BASE		0x20		/* sram start+header */
+#define CONFIG_SPL_MAX_SIZE		0x5fe0		/* 24KB on sun4i/sun7i */
+
+#define CONFIG_SPL_LIBDISK_SUPPORT
+#define CONFIG_SPL_MMC_SUPPORT
+
+#define CONFIG_SPL_LDSCRIPT "arch/arm/cpu/armv7/sunxi/u-boot-spl.lds"
+
+#define CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR	80	/* 40KiB */
+#define CONFIG_SPL_PAD_TO		32768		/* decimal for 'dd' */
+
+#endif /* CONFIG_SPL */
+
 /* end of 32 KiB in sram */
 #define LOW_LEVEL_SRAM_STACK		0x00008000 /* End of sram */
 #define CONFIG_SPL_STACK		LOW_LEVEL_SRAM_STACK
diff --git a/spl/Makefile b/spl/Makefile
index 6fec252..e7c7a95 100644
--- a/spl/Makefile
+++ b/spl/Makefile
@@ -188,6 +188,12 @@  ifdef CONFIG_SAMSUNG
 ALL-y	+= $(obj)/$(BOARD)-spl.bin
 endif
 
+ifdef CONFIG_SUNXI
+ifndef CONFIG_SPL_FEL
+ALL-y	+= $(obj)/sunxi-spl.bin
+endif
+endif
+
 all:	$(ALL-y)
 
 ifdef CONFIG_SAMSUNG
@@ -215,6 +221,13 @@  ifneq ($(CONFIG_SPL_TEXT_BASE),)
 LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE)
 endif
 
+ifdef CONFIG_SUNXI
+quiet_cmd_mksunxiboot = MKSUNXI $@
+cmd_mksunxiboot = $(objtree)/tools/mksunxiboot $< $@
+$(obj)/sunxi-spl.bin: $(obj)/$(SPL_BIN).bin
+	$(call if_changed,mksunxiboot)
+endif
+
 quiet_cmd_u-boot-spl = LD      $@
       cmd_u-boot-spl = cd $(obj) && $(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) \
 		       $(patsubst $(obj)/%,%,$(u-boot-spl-init)) --start-group \
diff --git a/tools/.gitignore b/tools/.gitignore
index 2a90dfe..3ad5db3 100644
--- a/tools/.gitignore
+++ b/tools/.gitignore
@@ -9,6 +9,7 @@ 
 /mkexynosspl
 /mpc86x_clk
 /mxsboot
+/mksunxiboot
 /ncb
 /proftool
 /relocate-rela
diff --git a/tools/Makefile b/tools/Makefile
index 097cc1d..062a404 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -120,6 +120,8 @@  hostprogs-$(CONFIG_MX23) += mxsboot$(SFX)
 hostprogs-$(CONFIG_MX28) += mxsboot$(SFX)
 HOSTCFLAGS_mxsboot$(SFX).o := -pedantic
 
+hostprogs-$(CONFIG_SUNXI) += mksunxiboot$(SFX)
+
 hostprogs-$(CONFIG_NETCONSOLE) += ncb$(SFX)
 hostprogs-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1$(SFX)
 
diff --git a/tools/mksunxiboot.c b/tools/mksunxiboot.c
new file mode 100644
index 0000000..50fcda5
--- /dev/null
+++ b/tools/mksunxiboot.c
@@ -0,0 +1,154 @@ 
+/*
+ * (C) Copyright 2007-2011
+ * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
+ * Tom Cubie <tangliang@allwinnertech.com>
+ *
+ * a simple tool to generate bootable image for sunxi platform.
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+typedef unsigned char u8;
+typedef unsigned int u32;
+
+/* boot head definition from sun4i boot code */
+struct boot_file_head {
+	u32 jump_instruction;	/* one intruction jumping to real code */
+	u8 magic[8];		/* ="eGON.BT0" or "eGON.BT1", not C-style str */
+	u32 check_sum;		/* generated by PC */
+	u32 length;		/* generated by PC */
+#if 1
+	/* We use a simplified header, only filling in what is needed by the
+	 * boot ROM. To be compatible with Allwinner tools the larger header
+	 * below should be used, followed by a custom header if desired. */
+	u8 pad[12];		/* align to 32 bytes */
+#else
+	u32 pub_head_size;	/* the size of boot_file_head */
+	u8 pub_head_vsn[4];	/* the version of boot_file_head */
+	u8 file_head_vsn[4];	/* the version of boot0_file_head or
+				   boot1_file_head */
+	u8 Boot_vsn[4];		/* Boot version */
+	u8 eGON_vsn[4];		/* eGON version */
+	u8 platform[8];		/* platform information */
+#endif
+};
+
+#define BOOT0_MAGIC                     "eGON.BT0"
+#define STAMP_VALUE                     0x5F0A6C39
+
+/* check sum functon from sun4i boot code */
+int gen_check_sum(void *boot_buf)
+{
+	struct boot_file_head *head_p;
+	u32 length;
+	u32 *buf;
+	u32 loop;
+	u32 i;
+	u32 sum;
+
+	head_p = (struct boot_file_head *)boot_buf;
+	length = head_p->length;
+	if ((length & 0x3) != 0)	/* must 4-byte-aligned */
+		return -1;
+	buf = (u32 *)boot_buf;
+	head_p->check_sum = STAMP_VALUE;	/* fill stamp */
+	loop = length >> 2;
+
+	/* calculate the sum */
+	for (i = 0, sum = 0; i < loop; i++)
+		sum += buf[i];
+
+	/* write back check sum */
+	head_p->check_sum = sum;
+
+	return 0;
+}
+
+#define ALIGN(x, a) __ALIGN_MASK((x), (typeof(x))(a)-1)
+#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
+
+#define SUN4I_SRAM_SIZE 0x7600	/* 0x7748+ is used by BROM */
+#define SRAM_LOAD_MAX_SIZE (SUN4I_SRAM_SIZE - sizeof(struct boot_file_head))
+#define BLOCK_SIZE 512
+
+struct boot_img {
+	struct boot_file_head header;
+	char code[SRAM_LOAD_MAX_SIZE];
+	char pad[BLOCK_SIZE];
+};
+
+int main(int argc, char *argv[])
+{
+	int fd_in, fd_out;
+	struct boot_img img;
+	unsigned file_size, load_size;
+	int count;
+
+	if (argc < 2) {
+		printf("\tThis program makes an input bin file to sun4i " \
+		       "bootable image.\n" \
+		       "\tUsage: %s input_file out_putfile\n", argv[0]);
+		return EXIT_FAILURE;
+	}
+
+	fd_in = open(argv[1], O_RDONLY);
+	if (fd_in < 0) {
+		perror("Open input file");
+		return EXIT_FAILURE;
+	}
+
+	memset((void *)img.pad, 0, BLOCK_SIZE);
+
+	/* get input file size */
+	file_size = lseek(fd_in, 0, SEEK_END);
+
+	if (file_size > SRAM_LOAD_MAX_SIZE) {
+		fprintf(stderr, "ERROR: File too large!\n");
+		return EXIT_FAILURE;
+	} else {
+		load_size = ALIGN(file_size, sizeof(int));
+	}
+
+	fd_out = open(argv[2], O_WRONLY | O_CREAT, 0666);
+	if (fd_out < 0) {
+		perror("Open output file");
+		return EXIT_FAILURE;
+	}
+
+	/* read file to buffer to calculate checksum */
+	lseek(fd_in, 0, SEEK_SET);
+	count = read(fd_in, img.code, load_size);
+	if (count != load_size) {
+		perror("Reading input image");
+		return EXIT_FAILURE;
+	}
+
+	/* fill the header */
+	img.header.jump_instruction =	/* b instruction */
+		0xEA000000 |	/* jump to the first instr after the header */
+		((sizeof(struct boot_file_head) / sizeof(int) - 2)
+		 & 0x00FFFFFF);
+	memcpy(img.header.magic, BOOT0_MAGIC, 8);	/* no '0' termination */
+	img.header.length =
+		ALIGN(load_size + sizeof(struct boot_file_head), BLOCK_SIZE);
+	gen_check_sum((void *)&img);
+
+	count = write(fd_out, (void *)&img, img.header.length);
+	if (count != img.header.length) {
+		perror("Writing output");
+		return EXIT_FAILURE;
+	}
+
+	close(fd_in);
+	close(fd_out);
+
+	return EXIT_SUCCESS;
+}