Re: [OpenWrt-Devel] [PATCH] Let MTD support skipping bad chunks

2013-08-12 Thread Rafał Miłecki
2013/8/12 Joe XUE lg...@hotmail.com:
 NAND flash has very high possibility to have bad blocks.


 Some bootloaders such as u-boot support to skip bad blocks when it read
 the kernel image from NAND falsh.

 For now, the mtd just exits when it meets the bad block. That means even

 there is one bad block in NAND flash, then we can't use mtd to write
 image to it.

 Change to let mtd skip bad blocks when it is writing the image to NAND
 flash.

Can you comment on nandwrite vs. mtd -w plans?

-- 
Rafał
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [Patch][packages] umurmur: update to 0.2.13

2013-08-12 Thread Dirk Neukirchen
uMurmur 0.2.13 update - requested by forum thread: 
https://forum.openwrt.org/viewtopic.php?id=21553


- prev. uMurmur 0.2.11 integrated PolarSSL support so that patches 
shouldn't be necessary

- git diff from packages feed

on ar71xx
size .2.10 openssl: 33690
size .2.13 openssl: 34797
size .2.10 polarssl: 32389
size .2.13 polarssl: 33301

Signed-off-by: Dirk Neukirchen dirkneukirc...@web.de

diff --git a/net/umurmur/Makefile b/net/umurmur/Makefile
index 8c82e6d..333fa2d 100644
--- a/net/umurmur/Makefile
+++ b/net/umurmur/Makefile
@@ -7,12 +7,12 @@
 include $(TOPDIR)/rules.mk

 PKG_NAME:=umurmur
-PKG_VERSION:=0.2.10
+PKG_VERSION:=0.2.13
 PKG_RELEASE:=1

 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=http://umurmur.googlecode.com/files
-PKG_MD5SUM:=4d71a699bddce3df0996b5dd0a279b47
+PKG_SHA1SUM:=c9345b67213f52688fef2113132c62d2edbf4bea

 
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(BUILD_VARIANT)/$(PKG_NAME)-$(PKG_VERSION)

diff --git a/net/umurmur/patches/100-polarssl_backport.patch 
b/net/umurmur/patches/100-polarssl_backport.patch

deleted file mode 100644
index 1c28ab3..000
--- a/net/umurmur/patches/100-polarssl_backport.patch
+++ /dev/null
@@ -1,74 +0,0 @@
 a/src/ssl.c
