[PATCH 08/16] efi: add helper functions to write EFI variables

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich 
---
 arch/efi/efi/efi.c  | 27 +++
 arch/efi/include/mach/efi.h |  4 
 2 files changed, 31 insertions(+)

diff --git a/arch/efi/efi/efi.c b/arch/efi/efi/efi.c
index c05d183c02fa..b0e98f95b02b 100644
--- a/arch/efi/efi/efi.c
+++ b/arch/efi/efi/efi.c
@@ -83,6 +83,33 @@ out:
return buf;
 }
 
+int efi_set_variable(char *name, efi_guid_t *vendor, uint32_t attributes,
+void *buf, unsigned long size)
+{
+   efi_status_t efiret = EFI_SUCCESS;
+   s16 *name16 = strdup_char_to_wchar(name);
+
+   efiret = RT->set_variable(name16, vendor, attributes, size, buf);
+
+   free(name16);
+
+   return -efi_errno(efiret);
+}
+
+int efi_set_variable_usec(char *name, efi_guid_t *vendor, uint64_t usec)
+{
+   char buf[20];
+   wchar_t buf16[40];
+
+   snprintf(buf, sizeof(buf), "%lld", usec);
+   strcpy_char_to_wchar(buf16, buf);
+
+   return efi_set_variable(name, vendor,
+   EFI_VARIABLE_BOOTSERVICE_ACCESS |
+   EFI_VARIABLE_RUNTIME_ACCESS, buf16,
+   (strlen(buf)+1) * sizeof(wchar_t));
+}
+
 struct efi_boot {
u32 attributes;
u16 file_path_len;
diff --git a/arch/efi/include/mach/efi.h b/arch/efi/include/mach/efi.h
index 1e9782a136c2..2b25cf1868ad 100644
--- a/arch/efi/include/mach/efi.h
+++ b/arch/efi/include/mach/efi.h
@@ -21,4 +21,8 @@ static inline void *efi_get_global_var(char *name, int 
*var_size)
return efi_get_variable(name, &efi_global_variable_guid, var_size);
 }
 
+int efi_set_variable(char *name, efi_guid_t *vendor, uint32_t attributes,
+void *buf, unsigned long size);
+int efi_set_variable_usec(char *name, efi_guid_t *vendor, uint64_t usec);
+
 #endif /* __MACH_EFI_H */
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 11/16] efi: use xstrdup_* when appropriate

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich 
---
 arch/efi/efi/efi.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/efi/efi/efi.c b/arch/efi/efi/efi.c
index 6cffac60f54b..07a4d9d0fc57 100644
--- a/arch/efi/efi/efi.c
+++ b/arch/efi/efi/efi.c
@@ -52,7 +52,7 @@ void *efi_get_variable(char *name, efi_guid_t *vendor, int 
*var_size)
efi_status_t efiret;
void *buf;
unsigned long size = 0;
-   s16 *name16 = strdup_char_to_wchar(name);
+   s16 *name16 = xstrdup_char_to_wchar(name);
 
efiret = RT->get_variable(name16, vendor, NULL, &size, NULL);
 
@@ -87,7 +87,7 @@ int efi_set_variable(char *name, efi_guid_t *vendor, uint32_t 
attributes,
 void *buf, unsigned long size)
 {
efi_status_t efiret = EFI_SUCCESS;
-   s16 *name16 = strdup_char_to_wchar(name);
+   s16 *name16 = xstrdup_char_to_wchar(name);
 
efiret = RT->set_variable(name16, vendor, attributes, size, buf);
 
@@ -146,7 +146,7 @@ struct efi_boot *efi_get_boot(int num)
 
ptr += sizeof(u16);
 
-   boot->description = strdup_wchar_to_char(ptr);
+   boot->description = xstrdup_wchar_to_char(ptr);
 
ptr += (strlen(boot->description) + 1) * 2;
 
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 03/16] efi: improve malloc pool allocation

2015-07-17 Thread Michael Olbrich
Use allocate_pages() instead of allocate_pool(). With allocate_pages() we
can specify the address. This way, any address passed to the kernel will
never exceed the lower 32 bit.
If possible, try to allocate a larger pool.

Signed-off-by: Michael Olbrich 
---
 arch/efi/efi/efi.c | 20 +---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/arch/efi/efi/efi.c b/arch/efi/efi/efi.c
index d351775a2868..c05d183c02fa 100644
--- a/arch/efi/efi/efi.c
+++ b/arch/efi/efi/efi.c
@@ -310,7 +310,8 @@ device_initcall(efi_init);
  */
 efi_status_t efi_main(efi_handle_t image, efi_system_table_t *sys_table)
 {
-   void *mem;
+   efi_physical_addr_t mem;
+   size_t memsize;
efi_status_t efiret;
 
 #ifdef DEBUG
@@ -332,8 +333,21 @@ efi_status_t efi_main(efi_handle_t image, 
efi_system_table_t *sys_table)
 
fixup_tables();
 
-   BS->allocate_pool(efi_loaded_image->image_data_type, SZ_16M, &mem);
-   mem_malloc_init(mem, mem + SZ_16M);
+   mem = 0x3fff;
+   for (memsize = SZ_256M; memsize >= SZ_8M; memsize /= 2) {
+   efiret  = BS->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
+EFI_LOADER_DATA,
+memsize/PAGE_SIZE, &mem);
+   if (!EFI_ERROR(efiret))
+   break;
+   if (efiret != EFI_OUT_OF_RESOURCES)
+   panic("failed to allocate malloc pool: %s\n",
+ efi_strerror(efiret));
+   }
+   if (EFI_ERROR(efiret))
+   panic("failed to allocate malloc pool: %s\n",
+ efi_strerror(efiret));
+   mem_malloc_init((void *)mem, (void *)mem + memsize);
 
efi_clocksource_init();
 
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 06/16] efi: add helper to get the GPT partition UUID for a device

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich 
---
v2: use xasprintf()

 common/efi-devicepath.c | 30 ++
 include/efi.h   |  1 +
 2 files changed, 31 insertions(+)

diff --git a/common/efi-devicepath.c b/common/efi-devicepath.c
index a53c6d2e8b9b..a1cd0952f929 100644
--- a/common/efi-devicepath.c
+++ b/common/efi-devicepath.c
@@ -1383,3 +1383,33 @@ u8 device_path_to_type(struct efi_device_path *dev_path)
 
return device_path_type(dev_path);
 }
+
+char *device_path_to_partuuid(struct efi_device_path *dev_path)
+{
+   struct efi_device_path *dev_path_node;
+   struct harddrive_device_path *hd;
+   char *str = NULL;;
+
+   dev_path = unpack_device_path(dev_path);
+
+   for (dev_path_node = dev_path; !is_device_path_end(dev_path_node);
+dev_path_node = next_device_path_node(dev_path_node)) {
+
+   if (device_path_type(dev_path_node) != MEDIA_DEVICE_PATH)
+   continue;
+
+   if (dev_path_node->sub_type != MEDIA_HARDDRIVE_DP)
+   continue;
+
+   hd = (struct harddrive_device_path *)dev_path_node;
+
+   if (hd->signature_type != SIGNATURE_TYPE_GUID)
+   continue;
+
+   str = xasprintf("%pU)", (efi_guid_t *)&(hd->signature[0]));
+   break;
+   }
+
+   return str;
+}
+
diff --git a/include/efi.h b/include/efi.h
index e79a407bc2c8..b6ee42b3fd49 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -624,6 +624,7 @@ static inline int efi_compare_guid(efi_guid_t *a, 
efi_guid_t *b)
 
 char *device_path_to_str(struct efi_device_path *dev_path);
 u8 device_path_to_type(struct efi_device_path *dev_path);
+char *device_path_to_partuuid(struct efi_device_path *dev_path);
 
 const char *efi_guid_string(efi_guid_t *g);
 
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 10/16] efi: use xasprintf() when appropriate

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich 
---
 arch/efi/efi/efi-block-io.c | 2 +-
 arch/efi/efi/efi.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/efi/efi/efi-block-io.c b/arch/efi/efi/efi-block-io.c
index 85603d913d5b..e02d3b49cc99 100644
--- a/arch/efi/efi/efi-block-io.c
+++ b/arch/efi/efi/efi-block-io.c
@@ -147,7 +147,7 @@ int efi_bio_probe(struct efi_device *efidev)
efi_bio_print_info(priv);
priv->dev = &efidev->dev;
 
-   priv->blk.cdev.name = asprintf("disk%d", cdev_find_free_index("disk"));
+   priv->blk.cdev.name = xasprintf("disk%d", cdev_find_free_index("disk"));
priv->blk.blockbits = ffs(media->block_size) - 1;
priv->blk.num_blocks = media->last_block + 1;
priv->blk.ops = &efi_bio_ops;
diff --git a/arch/efi/efi/efi.c b/arch/efi/efi/efi.c
index 1f0deed577f0..6cffac60f54b 100644
--- a/arch/efi/efi/efi.c
+++ b/arch/efi/efi/efi.c
@@ -125,7 +125,7 @@ struct efi_boot *efi_get_boot(int num)
int size;
char *name;
 
-   name = asprintf("Boot%04X", num);
+   name = xasprintf("Boot%04X", num);
 
buf = efi_get_global_var(name, &size);
 
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 13/16] fs: efivars: use xstrdup_* when appropriate

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich 
---
 fs/efivarfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/efivarfs.c b/fs/efivarfs.c
index ebace8bc8fb1..925e8e8be113 100644
--- a/fs/efivarfs.c
+++ b/fs/efivarfs.c
@@ -153,7 +153,7 @@ static int efivars_create(struct device_d *dev, const char 
*pathname, mode_t mod
inode->vendor = vendor;
 
 
-   name8 = strdup_wchar_to_char(inode->name);
+   name8 = xstrdup_wchar_to_char(inode->name);
inode->full_name = asprintf("%s-%pUl", name8, &inode->vendor);
free(name8);
 
@@ -391,11 +391,11 @@ static int efivarfs_probe(struct device_d *dev)
break;
 
inode = xzalloc(sizeof(*inode));
-   inode->name = strdup_wchar(name);
+   inode->name = xstrdup_wchar(name);
 
inode->vendor = vendor;
 
-   name8 = strdup_wchar_to_char(inode->name);
+   name8 = xstrdup_wchar_to_char(inode->name);
inode->full_name = asprintf("%s-%pUl", name8, &vendor);
free(name8);
 
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 04/16] efi: refactor & improve application loading code

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich 
---
v2: use xstrdup_char_to_wchar()

 arch/efi/efi/efi-image.c | 57 ++--
 include/efi.h|  2 +-
 2 files changed, 46 insertions(+), 13 deletions(-)

diff --git a/arch/efi/efi/efi-image.c b/arch/efi/efi/efi-image.c
index f7bda8dfcb2a..c88b3a0766ed 100644
--- a/arch/efi/efi/efi-image.c
+++ b/arch/efi/efi/efi-image.c
@@ -37,14 +37,13 @@
 #include 
 #include 
 
-static int efi_execute_image(const char *file)
+int efi_load_image(const char *file, efi_loaded_image_t **loaded_image,
+   efi_handle_t *h)
 {
void *exe;
size_t size;
efi_handle_t handle;
-   efi_status_t efiret;
-   const char *options;
-   efi_loaded_image_t *loaded_image;
+   efi_status_t efiret = EFI_SUCCESS;
 
exe = read_file(file, &size);
if (!exe)
@@ -54,25 +53,59 @@ static int efi_execute_image(const char *file)
&handle);
if (EFI_ERROR(efiret)) {
pr_err("failed to LoadImage: %s\n", efi_strerror(efiret));
-   return -efi_errno(efiret);;
+   goto out;
};
 
efiret = BS->open_protocol(handle, &efi_loaded_image_protocol_guid,
-   (void **)&loaded_image,
+   (void **)loaded_image,
efi_parent_image, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
-   if (EFI_ERROR(efiret))
-   return -efi_errno(efiret);
+   if (EFI_ERROR(efiret)) {
+   pr_err("failed to OpenProtocol: %s\n", efi_strerror(efiret));
+   BS->unload_image(handle);
+   goto out;
+   }
 
-   options = linux_bootargs_get();
-   loaded_image->load_options = strdup_char_to_wchar(options);
-   loaded_image->load_options_size = (strlen(options) + 1) * 
sizeof(wchar_t);
+   *h = handle;
+out:
+   memset(exe, 0, size);
+   free(exe);
+   return -efi_errno(efiret);
+}
+
+static int efi_execute_image(const char *file)
+{
+   efi_handle_t handle;
+   efi_loaded_image_t *loaded_image;
+   efi_status_t efiret;
+   struct linux_kernel_header *image_header;
+   const char *options;
+   int ret;
+
+   ret = efi_load_image(file, &loaded_image, &handle);
+   if (ret)
+   return ret;
+
+   image_header = (struct linux_kernel_header *)loaded_image->image_base;
+   if (image_header->boot_flag == 0xAA55 &&
+   image_header->header == 0x53726448) {
+   pr_debug("Linux kernel detected. Adding bootargs.");
+   options = linux_bootargs_get();
+   pr_err("add linux options '%s'\n", options);
+   loaded_image->load_options = xstrdup_char_to_wchar(options);
+   loaded_image->load_options_size =
+   (strlen(options) + 1) * sizeof(wchar_t);
+   }
 
efiret = BS->start_image(handle, NULL, NULL);
+   if (EFI_ERROR(efiret))
+   pr_err("failed to StartImage: %s\n", efi_strerror(efiret));
+
+   BS->unload_image(handle);
 
efi_connect_all();
efi_register_devices();
 
-   return 0;
+   return -efi_errno(efiret);
 }
 
 static int do_bootm_efi(struct image_data *data)
diff --git a/include/efi.h b/include/efi.h
index 9b4f16bd9f54..e79a407bc2c8 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -211,7 +211,7 @@ typedef struct {
unsigned long *exitdata_size, s16 **exitdata);
efi_status_t(EFIAPI *exit)(efi_handle_t handle,  efi_status_t 
exit_status,
unsigned long exitdata_size, s16 *exitdata);
-   void *unload_image;
+   efi_status_t (EFIAPI *unload_image)(efi_handle_t handle);
efi_status_t (EFIAPI *exit_boot_services)(efi_handle_t, unsigned long);
void *get_next_monotonic_count;
efi_status_t (EFIAPI *stall)(unsigned long usecs);
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 02/16] xfuncs: add wrapper for wchar strdup functions

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich 
---
 include/xfuncs.h |  5 +
 lib/xfuncs.c | 31 +++
 2 files changed, 36 insertions(+)

diff --git a/include/xfuncs.h b/include/xfuncs.h
index c7c0203f375b..b53cfdcddd31 100644
--- a/include/xfuncs.h
+++ b/include/xfuncs.h
@@ -3,6 +3,7 @@
 
 #include 
 #include 
+#include 
 
 void *xmalloc(size_t size);
 void *xrealloc(void *ptr, size_t size);
@@ -13,4 +14,8 @@ void* xmemdup(const void *orig, size_t size);
 char *xasprintf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 
2)));
 char *xvasprintf(const char *fmt, va_list ap);
 
+wchar_t *xstrdup_wchar(const wchar_t *src);
+wchar_t *xstrdup_char_to_wchar(const char *src);
+char *xstrdup_wchar_to_char(const wchar_t *src);
+
 #endif /* __XFUNCS_H */
diff --git a/lib/xfuncs.c b/lib/xfuncs.c
index ce89169547a4..c8c1da7dad7f 100644
--- a/lib/xfuncs.c
+++ b/lib/xfuncs.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 void *xmalloc(size_t size)
 {
@@ -105,3 +106,33 @@ char *xasprintf(const char *fmt, ...)
return p;
 }
 EXPORT_SYMBOL(xasprintf);
+
+wchar_t *xstrdup_wchar(const wchar_t *s)
+{
+   wchar_t *p = strdup_wchar(s);
+
+   if (!p)
+   panic("ERROR: out of memory\n");
+   return p;
+}
+EXPORT_SYMBOL(xstrdup_wchar);
+
+wchar_t *xstrdup_char_to_wchar(const char *s)
+{
+   wchar_t *p = strdup_char_to_wchar(s);
+
+   if (!p)
+   panic("ERROR: out of memory\n");
+   return p;
+}
+EXPORT_SYMBOL(xstrdup_char_to_wchar);
+
+char *xstrdup_wchar_to_char(const wchar_t *s)
+{
+   char *p = strdup_wchar_to_char(s);
+
+   if (!p)
+   panic("ERROR: out of memory\n");
+   return p;
+}
+EXPORT_SYMBOL(xstrdup_wchar_to_char);
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 01/16] xfuncs: add xasprintf() and xvasprintf()

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich 
---
 include/xfuncs.h |  3 +++
 lib/xfuncs.c | 24 
 2 files changed, 27 insertions(+)

diff --git a/include/xfuncs.h b/include/xfuncs.h
index 8efc99dbc455..c7c0203f375b 100644
--- a/include/xfuncs.h
+++ b/include/xfuncs.h
@@ -2,6 +2,7 @@
 #define __XFUNCS_H
 
 #include 
+#include 
 
 void *xmalloc(size_t size);
 void *xrealloc(void *ptr, size_t size);
@@ -9,5 +10,7 @@ void *xzalloc(size_t size);
 char *xstrdup(const char *s);
 void* xmemalign(size_t alignment, size_t bytes);
 void* xmemdup(const void *orig, size_t size);
+char *xasprintf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 
2)));
+char *xvasprintf(const char *fmt, va_list ap);
 
 #endif /* __XFUNCS_H */
diff --git a/lib/xfuncs.c b/lib/xfuncs.c
index 0e78b670a5d4..ce89169547a4 100644
--- a/lib/xfuncs.c
+++ b/lib/xfuncs.c
@@ -81,3 +81,27 @@ void *xmemdup(const void *orig, size_t size)
return buf;
 }
 EXPORT_SYMBOL(xmemdup);
+
+char *xvasprintf(const char *fmt, va_list ap)
+{
+   char *p;
+
+   p = vasprintf(fmt, ap);
+   if (!p)
+   panic("ERROR: out of memory\n");
+   return p;
+}
+EXPORT_SYMBOL(xvasprintf)
+
+char *xasprintf(const char *fmt, ...)
+{
+   va_list ap;
+   char *p;
+
+   va_start(ap, fmt);
+   p = xvasprintf(fmt, ap);
+   va_end(ap);
+
+   return p;
+}
+EXPORT_SYMBOL(xasprintf);
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 14/16] fs: efivars: add more error checking

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich 
---
 fs/efivarfs.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/fs/efivarfs.c b/fs/efivarfs.c
index 925e8e8be113..87fc771739e2 100644
--- a/fs/efivarfs.c
+++ b/fs/efivarfs.c
@@ -269,6 +269,7 @@ static int efivarfs_read(struct device_d *_dev, FILE *f, 
void *buf, size_t insiz
 static int efivarfs_write(struct device_d *_dev, FILE *f, const void *buf, 
size_t insize)
 {
struct efivars_file *efile = f->priv;
+   efi_status_t efiret;
 
if (efile->size < f->pos + insize) {
efile->buf = realloc(efile->buf, f->pos + insize);
@@ -277,8 +278,11 @@ static int efivarfs_write(struct device_d *_dev, FILE *f, 
const void *buf, size_
 
memcpy(efile->buf + f->pos, buf, insize);
 
-   RT->set_variable(efile->name, &efile->vendor, efile->attributes,
-efile->size ? efile->size : 1, efile->buf);
+   efiret = RT->set_variable(efile->name, &efile->vendor,
+ efile->attributes,
+ efile->size ? efile->size : 1, efile->buf);
+   if (EFI_ERROR(efiret))
+   return -efi_errno(efiret);
 
return insize;
 }
@@ -286,12 +290,16 @@ static int efivarfs_write(struct device_d *_dev, FILE *f, 
const void *buf, size_
 static int efivarfs_truncate(struct device_d *dev, FILE *f, ulong size)
 {
struct efivars_file *efile = f->priv;
+   efi_status_t efiret;
 
efile->size = size;
efile->buf = realloc(efile->buf, efile->size + sizeof(uint32_t));
 
-   RT->set_variable(efile->name, &efile->vendor, efile->attributes,
-efile->size ? efile->size : 1, efile->buf);
+   efiret = RT->set_variable(efile->name, &efile->vendor,
+ efile->attributes,
+ efile->size ? efile->size : 1, efile->buf);
+   if (EFI_ERROR(efiret))
+   return -efi_errno(efiret);
 
f->size = efile->size;
 
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 16/16] efi: use an EFI variable to save the environment

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich 
---
 arch/efi/efi/efi.c | 5 +
 common/efi-guid.c  | 1 +
 include/efi.h  | 1 +
 3 files changed, 7 insertions(+)

diff --git a/arch/efi/efi/efi.c b/arch/efi/efi/efi.c
index 07a4d9d0fc57..d3f520f60f14 100644
--- a/arch/efi/efi/efi.c
+++ b/arch/efi/efi/efi.c
@@ -326,8 +326,13 @@ static void fixup_tables(void)
 
 static int efi_init(void)
 {
+   char *env;
+
defaultenv_append_directory(env_efi);
 
+   env = xasprintf("/efivars/barebox-env-%pUl", &efi_barebox_vendor_guid);
+   default_environment_path_set(env);
+
return 0;
 }
 device_initcall(efi_init);
diff --git a/common/efi-guid.c b/common/efi-guid.c
index f4ff7feadfe4..64f3b1f65fd3 100644
--- a/common/efi-guid.c
+++ b/common/efi-guid.c
@@ -9,6 +9,7 @@ efi_guid_t efi_unknown_device_guid = EFI_UNKNOWN_DEVICE_GUID;
 efi_guid_t efi_null_guid = EFI_NULL_GUID;
 efi_guid_t efi_global_variable_guid = EFI_GLOBAL_VARIABLE_GUID;
 efi_guid_t efi_block_io_protocol_guid = EFI_BLOCK_IO_PROTOCOL_GUID;
+efi_guid_t efi_barebox_vendor_guid = EFI_BAREBOX_VENDOR_GUID;
 efi_guid_t efi_systemd_vendor_guid = EFI_SYSTEMD_VENDOR_GUID;
 
 #define EFI_GUID_STRING(guid, short, long) do {\
diff --git a/include/efi.h b/include/efi.h
index 5b0de119fb74..b2e965bae1d4 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -485,6 +485,7 @@ extern efi_guid_t efi_unknown_device_guid;
 extern efi_guid_t efi_null_guid;
 extern efi_guid_t efi_global_variable_guid;
 extern efi_guid_t efi_block_io_protocol_guid;
+extern efi_guid_t efi_barebox_vendor_guid;
 extern efi_guid_t efi_systemd_vendor_guid;
 
 #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 15/16] fs: efivars: read the attributes on the second get_variable()

2015-07-17 Thread Michael Olbrich
Some EFI get_variable() implementations don't set the attributes when
returning EFI_BUFFER_TOO_SMALL.

Signed-off-by: Michael Olbrich 
---
 fs/efivarfs.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/efivarfs.c b/fs/efivarfs.c
index 87fc771739e2..c7a282b05c63 100644
--- a/fs/efivarfs.c
+++ b/fs/efivarfs.c
@@ -216,7 +216,7 @@ static int efivarfs_open(struct device_d *dev, FILE *f, 
const char *filename)
return -ENOENT;
 
efiret = RT->get_variable(efile->name, &efile->vendor,
- &efile->attributes, &efile->size, NULL);
+ NULL, &efile->size, NULL);
if (EFI_ERROR(efiret) && efiret != EFI_BUFFER_TOO_SMALL) {
ret = -efi_errno(efiret);
goto out;
@@ -228,8 +228,9 @@ static int efivarfs_open(struct device_d *dev, FILE *f, 
const char *filename)
goto out;
}
 
-   efiret = RT->get_variable(efile->name, &efile->vendor, NULL, 
&efile->size,
-   efile->buf);
+   efiret = RT->get_variable(efile->name, &efile->vendor,
+ &efile->attributes, &efile->size,
+ efile->buf);
if (EFI_ERROR(efiret)) {
ret = -efi_errno(efiret);
goto out;
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCHv2 00/16] EFI updates

2015-07-17 Thread Michael Olbrich
Hi,

I've added a patch for xasprintf() and one to add xfuncs for the relevant
wchar functions. I've replaced all occurrences in the EFI code but I'm not
confident enough to do this elsewhere without being able to test it.

And I've added some patches to save the environment in an EFI variable.

Michael Olbrich (16):
  xfuncs: add xasprintf() and xvasprintf()
  xfuncs: add wrapper for wchar strdup functions
  efi: improve malloc pool allocation
  efi: refactor & improve application loading code
  efi: add support for initrd loading
  efi: add helper to get the GPT partition UUID for a device
  efi: export device_path_from_handle()
  efi: add helper functions to write EFI variables
  efi: write volatile EFI variables used by systemd
  efi: use xasprintf() when appropriate
  efi: use xstrdup_* when appropriate
  fs: efi: use xstrdup_* when appropriate
  fs: efivars: use xstrdup_* when appropriate
  fs: efivars: add more error checking
  fs: efivars: read the attributes on the second get_variable()
  efi: use an EFI variable to save the environment

 arch/efi/efi/efi-block-io.c |   2 +-
 arch/efi/efi/efi-image.c| 198 +---
 arch/efi/efi/efi.c  |  74 +++--
 arch/efi/include/mach/efi.h |   4 +
 common/efi-devicepath.c |  30 +++
 common/efi-guid.c   |   2 +
 fs/efi.c|   4 +-
 fs/efivarfs.c   |  29 ---
 include/efi.h   |  10 ++-
 include/xfuncs.h|   8 ++
 lib/xfuncs.c|  55 
 11 files changed, 383 insertions(+), 33 deletions(-)

-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 12/16] fs: efi: use xstrdup_* when appropriate

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich 
---
 fs/efi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/efi.c b/fs/efi.c
index 8f4739a99e24..a7adcb98db57 100644
--- a/fs/efi.c
+++ b/fs/efi.c
@@ -114,9 +114,9 @@ static wchar_t *path_to_efi(const char *path)
wchar_t *ret;
 
if (!*path)
-   return strdup_char_to_wchar("\\");
+   return xstrdup_char_to_wchar("\\");
 
-   dst = strdup_char_to_wchar(path);
+   dst = xstrdup_char_to_wchar(path);
if (!dst)
return NULL;
 
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 05/16] efi: add support for initrd loading

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich 
---
v2: xmemalign

 arch/efi/efi/efi-image.c | 136 ++-
 1 file changed, 135 insertions(+), 1 deletion(-)

diff --git a/arch/efi/efi/efi-image.c b/arch/efi/efi/efi-image.c
index c88b3a0766ed..de9b27755663 100644
--- a/arch/efi/efi/efi-image.c
+++ b/arch/efi/efi/efi-image.c
@@ -37,6 +37,55 @@
 #include 
 #include 
 
+struct linux_kernel_header {
+   /* first sector of the image */
+   uint8_t code1[0x0020];
+   uint16_t cl_magic;  /**< Magic number 0xA33F */
+   uint16_t cl_offset; /**< The offset of command line */
+   uint8_t code2[0x01F1 - 0x0020 - 2 - 2];
+   uint8_t setup_sects;/**< The size of the setup in sectors */
+   uint16_t root_flags;/**< If the root is mounted readonly */
+   uint16_t syssize;   /**< obsolete */
+   uint16_t swap_dev;  /**< obsolete */
+   uint16_t ram_size;  /**< obsolete */
+   uint16_t vid_mode;  /**< Video mode control */
+   uint16_t root_dev;  /**< Default root device number */
+   uint16_t boot_flag; /**< 0xAA55 magic number */
+
+   /* second sector of the image */
+   uint16_t jump;  /**< Jump instruction (this is code!) */
+   uint32_t header;/**< Magic signature "HdrS" */
+   uint16_t version;   /**< Boot protocol version supported */
+   uint32_t realmode_swtch;/**< Boot loader hook */
+   uint16_t start_sys; /**< The load-low segment (obsolete) */
+   uint16_t kernel_version;/**< Points to kernel version string */
+   uint8_t type_of_loader; /**< Boot loader identifier */
+   uint8_t loadflags;  /**< Boot protocol option flags */
+   uint16_t setup_move_size;   /**< Move to high memory size */
+   uint32_t code32_start;  /**< Boot loader hook */
+   uint32_t ramdisk_image; /**< initrd load address */
+   uint32_t ramdisk_size;  /**< initrd size */
+   uint32_t bootsect_kludge;   /**< obsolete */
+   uint16_t heap_end_ptr;  /**< Free memory after setup end */
+   uint8_t ext_loader_ver; /**< boot loader's extension of the 
version number */
+   uint8_t ext_loader_type;/**< boot loader's extension of its 
type */
+   uint32_t cmd_line_ptr;  /**< Points to the kernel command line 
*/
+   uint32_t initrd_addr_max;   /**< Highest address for initrd */
+   uint32_t kernel_alignment;  /**< Alignment unit required by the 
kernel */
+   uint8_t relocatable_kernel; /** */
+   uint8_t min_alignment;  /** */
+   uint16_t xloadflags;/** */
+   uint32_t cmdline_size;  /** */
+   uint32_t hardware_subarch;  /** */
+   uint64_t hardware_subarch_data; /** */
+   uint32_t payload_offset;/** */
+   uint32_t payload_length;/** */
+   uint64_t setup_data;/** */
+   uint64_t pref_address;  /** */
+   uint32_t init_size; /** */
+   uint32_t handover_offset;   /** */
+} __attribute__ ((packed));
+
 int efi_load_image(const char *file, efi_loaded_image_t **loaded_image,
efi_handle_t *h)
 {
@@ -108,9 +157,94 @@ static int efi_execute_image(const char *file)
return -efi_errno(efiret);
 }
 
+#ifdef __x86_64__
+typedef void(*handover_fn)(void *image, efi_system_table_t *table,
+   struct linux_kernel_header *header);
+
+static inline void linux_efi_handover(efi_handle_t handle,
+   struct linux_kernel_header *header)
+{
+   handover_fn handover;
+
+   asm volatile ("cli");
+   handover = (handover_fn)((long)header->code32_start + 512 +
+header->handover_offset);
+   handover(handle, efi_sys_table, header);
+}
+#else
+typedef void(*handover_fn)(VOID *image, EFI_SYSTEM_TABLE *table,
+   struct SetupHeader *setup) __attribute__((regparm(0)));
+
+static inline void linux_efi_handover(efi_handle_t handle,
+   struct linux_kernel_header *header)
+{
+   handover_fn handover;
+
+   handover = (handover_fn)((long)header->code32_start +
+header->handover_offset);
+   handover(handle, efi_sys_table, header);
+}
+#endif
+
 static int do_bootm_efi(struct image_data *data)
 {
-   return efi_execute_image(data->os_file);
+   void *tmp;
+   void *initrd;
+   size_t size;
+   efi_handle_t handle;
+   int ret;
+   const char *options;
+   efi_loaded_image_t *loaded_image;
+   struct linux_kernel_header *image_header, *boot_header;
+
+   ret = efi_load_image(data->os_file, &loaded_image, &handle);
+   if (ret)
+   return ret;
+
+   image_header = (struct linux_kernel_header *)

[PATCH 07/16] efi: export device_path_from_handle()

2015-07-17 Thread Michael Olbrich
Signed-off-by: Michael Olbrich 
---
 include/efi.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/efi.h b/include/efi.h
index b6ee42b3fd49..830e0457dd1c 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -622,6 +622,7 @@ static inline int efi_compare_guid(efi_guid_t *a, 
efi_guid_t *b)
return memcmp(a, b, sizeof(efi_guid_t));
 }
 
+struct efi_device_path *device_path_from_handle(efi_handle_t Handle);
 char *device_path_to_str(struct efi_device_path *dev_path);
 u8 device_path_to_type(struct efi_device_path *dev_path);
 char *device_path_to_partuuid(struct efi_device_path *dev_path);
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 09/16] efi: write volatile EFI variables used by systemd

2015-07-17 Thread Michael Olbrich
LoaderTimeInitUSec and LoaderTimeExecUSec are used e.g. in systemd-analyze
to calculate the time spent in the firmare and barebox.

LoaderDevicePartUUID is used to mount the EFI partition to /boot.

Signed-off-by: Michael Olbrich 
---
v2: use xstrdup_char_to_wchar() and free uuid/uuid16

 arch/efi/efi/efi-image.c |  5 +
 arch/efi/efi/efi.c   | 16 
 common/efi-guid.c|  1 +
 include/efi.h|  5 +
 4 files changed, 27 insertions(+)

diff --git a/arch/efi/efi/efi-image.c b/arch/efi/efi/efi-image.c
index de9b27755663..b6437f40787b 100644
--- a/arch/efi/efi/efi-image.c
+++ b/arch/efi/efi/efi-image.c
@@ -17,6 +17,7 @@
  *
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -242,6 +243,10 @@ static int do_bootm_efi(struct image_data *data)
   boot_header->ramdisk_image);
printf("...\n");
}
+
+   efi_set_variable_usec("LoaderTimeExecUSec", &efi_systemd_vendor_guid,
+ get_time_ns()/1000);
+
linux_efi_handover(handle, boot_header);
 
return 0;
diff --git a/arch/efi/efi/efi.c b/arch/efi/efi/efi.c
index b0e98f95b02b..1f0deed577f0 100644
--- a/arch/efi/efi/efi.c
+++ b/arch/efi/efi/efi.c
@@ -340,6 +340,7 @@ efi_status_t efi_main(efi_handle_t image, 
efi_system_table_t *sys_table)
efi_physical_addr_t mem;
size_t memsize;
efi_status_t efiret;
+   char *uuid;
 
 #ifdef DEBUG
sys_table->con_out->output_string(sys_table->con_out, L"barebox\n");
@@ -377,6 +378,21 @@ efi_status_t efi_main(efi_handle_t image, 
efi_system_table_t *sys_table)
mem_malloc_init((void *)mem, (void *)mem + memsize);
 
efi_clocksource_init();
+   efi_set_variable_usec("LoaderTimeInitUSec", &efi_systemd_vendor_guid,
+ get_time_ns()/1000);
+
+   uuid = device_path_to_partuuid(device_path_from_handle(
+  efi_loaded_image->device_handle));
+   if (uuid) {
+   wchar_t *uuid16 = xstrdup_char_to_wchar(uuid);
+   efi_set_variable("LoaderDevicePartUUID",
+&efi_systemd_vendor_guid,
+EFI_VARIABLE_BOOTSERVICE_ACCESS |
+EFI_VARIABLE_RUNTIME_ACCESS,
+uuid16, (strlen(uuid)+1) * sizeof(wchar_t));
+   free(uuid);
+   free(uuid16);
+   }
 
start_barebox();
 
diff --git a/common/efi-guid.c b/common/efi-guid.c
index f6b040410522..f4ff7feadfe4 100644
--- a/common/efi-guid.c
+++ b/common/efi-guid.c
@@ -9,6 +9,7 @@ efi_guid_t efi_unknown_device_guid = EFI_UNKNOWN_DEVICE_GUID;
 efi_guid_t efi_null_guid = EFI_NULL_GUID;
 efi_guid_t efi_global_variable_guid = EFI_GLOBAL_VARIABLE_GUID;
 efi_guid_t efi_block_io_protocol_guid = EFI_BLOCK_IO_PROTOCOL_GUID;
+efi_guid_t efi_systemd_vendor_guid = EFI_SYSTEMD_VENDOR_GUID;
 
 #define EFI_GUID_STRING(guid, short, long) do {\
if (!efi_guidcmp(guid, *g)) \
diff --git a/include/efi.h b/include/efi.h
index 830e0457dd1c..5b0de119fb74 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -473,6 +473,10 @@ extern efi_runtime_services_t *RT;
 #define EFI_BAREBOX_VENDOR_GUID \
EFI_GUID(0x5b91f69c, 0x8b88, 0x4a2b, 0x92, 0x69, 0x5f, 0x1d, 0x80, 
0x2b, 0x51, 0x75)
 
+/* for systemd */
+#define EFI_SYSTEMD_VENDOR_GUID \
+   EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, 0xb6, 0xc7, 0x44, 0x0b, 0x29, 
0xbb, 0x8c, 0x4f)
+
 extern efi_guid_t efi_file_info_id;
 extern efi_guid_t efi_simple_file_system_protocol_guid;
 extern efi_guid_t efi_device_path_protocol_guid;
@@ -481,6 +485,7 @@ extern efi_guid_t efi_unknown_device_guid;
 extern efi_guid_t efi_null_guid;
 extern efi_guid_t efi_global_variable_guid;
 extern efi_guid_t efi_block_io_protocol_guid;
+extern efi_guid_t efi_systemd_vendor_guid;
 
 #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
 
-- 
2.1.4


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 2/7] drivers: i2c: Only register available devices

2015-07-17 Thread Jan Lübbe
On Fr, 2015-07-17 at 13:13 +0200, Teresa Remmet wrote:
> -   for_each_child_of_node(adap->dev.device_node, n) {
> +   for_each_available_child_of_node(adap->dev.device_node, n) {
> struct i2c_board_info info = {};

I've submitted an identical patch last week, which was applied by
Sascha.

Regards,
Jan
-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH v3 2/2] ARM: am335x: Changed timer

2015-07-17 Thread Jan Lübbe
On Fr, 2015-07-17 at 15:39 +0200, Daniel Schultz wrote:
> The dmtimer0 is too inaccurate to be used for measurements.
> We switch to the more accurate dmtimer2.

Ah, OK, after looking at the TRM again, the real reason for the
inaccuracy seems to be that the 32KiHz for dmtimer0 is *not* derived
from the RTC crystal, but from an internal RC oscillator.

The kernel uses dmtimer1 for the clocksource by switching it to the
M_OSC in the PRCM.

The dmtimer2 is used for clockevents and runs from M_OSC by default.
While we could set the dmtimer1 source to M_OSC in the clock setup, it
seems simpler to just use dmtimer2.

The commit message should explain the reasoning behind the switch.

Regards,
Jan
-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH v2 2/2] ARM: am335x: Changed timer

2015-07-17 Thread Daniel Schultz

Am 17.07.2015 um 11:16 schrieb Jan Lübbe:

On Do, 2015-07-16 at 10:51 +0200, Daniel Schultz wrote:

The dmtimer0 is too inaccurate to be used for measurements.
We switch to the more accurate dmtimer2.


What are you trying to measure? Is the resolution or the accuracy too
low?
While testing with dhrystone on our boards, I figured out that the 
timestamps from dmtimer0 run 20% too quick.


You can also make a quick test on a am335x board with
sleep 10

You will notice that the sleep only takes 8 seconds. This quite too 
inaccurate.





+#define CLK_M_OSC  2500



+static int dmtimer_init(void)
+{
+   dmtimer_cs.mult = clocksource_hz2mult(CLK_M_OSC, dmtimer_cs.shift);
+   /* Enable counter */
+   writel(0x3, base + TCLR);
+
+   return init_clock(&dmtimer_cs);


You use a fixed M_OSC of 25 MHz, but this value actually depends on the
the board. The AM335x supports 19.2, 24 and 26 MHz in addition to 25
MHz.

see new patch.

The advantage of using dmtimer0 is that it is always available and runs
at 32KiHz on every board.

Regards,
Jan



Kind regards,
Daniel

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v3 2/2] ARM: am335x: Changed timer

2015-07-17 Thread Daniel Schultz
The dmtimer0 is too inaccurate to be used for measurements.
We switch to the more accurate dmtimer2.

Signed-off-by: Daniel Schultz 
---
 arch/arm/mach-omap/Kconfig   |   4 +-
 arch/arm/mach-omap/Makefile  |   2 +-
 arch/arm/mach-omap/dmtimer.c | 112 +++
 arch/arm/mach-omap/dmtimer0.c|  85 -
 arch/arm/mach-omap/include/mach/am33xx-silicon.h |   4 +
 5 files changed, 119 insertions(+), 88 deletions(-)
 create mode 100644 arch/arm/mach-omap/dmtimer.c
 delete mode 100644 arch/arm/mach-omap/dmtimer0.c

diff --git a/arch/arm/mach-omap/Kconfig b/arch/arm/mach-omap/Kconfig
index af35975..87e8d44 100644
--- a/arch/arm/mach-omap/Kconfig
+++ b/arch/arm/mach-omap/Kconfig
@@ -43,7 +43,7 @@ config ARCH_AM33XX
select CPU_V7
select GENERIC_GPIO
select OFTREE
-   select OMAP_CLOCK_SOURCE_DMTIMER0
+   select OMAP_CLOCK_SOURCE_DMTIMER
help
  Say Y here if you are using Texas Instrument's AM33xx based platform
 
@@ -51,7 +51,7 @@ config ARCH_AM33XX
 config OMAP_CLOCK_SOURCE_S32K
bool
 
-config OMAP_CLOCK_SOURCE_DMTIMER0
+config OMAP_CLOCK_SOURCE_DMTIMER
bool
 
 config OMAP_GPMC
diff --git a/arch/arm/mach-omap/Makefile b/arch/arm/mach-omap/Makefile
index 65072b9..db2856d 100644
--- a/arch/arm/mach-omap/Makefile
+++ b/arch/arm/mach-omap/Makefile
@@ -18,7 +18,7 @@
 obj-$(CONFIG_ARCH_OMAP) += syslib.o omap_devices.o omap_generic.o omap_fb.o
 pbl-$(CONFIG_ARCH_OMAP) += syslib.o
 obj-$(CONFIG_OMAP_CLOCK_SOURCE_S32K) += s32k_clksource.o
-obj-$(CONFIG_OMAP_CLOCK_SOURCE_DMTIMER0) += dmtimer0.o
+obj-$(CONFIG_OMAP_CLOCK_SOURCE_DMTIMER) += dmtimer.o
 obj-$(CONFIG_ARCH_OMAP3) += omap3_generic.o auxcr.o
 pbl-$(CONFIG_ARCH_OMAP3) += omap3_generic.o auxcr.o
 obj-$(CONFIG_ARCH_OMAP4) += omap4_generic.o omap4_clock.o
diff --git a/arch/arm/mach-omap/dmtimer.c b/arch/arm/mach-omap/dmtimer.c
new file mode 100644
index 000..56adda0
--- /dev/null
+++ b/arch/arm/mach-omap/dmtimer.c
@@ -0,0 +1,112 @@
+/**
+ * @file
+ * @brief Support DMTimer counter
+ *
+ * FileName: arch/arm/mach-omap/dmtimer.c
+ */
+/*
+ * This File is based on arch/arm/mach-omap/s32k_clksource.c
+ * (C) Copyright 2008
+ * Texas Instruments, 
+ * Nishanth Menon 
+ *
+ * (C) Copyright 2012 Phytec Messtechnik GmbH
+ * Author: Teresa Gámez 
+ * (C) Copyright 2015 Phytec Messtechnik GmbH
+ * Author: Daniel Schultz 
+ *
+ * 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.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define CLK_RC32K  32768
+
+#define TIDR   0x0
+#define TIOCP_CFG  0x10
+#define IRQ_EOI0x20
+#define IRQSTATUS_RAW  0x24
+#define IRQSTATUS  0x28
+#define IRQSTATUS_SET  0x2c
+#define IRQSTATUS_CLR  0x30
+#define IRQWAKEEN  0x34
+#define TCLR   0x38
+#define TCRR   0x3C
+#define TLDR   0x40
+#define TTGR   0x44
+#define TWPS   0x48
+#define TMAR   0x4C
+#define TCAR1  0x50
+#define TSICR  0x54
+#define TCAR2  0x58
+
+static void *base = (void *)AM33XX_DMTIMER2_BASE;
+
+/**
+ * @brief Provide a simple counter read
+ *
+ * @return DMTimer counter
+ */
+static uint64_t dmtimer_read(void)
+{
+   return readl(base + TCRR);
+}
+
+static struct clocksource dmtimer_cs = {
+   .read   = dmtimer_read,
+   .mask   = CLOCKSOURCE_MASK(32),
+   .shift  = 10,
+};
+
+/**
+ * @brief Initialize the Clock
+ *
+ * Enable dmtimer.
+ *
+ * @return result of @ref init_clock
+ */
+static int dmtimer_init(void)
+{
+   u64 clk_speed;
+   int sysboot;
+
+   sysboot = (readl(AM33XX_CTRL_STATUS) >> 22) & 3;
+   switch (sysboot) {
+   case 0:
+   clk_speed = 1920;
+   break;
+   case 1:
+   clk_speed = 2400;
+   break;
+   case 2:
+   clk_speed = 2500;
+   break;
+   case 3:
+   clk_speed = 2600;
+   break;
+   }
+
+   dmtimer_cs.mult = clocksource_hz2mult(clk_speed, dmtimer_cs.shift);
+
+   /* Enable counter */
+   writel(0x3, base + TCLR);
+
+   return init_clock(&dmtimer_cs);
+}
+
+/* Run me at boot time */
+core_initcall(dmtimer_init);
diff --git a/arch/arm/mach-omap/dmtimer0.c b/arch/arm/mach-omap/dmtimer0.c
deleted file mo

[PATCH 7/7] ARM: dts: Add support for all phyFLEX-AM335x options

2015-07-17 Thread Teresa Remmet
Add support for all possible combinations of phyFLEX-AM335x modules.

Signed-off-by: Teresa Remmet 
---
 arch/arm/boards/phytec-som-am335x/lowlevel.c   |  3 +++
 arch/arm/dts/Makefile  |  2 ++
 .../dts/am335x-phytec-phyflex-som-no-eeprom.dts| 22 ++
 .../am335x-phytec-phyflex-som-no-spi-no-eeprom.dts | 18 ++
 arch/arm/dts/am335x-phytec-phyflex-som-no-spi.dts  | 22 ++
 images/Makefile.am33xx | 12 
 6 files changed, 79 insertions(+)
 create mode 100644 arch/arm/dts/am335x-phytec-phyflex-som-no-eeprom.dts
 create mode 100644 arch/arm/dts/am335x-phytec-phyflex-som-no-spi-no-eeprom.dts
 create mode 100644 arch/arm/dts/am335x-phytec-phyflex-som-no-spi.dts

diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index adc19de..64c1c53 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -134,6 +134,9 @@ 
PHYTEC_ENTRY(start_am33xx_phytec_phycore_no_spi_no_eeprom_sdram, am335x_phytec_p
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phyflex_sram_256mb, 
am335x_phytec_phyflex_som_mlo, PHYFLEX_MT41K128M16JT_256MB);
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phyflex_sram_512mb, 
am335x_phytec_phyflex_som_mlo, PHYFLEX_MT41K256M16HA_512MB);
 PHYTEC_ENTRY(start_am33xx_phytec_phyflex_sdram, am335x_phytec_phyflex_som);
+PHYTEC_ENTRY(start_am33xx_phytec_phyflex_no_spi_sdram, 
am335x_phytec_phyflex_som_no_spi);
+PHYTEC_ENTRY(start_am33xx_phytec_phyflex_no_eeprom_sdram, 
am335x_phytec_phyflex_som_no_eeprom);
+PHYTEC_ENTRY(start_am33xx_phytec_phyflex_no_spi_no_eeprom_sdram, 
am335x_phytec_phyflex_som_no_spi_no_eeprom);
 
 /* phycard-som */
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycard_sram_256mb, 
am335x_phytec_phycard_som_mlo, PHYCARD_NT5CB128M16BP_256MB);
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 3d5cb53..15d620a 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -32,6 +32,8 @@ pbl-dtb-$(CONFIG_MACH_PCA100) += 
imx27-phytec-phycard-s-rdk-bb.dtb.o
 pbl-dtb-$(CONFIG_MACH_PCAAXL3) += imx6q-phytec-pbaa03.dtb.o
 pbl-dtb-$(CONFIG_MACH_PCM038) += imx27-phytec-phycore-rdk.dtb.o
 pbl-dtb-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += am335x-phytec-phyflex-som.dtb.o 
am335x-phytec-phyflex-som-mlo.dtb.o \
+   am335x-phytec-phyflex-som-no-spi.dtb.o 
am335x-phytec-phyflex-som-no-eeprom.dtb.o \
+   am335x-phytec-phyflex-som-no-spi-no-eeprom.dtb.o \
am335x-phytec-phycore-som.dtb.o am335x-phytec-phycore-som-no-spi.dtb.o 
am335x-phytec-phycore-som-mlo.dtb.o \
am335x-phytec-phycore-som-no-eeprom.dtb.o 
am335x-phytec-phycore-som-no-spi-no-eeprom.dtb.o \
am335x-phytec-phycard-som.dtb.o am335x-phytec-phycard-som-mlo.dtb.o
diff --git a/arch/arm/dts/am335x-phytec-phyflex-som-no-eeprom.dts 
b/arch/arm/dts/am335x-phytec-phyflex-som-no-eeprom.dts
new file mode 100644
index 000..0022e14
--- /dev/null
+++ b/arch/arm/dts/am335x-phytec-phyflex-som-no-eeprom.dts
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2015 PHYTEC Messtechnik GmbH
+ * Author: Wadim Egorov 
+ *Teresa Remmet 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+/dts-v1/;
+
+#include "am33xx.dtsi"
+#include "am335x-phytec-phyflex-som.dtsi"
+
+/ {
+   model = "Phytec phyFLEX AM335x";
+   compatible = "phytec,phyflex-am335x-som", "phytec,am335x-som", 
"ti,am33xx";
+};
+
+&spi0 {
+   status = "okay";
+};
diff --git a/arch/arm/dts/am335x-phytec-phyflex-som-no-spi-no-eeprom.dts 
b/arch/arm/dts/am335x-phytec-phyflex-som-no-spi-no-eeprom.dts
new file mode 100644
index 000..486aac6
--- /dev/null
+++ b/arch/arm/dts/am335x-phytec-phyflex-som-no-spi-no-eeprom.dts
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2015 PHYTEC Messtechnik GmbH
+ * Author: Wadim Egorov 
+ *Teresa Remmet 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+/dts-v1/;
+
+#include "am33xx.dtsi"
+#include "am335x-phytec-phyflex-som.dtsi"
+
+/ {
+   model = "Phytec phyFLEX AM335x";
+   compatible = "phytec,phyflex-am335x-som", "phytec,am335x-som", 
"ti,am33xx";
+};
diff --git a/arch/arm/dts/am335x-phytec-phyflex-som-no-spi.dts 
b/arch/arm/dts/am335x-phytec-phyflex-som-no-spi.dts
new file mode 100644
index 000..5f3a1e0
--- /dev/null
+++ b/arch/arm/dts/am335x-phytec-phyflex-som-no-spi.dts
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2015 PHYTEC Messtechnik GmbH
+ * Author: Wadim Egorov 
+ *Teresa Remmet 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+/dts-v1/;
+
+#include "am3

[PATCH 6/7] ARM: dts: Add support for all phyCORE-AM335x options

2015-07-17 Thread Teresa Remmet
Add support for all possible combinations of phyCORE-AM335x
modules.

Signed-off-by: Teresa Remmet 
---
 arch/arm/boards/phytec-som-am335x/lowlevel.c|  2 ++
 arch/arm/dts/Makefile   |  1 +
 .../arm/dts/am335x-phytec-phycore-som-no-eeprom.dts | 21 +
 .../am335x-phytec-phycore-som-no-spi-no-eeprom.dts  | 17 +
 images/Makefile.am33xx  |  8 
 5 files changed, 49 insertions(+)
 create mode 100644 arch/arm/dts/am335x-phytec-phycore-som-no-eeprom.dts
 create mode 100644 arch/arm/dts/am335x-phytec-phycore-som-no-spi-no-eeprom.dts

diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index 0ff62a3..adc19de 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -127,6 +127,8 @@ PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_2x512mb, 
am335x_phytec_phycore
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_1024mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_IM8G16D3FBBG15EI_1024MB);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_sdram, am335x_phytec_phycore_som);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_no_spi_sdram, 
am335x_phytec_phycore_som_no_spi);
+PHYTEC_ENTRY(start_am33xx_phytec_phycore_no_eeprom_sdram, 
am335x_phytec_phycore_som_no_eeprom);
+PHYTEC_ENTRY(start_am33xx_phytec_phycore_no_spi_no_eeprom_sdram, 
am335x_phytec_phycore_som_no_spi_no_eeprom);
 
 /* phyflex-som */
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phyflex_sram_256mb, 
am335x_phytec_phyflex_som_mlo, PHYFLEX_MT41K128M16JT_256MB);
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 06c29c8..3d5cb53 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -33,6 +33,7 @@ pbl-dtb-$(CONFIG_MACH_PCAAXL3) += imx6q-phytec-pbaa03.dtb.o
 pbl-dtb-$(CONFIG_MACH_PCM038) += imx27-phytec-phycore-rdk.dtb.o
 pbl-dtb-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += am335x-phytec-phyflex-som.dtb.o 
am335x-phytec-phyflex-som-mlo.dtb.o \
am335x-phytec-phycore-som.dtb.o am335x-phytec-phycore-som-no-spi.dtb.o 
am335x-phytec-phycore-som-mlo.dtb.o \
+   am335x-phytec-phycore-som-no-eeprom.dtb.o 
am335x-phytec-phycore-som-no-spi-no-eeprom.dtb.o \
am335x-phytec-phycard-som.dtb.o am335x-phytec-phycard-som-mlo.dtb.o
 pbl-dtb-$(CONFIG_MACH_PHYTEC_PFLA02) += imx6s-phytec-pbab01.dtb.o 
imx6dl-phytec-pbab01.dtb.o imx6q-phytec-pbab01.dtb.o 
imx6q-phytec-phyboard-alcor.dtb.o imx6dl-phytec-phyboard-subra.dtb.o
 pbl-dtb-$(CONFIG_MACH_PLATHOME_OPENBLOCKS_AX3) += 
armada-xp-openblocks-ax3-4-bb.dtb.o
diff --git a/arch/arm/dts/am335x-phytec-phycore-som-no-eeprom.dts 
b/arch/arm/dts/am335x-phytec-phycore-som-no-eeprom.dts
new file mode 100644
index 000..3dd130e
--- /dev/null
+++ b/arch/arm/dts/am335x-phytec-phycore-som-no-eeprom.dts
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2015 Phytec Messtechnik GmbH
+ * Author: Teresa Remmet 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+/dts-v1/;
+
+#include "am33xx.dtsi"
+#include "am335x-phytec-phycore-som.dtsi"
+
+/ {
+   model = "Phytec phyCORE AM335x";
+   compatible = "phytec,phycore-am335x-som", "phytec,am335x-som", 
"ti,am33xx";
+};
+
+&spi0 {
+   status = "okay";
+};
diff --git a/arch/arm/dts/am335x-phytec-phycore-som-no-spi-no-eeprom.dts 
b/arch/arm/dts/am335x-phytec-phycore-som-no-spi-no-eeprom.dts
new file mode 100644
index 000..397be77
--- /dev/null
+++ b/arch/arm/dts/am335x-phytec-phycore-som-no-spi-no-eeprom.dts
@@ -0,0 +1,17 @@
+/*
+ * Copyright (C) 2015 Phytec Messtechnik GmbH
+ * Author:  Teresa Remmet 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+/dts-v1/;
+
+#include "am33xx.dtsi"
+#include "am335x-phytec-phycore-som.dtsi"
+
+/ {
+   model = "Phytec phyCORE AM335x";
+   compatible = "phytec,phycore-am335x-som", "phytec,am335x-som", 
"ti,am33xx";
+};
diff --git a/images/Makefile.am33xx b/images/Makefile.am33xx
index df77f19..45813ca 100644
--- a/images/Makefile.am33xx
+++ b/images/Makefile.am33xx
@@ -33,6 +33,14 @@ pblx-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
start_am33xx_phytec_phycore_no_spi_sdra
 FILE_barebox-am33xx-phytec-phycore-no-spi.img = 
start_am33xx_phytec_phycore_no_spi_sdram.pblx
 am33xx-barebox-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-no-spi.img
 
+pblx-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
start_am33xx_phytec_phycore_no_eeprom_sdram
+FILE_barebox-am33xx-phytec-phycore-no-eeprom.img = 
start_am33xx_phytec_phycore_no_eeprom_sdram.pblx
+am33xx-barebox-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-no-eeprom.img
+
+pblx-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
start_am33xx_phytec_phycore_no_spi_no_eeprom_sdram
+FILE_barebo

[PATCH 3/7] ARM: dts: am335x-phytec boards: Fixup spi flash node name

2015-07-17 Thread Teresa Remmet
Signed-off-by: Teresa Remmet 
---
 arch/arm/dts/am335x-phytec-phycore-som.dtsi | 2 +-
 arch/arm/dts/am335x-phytec-phyflex-som.dtsi | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/dts/am335x-phytec-phycore-som.dtsi 
b/arch/arm/dts/am335x-phytec-phycore-som.dtsi
index ed8e257..59816d0 100644
--- a/arch/arm/dts/am335x-phytec-phycore-som.dtsi
+++ b/arch/arm/dts/am335x-phytec-phycore-som.dtsi
@@ -162,7 +162,7 @@
pinctrl-0 = <&spi0_pins>;
status = "disabled";
 
-   flash: m25p80 {
+   flash: m25p80@0 {
compatible = "m25p80";
spi-max-frequency = <4800>;
reg = <0>;
diff --git a/arch/arm/dts/am335x-phytec-phyflex-som.dtsi 
b/arch/arm/dts/am335x-phytec-phyflex-som.dtsi
index fc9c9ba..b8c6886 100644
--- a/arch/arm/dts/am335x-phytec-phyflex-som.dtsi
+++ b/arch/arm/dts/am335x-phytec-phyflex-som.dtsi
@@ -151,7 +151,7 @@
pinctrl-names = "default";
pinctrl-0 = <&spi0_pins>;
status = "disabled";
-   flash: m25p80 {
+   flash: m25p80@0 {
compatible = "m25p80";
spi-max-frequency = <4800>;
reg = <0>;
-- 
1.9.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 5/7] ARM: phytec-som-am335x: Add support for 1024MiB RAM on one chip

2015-07-17 Thread Teresa Remmet
Added support for IM8G16D3FBBG15EI 1024MiB RAM on one chip.

Signed-off-by: Teresa Remmet 
---
 arch/arm/boards/phytec-som-am335x/lowlevel.c|  1 +
 arch/arm/boards/phytec-som-am335x/ram-timings.h | 22 +-
 images/Makefile.am33xx  |  6 ++
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boards/phytec-som-am335x/lowlevel.c 
b/arch/arm/boards/phytec-som-am335x/lowlevel.c
index 948bfa5..0ff62a3 100644
--- a/arch/arm/boards/phytec-som-am335x/lowlevel.c
+++ b/arch/arm/boards/phytec-som-am335x/lowlevel.c
@@ -124,6 +124,7 @@ PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_128mb, 
am335x_phytec_phycore_s
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_256mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_MT41J128M16125IT_256MB);
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_512mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_MT41J256M16HA15EIT_512MB);
 PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_2x512mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_MT41J512M8125IT_2x512MB);
+PHYTEC_ENTRY_MLO(start_am33xx_phytec_phycore_sram_1024mb, 
am335x_phytec_phycore_som_mlo, PHYCORE_IM8G16D3FBBG15EI_1024MB);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_sdram, am335x_phytec_phycore_som);
 PHYTEC_ENTRY(start_am33xx_phytec_phycore_no_spi_sdram, 
am335x_phytec_phycore_som_no_spi);
 
diff --git a/arch/arm/boards/phytec-som-am335x/ram-timings.h 
b/arch/arm/boards/phytec-som-am335x/ram-timings.h
index 3dcee20..698b073 100644
--- a/arch/arm/boards/phytec-som-am335x/ram-timings.h
+++ b/arch/arm/boards/phytec-som-am335x/ram-timings.h
@@ -29,6 +29,7 @@ enum {
PHYCORE_MT41J64M1615IT_128MB,
PHYCORE_MT41J256M16HA15EIT_512MB,
PHYCORE_MT41J512M8125IT_2x512MB,
+   PHYCORE_IM8G16D3FBBG15EI_1024MB,
 
PHYCARD_NT5CB128M16BP_256MB,
 };
@@ -133,7 +134,7 @@ struct am335x_sdram_timings physom_timings[] = {
},
},
 
-   /* 1024MB */
+   /* 2x512MB */
[PHYCORE_MT41J512M8125IT_2x512MB] = {
.regs = {
.emif_read_latency  = 0x7,
@@ -152,6 +153,25 @@ struct am335x_sdram_timings physom_timings[] = {
},
},
 
+   /* 1024MB */
+   [PHYCORE_IM8G16D3FBBG15EI_1024MB] = {
+   .regs = {
+   .emif_read_latency  = 0x7,
+   .emif_tim1  = 0x0AAAE4DB,
+   .emif_tim2  = 0x268F7FDA,
+   .emif_tim3  = 0x501F88BF,
+   .sdram_config   = 0x61C053B2,
+   .zq_config  = 0x50074BE4,
+   .sdram_ref_ctrl = 0x0C30
+   },
+   .data = {
+   .rd_slave_ratio0= 0x33,
+   .wr_dqs_slave_ratio0= 0x4a,
+   .fifo_we_slave_ratio0   = 0xa4,
+   .wr_slave_ratio0= 0x85,
+   },
+   },
+
/* 256MB */
[PHYCARD_NT5CB128M16BP_256MB] = {
.regs = {
diff --git a/images/Makefile.am33xx b/images/Makefile.am33xx
index 657aeb0..df77f19 100644
--- a/images/Makefile.am33xx
+++ b/images/Makefile.am33xx
@@ -57,6 +57,12 @@ FILE_barebox-am33xx-phytec-phycore-mlo-2x512mb.spi.img = 
start_am33xx_phytec_phy
 am33xx-mlo-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-mlo-2x512mb.img
 am33xx-mlospi-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-mlo-2x512mb.spi.img
 
+pblx-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
start_am33xx_phytec_phycore_sram_1024mb
+FILE_barebox-am33xx-phytec-phycore-mlo-1024mb.img = 
start_am33xx_phytec_phycore_sram_1024mb.pblx.mlo
+FILE_barebox-am33xx-phytec-phycore-mlo-1024mb.spi.img = 
start_am33xx_phytec_phycore_sram_1024mb.pblx.mlospi
+am33xx-mlo-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-mlo-1024mb.img
+am33xx-mlospi-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phycore-mlo-1024mb.spi.img
+
 pblx-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += start_am33xx_phytec_phyflex_sdram
 FILE_barebox-am33xx-phytec-phyflex.img = start_am33xx_phytec_phyflex_sdram.pblx
 am33xx-barebox-$(CONFIG_MACH_PHYTEC_SOM_AM335X) += 
barebox-am33xx-phytec-phyflex.img
-- 
1.9.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 1/7] mtd: core: Check partitions for empty string

2015-07-17 Thread Teresa Remmet
Make setting partitions a litte bit more robust.

Signed-off-by: Teresa Remmet 
---
 drivers/mtd/core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index fda9034..3bdf441 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -386,6 +386,9 @@ static int mtd_partition_set(struct device_d *dev, struct 
param_d *p, const char
struct mtd_info *mtdpart, *tmp;
int ret;
 
+   if (!val)
+   return -EINVAL;
+
list_for_each_entry_safe(mtdpart, tmp, &mtd->partitions, 
partitions_entry) {
ret = mtd_del_partition(mtdpart);
if (ret)
-- 
1.9.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 4/7] ARM: dts: phyFLEX-AM335x-som: Disable eeprom on default

2015-07-17 Thread Teresa Remmet
Only enable eeprom when populated. So disable it in dtsi
file and enable if needed in board dts.

Signed-off-by: Teresa Remmet 
---
 arch/arm/dts/am335x-phytec-phyflex-som.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/dts/am335x-phytec-phyflex-som.dtsi 
b/arch/arm/dts/am335x-phytec-phyflex-som.dtsi
index b8c6886..81ecf9d 100644
--- a/arch/arm/dts/am335x-phytec-phyflex-som.dtsi
+++ b/arch/arm/dts/am335x-phytec-phyflex-som.dtsi
@@ -138,6 +138,7 @@
byte_len = <4096>;
pagesize = <32>;
reg = <0x52>;
+   status = "disabled";
};
 };
 
-- 
1.9.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 2/7] drivers: i2c: Only register available devices

2015-07-17 Thread Teresa Remmet
Only register i2c devices from device tree where status is enabled.

Signed-off-by: Teresa Remmet 
---
 drivers/i2c/i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 5d0fa06..f0df666 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -278,7 +278,7 @@ static void of_i2c_register_devices(struct i2c_adapter 
*adap)
if (!IS_ENABLED(CONFIG_OFDEVICE) || !adap->dev.device_node)
return;
 
-   for_each_child_of_node(adap->dev.device_node, n) {
+   for_each_available_child_of_node(adap->dev.device_node, n) {
struct i2c_board_info info = {};
struct i2c_client *result;
const __be32 *addr;
-- 
1.9.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH v2 2/2] ARM: am335x: Changed timer

2015-07-17 Thread Jan Lübbe
On Do, 2015-07-16 at 10:51 +0200, Daniel Schultz wrote:
> The dmtimer0 is too inaccurate to be used for measurements.
> We switch to the more accurate dmtimer2.

What are you trying to measure? Is the resolution or the accuracy too
low?

> +#define CLK_M_OSC2500

> +static int dmtimer_init(void)
> +{
> + dmtimer_cs.mult = clocksource_hz2mult(CLK_M_OSC, dmtimer_cs.shift);
> + /* Enable counter */
> + writel(0x3, base + TCLR);
> +
> + return init_clock(&dmtimer_cs);

You use a fixed M_OSC of 25 MHz, but this value actually depends on the
the board. The AM335x supports 19.2, 24 and 26 MHz in addition to 25
MHz.

The advantage of using dmtimer0 is that it is always available and runs
at 32KiHz on every board.

Regards,
Jan
-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 7/7] efi: write volatile EFI variables used by systemd

2015-07-17 Thread Sascha Hauer
On Fri, Jul 17, 2015 at 09:05:40AM +0200, Michael Olbrich wrote:
> On Thu, Jul 16, 2015 at 10:08:48PM +0200, Sascha Hauer wrote:
> > On Thu, Jul 16, 2015 at 10:43:56AM +0200, Michael Olbrich wrote:
> > > LoaderTimeInitUSec and LoaderTimeExecUSec are used e.g. in systemd-analyze
> > > to calculate the time spent in the firmare and barebox.
> > > 
> > > LoaderDevicePartUUID is used to mount the EFI partition to /boot.
> > > 
> > > Signed-off-by: Michael Olbrich 
> > > ---
> > >  arch/efi/efi/efi-image.c |  5 +
> > >  arch/efi/efi/efi.c   | 14 ++
> > >  common/efi-guid.c|  1 +
> > >  include/efi.h|  5 +
> > >  4 files changed, 25 insertions(+)
> > > 
> > > diff --git a/arch/efi/efi/efi-image.c b/arch/efi/efi/efi-image.c
> > > index f41322744bbc..89b712baab1f 100644
> > > --- a/arch/efi/efi/efi-image.c
> > > +++ b/arch/efi/efi/efi-image.c
> > > @@ -17,6 +17,7 @@
> > >   *
> > >   */
> > >  
> > > +#include 
> > >  #include 
> > >  #include 
> > >  #include 
> > > @@ -242,6 +243,10 @@ static int do_bootm_efi(struct image_data *data)
> > >  boot_header->ramdisk_image);
> > >   printf("...\n");
> > >   }
> > > +
> > > + efi_set_variable_usec("LoaderTimeExecUSec", &efi_systemd_vendor_guid,
> > > +   get_time_ns()/1000);
> > > +
> > >   linux_efi_handover(handle, boot_header);
> > >  
> > >   return 0;
> > > diff --git a/arch/efi/efi/efi.c b/arch/efi/efi/efi.c
> > > index b0e98f95b02b..a665a546be90 100644
> > > --- a/arch/efi/efi/efi.c
> > > +++ b/arch/efi/efi/efi.c
> > > @@ -340,6 +340,7 @@ efi_status_t efi_main(efi_handle_t image, 
> > > efi_system_table_t *sys_table)
> > >   efi_physical_addr_t mem;
> > >   size_t memsize;
> > >   efi_status_t efiret;
> > > + char *uuid;
> > >  
> > >  #ifdef DEBUG
> > >   sys_table->con_out->output_string(sys_table->con_out, L"barebox\n");
> > > @@ -377,6 +378,19 @@ efi_status_t efi_main(efi_handle_t image, 
> > > efi_system_table_t *sys_table)
> > >   mem_malloc_init((void *)mem, (void *)mem + memsize);
> > >  
> > >   efi_clocksource_init();
> > > + efi_set_variable_usec("LoaderTimeInitUSec", &efi_systemd_vendor_guid,
> > > +   get_time_ns()/1000);
> > > +
> > > + uuid = device_path_to_partuuid(device_path_from_handle(
> > > +efi_loaded_image->device_handle));
> > > + if (uuid) {
> > > + wchar_t *uuid16 = strdup_char_to_wchar(uuid);
> > > + efi_set_variable("LoaderDevicePartUUID",
> > > +  &efi_systemd_vendor_guid,
> > > +  EFI_VARIABLE_BOOTSERVICE_ACCESS |
> > > +  EFI_VARIABLE_RUNTIME_ACCESS,
> > > +  uuid16, (strlen(uuid)+1) * sizeof(wchar_t));
> > > + }
> > 
> > Shouldn't you free uuid here?
> 
> Yes, and uuid16.
> 
> Hmmm, what's the policy for OOM checks for string functions? None of the
> existing calls of strdup_char_to_wchar() check for NULL. And I didn't find
> any checks for asprintf() either.

Introducing xasprintf and using it throughout the tree is on my mental
todo list for some time now. I think You can skip the error check, or,
even better, introduce xasprintf ;)

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [RFC 04/12] WIP: fs/nfs.c: convert to picotcp

2015-07-17 Thread Antony Pavlov
On Thu, 16 Jul 2015 21:51:50 +0200
Sascha Hauer  wrote:

> Hi Antony,
> 
> On Wed, Jul 15, 2015 at 11:13:42PM +0300, Antony Pavlov wrote:
> > Signed-off-by: Antony Pavlov 
> > ---
> >  fs/nfs.c | 150 
> > +++
> >  1 file changed, 133 insertions(+), 17 deletions(-)
> > 
> > @@ -1346,19 +1424,38 @@ static int nfs_probe(struct device_d *dev)
> >  
> > npriv->path = xstrdup(path + 1);
> >  
> > -   npriv->server = resolv(tmp);
> > +   if (IS_ENABLED(CONFIG_NET_LEGACY)) {
> > +   npriv->server = resolv(tmp);
> > +   } else if (IS_ENABLED(CONFIG_NET_PICOTCP)) {
> > +   /* FIXME: check corectness */
> > +   npriv->remote_address.ip4.addr = resolv(tmp);
> > +   }
> >  
> > debug("nfs: server: %s path: %s\n", tmp, npriv->path);
> >  
> > -   npriv->con = net_udp_new(npriv->server, 0, nfs_handler, npriv);
> > -   if (IS_ERR(npriv->con)) {
> > -   ret = PTR_ERR(npriv->con);
> > -   goto err1;
> > +   if (IS_ENABLED(CONFIG_NET_LEGACY)) {
> > +   npriv->con = net_udp_new(npriv->server, 0, nfs_handler, npriv);
> > +   if (IS_ERR(npriv->con)) {
> > +   ret = PTR_ERR(npriv->con);
> > +   goto err1;
> > +   }
> > +
> > +   /* Need a priviliged source port */
> > +   net_udp_bind(npriv->con, 1000);
> > +   } else if (IS_ENABLED(CONFIG_NET_PICOTCP)) {
> > +   /* FIXME: 2048 */
> > +   npriv->pkt = xzalloc(2048);
> > +
> > +   /* Need a priviliged source port */
> > +   npriv->sock = nfs_socket_open(1000);
> > +   if (!npriv->sock) {
> > +   ret = -1;
> > +   goto err1;
> > +   }
> > +
> > +   npriv->sock->priv = npriv;
> > }
> 
> The different network stacks should be transparent to the users. Instead
> of implementing them in tftp/nfs/... I would expect the abstraction in the
> current network functions, something like:

It's near impossible with current network stack implementation.

We have to drop direct access to net_connection private fields from application 
code;
e.g. direct access to packet UDP fields in tftp code:

  priv->tftp_con->udp->uh_dport = uh_sport;

My patch series was not intended to change legacy network code in any way.
On the contrary it intentionaly keeps original code "as is".
This approach demonstrates in practice picotcp and legacy network stack 
differences,
so future work on integration is much more evident.

I can start next round of picotcp integration with removing direct access to 
net_connection private fields
from application code.


> struct net_connection *net_udp_new(IPaddr_t dest, uint16_t dport,
> rx_handler_f *handler, void *ctx)
> {
>   struct net_connection *con = net_new(dest, handler, ctx);
>   if (IS_ERR(con))
> return con;
> 
>   con->proto = IPPROTO_UDP;
>   con->udp->uh_dport = htons(dport);
>   con->udp->uh_sport = htons(net_udp_new_localport());
>   con->ip->protocol = IPPROTO_UDP;
> 
>   if (IS_ENABLED(CONFIG_NET_PICOTCP)) {
>   con->sock = pico_socket_open(PICO_PROTO_IPV4, PICO_PROTO_UDP, 
> handler);
>   }
> 
>   return con;
> }
> 
> static inline int net_udp_bind(struct net_connection *con, int sport)
> {
>   if (IS_ENABLED(CONFIG_NET_PICOTCP)) {
>   memset(&local_address, 0, sizeof(union pico_address));
>   pico_socket_bind(con->sock, &local_address, &sport);
>   } else {
>   con->udp->uh_sport = ntohs(sport);
>   }
> 
>   return 0;
> }
> 
> int net_udp_send(struct net_connection *con, int len)
> {
>   if (IS_ENABLED(CONFIG_NET_PICOTCP)) {
>   return pico_socket_sendto(con->sock, npriv->pkt,
>   sizeof(pkt) + datalen * sizeof(uint32_t),
>   con->ip->daddr, con->udp->uh_dport);
>   }
> 
>   con->udp->uh_ulen = htons(len + 8);
>   con->udp->uh_sum = 0;
> 
>   return net_ip_send(con, sizeof(struct udphdr) + len);
> }
> 
> The APIs between current barebox implementation and picotcp probably do
> not match exactly. Where the APIs don't match we can change the existing
> barebox API to what picotcp expects.

Yeah, picotcp uses more advanced API so we have to "pull up" existing API.

> 
> With that the remaining pieces like DHCP, netconsole and DNS would work
> without additional effort.

-- 
Best regards,
  Antony Pavlov

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 7/7] efi: write volatile EFI variables used by systemd

2015-07-17 Thread Michael Olbrich
On Thu, Jul 16, 2015 at 10:08:48PM +0200, Sascha Hauer wrote:
> On Thu, Jul 16, 2015 at 10:43:56AM +0200, Michael Olbrich wrote:
> > LoaderTimeInitUSec and LoaderTimeExecUSec are used e.g. in systemd-analyze
> > to calculate the time spent in the firmare and barebox.
> > 
> > LoaderDevicePartUUID is used to mount the EFI partition to /boot.
> > 
> > Signed-off-by: Michael Olbrich 
> > ---
> >  arch/efi/efi/efi-image.c |  5 +
> >  arch/efi/efi/efi.c   | 14 ++
> >  common/efi-guid.c|  1 +
> >  include/efi.h|  5 +
> >  4 files changed, 25 insertions(+)
> > 
> > diff --git a/arch/efi/efi/efi-image.c b/arch/efi/efi/efi-image.c
> > index f41322744bbc..89b712baab1f 100644
> > --- a/arch/efi/efi/efi-image.c
> > +++ b/arch/efi/efi/efi-image.c
> > @@ -17,6 +17,7 @@
> >   *
> >   */
> >  
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -242,6 +243,10 @@ static int do_bootm_efi(struct image_data *data)
> >boot_header->ramdisk_image);
> > printf("...\n");
> > }
> > +
> > +   efi_set_variable_usec("LoaderTimeExecUSec", &efi_systemd_vendor_guid,
> > + get_time_ns()/1000);
> > +
> > linux_efi_handover(handle, boot_header);
> >  
> > return 0;
> > diff --git a/arch/efi/efi/efi.c b/arch/efi/efi/efi.c
> > index b0e98f95b02b..a665a546be90 100644
> > --- a/arch/efi/efi/efi.c
> > +++ b/arch/efi/efi/efi.c
> > @@ -340,6 +340,7 @@ efi_status_t efi_main(efi_handle_t image, 
> > efi_system_table_t *sys_table)
> > efi_physical_addr_t mem;
> > size_t memsize;
> > efi_status_t efiret;
> > +   char *uuid;
> >  
> >  #ifdef DEBUG
> > sys_table->con_out->output_string(sys_table->con_out, L"barebox\n");
> > @@ -377,6 +378,19 @@ efi_status_t efi_main(efi_handle_t image, 
> > efi_system_table_t *sys_table)
> > mem_malloc_init((void *)mem, (void *)mem + memsize);
> >  
> > efi_clocksource_init();
> > +   efi_set_variable_usec("LoaderTimeInitUSec", &efi_systemd_vendor_guid,
> > + get_time_ns()/1000);
> > +
> > +   uuid = device_path_to_partuuid(device_path_from_handle(
> > +  efi_loaded_image->device_handle));
> > +   if (uuid) {
> > +   wchar_t *uuid16 = strdup_char_to_wchar(uuid);
> > +   efi_set_variable("LoaderDevicePartUUID",
> > +&efi_systemd_vendor_guid,
> > +EFI_VARIABLE_BOOTSERVICE_ACCESS |
> > +EFI_VARIABLE_RUNTIME_ACCESS,
> > +uuid16, (strlen(uuid)+1) * sizeof(wchar_t));
> > +   }
> 
> Shouldn't you free uuid here?

Yes, and uuid16.

Hmmm, what's the policy for OOM checks for string functions? None of the
existing calls of strdup_char_to_wchar() check for NULL. And I didn't find
any checks for asprintf() either.

Michael

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox