From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from arcturus.kleine-koenig.org ([78.47.169.190]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aMhTD-0002IE-PL for barebox@lists.infradead.org; Fri, 22 Jan 2016 19:34:08 +0000 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Date: Fri, 22 Jan 2016 20:33:40 +0100 Message-Id: <1453491220-25044-1-git-send-email-uwe@kleine-koenig.org> MIME-Version: 1.0 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 Sender: "barebox" Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: [PATCH v3] kwboot: do a filetype check before sending the image To: barebox@lists.infradead.org Cc: Trent Piepho U2lnbmVkLW9mZi1ieTogVXdlIEtsZWluZS1Lw7ZuaWcgPHV3ZUBrbGVpbmUta29lbmlnLm9yZz4K LS0tCkNoYW5nZXMgc2luY2UgKGltcGxpY2l0KSB2MSwgc2VudCB3aXRoCk1lc3NhZ2UtSWQ6IDE0 NTMyNzYwMTAtNDY2OS0xLWdpdC1zZW5kLWVtYWlsLXV3ZUBrbGVpbmUta29lbmlnLm9yZzoKCi0g d2hpdGVzcGFjZSBmaXgKLSBlcnJvciBvdXQgaWYgYSBwcm9ibGVtIGlzIGRldGVjdGVkCi0gYWRk IGEgY29tbWl0IGxvZwoKQ2hhbmdlcyBzaW5jZSB2Miwgc2VudCB3aXRoCk1lc3NhZ2UtSWQ6IDE0 NTMyNzc3MDEtMTAzNjctMS1naXQtc2VuZC1lbWFpbC11d2VAa2xlaW5lLWtvZW5pZy5vcmc6Cgot IGFkZCAtZiB0byBub3QgcXVpdCBvbiBmYWlsZWQgdGVzdAotIGFkZCBjb25zdCB0byBpbWcgcGFy YW1ldGVyCi0gY2hlY2sgaW1hZ2UgbGVuZ3RoIGZpcnN0Ci0gd3JpdGUg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