* [PATCH 01/12] ARM zImage: do memmap if possible
2010-03-29 9:36 Patches for next merge window Sascha Hauer
@ 2010-03-29 9:36 ` Sascha Hauer
2010-03-29 18:47 ` Peter Korsgaard
2010-03-29 9:36 ` [PATCH 02/12] nand_imx: use optimized memcpy Sascha Hauer
` (10 subsequent siblings)
11 siblings, 1 reply; 22+ messages in thread
From: Sascha Hauer @ 2010-03-29 9:36 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/lib/armlinux.c | 16 ++++++++++------
1 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/arch/arm/lib/armlinux.c b/arch/arm/lib/armlinux.c
index 2415c29..ec9ad8e 100644
--- a/arch/arm/lib/armlinux.c
+++ b/arch/arm/lib/armlinux.c
@@ -241,7 +241,7 @@ static int do_bootz(struct command *cmdtp, int argc, char *argv[])
const char *commandline = getenv("bootargs");
int fd, ret;
struct zimage_header header;
- void *zimage;
+ void *zimage, *m;
if (argc != 2) {
barebox_cmd_usage(cmdtp);
@@ -263,11 +263,15 @@ static int do_bootz(struct command *cmdtp, int argc, char *argv[])
zimage = xmalloc(header.end);
memcpy(zimage, &header, sizeof(header));
-
- ret = read(fd, zimage + sizeof(header), header.end - sizeof(header));
- if (ret < header.end - sizeof(header)) {
- printf("could not read %s\n", argv[1]);
- goto err_out1;
+ m = memmap(fd, PROT_READ);
+ if (m != (void *)-1) {
+ memcpy(zimage, m, header.end);
+ } else {
+ ret = read(fd, zimage + sizeof(header), header.end - sizeof(header));
+ if (ret < header.end - sizeof(header)) {
+ printf("could not read %s\n", argv[1]);
+ goto err_out1;
+ }
}
theKernel = zimage;
--
1.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 01/12] ARM zImage: do memmap if possible
2010-03-29 9:36 ` [PATCH 01/12] ARM zImage: do memmap if possible Sascha Hauer
@ 2010-03-29 18:47 ` Peter Korsgaard
2010-03-30 9:20 ` Sascha Hauer
0 siblings, 1 reply; 22+ messages in thread
From: Peter Korsgaard @ 2010-03-29 18:47 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
>>>>> "Sascha" == Sascha Hauer <s.hauer@pengutronix.de> writes:
Hi,
Sascha> zimage = xmalloc(header.end);
Sascha> memcpy(zimage, &header, sizeof(header));
Sascha> -
Sascha> - ret = read(fd, zimage + sizeof(header), header.end - sizeof(header));
Sascha> - if (ret < header.end - sizeof(header)) {
Sascha> - printf("could not read %s\n", argv[1]);
Sascha> - goto err_out1;
Sascha> + m = memmap(fd, PROT_READ);
Sascha> + if (m != (void *)-1) {
Sascha> + memcpy(zimage, m, header.end);
Here you're rereading the header as well, instead of everything past it
like the normal case.
Does this give a significant boost? read() from something memmap'able
(like NOR) boils down to a memcpy as well, right?
Sascha> + } else {
Sascha> + ret = read(fd, zimage + sizeof(header), header.end - sizeof(header));
--
Bye, Peter Korsgaard
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 01/12] ARM zImage: do memmap if possible
2010-03-29 18:47 ` Peter Korsgaard
@ 2010-03-30 9:20 ` Sascha Hauer
2010-03-30 10:01 ` Peter Korsgaard
0 siblings, 1 reply; 22+ messages in thread
From: Sascha Hauer @ 2010-03-30 9:20 UTC (permalink / raw)
To: Peter Korsgaard; +Cc: barebox
Hi Peter,
On Mon, Mar 29, 2010 at 08:47:57PM +0200, Peter Korsgaard wrote:
> >>>>> "Sascha" == Sascha Hauer <s.hauer@pengutronix.de> writes:
>
> Hi,
>
> Sascha> zimage = xmalloc(header.end);
> Sascha> memcpy(zimage, &header, sizeof(header));
> Sascha> -
> Sascha> - ret = read(fd, zimage + sizeof(header), header.end - sizeof(header));
> Sascha> - if (ret < header.end - sizeof(header)) {
> Sascha> - printf("could not read %s\n", argv[1]);
> Sascha> - goto err_out1;
> Sascha> + m = memmap(fd, PROT_READ);
> Sascha> + if (m != (void *)-1) {
> Sascha> + memcpy(zimage, m, header.end);
>
> Here you're rereading the header as well, instead of everything past it
> like the normal case.
Yes, mostly because I was too lazy to calculate the offsets.
>
> Does this give a significant boost? read() from something memmap'able
> (like NOR) boils down to a memcpy as well, right?
Hmm, with memmap it's 149ms and with read 156ms in my case. I think this
is because with memmap it goes down to a single memcpy whereas with read
we memcpy in chunks of 4k. I implemented this out of reflex, but maybe
it's really not worth the added complexity.
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-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 01/12] ARM zImage: do memmap if possible
2010-03-30 9:20 ` Sascha Hauer
@ 2010-03-30 10:01 ` Peter Korsgaard
2010-03-30 12:18 ` Sascha Hauer
0 siblings, 1 reply; 22+ messages in thread
From: Peter Korsgaard @ 2010-03-30 10:01 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
>>>>> "Sascha" == Sascha Hauer <s.hauer@pengutronix.de> writes:
Hi,
>> Here you're rereading the header as well, instead of everything past
>> it like the normal case.
Sascha> Yes, mostly because I was too lazy to calculate the offsets.
You could just have copied it from the line above ;)
>> Does this give a significant boost? read() from something memmap'able
>> (like NOR) boils down to a memcpy as well, right?
Sascha> Hmm, with memmap it's 149ms and with read 156ms in my case. I
Sascha> think this is because with memmap it goes down to a single
Sascha> memcpy whereas with read we memcpy in chunks of 4k. I
Sascha> implemented this out of reflex, but maybe it's really not worth
Sascha> the added complexity.
I imho don't think it's worth it. One of barebox' big advantages is how
readable and clean the source code is.
--
Bye, Peter Korsgaard
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 01/12] ARM zImage: do memmap if possible
2010-03-30 10:01 ` Peter Korsgaard
@ 2010-03-30 12:18 ` Sascha Hauer
0 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2010-03-30 12:18 UTC (permalink / raw)
To: Peter Korsgaard; +Cc: barebox
On Tue, Mar 30, 2010 at 12:01:42PM +0200, Peter Korsgaard wrote:
> >>>>> "Sascha" == Sascha Hauer <s.hauer@pengutronix.de> writes:
>
> Hi,
>
> >> Here you're rereading the header as well, instead of everything past
> >> it like the normal case.
>
> Sascha> Yes, mostly because I was too lazy to calculate the offsets.
>
> You could just have copied it from the line above ;)
>
> >> Does this give a significant boost? read() from something memmap'able
> >> (like NOR) boils down to a memcpy as well, right?
>
> Sascha> Hmm, with memmap it's 149ms and with read 156ms in my case. I
> Sascha> think this is because with memmap it goes down to a single
> Sascha> memcpy whereas with read we memcpy in chunks of 4k. I
> Sascha> implemented this out of reflex, but maybe it's really not worth
> Sascha> the added complexity.
>
> I imho don't think it's worth it. One of barebox' big advantages is how
> readable and clean the source code is.
Ok, I'll drop this patch.
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-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 02/12] nand_imx: use optimized memcpy
2010-03-29 9:36 Patches for next merge window Sascha Hauer
2010-03-29 9:36 ` [PATCH 01/12] ARM zImage: do memmap if possible Sascha Hauer
@ 2010-03-29 9:36 ` Sascha Hauer
2010-03-29 9:36 ` [PATCH 03/12] nand_imx: Speed up sequential read Sascha Hauer
` (9 subsequent siblings)
11 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2010-03-29 9:36 UTC (permalink / raw)
To: barebox
The internal SRAM buffer of the i.MX NAND controller does not
allow byte accesses. We use the memcpy32 function to handle this.
If we have assembler optimized string functions we can do better
because they won't do byte accesses when source and target are word
aligned.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/nand/nand_imx.c | 19 +++++++++++++++++--
1 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/drivers/nand/nand_imx.c b/drivers/nand/nand_imx.c
index afd5637..da9b2d5 100644
--- a/drivers/nand/nand_imx.c
+++ b/drivers/nand/nand_imx.c
@@ -200,12 +200,17 @@ static struct nand_ecclayout nandv2_hw_eccoob_largepage = {
}
};
-static void __nand_boot_init memcpy32(void *trg, const void *src, int size)
+static void memcpy32(void *trg, const void *src, int size)
{
int i;
unsigned int *t = trg;
unsigned const int *s = src;
+#ifdef CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS
+ if (!((unsigned long)trg & 0x3) && !((unsigned long)src & 0x3))
+ memcpy(trg, src, size);
+ else
+#endif
for (i = 0; i < (size >> 2); i++)
*t++ = *s++;
}
@@ -1025,6 +1030,16 @@ static void __nand_boot_init nfc_addr(struct imx_nand_host *host, u32 offs)
}
}
+static void __nand_boot_init __memcpy32(void *trg, const void *src, int size)
+{
+ int i;
+ unsigned int *t = trg;
+ unsigned const int *s = src;
+
+ for (i = 0; i < (size >> 2); i++)
+ *t++ = *s++;
+}
+
void __nand_boot_init imx_nand_load_image(void *dest, int size)
{
struct imx_nand_host host;
@@ -1135,7 +1150,7 @@ void __nand_boot_init imx_nand_load_image(void *dest, int size)
continue;
}
- memcpy32(dest, host.base, pagesize);
+ __memcpy32(dest, host.base, pagesize);
dest += pagesize;
size -= pagesize;
--
1.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 03/12] nand_imx: Speed up sequential read
2010-03-29 9:36 Patches for next merge window Sascha Hauer
2010-03-29 9:36 ` [PATCH 01/12] ARM zImage: do memmap if possible Sascha Hauer
2010-03-29 9:36 ` [PATCH 02/12] nand_imx: use optimized memcpy Sascha Hauer
@ 2010-03-29 9:36 ` Sascha Hauer
2010-03-29 9:36 ` [PATCH 04/12] imx_nand: use memcpy for copying from/to buffer Sascha Hauer
` (8 subsequent siblings)
11 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2010-03-29 9:36 UTC (permalink / raw)
To: barebox
When reading a page from nand prefetch the next page afterwards to
keep the controller busy. This way we can improve sequential reading
from NAND which is the common case for barebox.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/nand/nand_imx.c | 60 ++++++++++++++++++++++++++++++++++++----------
1 files changed, 47 insertions(+), 13 deletions(-)
diff --git a/drivers/nand/nand_imx.c b/drivers/nand/nand_imx.c
index da9b2d5..5f92e2f 100644
--- a/drivers/nand/nand_imx.c
+++ b/drivers/nand/nand_imx.c
@@ -295,7 +295,7 @@ static void __nand_boot_init noinline send_addr(struct imx_nand_host *host, u16
* @param spare_only set true if only the spare area is transferred
*/
static void __nand_boot_init send_page(struct imx_nand_host *host,
- unsigned int ops)
+ unsigned int ops, int wait)
{
int bufs, i;
@@ -311,7 +311,8 @@ static void __nand_boot_init send_page(struct imx_nand_host *host,
writew(ops, host->regs + NFC_CONFIG2);
/* Wait for operation to complete */
- wait_op_done(host);
+ if (wait)
+ wait_op_done(host);
}
}
@@ -671,11 +672,17 @@ static void imx_nand_command(struct mtd_info *mtd, unsigned command,
{
struct nand_chip *nand_chip = mtd->priv;
struct imx_nand_host *host = nand_chip->priv;
+ static int cached = -1;
MTD_DEBUG(MTD_DEBUG_LEVEL3,
"imx_nand_command (cmd = 0x%x, col = 0x%x, page = 0x%x)\n",
command, column, page_addr);
+ if (cached != -1)
+ wait_op_done(host);
+ if (command != NAND_CMD_READ0)
+ cached = -1;
+
/*
* Reset command state information
*/
@@ -702,17 +709,44 @@ static void imx_nand_command(struct mtd_info *mtd, unsigned command,
command = NAND_CMD_READ0;
- send_cmd(host, command);
- mxc_do_addr_cycle(mtd, column, page_addr);
+ if (cached == page_addr) {
+ memcpy32(host->data_buf, host->main_area0, mtd->writesize);
+ copy_spare(mtd, 1);
- if (host->pagesize_2k)
- /* send read confirm command */
- send_cmd(host, NAND_CMD_READSTART);
+ send_cmd(host, command);
+ mxc_do_addr_cycle(mtd, column, page_addr + 1);
+
+ if (host->pagesize_2k)
+ /* send read confirm command */
+ send_cmd(host, NAND_CMD_READSTART);
+
+ send_page(host, NFC_OUTPUT, 0);
- send_page(host, NFC_OUTPUT);
+ cached = page_addr + 1;
+ } else {
+ host->buf_start = column;
+ send_cmd(host, command);
+ mxc_do_addr_cycle(mtd, column, page_addr);
+
+ if (host->pagesize_2k)
+ /* send read confirm command */
+ send_cmd(host, NAND_CMD_READSTART);
+
+ send_page(host, NFC_OUTPUT, 1);
+ memcpy32(host->data_buf, host->main_area0, mtd->writesize);
+ copy_spare(mtd, 1);
+
+ send_cmd(host, command);
+ mxc_do_addr_cycle(mtd, column, page_addr + 1);
+
+ if (host->pagesize_2k)
+ /* send read confirm command */
+ send_cmd(host, NAND_CMD_READSTART);
+
+ send_page(host, NFC_OUTPUT, 0);
+ cached = page_addr + 1;
+ }
- memcpy32(host->data_buf, host->main_area0, mtd->writesize);
- copy_spare(mtd, 1);
break;
case NAND_CMD_SEQIN:
@@ -749,7 +783,7 @@ static void imx_nand_command(struct mtd_info *mtd, unsigned command,
case NAND_CMD_PAGEPROG:
memcpy32(host->main_area0, host->data_buf, mtd->writesize);
copy_spare(mtd, 0);
- send_page(host, NFC_INPUT);
+ send_page(host, NFC_INPUT, 1);
send_cmd(host, command);
mxc_do_addr_cycle(mtd, column, page_addr);
break;
@@ -850,7 +884,7 @@ static int __init imxnd_probe(struct device_d *dev)
#endif
/* Allocate memory for MTD device structure and private data */
host = kzalloc(sizeof(struct imx_nand_host) + NAND_MAX_PAGESIZE +
- NAND_MAX_OOBSIZE, GFP_KERNEL);
+ NAND_MAX_OOBSIZE * 2, GFP_KERNEL);
if (!host)
return -ENOMEM;
@@ -1137,7 +1171,7 @@ void __nand_boot_init imx_nand_load_image(void *dest, int size)
page * pagesize);
if (host.pagesize_2k)
send_cmd(&host, NAND_CMD_READSTART);
- send_page(&host, NFC_OUTPUT);
+ send_page(&host, NFC_OUTPUT, 1);
page++;
if (host.pagesize_2k) {
--
1.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 04/12] imx_nand: use memcpy for copying from/to buffer
2010-03-29 9:36 Patches for next merge window Sascha Hauer
` (2 preceding siblings ...)
2010-03-29 9:36 ` [PATCH 03/12] nand_imx: Speed up sequential read Sascha Hauer
@ 2010-03-29 9:36 ` Sascha Hauer
2010-03-29 10:42 ` Ivo Clarysse
2010-03-29 9:36 ` [PATCH 05/12] add unaligned access support Sascha Hauer
` (7 subsequent siblings)
11 siblings, 1 reply; 22+ messages in thread
From: Sascha Hauer @ 2010-03-29 9:36 UTC (permalink / raw)
To: barebox
We do not need to use memcpy32 in read_buf/write_buf because
in these functions we only access SDRAM and not the internal SRAM
buffer.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/nand/nand_imx.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/nand/nand_imx.c b/drivers/nand/nand_imx.c
index 5f92e2f..398a268 100644
--- a/drivers/nand/nand_imx.c
+++ b/drivers/nand/nand_imx.c
@@ -505,7 +505,7 @@ static void imx_nand_write_buf(struct mtd_info *mtd,
int n = mtd->oobsize + mtd->writesize - col;
n = min(n, len);
- memcpy32(host->data_buf + col, buf, n);
+ memcpy(host->data_buf + col, buf, n);
host->buf_start += n;
}
@@ -529,7 +529,7 @@ static void imx_nand_read_buf(struct mtd_info *mtd, u_char * buf, int len)
n = min(n, len);
- memcpy32(buf, host->data_buf + col, len);
+ memcpy(buf, host->data_buf + col, len);
host->buf_start += len;
}
--
1.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 05/12] add unaligned access support
2010-03-29 9:36 Patches for next merge window Sascha Hauer
` (3 preceding siblings ...)
2010-03-29 9:36 ` [PATCH 04/12] imx_nand: use memcpy for copying from/to buffer Sascha Hauer
@ 2010-03-29 9:36 ` Sascha Hauer
2010-03-29 9:36 ` [PATCH 06/12] add unlzo support Sascha Hauer
` (6 subsequent siblings)
11 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2010-03-29 9:36 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/include/asm/unaligned.h | 19 ++++++++++
include/unaligned/access_ok.h | 67 +++++++++++++++++++++++++++++++++++
include/unaligned/be_byteshift.h | 70 +++++++++++++++++++++++++++++++++++++
include/unaligned/be_memmove.h | 36 +++++++++++++++++++
include/unaligned/be_struct.h | 36 +++++++++++++++++++
include/unaligned/generic.h | 68 +++++++++++++++++++++++++++++++++++
include/unaligned/le_byteshift.h | 70 +++++++++++++++++++++++++++++++++++++
include/unaligned/le_memmove.h | 36 +++++++++++++++++++
include/unaligned/le_struct.h | 36 +++++++++++++++++++
include/unaligned/memmove.h | 45 +++++++++++++++++++++++
include/unaligned/packed_struct.h | 46 ++++++++++++++++++++++++
11 files changed, 529 insertions(+), 0 deletions(-)
create mode 100644 arch/arm/include/asm/unaligned.h
create mode 100644 include/unaligned/access_ok.h
create mode 100644 include/unaligned/be_byteshift.h
create mode 100644 include/unaligned/be_memmove.h
create mode 100644 include/unaligned/be_struct.h
create mode 100644 include/unaligned/generic.h
create mode 100644 include/unaligned/le_byteshift.h
create mode 100644 include/unaligned/le_memmove.h
create mode 100644 include/unaligned/le_struct.h
create mode 100644 include/unaligned/memmove.h
create mode 100644 include/unaligned/packed_struct.h
diff --git a/arch/arm/include/asm/unaligned.h b/arch/arm/include/asm/unaligned.h
new file mode 100644
index 0000000..34f7838
--- /dev/null
+++ b/arch/arm/include/asm/unaligned.h
@@ -0,0 +1,19 @@
+#ifndef _ASM_ARM_UNALIGNED_H
+#define _ASM_ARM_UNALIGNED_H
+
+#include <unaligned/le_byteshift.h>
+#include <unaligned/be_byteshift.h>
+#include <unaligned/generic.h>
+
+/*
+ * Select endianness
+ */
+#ifndef __ARMEB__
+#define get_unaligned __get_unaligned_le
+#define put_unaligned __put_unaligned_le
+#else
+#define get_unaligned __get_unaligned_be
+#define put_unaligned __put_unaligned_be
+#endif
+
+#endif /* _ASM_ARM_UNALIGNED_H */
diff --git a/include/unaligned/access_ok.h b/include/unaligned/access_ok.h
new file mode 100644
index 0000000..99c1b4d
--- /dev/null
+++ b/include/unaligned/access_ok.h
@@ -0,0 +1,67 @@
+#ifndef _LINUX_UNALIGNED_ACCESS_OK_H
+#define _LINUX_UNALIGNED_ACCESS_OK_H
+
+#include <linux/kernel.h>
+#include <asm/byteorder.h>
+
+static inline u16 get_unaligned_le16(const void *p)
+{
+ return le16_to_cpup((__le16 *)p);
+}
+
+static inline u32 get_unaligned_le32(const void *p)
+{
+ return le32_to_cpup((__le32 *)p);
+}
+
+static inline u64 get_unaligned_le64(const void *p)
+{
+ return le64_to_cpup((__le64 *)p);
+}
+
+static inline u16 get_unaligned_be16(const void *p)
+{
+ return be16_to_cpup((__be16 *)p);
+}
+
+static inline u32 get_unaligned_be32(const void *p)
+{
+ return be32_to_cpup((__be32 *)p);
+}
+
+static inline u64 get_unaligned_be64(const void *p)
+{
+ return be64_to_cpup((__be64 *)p);
+}
+
+static inline void put_unaligned_le16(u16 val, void *p)
+{
+ *((__le16 *)p) = cpu_to_le16(val);
+}
+
+static inline void put_unaligned_le32(u32 val, void *p)
+{
+ *((__le32 *)p) = cpu_to_le32(val);
+}
+
+static inline void put_unaligned_le64(u64 val, void *p)
+{
+ *((__le64 *)p) = cpu_to_le64(val);
+}
+
+static inline void put_unaligned_be16(u16 val, void *p)
+{
+ *((__be16 *)p) = cpu_to_be16(val);
+}
+
+static inline void put_unaligned_be32(u32 val, void *p)
+{
+ *((__be32 *)p) = cpu_to_be32(val);
+}
+
+static inline void put_unaligned_be64(u64 val, void *p)
+{
+ *((__be64 *)p) = cpu_to_be64(val);
+}
+
+#endif /* _LINUX_UNALIGNED_ACCESS_OK_H */
diff --git a/include/unaligned/be_byteshift.h b/include/unaligned/be_byteshift.h
new file mode 100644
index 0000000..9356b24
--- /dev/null
+++ b/include/unaligned/be_byteshift.h
@@ -0,0 +1,70 @@
+#ifndef _LINUX_UNALIGNED_BE_BYTESHIFT_H
+#define _LINUX_UNALIGNED_BE_BYTESHIFT_H
+
+#include <linux/types.h>
+
+static inline u16 __get_unaligned_be16(const u8 *p)
+{
+ return p[0] << 8 | p[1];
+}
+
+static inline u32 __get_unaligned_be32(const u8 *p)
+{
+ return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
+}
+
+static inline u64 __get_unaligned_be64(const u8 *p)
+{
+ return (u64)__get_unaligned_be32(p) << 32 |
+ __get_unaligned_be32(p + 4);
+}
+
+static inline void __put_unaligned_be16(u16 val, u8 *p)
+{
+ *p++ = val >> 8;
+ *p++ = val;
+}
+
+static inline void __put_unaligned_be32(u32 val, u8 *p)
+{
+ __put_unaligned_be16(val >> 16, p);
+ __put_unaligned_be16(val, p + 2);
+}
+
+static inline void __put_unaligned_be64(u64 val, u8 *p)
+{
+ __put_unaligned_be32(val >> 32, p);
+ __put_unaligned_be32(val, p + 4);
+}
+
+static inline u16 get_unaligned_be16(const void *p)
+{
+ return __get_unaligned_be16((const u8 *)p);
+}
+
+static inline u32 get_unaligned_be32(const void *p)
+{
+ return __get_unaligned_be32((const u8 *)p);
+}
+
+static inline u64 get_unaligned_be64(const void *p)
+{
+ return __get_unaligned_be64((const u8 *)p);
+}
+
+static inline void put_unaligned_be16(u16 val, void *p)
+{
+ __put_unaligned_be16(val, p);
+}
+
+static inline void put_unaligned_be32(u32 val, void *p)
+{
+ __put_unaligned_be32(val, p);
+}
+
+static inline void put_unaligned_be64(u64 val, void *p)
+{
+ __put_unaligned_be64(val, p);
+}
+
+#endif /* _LINUX_UNALIGNED_BE_BYTESHIFT_H */
diff --git a/include/unaligned/be_memmove.h b/include/unaligned/be_memmove.h
new file mode 100644
index 0000000..c2a76c5
--- /dev/null
+++ b/include/unaligned/be_memmove.h
@@ -0,0 +1,36 @@
+#ifndef _LINUX_UNALIGNED_BE_MEMMOVE_H
+#define _LINUX_UNALIGNED_BE_MEMMOVE_H
+
+#include <linux/unaligned/memmove.h>
+
+static inline u16 get_unaligned_be16(const void *p)
+{
+ return __get_unaligned_memmove16((const u8 *)p);
+}
+
+static inline u32 get_unaligned_be32(const void *p)
+{
+ return __get_unaligned_memmove32((const u8 *)p);
+}
+
+static inline u64 get_unaligned_be64(const void *p)
+{
+ return __get_unaligned_memmove64((const u8 *)p);
+}
+
+static inline void put_unaligned_be16(u16 val, void *p)
+{
+ __put_unaligned_memmove16(val, p);
+}
+
+static inline void put_unaligned_be32(u32 val, void *p)
+{
+ __put_unaligned_memmove32(val, p);
+}
+
+static inline void put_unaligned_be64(u64 val, void *p)
+{
+ __put_unaligned_memmove64(val, p);
+}
+
+#endif /* _LINUX_UNALIGNED_LE_MEMMOVE_H */
diff --git a/include/unaligned/be_struct.h b/include/unaligned/be_struct.h
new file mode 100644
index 0000000..1324158
--- /dev/null
+++ b/include/unaligned/be_struct.h
@@ -0,0 +1,36 @@
+#ifndef _LINUX_UNALIGNED_BE_STRUCT_H
+#define _LINUX_UNALIGNED_BE_STRUCT_H
+
+#include <linux/unaligned/packed_struct.h>
+
+static inline u16 get_unaligned_be16(const void *p)
+{
+ return __get_unaligned_cpu16((const u8 *)p);
+}
+
+static inline u32 get_unaligned_be32(const void *p)
+{
+ return __get_unaligned_cpu32((const u8 *)p);
+}
+
+static inline u64 get_unaligned_be64(const void *p)
+{
+ return __get_unaligned_cpu64((const u8 *)p);
+}
+
+static inline void put_unaligned_be16(u16 val, void *p)
+{
+ __put_unaligned_cpu16(val, p);
+}
+
+static inline void put_unaligned_be32(u32 val, void *p)
+{
+ __put_unaligned_cpu32(val, p);
+}
+
+static inline void put_unaligned_be64(u64 val, void *p)
+{
+ __put_unaligned_cpu64(val, p);
+}
+
+#endif /* _LINUX_UNALIGNED_BE_STRUCT_H */
diff --git a/include/unaligned/generic.h b/include/unaligned/generic.h
new file mode 100644
index 0000000..02d97ff
--- /dev/null
+++ b/include/unaligned/generic.h
@@ -0,0 +1,68 @@
+#ifndef _LINUX_UNALIGNED_GENERIC_H
+#define _LINUX_UNALIGNED_GENERIC_H
+
+/*
+ * Cause a link-time error if we try an unaligned access other than
+ * 1,2,4 or 8 bytes long
+ */
+extern void __bad_unaligned_access_size(void);
+
+#define __get_unaligned_le(ptr) ((__force typeof(*(ptr)))({ \
+ __builtin_choose_expr(sizeof(*(ptr)) == 1, *(ptr), \
+ __builtin_choose_expr(sizeof(*(ptr)) == 2, get_unaligned_le16((ptr)), \
+ __builtin_choose_expr(sizeof(*(ptr)) == 4, get_unaligned_le32((ptr)), \
+ __builtin_choose_expr(sizeof(*(ptr)) == 8, get_unaligned_le64((ptr)), \
+ __bad_unaligned_access_size())))); \
+ }))
+
+#define __get_unaligned_be(ptr) ((__force typeof(*(ptr)))({ \
+ __builtin_choose_expr(sizeof(*(ptr)) == 1, *(ptr), \
+ __builtin_choose_expr(sizeof(*(ptr)) == 2, get_unaligned_be16((ptr)), \
+ __builtin_choose_expr(sizeof(*(ptr)) == 4, get_unaligned_be32((ptr)), \
+ __builtin_choose_expr(sizeof(*(ptr)) == 8, get_unaligned_be64((ptr)), \
+ __bad_unaligned_access_size())))); \
+ }))
+
+#define __put_unaligned_le(val, ptr) ({ \
+ void *__gu_p = (ptr); \
+ switch (sizeof(*(ptr))) { \
+ case 1: \
+ *(u8 *)__gu_p = (__force u8)(val); \
+ break; \
+ case 2: \
+ put_unaligned_le16((__force u16)(val), __gu_p); \
+ break; \
+ case 4: \
+ put_unaligned_le32((__force u32)(val), __gu_p); \
+ break; \
+ case 8: \
+ put_unaligned_le64((__force u64)(val), __gu_p); \
+ break; \
+ default: \
+ __bad_unaligned_access_size(); \
+ break; \
+ } \
+ (void)0; })
+
+#define __put_unaligned_be(val, ptr) ({ \
+ void *__gu_p = (ptr); \
+ switch (sizeof(*(ptr))) { \
+ case 1: \
+ *(u8 *)__gu_p = (__force u8)(val); \
+ break; \
+ case 2: \
+ put_unaligned_be16((__force u16)(val), __gu_p); \
+ break; \
+ case 4: \
+ put_unaligned_be32((__force u32)(val), __gu_p); \
+ break; \
+ case 8: \
+ put_unaligned_be64((__force u64)(val), __gu_p); \
+ break; \
+ default: \
+ __bad_unaligned_access_size(); \
+ break; \
+ } \
+ (void)0; })
+
+#endif /* _LINUX_UNALIGNED_GENERIC_H */
diff --git a/include/unaligned/le_byteshift.h b/include/unaligned/le_byteshift.h
new file mode 100644
index 0000000..be376fb
--- /dev/null
+++ b/include/unaligned/le_byteshift.h
@@ -0,0 +1,70 @@
+#ifndef _LINUX_UNALIGNED_LE_BYTESHIFT_H
+#define _LINUX_UNALIGNED_LE_BYTESHIFT_H
+
+#include <linux/types.h>
+
+static inline u16 __get_unaligned_le16(const u8 *p)
+{
+ return p[0] | p[1] << 8;
+}
+
+static inline u32 __get_unaligned_le32(const u8 *p)
+{
+ return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
+}
+
+static inline u64 __get_unaligned_le64(const u8 *p)
+{
+ return (u64)__get_unaligned_le32(p + 4) << 32 |
+ __get_unaligned_le32(p);
+}
+
+static inline void __put_unaligned_le16(u16 val, u8 *p)
+{
+ *p++ = val;
+ *p++ = val >> 8;
+}
+
+static inline void __put_unaligned_le32(u32 val, u8 *p)
+{
+ __put_unaligned_le16(val >> 16, p + 2);
+ __put_unaligned_le16(val, p);
+}
+
+static inline void __put_unaligned_le64(u64 val, u8 *p)
+{
+ __put_unaligned_le32(val >> 32, p + 4);
+ __put_unaligned_le32(val, p);
+}
+
+static inline u16 get_unaligned_le16(const void *p)
+{
+ return __get_unaligned_le16((const u8 *)p);
+}
+
+static inline u32 get_unaligned_le32(const void *p)
+{
+ return __get_unaligned_le32((const u8 *)p);
+}
+
+static inline u64 get_unaligned_le64(const void *p)
+{
+ return __get_unaligned_le64((const u8 *)p);
+}
+
+static inline void put_unaligned_le16(u16 val, void *p)
+{
+ __put_unaligned_le16(val, p);
+}
+
+static inline void put_unaligned_le32(u32 val, void *p)
+{
+ __put_unaligned_le32(val, p);
+}
+
+static inline void put_unaligned_le64(u64 val, void *p)
+{
+ __put_unaligned_le64(val, p);
+}
+
+#endif /* _LINUX_UNALIGNED_LE_BYTESHIFT_H */
diff --git a/include/unaligned/le_memmove.h b/include/unaligned/le_memmove.h
new file mode 100644
index 0000000..269849b
--- /dev/null
+++ b/include/unaligned/le_memmove.h
@@ -0,0 +1,36 @@
+#ifndef _LINUX_UNALIGNED_LE_MEMMOVE_H
+#define _LINUX_UNALIGNED_LE_MEMMOVE_H
+
+#include <linux/unaligned/memmove.h>
+
+static inline u16 get_unaligned_le16(const void *p)
+{
+ return __get_unaligned_memmove16((const u8 *)p);
+}
+
+static inline u32 get_unaligned_le32(const void *p)
+{
+ return __get_unaligned_memmove32((const u8 *)p);
+}
+
+static inline u64 get_unaligned_le64(const void *p)
+{
+ return __get_unaligned_memmove64((const u8 *)p);
+}
+
+static inline void put_unaligned_le16(u16 val, void *p)
+{
+ __put_unaligned_memmove16(val, p);
+}
+
+static inline void put_unaligned_le32(u32 val, void *p)
+{
+ __put_unaligned_memmove32(val, p);
+}
+
+static inline void put_unaligned_le64(u64 val, void *p)
+{
+ __put_unaligned_memmove64(val, p);
+}
+
+#endif /* _LINUX_UNALIGNED_LE_MEMMOVE_H */
diff --git a/include/unaligned/le_struct.h b/include/unaligned/le_struct.h
new file mode 100644
index 0000000..088c457
--- /dev/null
+++ b/include/unaligned/le_struct.h
@@ -0,0 +1,36 @@
+#ifndef _LINUX_UNALIGNED_LE_STRUCT_H
+#define _LINUX_UNALIGNED_LE_STRUCT_H
+
+#include <linux/unaligned/packed_struct.h>
+
+static inline u16 get_unaligned_le16(const void *p)
+{
+ return __get_unaligned_cpu16((const u8 *)p);
+}
+
+static inline u32 get_unaligned_le32(const void *p)
+{
+ return __get_unaligned_cpu32((const u8 *)p);
+}
+
+static inline u64 get_unaligned_le64(const void *p)
+{
+ return __get_unaligned_cpu64((const u8 *)p);
+}
+
+static inline void put_unaligned_le16(u16 val, void *p)
+{
+ __put_unaligned_cpu16(val, p);
+}
+
+static inline void put_unaligned_le32(u32 val, void *p)
+{
+ __put_unaligned_cpu32(val, p);
+}
+
+static inline void put_unaligned_le64(u64 val, void *p)
+{
+ __put_unaligned_cpu64(val, p);
+}
+
+#endif /* _LINUX_UNALIGNED_LE_STRUCT_H */
diff --git a/include/unaligned/memmove.h b/include/unaligned/memmove.h
new file mode 100644
index 0000000..eeb5a77
--- /dev/null
+++ b/include/unaligned/memmove.h
@@ -0,0 +1,45 @@
+#ifndef _LINUX_UNALIGNED_MEMMOVE_H
+#define _LINUX_UNALIGNED_MEMMOVE_H
+
+#include <linux/kernel.h>
+#include <linux/string.h>
+
+/* Use memmove here, so gcc does not insert a __builtin_memcpy. */
+
+static inline u16 __get_unaligned_memmove16(const void *p)
+{
+ u16 tmp;
+ memmove(&tmp, p, 2);
+ return tmp;
+}
+
+static inline u32 __get_unaligned_memmove32(const void *p)
+{
+ u32 tmp;
+ memmove(&tmp, p, 4);
+ return tmp;
+}
+
+static inline u64 __get_unaligned_memmove64(const void *p)
+{
+ u64 tmp;
+ memmove(&tmp, p, 8);
+ return tmp;
+}
+
+static inline void __put_unaligned_memmove16(u16 val, void *p)
+{
+ memmove(p, &val, 2);
+}
+
+static inline void __put_unaligned_memmove32(u32 val, void *p)
+{
+ memmove(p, &val, 4);
+}
+
+static inline void __put_unaligned_memmove64(u64 val, void *p)
+{
+ memmove(p, &val, 8);
+}
+
+#endif /* _LINUX_UNALIGNED_MEMMOVE_H */
diff --git a/include/unaligned/packed_struct.h b/include/unaligned/packed_struct.h
new file mode 100644
index 0000000..2498bb9
--- /dev/null
+++ b/include/unaligned/packed_struct.h
@@ -0,0 +1,46 @@
+#ifndef _LINUX_UNALIGNED_PACKED_STRUCT_H
+#define _LINUX_UNALIGNED_PACKED_STRUCT_H
+
+#include <linux/kernel.h>
+
+struct __una_u16 { u16 x __attribute__((packed)); };
+struct __una_u32 { u32 x __attribute__((packed)); };
+struct __una_u64 { u64 x __attribute__((packed)); };
+
+static inline u16 __get_unaligned_cpu16(const void *p)
+{
+ const struct __una_u16 *ptr = (const struct __una_u16 *)p;
+ return ptr->x;
+}
+
+static inline u32 __get_unaligned_cpu32(const void *p)
+{
+ const struct __una_u32 *ptr = (const struct __una_u32 *)p;
+ return ptr->x;
+}
+
+static inline u64 __get_unaligned_cpu64(const void *p)
+{
+ const struct __una_u64 *ptr = (const struct __una_u64 *)p;
+ return ptr->x;
+}
+
+static inline void __put_unaligned_cpu16(u16 val, void *p)
+{
+ struct __una_u16 *ptr = (struct __una_u16 *)p;
+ ptr->x = val;
+}
+
+static inline void __put_unaligned_cpu32(u32 val, void *p)
+{
+ struct __una_u32 *ptr = (struct __una_u32 *)p;
+ ptr->x = val;
+}
+
+static inline void __put_unaligned_cpu64(u64 val, void *p)
+{
+ struct __una_u64 *ptr = (struct __una_u64 *)p;
+ ptr->x = val;
+}
+
+#endif /* _LINUX_UNALIGNED_PACKED_STRUCT_H */
--
1.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 06/12] add unlzo support
2010-03-29 9:36 Patches for next merge window Sascha Hauer
` (4 preceding siblings ...)
2010-03-29 9:36 ` [PATCH 05/12] add unaligned access support Sascha Hauer
@ 2010-03-29 9:36 ` Sascha Hauer
2010-03-30 11:04 ` Sascha Hauer
2010-03-29 9:36 ` [PATCH 07/12] add snprintf function Sascha Hauer
` (5 subsequent siblings)
11 siblings, 1 reply; 22+ messages in thread
From: Sascha Hauer @ 2010-03-29 9:36 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/Kconfig | 8 ++
commands/Makefile | 1 +
commands/unlzo.c | 69 ++++++++++++
include/lzo.h | 46 ++++++++
lib/Kconfig | 2 +
lib/Makefile | 2 +
lib/decompress_unlzo.c | 199 +++++++++++++++++++++++++++++++++++
lib/lzo/Kconfig | 6 +
lib/lzo/Makefile | 4 +
lib/lzo/lzo1x_compress.c | 226 ++++++++++++++++++++++++++++++++++++++++
lib/lzo/lzo1x_decompress.c | 247 ++++++++++++++++++++++++++++++++++++++++++++
lib/lzo/lzodefs.h | 43 ++++++++
lib/lzo/modules.builtin | 2 +
13 files changed, 855 insertions(+), 0 deletions(-)
create mode 100644 commands/unlzo.c
create mode 100644 include/lzo.h
create mode 100644 lib/decompress_unlzo.c
create mode 100644 lib/lzo/Kconfig
create mode 100644 lib/lzo/Makefile
create mode 100644 lib/lzo/lzo1x_compress.c
create mode 100644 lib/lzo/lzo1x_decompress.c
create mode 100644 lib/lzo/lzodefs.h
create mode 100644 lib/lzo/modules.builtin
diff --git a/commands/Kconfig b/commands/Kconfig
index bb264fc..543ee71 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -300,4 +300,12 @@ config CMD_GPIO
include gpio_set_value, gpio_get_value, gpio_direction_input and
gpio_direction_output commands to control gpios.
+config CMD_UNLZO
+ bool
+ select LZO_DECOMPRESS
+ prompt "unlzo"
+ help
+ Say yes here to get the unlzo command. lzo is a fast compression
+ algorithm by Markus Franz Xaver Johannes Oberhumer.
+
endmenu
diff --git a/commands/Makefile b/commands/Makefile
index b32fa05..74b0994 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -47,3 +47,4 @@ obj-$(CONFIG_CMD_INSMOD) += insmod.o
obj-$(CONFIG_CMD_BMP) += bmp.o
obj-$(CONFIG_USB_GADGET_DFU) += dfu.o
obj-$(CONFIG_CMD_GPIO) += gpio.o
+obj-$(CONFIG_CMD_UNLZO) += unlzo.o
diff --git a/commands/unlzo.c b/commands/unlzo.c
new file mode 100644
index 0000000..0b6dd4b
--- /dev/null
+++ b/commands/unlzo.c
@@ -0,0 +1,69 @@
+/*
+ * unlzo.c - uncompress a lzo compressed file
+ *
+ * Copyright (c) 2010 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <command.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <fs.h>
+#include <lzo.h>
+
+static int do_unlzo(struct command *cmdtp, int argc, char *argv[])
+{
+ int from, to, ret, retlen;
+
+ if (argc != 3)
+ return COMMAND_ERROR_USAGE;
+
+ from = open(argv[1], O_RDONLY);
+ if (from < 0) {
+ perror("open");
+ return 1;
+ }
+
+ to = open(argv[2], O_WRONLY | O_CREAT);
+ if (to < 0) {
+ perror("open");
+ ret = 1;
+ goto exit_close;
+ }
+
+ ret = unlzo(from, to, &retlen);
+ if (ret)
+ printf("failed to decompress\n");
+
+ close(to);
+exit_close:
+ close(from);
+ return ret;
+}
+
+static const __maybe_unused char cmd_unlzo_help[] =
+"Usage: unlzo <infile> <outfile>\n"
+"Uncompress a lzo compressed file\n";
+
+BAREBOX_CMD_START(unlzo)
+ .cmd = do_unlzo,
+ .usage = "lzop <infile> <outfile>",
+ BAREBOX_CMD_HELP(cmd_unlzo_help)
+BAREBOX_CMD_END
+
diff --git a/include/lzo.h b/include/lzo.h
new file mode 100644
index 0000000..5694985
--- /dev/null
+++ b/include/lzo.h
@@ -0,0 +1,46 @@
+#ifndef __LZO_H__
+#define __LZO_H__
+/*
+ * LZO Public Kernel Interface
+ * A mini subset of the LZO real-time data compression library
+ *
+ * Copyright (C) 1996-2005 Markus F.X.J. Oberhumer <markus@oberhumer.com>
+ *
+ * The full LZO package can be found at:
+ * http://www.oberhumer.com/opensource/lzo/
+ *
+ * Changed for kernel use by:
+ * Nitin Gupta <nitingupta910@gmail.com>
+ * Richard Purdie <rpurdie@openedhand.com>
+ */
+
+#define LZO1X_MEM_COMPRESS (16384 * sizeof(unsigned char *))
+#define LZO1X_1_MEM_COMPRESS LZO1X_MEM_COMPRESS
+
+#define lzo1x_worst_compress(x) ((x) + ((x) / 16) + 64 + 3)
+
+/* This requires 'workmem' of size LZO1X_1_MEM_COMPRESS */
+int lzo1x_1_compress(const unsigned char *src, size_t src_len,
+ unsigned char *dst, size_t *dst_len, void *wrkmem);
+
+/* safe decompression with overrun testing */
+int lzo1x_decompress_safe(const unsigned char *src, size_t src_len,
+ unsigned char *dst, size_t *dst_len);
+
+/*
+ * Return values (< 0 = Error)
+ */
+#define LZO_E_OK 0
+#define LZO_E_ERROR (-1)
+#define LZO_E_OUT_OF_MEMORY (-2)
+#define LZO_E_NOT_COMPRESSIBLE (-3)
+#define LZO_E_INPUT_OVERRUN (-4)
+#define LZO_E_OUTPUT_OVERRUN (-5)
+#define LZO_E_LOOKBEHIND_OVERRUN (-6)
+#define LZO_E_EOF_NOT_FOUND (-7)
+#define LZO_E_INPUT_NOT_CONSUMED (-8)
+#define LZO_E_NOT_YET_IMPLEMENTED (-9)
+
+int unlzo(int in_fd, int out_fd, int *dest_len);
+
+#endif
diff --git a/lib/Kconfig b/lib/Kconfig
index c272078..90cf784 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -13,3 +13,5 @@ config CRC16
config GENERIC_FIND_NEXT_BIT
def_bool n
+source lib/lzo/Kconfig
+
diff --git a/lib/Makefile b/lib/Makefile
index b532690..74f7d82 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -28,3 +28,5 @@ obj-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o
obj-y += glob.o
obj-y += notifier.o
obj-y += copy_file.o
+obj-y += lzo/
+obj-y += decompress_unlzo.o
diff --git a/lib/decompress_unlzo.c b/lib/decompress_unlzo.c
new file mode 100644
index 0000000..8f9cdcf
--- /dev/null
+++ b/lib/decompress_unlzo.c
@@ -0,0 +1,199 @@
+/*
+ * LZO decompressor for barebox. Code borrowed from the lzo
+ * implementation by Markus Franz Xaver Johannes Oberhumer.
+ *
+ * Linux kernel adaptation:
+ * Copyright (C) 2009
+ * Albin Tonnerre, Free Electrons <albin.tonnerre@free-electrons.com>
+ *
+ * Original code:
+ * Copyright (C) 1996-2005 Markus Franz Xaver Johannes Oberhumer
+ * All Rights Reserved.
+ *
+ * lzop and the LZO library are free software; you can redistribute them
+ * and/or modify them 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING.
+ * If not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Markus F.X.J. Oberhumer
+ * <markus@oberhumer.com>
+ * http://www.oberhumer.com/opensource/lzop/
+ */
+
+#include <common.h>
+#include <malloc.h>
+#include <linux/types.h>
+#include <lzo.h>
+#include <errno.h>
+#include <fs.h>
+#include <xfuncs.h>
+
+#include <linux/compiler.h>
+#include <asm/unaligned.h>
+
+static const unsigned char lzop_magic[] = {
+ 0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a };
+
+#define LZO_BLOCK_SIZE (256*1024l)
+#define HEADER_HAS_FILTER 0x00000800L
+
+static inline int parse_header(int in_fd)
+{
+ u8 l;
+ u16 version;
+ int ret;
+ unsigned char buf[256]; /* maximum filename length + 1 */
+
+ /* read magic (9), library version (2), 'need to be extracted'
+ * version (2) and method (1)
+ */
+ ret = read(in_fd, buf, 9);
+ if (ret < 0)
+ return ret;
+
+ /* check magic */
+ for (l = 0; l < 9; l++) {
+ if (buf[l] != lzop_magic[l])
+ return -EINVAL;
+ }
+
+ ret = read(in_fd, buf, 4); /* version, lib_version */
+ if (ret < 0)
+ return ret;
+ version = get_unaligned_be16(buf);
+
+ if (version >= 0x0940) {
+ ret = read(in_fd, buf, 2); /* version to extract */
+ if (ret < 0)
+ return ret;
+ }
+
+ ret = read(in_fd, buf, 1); /* method */
+ if (ret < 0)
+ return ret;
+
+ if (version >= 0x0940)
+ read(in_fd, buf, 1); /* level */
+
+ ret = read(in_fd, buf, 4); /* flags */
+ if (ret < 0)
+ return ret;
+
+ if (get_unaligned_be32(buf) & HEADER_HAS_FILTER) {
+ ret = read(in_fd, buf, 4); /* skip filter info */
+ if (ret < 0)
+ return ret;
+ }
+
+ /* skip mode and mtime_low */
+ ret = read(in_fd, buf, 8);
+ if (ret < 0)
+ return ret;
+
+ if (version >= 0x0940) {
+ ret = read(in_fd, buf, 4); /* skip mtime_high */
+ if (ret < 0)
+ return ret;
+ }
+
+ ret = read(in_fd, &l, 1);
+ if (ret < 0)
+ return ret;
+ /* don't care about the file name, and skip checksum */
+ ret = read(in_fd, buf, l + 4);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+int unlzo(int in_fd, int out_fd, int *dest_len)
+{
+ u8 r = 0;
+ u32 src_len, dst_len;
+ size_t tmp;
+ u8 *in_buf, *out_buf;
+ int obytes_processed = 0;
+ unsigned char buf[8];
+ int ret;
+
+ if (parse_header(in_fd))
+ return -EINVAL;
+
+ out_buf = xmalloc(LZO_BLOCK_SIZE);
+ in_buf = xmalloc(lzo1x_worst_compress(LZO_BLOCK_SIZE));
+
+ for (;;) {
+ /* read uncompressed block size */
+ ret = read(in_fd, buf, 4);
+ if (ret < 0)
+ goto exit_free;
+ dst_len = get_unaligned_be32(buf);
+
+ /* exit if last block */
+ if (dst_len == 0)
+ break;
+
+ if (dst_len > LZO_BLOCK_SIZE) {
+ printf("dest len longer than block size");
+ goto exit_free;
+ }
+
+ /* read compressed block size, and skip block checksum info */
+ ret = read(in_fd, buf, 8);
+ if (ret < 0)
+ goto exit_free;
+
+ src_len = get_unaligned_be32(buf);
+
+ if (src_len <= 0 || src_len > dst_len) {
+ printf("file corrupted");
+ goto exit_free;
+ }
+ ret = read(in_fd, in_buf, src_len);
+ if (ret < 0)
+ goto exit_free;
+
+ /* decompress */
+ tmp = dst_len;
+ if (src_len < dst_len) {
+ r = lzo1x_decompress_safe((u8 *) in_buf, src_len,
+ out_buf, &tmp);
+ if (r != LZO_E_OK || dst_len != tmp) {
+ printf("Compressed data violation");
+ goto exit_free;
+ }
+ ret = write(out_fd, out_buf, dst_len);
+ if (ret < 0)
+ goto exit_free;
+ } else {
+ if (src_len != dst_len) {
+ printf("Compressed data violation");
+ goto exit_free;
+ }
+ ret = write(out_fd, in_buf, dst_len);
+ if (ret < 0)
+ goto exit_free;
+ }
+
+ obytes_processed += dst_len;
+ }
+
+exit_free:
+ free(in_buf);
+ free(out_buf);
+
+ *dest_len = obytes_processed;
+ return 0;
+}
+
diff --git a/lib/lzo/Kconfig b/lib/lzo/Kconfig
new file mode 100644
index 0000000..4016785
--- /dev/null
+++ b/lib/lzo/Kconfig
@@ -0,0 +1,6 @@
+config LZO_DECOMPRESS
+ bool
+
+config LZO_COMPRESS
+ bool
+
diff --git a/lib/lzo/Makefile b/lib/lzo/Makefile
new file mode 100644
index 0000000..e1a97ae
--- /dev/null
+++ b/lib/lzo/Makefile
@@ -0,0 +1,4 @@
+
+obj-$(CONFIG_LZO_COMPRESS) += lzo1x_compress.o
+obj-$(CONFIG_LZO_DECOMPRESS) += lzo1x_decompress.o
+
diff --git a/lib/lzo/lzo1x_compress.c b/lib/lzo/lzo1x_compress.c
new file mode 100644
index 0000000..a604099
--- /dev/null
+++ b/lib/lzo/lzo1x_compress.c
@@ -0,0 +1,226 @@
+/*
+ * LZO1X Compressor from MiniLZO
+ *
+ * Copyright (C) 1996-2005 Markus F.X.J. Oberhumer <markus@oberhumer.com>
+ *
+ * The full LZO package can be found at:
+ * http://www.oberhumer.com/opensource/lzo/
+ *
+ * Changed for kernel use by:
+ * Nitin Gupta <nitingupta910@gmail.com>
+ * Richard Purdie <rpurdie@openedhand.com>
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/lzo.h>
+#include <asm/unaligned.h>
+#include "lzodefs.h"
+
+static noinline size_t
+_lzo1x_1_do_compress(const unsigned char *in, size_t in_len,
+ unsigned char *out, size_t *out_len, void *wrkmem)
+{
+ const unsigned char * const in_end = in + in_len;
+ const unsigned char * const ip_end = in + in_len - M2_MAX_LEN - 5;
+ const unsigned char ** const dict = wrkmem;
+ const unsigned char *ip = in, *ii = ip;
+ const unsigned char *end, *m, *m_pos;
+ size_t m_off, m_len, dindex;
+ unsigned char *op = out;
+
+ ip += 4;
+
+ for (;;) {
+ dindex = ((size_t)(0x21 * DX3(ip, 5, 5, 6)) >> 5) & D_MASK;
+ m_pos = dict[dindex];
+
+ if (m_pos < in)
+ goto literal;
+
+ if (ip == m_pos || ((size_t)(ip - m_pos) > M4_MAX_OFFSET))
+ goto literal;
+
+ m_off = ip - m_pos;
+ if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
+ goto try_match;
+
+ dindex = (dindex & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f);
+ m_pos = dict[dindex];
+
+ if (m_pos < in)
+ goto literal;
+
+ if (ip == m_pos || ((size_t)(ip - m_pos) > M4_MAX_OFFSET))
+ goto literal;
+
+ m_off = ip - m_pos;
+ if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
+ goto try_match;
+
+ goto literal;
+
+try_match:
+ if (get_unaligned((const unsigned short *)m_pos)
+ == get_unaligned((const unsigned short *)ip)) {
+ if (likely(m_pos[2] == ip[2]))
+ goto match;
+ }
+
+literal:
+ dict[dindex] = ip;
+ ++ip;
+ if (unlikely(ip >= ip_end))
+ break;
+ continue;
+
+match:
+ dict[dindex] = ip;
+ if (ip != ii) {
+ size_t t = ip - ii;
+
+ if (t <= 3) {
+ op[-2] |= t;
+ } else if (t <= 18) {
+ *op++ = (t - 3);
+ } else {
+ size_t tt = t - 18;
+
+ *op++ = 0;
+ while (tt > 255) {
+ tt -= 255;
+ *op++ = 0;
+ }
+ *op++ = tt;
+ }
+ do {
+ *op++ = *ii++;
+ } while (--t > 0);
+ }
+
+ ip += 3;
+ if (m_pos[3] != *ip++ || m_pos[4] != *ip++
+ || m_pos[5] != *ip++ || m_pos[6] != *ip++
+ || m_pos[7] != *ip++ || m_pos[8] != *ip++) {
+ --ip;
+ m_len = ip - ii;
+
+ if (m_off <= M2_MAX_OFFSET) {
+ m_off -= 1;
+ *op++ = (((m_len - 1) << 5)
+ | ((m_off & 7) << 2));
+ *op++ = (m_off >> 3);
+ } else if (m_off <= M3_MAX_OFFSET) {
+ m_off -= 1;
+ *op++ = (M3_MARKER | (m_len - 2));
+ goto m3_m4_offset;
+ } else {
+ m_off -= 0x4000;
+
+ *op++ = (M4_MARKER | ((m_off & 0x4000) >> 11)
+ | (m_len - 2));
+ goto m3_m4_offset;
+ }
+ } else {
+ end = in_end;
+ m = m_pos + M2_MAX_LEN + 1;
+
+ while (ip < end && *m == *ip) {
+ m++;
+ ip++;
+ }
+ m_len = ip - ii;
+
+ if (m_off <= M3_MAX_OFFSET) {
+ m_off -= 1;
+ if (m_len <= 33) {
+ *op++ = (M3_MARKER | (m_len - 2));
+ } else {
+ m_len -= 33;
+ *op++ = M3_MARKER | 0;
+ goto m3_m4_len;
+ }
+ } else {
+ m_off -= 0x4000;
+ if (m_len <= M4_MAX_LEN) {
+ *op++ = (M4_MARKER
+ | ((m_off & 0x4000) >> 11)
+ | (m_len - 2));
+ } else {
+ m_len -= M4_MAX_LEN;
+ *op++ = (M4_MARKER
+ | ((m_off & 0x4000) >> 11));
+m3_m4_len:
+ while (m_len > 255) {
+ m_len -= 255;
+ *op++ = 0;
+ }
+
+ *op++ = (m_len);
+ }
+ }
+m3_m4_offset:
+ *op++ = ((m_off & 63) << 2);
+ *op++ = (m_off >> 6);
+ }
+
+ ii = ip;
+ if (unlikely(ip >= ip_end))
+ break;
+ }
+
+ *out_len = op - out;
+ return in_end - ii;
+}
+
+int lzo1x_1_compress(const unsigned char *in, size_t in_len, unsigned char *out,
+ size_t *out_len, void *wrkmem)
+{
+ const unsigned char *ii;
+ unsigned char *op = out;
+ size_t t;
+
+ if (unlikely(in_len <= M2_MAX_LEN + 5)) {
+ t = in_len;
+ } else {
+ t = _lzo1x_1_do_compress(in, in_len, op, out_len, wrkmem);
+ op += *out_len;
+ }
+
+ if (t > 0) {
+ ii = in + in_len - t;
+
+ if (op == out && t <= 238) {
+ *op++ = (17 + t);
+ } else if (t <= 3) {
+ op[-2] |= t;
+ } else if (t <= 18) {
+ *op++ = (t - 3);
+ } else {
+ size_t tt = t - 18;
+
+ *op++ = 0;
+ while (tt > 255) {
+ tt -= 255;
+ *op++ = 0;
+ }
+
+ *op++ = tt;
+ }
+ do {
+ *op++ = *ii++;
+ } while (--t > 0);
+ }
+
+ *op++ = M4_MARKER | 1;
+ *op++ = 0;
+ *op++ = 0;
+
+ *out_len = op - out;
+ return LZO_E_OK;
+}
+EXPORT_SYMBOL_GPL(lzo1x_1_compress);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("LZO1X-1 Compressor");
+
diff --git a/lib/lzo/lzo1x_decompress.c b/lib/lzo/lzo1x_decompress.c
new file mode 100644
index 0000000..af94382
--- /dev/null
+++ b/lib/lzo/lzo1x_decompress.c
@@ -0,0 +1,247 @@
+/*
+ * LZO1X Decompressor from MiniLZO
+ *
+ * Copyright (C) 1996-2005 Markus F.X.J. Oberhumer <markus@oberhumer.com>
+ *
+ * The full LZO package can be found at:
+ * http://www.oberhumer.com/opensource/lzo/
+ *
+ * Changed for kernel use by:
+ * Nitin Gupta <nitingupta910@gmail.com>
+ * Richard Purdie <rpurdie@openedhand.com>
+ */
+
+#include <asm/unaligned.h>
+#include <common.h>
+#include <lzo.h>
+#include "lzodefs.h"
+
+#define HAVE_IP(x, ip_end, ip) ((size_t)(ip_end - ip) < (x))
+#define HAVE_OP(x, op_end, op) ((size_t)(op_end - op) < (x))
+#define HAVE_LB(m_pos, out, op) (m_pos < out || m_pos >= op)
+
+#define COPY4(dst, src) \
+ put_unaligned(get_unaligned((const u32 *)(src)), (u32 *)(dst))
+
+int lzo1x_decompress_safe(const unsigned char *in, size_t in_len,
+ unsigned char *out, size_t *out_len)
+{
+ const unsigned char * const ip_end = in + in_len;
+ unsigned char * const op_end = out + *out_len;
+ const unsigned char *ip = in, *m_pos;
+ unsigned char *op = out;
+ size_t t;
+
+ *out_len = 0;
+
+ if (*ip > 17) {
+ t = *ip++ - 17;
+ if (t < 4)
+ goto match_next;
+ if (HAVE_OP(t, op_end, op))
+ goto output_overrun;
+ if (HAVE_IP(t + 1, ip_end, ip))
+ goto input_overrun;
+ do {
+ *op++ = *ip++;
+ } while (--t > 0);
+ goto first_literal_run;
+ }
+
+ while ((ip < ip_end)) {
+ t = *ip++;
+ if (t >= 16)
+ goto match;
+ if (t == 0) {
+ if (HAVE_IP(1, ip_end, ip))
+ goto input_overrun;
+ while (*ip == 0) {
+ t += 255;
+ ip++;
+ if (HAVE_IP(1, ip_end, ip))
+ goto input_overrun;
+ }
+ t += 15 + *ip++;
+ }
+ if (HAVE_OP(t + 3, op_end, op))
+ goto output_overrun;
+ if (HAVE_IP(t + 4, ip_end, ip))
+ goto input_overrun;
+
+ COPY4(op, ip);
+ op += 4;
+ ip += 4;
+ if (--t > 0) {
+ if (t >= 4) {
+ do {
+ COPY4(op, ip);
+ op += 4;
+ ip += 4;
+ t -= 4;
+ } while (t >= 4);
+ if (t > 0) {
+ do {
+ *op++ = *ip++;
+ } while (--t > 0);
+ }
+ } else {
+ do {
+ *op++ = *ip++;
+ } while (--t > 0);
+ }
+ }
+
+first_literal_run:
+ t = *ip++;
+ if (t >= 16)
+ goto match;
+ m_pos = op - (1 + M2_MAX_OFFSET);
+ m_pos -= t >> 2;
+ m_pos -= *ip++ << 2;
+
+ if (HAVE_LB(m_pos, out, op))
+ goto lookbehind_overrun;
+
+ if (HAVE_OP(3, op_end, op))
+ goto output_overrun;
+ *op++ = *m_pos++;
+ *op++ = *m_pos++;
+ *op++ = *m_pos;
+
+ goto match_done;
+
+ do {
+match:
+ if (t >= 64) {
+ m_pos = op - 1;
+ m_pos -= (t >> 2) & 7;
+ m_pos -= *ip++ << 3;
+ t = (t >> 5) - 1;
+ if (HAVE_LB(m_pos, out, op))
+ goto lookbehind_overrun;
+ if (HAVE_OP(t + 3 - 1, op_end, op))
+ goto output_overrun;
+ goto copy_match;
+ } else if (t >= 32) {
+ t &= 31;
+ if (t == 0) {
+ if (HAVE_IP(1, ip_end, ip))
+ goto input_overrun;
+ while (*ip == 0) {
+ t += 255;
+ ip++;
+ if (HAVE_IP(1, ip_end, ip))
+ goto input_overrun;
+ }
+ t += 31 + *ip++;
+ }
+ m_pos = op - 1;
+ m_pos -= get_unaligned_le16(ip) >> 2;
+ ip += 2;
+ } else if (t >= 16) {
+ m_pos = op;
+ m_pos -= (t & 8) << 11;
+
+ t &= 7;
+ if (t == 0) {
+ if (HAVE_IP(1, ip_end, ip))
+ goto input_overrun;
+ while (*ip == 0) {
+ t += 255;
+ ip++;
+ if (HAVE_IP(1, ip_end, ip))
+ goto input_overrun;
+ }
+ t += 7 + *ip++;
+ }
+ m_pos -= get_unaligned_le16(ip) >> 2;
+ ip += 2;
+ if (m_pos == op)
+ goto eof_found;
+ m_pos -= 0x4000;
+ } else {
+ m_pos = op - 1;
+ m_pos -= t >> 2;
+ m_pos -= *ip++ << 2;
+
+ if (HAVE_LB(m_pos, out, op))
+ goto lookbehind_overrun;
+ if (HAVE_OP(2, op_end, op))
+ goto output_overrun;
+
+ *op++ = *m_pos++;
+ *op++ = *m_pos;
+ goto match_done;
+ }
+
+ if (HAVE_LB(m_pos, out, op))
+ goto lookbehind_overrun;
+ if (HAVE_OP(t + 3 - 1, op_end, op))
+ goto output_overrun;
+
+ if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) {
+ COPY4(op, m_pos);
+ op += 4;
+ m_pos += 4;
+ t -= 4 - (3 - 1);
+ do {
+ COPY4(op, m_pos);
+ op += 4;
+ m_pos += 4;
+ t -= 4;
+ } while (t >= 4);
+ if (t > 0)
+ do {
+ *op++ = *m_pos++;
+ } while (--t > 0);
+ } else {
+copy_match:
+ *op++ = *m_pos++;
+ *op++ = *m_pos++;
+ do {
+ *op++ = *m_pos++;
+ } while (--t > 0);
+ }
+match_done:
+ t = ip[-2] & 3;
+ if (t == 0)
+ break;
+match_next:
+ if (HAVE_OP(t, op_end, op))
+ goto output_overrun;
+ if (HAVE_IP(t + 1, ip_end, ip))
+ goto input_overrun;
+
+ *op++ = *ip++;
+ if (t > 1) {
+ *op++ = *ip++;
+ if (t > 2)
+ *op++ = *ip++;
+ }
+
+ t = *ip++;
+ } while (ip < ip_end);
+ }
+
+ *out_len = op - out;
+ return LZO_E_EOF_NOT_FOUND;
+
+eof_found:
+ *out_len = op - out;
+ return (ip == ip_end ? LZO_E_OK :
+ (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
+input_overrun:
+ *out_len = op - out;
+ return LZO_E_INPUT_OVERRUN;
+
+output_overrun:
+ *out_len = op - out;
+ return LZO_E_OUTPUT_OVERRUN;
+
+lookbehind_overrun:
+ *out_len = op - out;
+ return LZO_E_LOOKBEHIND_OVERRUN;
+}
+
+EXPORT_SYMBOL(lzo1x_decompress_safe);
+
diff --git a/lib/lzo/lzodefs.h b/lib/lzo/lzodefs.h
new file mode 100644
index 0000000..b6d482c
--- /dev/null
+++ b/lib/lzo/lzodefs.h
@@ -0,0 +1,43 @@
+/*
+ * lzodefs.h -- architecture, OS and compiler specific defines
+ *
+ * Copyright (C) 1996-2005 Markus F.X.J. Oberhumer <markus@oberhumer.com>
+ *
+ * The full LZO package can be found at:
+ * http://www.oberhumer.com/opensource/lzo/
+ *
+ * Changed for kernel use by:
+ * Nitin Gupta <nitingupta910@gmail.com>
+ * Richard Purdie <rpurdie@openedhand.com>
+ */
+
+#define LZO_VERSION 0x2020
+#define LZO_VERSION_STRING "2.02"
+#define LZO_VERSION_DATE "Oct 17 2005"
+
+#define M1_MAX_OFFSET 0x0400
+#define M2_MAX_OFFSET 0x0800
+#define M3_MAX_OFFSET 0x4000
+#define M4_MAX_OFFSET 0xbfff
+
+#define M1_MIN_LEN 2
+#define M1_MAX_LEN 2
+#define M2_MIN_LEN 3
+#define M2_MAX_LEN 8
+#define M3_MIN_LEN 3
+#define M3_MAX_LEN 33
+#define M4_MIN_LEN 3
+#define M4_MAX_LEN 9
+
+#define M1_MARKER 0
+#define M2_MARKER 64
+#define M3_MARKER 32
+#define M4_MARKER 16
+
+#define D_BITS 14
+#define D_MASK ((1u << D_BITS) - 1)
+#define D_HIGH ((D_MASK >> 1) + 1)
+
+#define DX2(p, s1, s2) (((((size_t)((p)[2]) << (s2)) ^ (p)[1]) \
+ << (s1)) ^ (p)[0])
+#define DX3(p, s1, s2, s3) ((DX2((p)+1, s2, s3) << (s1)) ^ (p)[0])
diff --git a/lib/lzo/modules.builtin b/lib/lzo/modules.builtin
new file mode 100644
index 0000000..d860562
--- /dev/null
+++ b/lib/lzo/modules.builtin
@@ -0,0 +1,2 @@
+kernel/lib/lzo/lzo_compress.ko
+kernel/lib/lzo/lzo_decompress.ko
--
1.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 07/12] add snprintf function
2010-03-29 9:36 Patches for next merge window Sascha Hauer
` (5 preceding siblings ...)
2010-03-29 9:36 ` [PATCH 06/12] add unlzo support Sascha Hauer
@ 2010-03-29 9:36 ` Sascha Hauer
2010-03-29 9:36 ` [PATCH 08/12] echo: add -e option support Sascha Hauer
` (4 subsequent siblings)
11 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2010-03-29 9:36 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
include/stdio.h | 1 +
lib/vsprintf.c | 12 ++++++++++++
2 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/include/stdio.h b/include/stdio.h
index c23dfc6..cd1a913 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -31,6 +31,7 @@ static inline void putchar(char c) {
int printf(const char *fmt, ...);
int vprintf(const char *fmt, va_list args);
int sprintf(char * buf, const char *fmt, ...);
+int snprintf(char *buf, size_t size, const char *fmt, ...);
int vsprintf(char *buf, const char *fmt, va_list args);
char *asprintf(const char *fmt, ...);
char *vasprintf(const char *fmt, va_list ap);
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 6008305..26fcaa7 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -547,6 +547,18 @@ int sprintf(char * buf, const char *fmt, ...)
}
EXPORT_SYMBOL(sprintf);
+int snprintf(char * buf, size_t size, const char *fmt, ...)
+{
+ va_list args;
+ int i;
+
+ va_start(args, fmt);
+ i = vsnprintf(buf, size, fmt, args);
+ va_end(args);
+ return i;
+}
+EXPORT_SYMBOL(sprintf);
+
/* Simplified asprintf. */
char *vasprintf(const char *fmt, va_list ap)
{
--
1.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 08/12] echo: add -e option support
2010-03-29 9:36 Patches for next merge window Sascha Hauer
` (6 preceding siblings ...)
2010-03-29 9:36 ` [PATCH 07/12] add snprintf function Sascha Hauer
@ 2010-03-29 9:36 ` Sascha Hauer
2010-03-30 11:45 ` Peter Korsgaard
2010-03-29 9:36 ` [PATCH 09/12] add process_escape_sequence function Sascha Hauer
` (3 subsequent siblings)
11 siblings, 1 reply; 22+ messages in thread
From: Sascha Hauer @ 2010-03-29 9:36 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/echo.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 51 insertions(+), 1 deletions(-)
diff --git a/commands/echo.c b/commands/echo.c
index d5640a0..6f4f136 100644
--- a/commands/echo.c
+++ b/commands/echo.c
@@ -26,12 +26,59 @@
#include <fcntl.h>
#include <errno.h>
+static int my_fputs(int fd, const char *s)
+{
+ int c;
+
+ while (*s) {
+ if (*s == '\\') {
+ switch (*(s + 1)) {
+ case 0:
+ return 0;
+ case '\\':
+ c = '\\';
+ break;
+ case 'a':
+ c = '\a';
+ break;
+ case 'b':
+ c = '\b';
+ break;
+ case 'n':
+ c = '\n';
+ break;
+ case 'r':
+ c = '\r';
+ break;
+ case 't':
+ c = '\t';
+ break;
+ case 'f':
+ c = '\f';
+ break;
+ case 'e':
+ c = 0x1b;
+ break;
+ default:
+ fputc(fd, '\\');
+ c = *(s + 1);
+ }
+ s++;
+ fputc(fd, c);
+ } else
+ fputc(fd, *s);
+ s++;
+ }
+ return 0;
+}
+
static int do_echo(struct command *cmdtp, int argc, char *argv[])
{
int i, optind = 1;
int fd = stdout, opt, newline = 1;
char *file = NULL;
int oflags = O_WRONLY | O_CREAT;
+ int (*fputsfunc)(int, const char *) = fputs;
/* We can't use getopt() here because we want to
* echo all things we don't understand.
@@ -62,6 +109,9 @@ static int do_echo(struct command *cmdtp, int argc, char *argv[])
goto no_optarg_out;
optind++;
break;
+ case 'e':
+ fputsfunc = my_fputs;
+ break;
default:
goto exit_parse;
}
@@ -80,7 +130,7 @@ exit_parse:
for (i = optind; i < argc; i++) {
if (i > optind)
fputc(fd, ' ');
- fputs(fd, argv[i]);
+ fputsfunc(fd, argv[i]);
}
if (newline)
--
1.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 08/12] echo: add -e option support
2010-03-29 9:36 ` [PATCH 08/12] echo: add -e option support Sascha Hauer
@ 2010-03-30 11:45 ` Peter Korsgaard
2010-03-30 12:17 ` Sascha Hauer
0 siblings, 1 reply; 22+ messages in thread
From: Peter Korsgaard @ 2010-03-30 11:45 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
>>>>> "Sascha" == Sascha Hauer <s.hauer@pengutronix.de> writes:
Sascha> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Sascha> ---
Sascha> commands/echo.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
Sascha> 1 files changed, 51 insertions(+), 1 deletions(-)
Sascha> diff --git a/commands/echo.c b/commands/echo.c
Sascha> index d5640a0..6f4f136 100644
Sascha> --- a/commands/echo.c
Sascha> +++ b/commands/echo.c
Sascha> @@ -26,12 +26,59 @@
Sascha> #include <fcntl.h>
Sascha> #include <errno.h>
Sascha> +static int my_fputs(int fd, const char *s)
That's not a very descriptive name - What about something like
advanced_fputs, escape_fputs or format_fputs?
--
Bye, Peter Korsgaard
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 08/12] echo: add -e option support
2010-03-30 11:45 ` Peter Korsgaard
@ 2010-03-30 12:17 ` Sascha Hauer
0 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2010-03-30 12:17 UTC (permalink / raw)
To: Peter Korsgaard; +Cc: barebox
On Tue, Mar 30, 2010 at 01:45:33PM +0200, Peter Korsgaard wrote:
> >>>>> "Sascha" == Sascha Hauer <s.hauer@pengutronix.de> writes:
>
> Sascha> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> Sascha> ---
> Sascha> commands/echo.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
> Sascha> 1 files changed, 51 insertions(+), 1 deletions(-)
>
> Sascha> diff --git a/commands/echo.c b/commands/echo.c
> Sascha> index d5640a0..6f4f136 100644
> Sascha> --- a/commands/echo.c
> Sascha> +++ b/commands/echo.c
> Sascha> @@ -26,12 +26,59 @@
> Sascha> #include <fcntl.h>
> Sascha> #include <errno.h>
>
> Sascha> +static int my_fputs(int fd, const char *s)
>
> That's not a very descriptive name - What about something like
> advanced_fputs, escape_fputs or format_fputs?
Uh, I forgot to squash this commit with 10/12. This is what this patch
should look like:
From a9ff0c8e8b720f1902a1e89444072e9469847a2f Mon Sep 17 00:00:00 2001
From: Sascha Hauer <s.hauer@pengutronix.de>
Date: Tue, 23 Mar 2010 15:35:39 +0100
Subject: [PATCH 09/23] echo: add -e option support
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/Kconfig | 6 ++++++
commands/echo.c | 19 +++++++++++++++++--
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/commands/Kconfig b/commands/Kconfig
index 543ee71..0c09f91 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -118,6 +118,12 @@ config CMD_ECHO
default y
prompt "echo"
+config CMD_ECHO_E
+ bool
+ depends on CMD_ECHO
+ select PROCESS_ESCAPE_SEQUENCE
+ prompt "support -e option to echo"
+
endmenu
menu "memory "
diff --git a/commands/echo.c b/commands/echo.c
index d5640a0..dfa14d6 100644
--- a/commands/echo.c
+++ b/commands/echo.c
@@ -25,6 +25,7 @@
#include <fs.h>
#include <fcntl.h>
#include <errno.h>
+#include <libbb.h>
static int do_echo(struct command *cmdtp, int argc, char *argv[])
{
@@ -32,7 +33,10 @@ static int do_echo(struct command *cmdtp, int argc, char *argv[])
int fd = stdout, opt, newline = 1;
char *file = NULL;
int oflags = O_WRONLY | O_CREAT;
-
+#ifdef CONFIG_CMD_ECHO_E
+ char str[CONFIG_CBSIZE];
+ int process_escape = 0;
+#endif
/* We can't use getopt() here because we want to
* echo all things we don't understand.
*/
@@ -62,6 +66,11 @@ static int do_echo(struct command *cmdtp, int argc, char *argv[])
goto no_optarg_out;
optind++;
break;
+#ifdef CONFIG_CMD_ECHO_E
+ case 'e':
+ process_escape = 1;
+ break;
+#endif
default:
goto exit_parse;
}
@@ -80,7 +89,13 @@ exit_parse:
for (i = optind; i < argc; i++) {
if (i > optind)
fputc(fd, ' ');
- fputs(fd, argv[i]);
+#ifdef CONFIG_CMD_ECHO_E
+ if (process_escape) {
+ process_escape_sequence(argv[i], str, CONFIG_CBSIZE);
+ fputs(fd, str);
+ } else
+#endif
+ fputs(fd, argv[i]);
}
if (newline)
--
1.7.0
--
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-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 09/12] add process_escape_sequence function
2010-03-29 9:36 Patches for next merge window Sascha Hauer
` (7 preceding siblings ...)
2010-03-29 9:36 ` [PATCH 08/12] echo: add -e option support Sascha Hauer
@ 2010-03-29 9:36 ` Sascha Hauer
2010-03-29 9:36 ` [PATCH 10/12] echo command: Add -e option Sascha Hauer
` (2 subsequent siblings)
11 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2010-03-29 9:36 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
include/libbb.h | 2 +
lib/Kconfig | 3 ++
lib/Makefile | 1 +
lib/process_escape_sequence.c | 78 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 84 insertions(+), 0 deletions(-)
create mode 100644 lib/process_escape_sequence.c
diff --git a/include/libbb.h b/include/libbb.h
index 735ed21..4151230 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -28,4 +28,6 @@ char * safe_strncpy(char *dst, const char *src, size_t size);
int copy_file(const char *src, const char *dst);
+int process_escape_sequence(const char *source, char *dest, int destlen);
+
#endif /* __LIBBB_H */
diff --git a/lib/Kconfig b/lib/Kconfig
index 90cf784..28c92cd 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -13,5 +13,8 @@ config CRC16
config GENERIC_FIND_NEXT_BIT
def_bool n
+config PROCESS_ESCAPE_SEQUENCE
+ def_bool n
+
source lib/lzo/Kconfig
diff --git a/lib/Makefile b/lib/Makefile
index 74f7d82..817165d 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -30,3 +30,4 @@ obj-y += notifier.o
obj-y += copy_file.o
obj-y += lzo/
obj-y += decompress_unlzo.o
+obj-$(CONFIG_PROCESS_ESCAPE_SEQUENCE) += process_escape_sequence.o
diff --git a/lib/process_escape_sequence.c b/lib/process_escape_sequence.c
new file mode 100644
index 0000000..546edaa
--- /dev/null
+++ b/lib/process_escape_sequence.c
@@ -0,0 +1,78 @@
+/*
+ * process_esacpe_sequence.c
+ *
+ * Copyright (c) 2010 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <common.h>
+#include <fs.h>
+
+int process_escape_sequence(const char *source, char *dest, int destlen)
+{
+ int i = 0;
+
+ while (*source) {
+ if (*source == '\\') {
+ switch (*(source + 1)) {
+ case 0:
+ return 0;
+ case '\\':
+ dest[i++] = '\\';
+ break;
+ case 'a':
+ dest[i++] = '\a';
+ break;
+ case 'b':
+ dest[i++] = '\b';
+ break;
+ case 'n':
+ dest[i++] = '\n';
+ break;
+ case 'r':
+ dest[i++] = '\r';
+ break;
+ case 't':
+ dest[i++] = '\t';
+ break;
+ case 'f':
+ dest[i++] = '\f';
+ break;
+ case 'e':
+ dest[i++] = 0x1b;
+ break;
+ case 'h':
+ i += snprintf(dest + i, destlen - i, "%s", CONFIG_BOARDINFO);
+ break;
+ case 'w':
+ i += snprintf(dest + i, destlen - i, "%s", getcwd());
+ break;
+ default:
+ dest[i++] = '\\';
+ dest[i++] = *(source + 1);
+ }
+ source++;
+ } else
+ dest[i++] = *source;
+ source++;
+ if (!(destlen - i))
+ break;
+ }
+ dest[i] = 0;
+ return 0;
+}
+
--
1.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 10/12] echo command: Add -e option
2010-03-29 9:36 Patches for next merge window Sascha Hauer
` (8 preceding siblings ...)
2010-03-29 9:36 ` [PATCH 09/12] add process_escape_sequence function Sascha Hauer
@ 2010-03-29 9:36 ` Sascha Hauer
2010-03-29 9:36 ` [PATCH 11/12] hush: only remove backslashes introduced from glob Sascha Hauer
2010-03-29 9:36 ` [PATCH 12/12] hush: allow fancy prompts Sascha Hauer
11 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2010-03-29 9:36 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/Kconfig | 6 +++++
commands/echo.c | 65 ++++++++++++-----------------------------------------
2 files changed, 21 insertions(+), 50 deletions(-)
diff --git a/commands/Kconfig b/commands/Kconfig
index 543ee71..0c09f91 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -118,6 +118,12 @@ config CMD_ECHO
default y
prompt "echo"
+config CMD_ECHO_E
+ bool
+ depends on CMD_ECHO
+ select PROCESS_ESCAPE_SEQUENCE
+ prompt "support -e option to echo"
+
endmenu
menu "memory "
diff --git a/commands/echo.c b/commands/echo.c
index 6f4f136..dfa14d6 100644
--- a/commands/echo.c
+++ b/commands/echo.c
@@ -25,52 +25,7 @@
#include <fs.h>
#include <fcntl.h>
#include <errno.h>
-
-static int my_fputs(int fd, const char *s)
-{
- int c;
-
- while (*s) {
- if (*s == '\\') {
- switch (*(s + 1)) {
- case 0:
- return 0;
- case '\\':
- c = '\\';
- break;
- case 'a':
- c = '\a';
- break;
- case 'b':
- c = '\b';
- break;
- case 'n':
- c = '\n';
- break;
- case 'r':
- c = '\r';
- break;
- case 't':
- c = '\t';
- break;
- case 'f':
- c = '\f';
- break;
- case 'e':
- c = 0x1b;
- break;
- default:
- fputc(fd, '\\');
- c = *(s + 1);
- }
- s++;
- fputc(fd, c);
- } else
- fputc(fd, *s);
- s++;
- }
- return 0;
-}
+#include <libbb.h>
static int do_echo(struct command *cmdtp, int argc, char *argv[])
{
@@ -78,8 +33,10 @@ static int do_echo(struct command *cmdtp, int argc, char *argv[])
int fd = stdout, opt, newline = 1;
char *file = NULL;
int oflags = O_WRONLY | O_CREAT;
- int (*fputsfunc)(int, const char *) = fputs;
-
+#ifdef CONFIG_CMD_ECHO_E
+ char str[CONFIG_CBSIZE];
+ int process_escape = 0;
+#endif
/* We can't use getopt() here because we want to
* echo all things we don't understand.
*/
@@ -109,9 +66,11 @@ static int do_echo(struct command *cmdtp, int argc, char *argv[])
goto no_optarg_out;
optind++;
break;
+#ifdef CONFIG_CMD_ECHO_E
case 'e':
- fputsfunc = my_fputs;
+ process_escape = 1;
break;
+#endif
default:
goto exit_parse;
}
@@ -130,7 +89,13 @@ exit_parse:
for (i = optind; i < argc; i++) {
if (i > optind)
fputc(fd, ' ');
- fputsfunc(fd, argv[i]);
+#ifdef CONFIG_CMD_ECHO_E
+ if (process_escape) {
+ process_escape_sequence(argv[i], str, CONFIG_CBSIZE);
+ fputs(fd, str);
+ } else
+#endif
+ fputs(fd, argv[i]);
}
if (newline)
--
1.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 11/12] hush: only remove backslashes introduced from glob
2010-03-29 9:36 Patches for next merge window Sascha Hauer
` (9 preceding siblings ...)
2010-03-29 9:36 ` [PATCH 10/12] echo command: Add -e option Sascha Hauer
@ 2010-03-29 9:36 ` Sascha Hauer
2010-03-29 10:00 ` Sascha Hauer
2010-03-29 9:36 ` [PATCH 12/12] hush: allow fancy prompts Sascha Hauer
11 siblings, 1 reply; 22+ messages in thread
From: Sascha Hauer @ 2010-03-29 9:36 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/hush.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/common/hush.c b/common/hush.c
index 6a8b56b..afa67d1 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -779,8 +779,9 @@ static int globhack(const char *src, int flags, glob_t *pglob)
int cnt=0, pathc;
const char *s;
char *dest;
+
for (cnt=1, s=src; s && *s; s++) {
- if (*s == '\\') s++;
+ if (*s == '\\' && strchr("*[?", *(s + 1))) s++;
cnt++;
}
dest = xmalloc(cnt);
@@ -794,7 +795,7 @@ static int globhack(const char *src, int flags, glob_t *pglob)
pglob->gl_pathv[pathc-1] = dest;
pglob->gl_pathv[pathc] = NULL;
for (s=src; s && *s; s++, dest++) {
- if (*s == '\\') s++;
+ if (*s == '\\' && strchr("*[?", *(s + 1))) s++;
*dest = *s;
}
*dest='\0';
--
1.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 11/12] hush: only remove backslashes introduced from glob
2010-03-29 9:36 ` [PATCH 11/12] hush: only remove backslashes introduced from glob Sascha Hauer
@ 2010-03-29 10:00 ` Sascha Hauer
0 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2010-03-29 10:00 UTC (permalink / raw)
To: barebox
On Mon, Mar 29, 2010 at 11:36:22AM +0200, Sascha Hauer wrote:
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
> common/hush.c | 5 +++--
> 1 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/common/hush.c b/common/hush.c
> index 6a8b56b..afa67d1 100644
> --- a/common/hush.c
> +++ b/common/hush.c
> @@ -779,8 +779,9 @@ static int globhack(const char *src, int flags, glob_t *pglob)
> int cnt=0, pathc;
> const char *s;
> char *dest;
> +
> for (cnt=1, s=src; s && *s; s++) {
> - if (*s == '\\') s++;
> + if (*s == '\\' && strchr("*[?", *(s + 1))) s++;
> cnt++;
> }
> dest = xmalloc(cnt);
> @@ -794,7 +795,7 @@ static int globhack(const char *src, int flags, glob_t *pglob)
> pglob->gl_pathv[pathc-1] = dest;
> pglob->gl_pathv[pathc] = NULL;
> for (s=src; s && *s; s++, dest++) {
> - if (*s == '\\') s++;
> + if (*s == '\\' && strchr("*[?", *(s + 1))) s++;
> *dest = *s;
> }
> *dest='\0';
This patch also fixes a quoting workaround found in many
/env/bin/_update scripts:
if [ \! -e "$part" ]; then
echo "Partition $part does not exist"
exit 1
fi
The backslash is not needed anymore (and in fact now breaks the script)
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-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 12/12] hush: allow fancy prompts
2010-03-29 9:36 Patches for next merge window Sascha Hauer
` (10 preceding siblings ...)
2010-03-29 9:36 ` [PATCH 11/12] hush: only remove backslashes introduced from glob Sascha Hauer
@ 2010-03-29 9:36 ` Sascha Hauer
11 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2010-03-29 9:36 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/Kconfig | 9 +++++++++
common/hush.c | 12 ++++++++----
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/common/Kconfig b/common/Kconfig
index 4c4a627..f514759 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -226,6 +226,15 @@ config PROMPT_HUSH_PS2
prompt "hush PS2"
default "> "
+config HUSH_FANCY_PROMPT
+ bool
+ depends on SHELL_HUSH
+ select PROCESS_ESCAPE_SEQUENCE
+ prompt "allow fancy hush prompts"
+ help
+ Allow to set PS1 from the command line. PS1 can have several escaped commands
+ like \h for CONFIG_BOARDINFO or \w for the current working directory.
+
config CMDLINE_EDITING
bool
prompt "Enable command line editing"
diff --git a/common/hush.c b/common/hush.c
index afa67d1..19e35f5 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -389,15 +389,19 @@ static int static_peek(struct in_str *i)
return *i->p;
}
-
static char *getprompt(void)
{
- static char *prompt;
+ static char prompt[PATH_MAX + 32];
- if (!prompt)
- prompt = xmalloc(PATH_MAX + strlen(CONFIG_PROMPT) + 1);
+#ifdef CONFIG_HUSH_FANCY_PROMPT
+ const char *ps1 = getenv("PS1");
+ if (ps1)
+ process_escape_sequence(ps1, prompt, PATH_MAX + 32);
+ else
+#endif
sprintf(prompt, "%s%s ", CONFIG_PROMPT, getcwd());
+
return prompt;
}
--
1.7.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 22+ messages in thread