-+++ b/src/ssl.c
-@@ -46,20 +46,23 @@
- #include polarssl/ssl.h
- #include polarssl/net.h
-
-+#ifdef POLARSSL_API_V1_2
-+int ciphers[] =
-+{
-+TLS_DHE_RSA_WITH_AES_256_CBC_SHA,
-+TLS_RSA_WITH_AES_256_CBC_SHA,
-+TLS_RSA_WITH_AES_128_CBC_SHA,
-+0
-+};
-+#else
- int ciphers[] =
- {
- SSL_EDH_RSA_AES_256_SHA,
--SSL_EDH_RSA_CAMELLIA_256_SHA,
--SSL_EDH_RSA_DES_168_SHA,
- SSL_RSA_AES_256_SHA,
--SSL_RSA_CAMELLIA_256_SHA,
- SSL_RSA_AES_128_SHA,
--SSL_RSA_CAMELLIA_128_SHA,
--SSL_RSA_DES_168_SHA,
--SSL_RSA_RC4_128_SHA,
--SSL_RSA_RC4_128_MD5,
- 0
- };
-+#endif
- static x509_cert certificate;
- static rsa_context key;
- bool_t builtInTestCertificate;
-@@ -170,8 +173,13 @@ void SSLi_deinit(void)
- /* Create SHA1 of last certificate in the peer's chain. */
- bool_t SSLi_getSHA1Hash(SSL_handle_t *ssl, uint8_t *hash)
- {
--x509_cert *cert = ssl-peer_cert;
--if (!ssl-peer_cert) {
-+x509_cert *cert;
-+#ifdef POLARSSL_API_V1_2
-+cert = ssl_get_peer_cert(ssl);
-+#else
-+cert = ssl-peer_cert;
-+#endif
-+if (!cert) {
- return false;
- }
- sha1(cert-raw.p, cert-raw.len, hash);
-@@ -207,7 +215,12 @@ SSL_handle_t *SSLi_newconnection(int *fd
- #else
- ssl_set_ciphers(ssl, ciphers);
- #endif
-+
-+#ifdef POLARSSL_API_V1_2
-+ssl_set_session(ssl, ssn);
-+#else
- ssl_set_session(ssl, 0, 0, ssn);
-+#endif
-
- ssl_set_ca_chain(ssl, certificate, NULL, NULL);
- ssl_set_own_cert(ssl, certificate, key);
 a/src/ssl.h
-+++ b/src/ssl.h
-@@ -68,6 +68,9 @@
-  } \
- } while (0)
- #endif
-+#if (POLARSSL_VERSION_MINOR = 2)
-+#define POLARSSL_API_V1_2
-+#endif
- #endif
- #endif
-
diff --git a/net/umurmur/patches/110-reduced_polarssl_support.patch 
b/net/umurmur/patches/110-reduced_polarssl_support.patch

deleted file mode 100644
index 6f7de25..000
--- a/net/umurmur/patches/110-reduced_polarssl_support.patch
+++ /dev/null
@@ -1,141 +0,0 @@
 a/src/ssl.c
-+++ b/src/ssl.c
-@@ -30,6 +30,7 @@
- */
- #include string.h
- #include stdlib.h
-+#include fcntl.h
-
- #include conf.h
- #include log.h
-@@ -66,8 +67,7 @@ int ciphers[] =
- static x509_cert certificate;
- static rsa_context key;
- bool_t builtInTestCertificate;
--
--havege_state hs; /* exported to crypt.c */
-+static int urandom_fd;
-
- /* DH prime */
- char *my_dhm_P =
-@@ -83,9 +83,13 @@ char *my_dhm_G = 4;
- static void initTestCert()
- {
- int rc;
-+#ifdef POLARSSL_CERTS_C
- builtInTestCertificate = true;
- rc = x509parse_crt(certificate, (unsigned char *)test_srv_crt,
-strlen(test_srv_crt));
-+#else
-+rc = -1;
-+#endif
- if (rc != 0)
- Log_fatal(Could not parse built-in test certificate);
- }
-@@ -93,9 +97,12 @@ static void initTestCert()
- static void initTestKey()
- {
- int rc;
--
-+#ifdef POLARSSL_CERTS_C
- rc = x509parse_key(key, (unsigned char *)test_srv_key,
-strlen(test_srv_key), NULL, 0);
-+#else
-+rc = -1;
-+#endif
- if (rc != 0)
- Log_fatal(Could not parse built-in test RSA key);
- }
-@@ -135,6 +142,19 @@ static void initKey()
- Log_fatal(Could not read RSA key file %s, keyfile);
- }
-
-+int urandom_bytes(void *ctx, unsigned char *dest, size_t len)
-+{
-+int cur;
-+
-+while (len) {
-+cur = read(urandom_fd, dest, len);
-+if (cur  0)
-+continue;
-+
-+len -= cur;
-+}
-+}
-+
- #define DEBUG_LEVEL 0
- static void pssl_debug(void *ctx, int level, const char *str)
- {
-@@ -154,8 +174,11 @@ void SSLi_init(void)
- }
- else
- initKey();
--havege_init(hs);
--
-+
-+urandom_fd = open(/dev/urandom, O_RDONLY);
-+if (urandom_fd  0)
-+Log_fatal(Cannot open 

Re: [OpenWrt-Devel] [PATCH] Let MTD support skipping bad chunks

2013-08-12 Thread Joe XUE
NAND flash has very high possibility to has bad blocks.

Some bootloaders such as u-boot support to skip bad blocks when it read
the kernel image from NAND falsh.

For now, the mtd just exits when it meet the bad block. That means even
there is one bad block in NAND flash, then we can't use mtd to write
image to it.

Change to let mtd skip bad blocks when it is writing the image to NAND flash.

    modified:   package/system/mtd/src/mtd.c
---
 package/system/mtd/src/mtd.c | 21 -
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/package/system/mtd/src/mtd.c b/package/system/mtd/src/mtd.c
index a660486..675f26c 100644
--- a/package/system/mtd/src/mtd.c
+++ b/package/system/mtd/src/mtd.c
@@ -55,6 +55,7 @@ int quiet;
 int no_erase;
 int mtdsize = 0;
 int erasesize = 0;
+int mtdtype = 0;
 
 int mtd_open(const char *mtd, bool block)
 {
@@ -100,6 +101,7 @@ int mtd_check_open(const char *mtd)
 }
 mtdsize = mtdInfo.size;
 erasesize = mtdInfo.erasesize;
+    mtdtype = mtdInfo.type;
 
 return fd;
 }
@@ -425,13 +427,22 @@ resume:
                     fprintf(stderr, \b\b\b   \n);
                     goto resume;
                 } else {
-                        fprintf(stderr, Failed to erase block\n);
-                        exit(1);
+                        /* skip this bad chunk */
+                        if (mtdtype == MTD_NANDFLASH) {
+                            lseek(fd, erasesize, SEEK_CUR);
+                            e += erasesize;
+                            w += erasesize;
+                            fprintf(stderr, Skip a bad chunk\n);
+                        } else {
+                            fprintf(stderr, Failed to erase block\n);
+                            exit(1);
+                        }
                 }
-                }
+                } else {
 
-                /* erase the chunk */
-                e += erasesize;
+                    /* erase the chunk */
+                    e += erasesize;
+                }
         }
     }
 
-- 
1.8.1.2

 Date: Mon, 12 Aug 2013 07:57:02 +0200
 From: n...@openwrt.org
 To: lg...@hotmail.com
 CC: openwrt-devel@lists.openwrt.org
 Subject: Re: [PATCH] Let MTD support skipping bad chunks

 On 2013-08-12 1:54 AM, Joe XUE wrote:
 NAND flash has very high possibility to have bad blocks.

 Some bootloaders such as u-boot support to skip bad blocks when it read
 the kernel image from NAND falsh.

 For now, the mtd just exits when it meets the bad block. That means even
 there is one bad block in NAND flash, then we can't use mtd to write
 image to it.

 Change to let mtd skip bad blocks when it is writing the image to NAND
 flash.

 modified: package/system/mtd/src/mtd.c
 The email does not preserve whitespace, so the patch doesn't apply
 (probably because it was sent as HTML email). Please fix your email
 client settings and resend (or use git-send-email).

 - Felix 
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH] Add events support to ubus-lua bindings

2013-08-12 Thread Jeff Remy
This patch add Lua bindings for ubus events (I don't know why they
were not added, can be quite convenient).
It mostly mimick the style of the existing code.

With it and the ubox Lua bindings, you can now send ubus events
through Lua or listen for events (you can register for multiple events
at the same time).

Signed-off-by: Jeff Remy jeff.r...@gmail.com
---
 lua/ubus.c | 101 +
 1 file changed, 101 insertions(+)

diff --git a/lua/ubus.c b/lua/ubus.c
index 77624d7..16dc348 100644
--- a/lua/ubus.c
+++ b/lua/ubus.c
@@ -17,6 +17,7 @@
 #include libubox/blobmsg.h
 #include libubox/blobmsg_json.h
 #include lauxlib.h
+#include lua.h


 #define MODNAMEubus
@@ -35,6 +36,11 @@ struct ubus_lua_object {
  int r;
 };

+struct ubus_lua_event {
+ struct ubus_event_handler e;
+ int r;
+};
+
 static int
 ubus_lua_parse_blob(lua_State *L, struct blob_attr *attr, bool table);

@@ -443,6 +449,7 @@ static struct ubus_object*
ubus_lua_load_object(lua_State *L)
  return obj-o;
 }

+
 static int ubus_lua_add(lua_State *L)
 {
  struct ubus_lua_connection *c = luaL_checkudata(L, 1, METANAME);
@@ -572,6 +579,95 @@ ubus_lua__gc(lua_State *L)
  return 0;
 }

+static void
+ubus_event_handler(struct ubus_context *ctx, struct ubus_event_handler *ev,
+  const char *type, struct blob_attr *msg)
+{
+ struct ubus_lua_event *listener = container_of(ev, struct ubus_lua_event, e);
+
+ lua_getglobal(state, __ubus_cb_event);
+ lua_rawgeti(state, -1, listener-r);
+
+ if (lua_isfunction(state, -1)) {
+ ubus_lua_parse_blob_array(state, blob_data(msg), blob_len(msg), true);
+ lua_call(state, 1, 0);
+ }
+ return;
+}
+
+static struct ubus_event_handler*
+ubus_lua_load_event(lua_State *L) {
+ struct ubus_lua_event* event = NULL;
+
+ event = malloc(sizeof(struct ubus_lua_event));
+ memset(event, 0, sizeof(struct ubus_lua_event));
+ event-e.cb = ubus_event_handler;
+
+ /* update the he callback lookup table */
+ lua_getglobal(L, __ubus_cb_event);
+ lua_pushvalue(L, -2);
+ event-r = luaL_ref(L, -2);
+ lua_setfield(L, -1, lua_tostring(L, -3));
+
+ return event-e;
+}
+
+static int
+ubus_lua_listen(lua_State *L) {
+ // Registers event listener(s).
+ // Expected format is conn:listen(eventMap:table)
+ // Event map is an associative table where the key name is the event
(* possible for everything) and the value is the cb function
+
+ // Self is the connection itself
+ struct ubus_lua_connection *c = luaL_checkudata(L, 1, METANAME);
+
+ /* verify top level object */
+ luaL_checktype(L, 2, LUA_TTABLE);
+
+ /* scan each object */
+ lua_pushnil(L);
+ while (lua_next(L, -2) != 0) {
+ struct ubus_event_handler *listener;
+
+ /* check if the key is a string and the value is a method */
+ if ((lua_type(L, -2) == LUA_TSTRING)  (lua_type(L, -1) == LUA_TFUNCTION)) {
+ listener = ubus_lua_load_event(L);
+ if(listener != NULL) {
+ ubus_register_event_handler(c-ctx, listener, lua_tostring(L, -2));
+ }
+ }
+ lua_pop(L, 1);
+ }
+ return 0;
+}
+
+static int
+ubus_lua_send(lua_State *L) {
+ // Send an event conn:send(eventName:string, event:table)
+ // Self is the connection itself
+ struct ubus_lua_connection *c = luaL_checkudata(L, 1, METANAME);
+ // Event name
+ const char *event = luaL_checkstring(L, 2);
+ if(*event == 0) {
+ return luaL_argerror(L, 2, no event name);
+ }
+ // Event content convert to ubus form
+ luaL_checktype(L, 3, LUA_TTABLE);
+ blob_buf_init(c-buf, 0);
+
+ if (!ubus_lua_format_blob_array(L, c-buf, true))
+ {
+ lua_pushnil(L);
+ lua_pushinteger(L, UBUS_STATUS_INVALID_ARGUMENT);
+ return 2;
+ }
+
+ // Send the event
+ ubus_send_event(c-ctx, event, c-buf.head);
+
+ return 0;
+}
+
 static const luaL_Reg ubus[] = {
  { connect, ubus_lua_connect },
  { objects, ubus_lua_objects },
@@ -581,6 +677,8 @@ static const luaL_Reg ubus[] = {
  { call, ubus_lua_call },
  { close, ubus_lua__gc },
  { __gc, ubus_lua__gc },
+ { listen, ubus_lua_listen },
+ { send, ubus_lua_send },
  { NULL, NULL },
 };

@@ -628,6 +726,9 @@ luaopen_ubus(lua_State *L)
  /* create the callback table */
  lua_createtable(L, 1, 0);
  lua_setglobal(L, __ubus_cb);
+ /* create the callback table */
+ lua_createtable(L, 1, 0);
+ lua_setglobal(L, __ubus_cb_event);

  return 0;
 }
-- 
1.8.1.2
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] Kernel panic Process batadv.sh - Fatal

2013-08-12 Thread Gui Iribarren

On 08/12/2013 09:43 PM, cmsv wrote:

OpenWrt version: Attitude Adjustment (r37747)

Recently there was someone (Lucaspost) on #batman with a problem caused
by mixing the latest AA and Batman-adv 2013.3.0 and while i can't be
sure the problem is exactly this one; here goes my testing with a D-link
615C1



maybe you're mixing module and kernel versions?

try to make dirclean and rebuild

batadv.sh only does this

echo $mesh  /sys/class/net/$iface/batman_adv/mesh_iface

where $iface is something like wlan0 and $mesh is bat0

HTH,

Gui
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel