mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Antony Pavlov <antonynpavlov@gmail.com>
To: barebox@lists.infradead.org
Subject: [PATCH v2 10/11] ARM: add Canon A1100 DISKBOOT.BIN image generation stuff
Date: Tue, 29 Jul 2014 01:15:29 +0400	[thread overview]
Message-ID: <1406582130-10116-11-git-send-email-antonynpavlov@gmail.com> (raw)
In-Reply-To: <1406582130-10116-1-git-send-email-antonynpavlov@gmail.com>

This commit makes it possible to run barebox on real
Canon A1100 camera.

The 'dancingbits' utility imported from CHDK software;
see http://chdk.wikia.com/ for details.

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 .gitignore            |  1 +
 Makefile              |  2 +-
 arch/arm/Makefile     |  8 +++++-
 scripts/.gitignore    |  1 +
 scripts/Makefile      |  1 +
 scripts/dancingbits.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++
 scripts/dancingbits.h | 20 +++++++++++++
 scripts/mkdiskboot    | 13 +++++++++
 8 files changed, 121 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore
index a62e08c..39e10b1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -48,6 +48,7 @@ barebox.kwb
 barebox.kwbuart
 barebox.efi
 barebox.canon-a1100.bin
+DISKBOOT-A1100.BIN
 barebox-flash-image
 System.map
 Module.symvers
diff --git a/Makefile b/Makefile
index 1ec0bfd..932bd4a 100644
--- a/Makefile
+++ b/Makefile
@@ -994,7 +994,7 @@ CLEAN_FILES +=	barebox System.map include/generated/barebox_default_env.h \
 		scripts/bareboxenv-target barebox-flash-image \
 		barebox.srec barebox.s5p barebox.ubl barebox.zynq \
 		barebox.uimage barebox.spi barebox.kwb barebox.kwbuart \
-		barebox.efi barebox.canon-a1100.bin
+		barebox.efi barebox.canon-a1100.bin DISKBOOT-A1100.BIN
 
 # Directories & files removed with 'make mrproper'
 MRPROPER_DIRS  += include/config include2 usr/include
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 337aef1..6960397 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -191,8 +191,14 @@ quiet_cmd_canon_a1100_image = DD      $@
 barebox.canon-a1100.bin: $(KBUILD_BINARY) FORCE
 	$(call if_changed,canon_a1100_image)
 
+quiet_cmd_canon_a1100_diskboot_image = DB      $@
+      cmd_canon_a1100_diskboot_image = scripts/mkdiskboot $< $@ || \
+	echo "WARNING: Couldn't create Canon A1100 DISKBOOT image due to previous errors."
+DISKBOOT-A1100.BIN: $(KBUILD_BINARY) FORCE
+	$(call if_changed,canon_a1100_diskboot_image)
+
 ifeq ($(CONFIG_MACH_CANON_A1100),y)
-KBUILD_IMAGE := barebox.canon-a1100.bin
+KBUILD_IMAGE := barebox.canon-a1100.bin DISKBOOT-A1100.BIN
 endif
 
 KWBIMAGE_OPTS = \
diff --git a/scripts/.gitignore b/scripts/.gitignore
index fddc04b..09d0611 100644
--- a/scripts/.gitignore
+++ b/scripts/.gitignore
@@ -1,5 +1,6 @@
 bareboxenv
 bin2c
+dancingbits
 fix_size
 gen_netx_image
 kallsyms
diff --git a/scripts/Makefile b/scripts/Makefile
index 9c77680..3d92228 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -11,6 +11,7 @@ hostprogs-y                      += bareboxenv
 hostprogs-y                      += bareboxcrc32
 hostprogs-y                      += kernel-install
 hostprogs-$(CONFIG_KALLSYMS)     += kallsyms
+hostprogs-$(CONFIG_ARCH_DIGIC)   += dancingbits
 hostprogs-$(CONFIG_ARCH_MVEBU)   += kwbimage kwboot
 hostprogs-$(CONFIG_ARCH_NETX)    += gen_netx_image
 hostprogs-$(CONFIG_ARCH_OMAP)    += omap_signGP mk-am3xxx-spi-image
diff --git a/scripts/dancingbits.c b/scripts/dancingbits.c
new file mode 100644
index 0000000..7d3c2b6
--- /dev/null
+++ b/scripts/dancingbits.c
@@ -0,0 +1,77 @@
+/*
+ * make an image bootable for latest cams
+ * (c) 2008 chr
+ *
+ * GPL v3+
+ *
+ * Why make things easy if complex sells better?
+ */
+#include <stdio.h>
+#include <stddef.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include "dancingbits.h"
+
+unsigned char dance(unsigned char allbest, int fudgey);
+
+#define GHOST 0x400
+#define BARNEY 0x00
+
+int main(int whim, char **reyalp) {
+	FILE *jeff666, *jucifer;
+	unsigned char *ewavr;
+	int oldgit;
+
+	if (whim != 4) {
+		printf("usage: <in file> <out file> <version>\n");
+		exit(1);
+	}
+
+	jeff666  = fopen(reyalp[1], "rb");
+	if (jeff666 == NULL) {
+		printf("Error open %s: %s\n", reyalp[1], strerror(errno));
+		exit(1);
+	}
+	jucifer = fopen(reyalp[2], "w+b");
+	if (jucifer == NULL) {
+		printf("Error open %s: %s\n", reyalp[2], strerror(errno));
+		exit(1);
+	}
+	oldgit = atoi(reyalp[3]);
+	if (oldgit < 1 || oldgit > VITALY) {
+		printf("Error version must be between 1 and %d, not %s\n", VITALY,reyalp[3]);
+		exit(1);
+	}
+	oldgit-=1;
+
+	fputc(BARNEY, jucifer);
+	ewavr = malloc(GHOST);
+
+	int grand, hacki = 0;
+	int phox = fread(ewavr, 1, GHOST, jeff666);
+	while (phox > 0) {
+		for (grand=0; grand<phox; grand+=8) {
+			unsigned char fe50[8];
+			for (hacki=0; hacki<8; hacki++) {
+				// fe50[hacki] = dance(ewavr[grand + _chr_[hacki]], grand+hacki);
+				fe50[_chr_[oldgit][hacki]] = dance(ewavr[grand + hacki], grand+hacki);
+			}
+			fwrite(fe50, 1, 8, jucifer);
+		}
+		phox = fread(ewavr, 1, GHOST, jeff666);
+	}
+	fclose(jeff666);
+	fclose(jucifer);
+	free(ewavr);
+	exit(0);
+}
+
+unsigned char dance(unsigned char allbest, int fudgey) {
+	if ((fudgey % 3) !=0)
+		return allbest ^ 0xff;
+	if ((fudgey & 1) == 0)
+		return allbest ^ 0xa0;
+	return (allbest >> 4) | (allbest << 4);
+}
diff --git a/scripts/dancingbits.h b/scripts/dancingbits.h
new file mode 100644
index 0000000..787f85f
--- /dev/null
+++ b/scripts/dancingbits.h
@@ -0,0 +1,20 @@
+
+// Dancing bits data for encoding diskboot.bin file
+// Used by dancingbits.c and finsig_dryos.c
+
+#define VITALY 12
+unsigned char _chr_[VITALY][8] = {
+									{ 4,6,1,0,7,2,5,3 }, // original flavor
+									{ 5,3,6,1,2,7,0,4 }, // nacho cheese sx200is, ixus100_sd780, ixu95_sd1200, a1100, d10
+									{ 2,5,0,4,6,1,3,7 }, // mesquite bbq ixus200_sd980, sx20 (dryos r39)
+									{ 4,7,3,2,6,5,0,1 }, // cool ranch a3100 (dryos r43)
+									{ 3,2,7,5,1,4,6,0 }, // cajun chicken s95, g12, sx30 (dryos r45)
+									{ 0,4,2,7,3,6,5,1 }, // spicy wasabi sx220, sx230, ixus310 (dryos r47)
+									{ 7,1,5,3,0,6,4,2 }, // sea salt & vinegar sx40hs, sx150is (dryos r49)
+									{ 6,3,1,0,5,7,2,4 }, // spicy habenaro sx260hs (dryos r50)
+									{ 1,0,4,6,2,3,7,5 }, // tapatio hot sauce sx160is (dryos r51)
+									{ 3,6,7,2,4,5,1,0 }, // blazin' jalapeno a1400 (dryos r52)
+									{ 0,2,6,3,1,4,7,5 }, // guacamole sx510hs (dryos r52)
+									{ 2,7,0,6,3,1,5,4 }, // (dryos r54)
+								};
+
diff --git a/scripts/mkdiskboot b/scripts/mkdiskboot
new file mode 100755
index 0000000..d7d62d2
--- /dev/null
+++ b/scripts/mkdiskboot
@@ -0,0 +1,13 @@
+#!/bin/bash -e
+
+IFILE=$1
+OFILE=$2
+
+TFILE=$(mktemp)
+
+dd if=/dev/zero of=$TFILE bs=1k count=128 2>/dev/null
+dd if=$IFILE of=$TFILE conv=notrunc 2>/dev/null
+
+scripts/dancingbits $TFILE $OFILE 2
+
+rm -f $TFILE
-- 
2.0.1


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

  parent reply	other threads:[~2014-07-28 21:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-28 21:15 [PATCH v2 00/11] ARM: add support for Canon DIGIC chips and Canon PowerShot A1100 IS Antony Pavlov
2014-07-28 21:15 ` [PATCH v2 01/11] ARM: add ARM946E-S CPU type Antony Pavlov
2014-07-28 21:15 ` [PATCH v2 02/11] ARM: add very initial support for Canon DIGIC chips Antony Pavlov
2014-07-28 21:15 ` [PATCH v2 03/11] clocksource: add driver for Canon DIGIC timer Antony Pavlov
2014-07-28 21:15 ` [PATCH v2 04/11] serial: add driver for Canon DIGIC UART Antony Pavlov
2014-07-28 21:15 ` [PATCH v2 05/11] gpio: add driver for Canon DIGIC Antony Pavlov
2014-07-28 21:15 ` [PATCH v2 06/11] ARM: DIGIC: add Canon PowerShot A1100 IS support Antony Pavlov
2014-07-28 21:15 ` [PATCH v2 07/11] ARM: add Canon A1100 ROM image generation Antony Pavlov
2014-07-28 21:15 ` [PATCH v2 08/11] ARM: DIGIC: add canon-a1100_defconfig Antony Pavlov
2014-07-28 21:15 ` [PATCH v2 09/11] Documentation: add QEMU Canon A1100 barebox mini-howto Antony Pavlov
2014-07-28 21:15 ` Antony Pavlov [this message]
2014-07-28 21:15 ` [PATCH v2 11/11] Documentation: add real Canon A1100 camera " Antony Pavlov
2014-07-29 13:20 ` [PATCH v2 00/11] ARM: add support for Canon DIGIC chips and Canon PowerShot A1100 IS Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1406582130-10116-11-git-send-email-antonynpavlov@gmail.com \
    --to=antonynpavlov@gmail.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox