From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hacfT-0006pb-0V for barebox@lists.infradead.org; Tue, 11 Jun 2019 09:02:13 +0000 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Date: Tue, 11 Jun 2019 11:02:02 +0200 Message-Id: <20190611090204.5752-2-u.kleine-koenig@pengutronix.de> In-Reply-To: <20190611090204.5752-1-u.kleine-koenig@pengutronix.de> References: <20190611090204.5752-1-u.kleine-koenig@pengutronix.de> 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 2/4] mvebuimg: new tool to create kwb version1 boot images To: barebox@lists.infradead.org VGhlIHB1cnBvc2UgaXMgdGhlIHNhbWUgYXMga3diaW1hZ2UsIGJ1dCB0aGUgY29kZSBpcyBzYW5l ciAoaW4gbXkgZXllcwphdCBsZWFzdCkuIEN1cnJlbnRseSBpdCBvbmx5IHN1cHBvcnRzIGNyZWF0 aW5nIHYxIGltYWdlcywgYnV0IGNhbiBiZQplYXNpbHkgZXhwYW5kZWQgdG8gc3VwcG9ydCB2MCBh bmQgZXh0cmFjdGlvbiwgdG9vLiBUaGUgbWFpbiBhZHZhbnRhZ2UgaXMKdGhhdCB0aGUgZmlsZSBu YW1lIG9mIHRoZSBiaW5hcnkgaGVhZGVycyBpcyBwYXNzZWQgdmlhIGNtZGxpbmUgYW5kIHNvCnRo ZSBiYXJlYm94IGJ1aWxkIHN5c3RlbSBjYW4ga25vdyBhYm91dCB0aGVtIHdpdGhvdXQgc3BlY2lm eWluZyB0aGVtCnR3aWNlLgoKQWRkaXRpb25hbGx5IGl0IHN1cHBvcnRz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SAwOworCisJd2hpbGUgKGNv dW50X3dyaXR0ZW4gPCBjb3VudCkgeworCQlpZiAoaGVhZCA9PSB0YWlsKSB7CisJCQloZWFkID0g MDsKKwkJCXRhaWwgPSAwOworCQl9CisKKwkJaWYgKHRhaWwgPCBzaXplb2YoYnVmKSAmJiBjb3Vu dF9yZWFkIDwgY291bnQpIHsKKwkJCXJldCA9IHJlYWQoaW5mZCwgYnVmICsgdGFpbCwKKwkJCQkg ICBtaW4oY291bnQsIHNpemVvZihidWYpIC0gdGFpbCkpOworCQkJaWYgKHJldCA8IDApIHsKKwkJ CQlwcl9lcnIoInJlYWQgZXJyb3JcbiIpOworCQkJCXJldHVybiByZXQ7CisJCQl9CisKKwkJCWlm IChyZXQgPT0gMCkgeworCQkJCXByX2VycigiaGl0IEVPRlxuIik7CisJCQkJcmV0dXJuIC1FSU5W QUw7CisJCQl9CisKKwkJCWlmIChjc3VtbSkKKwkJCQljc3VtbS0+dXBkYXRlKGNzdW1tLCBidWYg KyB0YWlsLCByZXQpOworCisJCQl0YWlsICs9IHJldDsKKwkJCWNvdW50X3JlYWQgKz0gcmV0Owor CQl9CisKKwkJaWYgKGhlYWQgPCB0YWlsKSB7CisJCQlyZXQgPSB3cml0ZShvdXRmZCwgYnVmICsg aGVhZCwgdGFpbCAtIGhlYWQpOworCQkJaWYgKHJldCA8IDApCisJCQkJcmV0dXJuIHJldDsKKwor CQkJaGVhZCArPSByZXQ7CisJCQljb3VudF93cml0dGVuICs9IHJldDsKKwkJfQorCX0KKworCXJl dHVybiAwOworfQorCitzdGF0aWMgaW50IG12ZWJ1aW1nX3YxX3dyaXRlX2JpbmhkcihpbnQgZmQs IHNpemVfdCAqb2Zmc2V0LAorCQkJCSAgICBjb25zdCBjaGFyICpmaWxlbmFtZSwKKwkJCQkgICAg c3RydWN0IG12ZWJ1aW1nX2NoZWNrc3VtX21ldGhvZDggKnN1bW0sCisJCQkJICAgIGludCBpc19s YXN0X2hlYWRlcikKK3sKKwlpbnQgYmluaGRyX2ZkOworCWNoYXIgYmluaGRyWzE2XSA9IHsgMCwg fTsKKwlzdHJ1Y3Qgc3RhdCBzOworCXVpbnQzMl90IGhkcnNpemU7CisJaW50IHJldDsKKwlvZmZf dCByZXRfbHNlZWs7CisJY2hhciB0cmFpbGVyWzRdID0geyAwLCB9OworCisJYmluaGRyWzBdID0g MHgyOworCisJYmluaGRyX2ZkID0gb3BlbihmaWxlbmFtZSwgT19SRE9OTFkpOworCWlmIChiaW5o ZHJfZmQgPCAwKSB7CisJCXByX2VycigiRmFpbGVkIHRvIG9wZW4gYmluaGRyIHNvdXJjZSBcIiVz XCIgKCVzKVxuIiwKKwkJICAgICAgIGZpbGVuYW1lLCBzdHJlcnJvcihlcnJubykpOworCQlyZXR1 cm4gLWVycm5vOworCX0KKworCXJldCA9IGZzdGF0KGJpbmhkcl9mZCwgJnMpOworCWlmIChyZXQg PCAwKSB7CisJCXByX2VycigiRmFpbGVkIHRvIHN0YXQgYmluaGRyIHNvdXJjZSBcIiVzXCIgKCVz KVxuIiwKKwkJICAgICAgIGZpbGVuYW1lLCBzdHJlcnJvcihlcnJubykpOworCQlyZXR1cm4gLWVy cm5vOworCX0KKworCWlmIChBTElHTl9TVVAocy5zdF9zaXplLCA0KSA+IDB4ZmZmZmZmIC0gMHgx NCkgeworCQlwcl9lcnIoImJpbmhkciBcIiVzXCIgdG9vIGJpZ1xuIiwgZmlsZW5hbWUpOworCQly ZXR1cm4gLUVJTlZBTDsKKwl9CisKKwloZHJzaXplID0gLyogbGVuIG9mIGhkcidzIGhlYWRlciAq LyAweDEwICsKKwkJLyogYWN0dWFsIGltYWdlICovIEFMSUdOX1NVUChzLnN0X3NpemUsIDQpICsK KwkJLyogdHJhaWxlciB3b3JkICovIDQ7CisKKwliaW5oZHJbMV0gPSBoZHJzaXplID4+IDE2Owor CWJpbmhkclsyXSA9IGhkcnNpemU7CisJYmluaGRyWzNdID0gaGRyc2l6ZSA+PiA4OworCisJLyog cGFyYW1ldGVycyB0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CQkJCXJldHVybiBF WElUX0ZBSUxVUkU7CisJCQl9CisJCQlicmVhazsKKworCQljYXNlICdiJzoKKwkJCSsrZXh0ZW5z aW9uaGVhZGVyczsKKwkJCWJyZWFrOworCisJCWNhc2UgJ0InOgorCQkJZXJybm8gPSAwOworCQkJ bCA9IHN0cnRvbChvcHRhcmcsICZlbmRwdHIsIDApOworCQkJaWYgKGVycm5vIHx8ICgqZW5kcHRy ICE9ICdcMCcgJiYgKmVuZHB0ciAhPSAnOicpIHx8CisJCQkgICAgKGwgIT0gMCAmJiAobCA8IDB4 MTAwMDAgfHwgbCA+IDB4ZmYwMDAwIHx8CisJCQkJCSFpc19wb3dlcl9vZl90d28obCkpKSkgewor CQkJCXByX2VycigiSW52YWxpZCBOQU5EIGJsb2NrIHNpemVcbiIpOworCQkJCXJldHVybiBFWElU X0ZBSUxVUkU7CisJCQl9CisJCQluYW5kX2Jsa3N6ID0gbCA+PiAxNjsKKworCQkJaWYgKCplbmRw dHIgIT0gJzonKQorCQkJCWJyZWFrOworCisJCQlpZiAoKCooZW5kcHRyICsgMSkgPT0gJzAnIHx8 ICooZW5kcHRyICsgMSkgPT0gJzEnKSAmJgorCQkJICAgICooZW5kcHRyICsgMikgPT0gJ1wwJykg eworCQkJCW5hbmRfYmJsb2MgPSAqKGVuZHB0ciArIDEpIC0gJzAnOworCQkJfSBlbHNlIHsKKwkJ CQlwcl9lcnIoIkludmFsaWQgTkFORCBiYWQgYmxvY2sgbG9jYXRpb25cbiIpOworCQkJCXJldHVy biBFWElUX0ZBSUxVUkU7CisJCQl9CisKKwkJCWJyZWFrOworCisJCWNhc2UgJ0QnOgorCQkJZGVi dWcgPSAxOworCQkJYnJlYWs7CisKKwkJY2FzZSAnZCc6CisJCQllcnJubyA9IDA7CisJCQlkZXN0 YWRkciA9IHN0cnRvbChvcHRhcmcsICZlbmRwdHIsIDApOworCQkJaWYgKGVycm5vIHx8ICplbmRw dHIgIT0gJ1wwJyB8fAorCQkJICAgIGRlc3R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