From: Heiko Schocher <hs@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] CRAMFS: support cramfs in RAM
Date: Thu, 07 Jan 2010 08:55:54 +0100 [thread overview]
Message-ID: <4B45938A.3050101@denx.de> (raw)
cramfsls and cramfsload are added to the command list.
A cramfs placed at 'cramfs_addr' can the be listed with 'cramfsls' and files
can be loaded with 'cramfsload'. 'cramfs_addr' is an environment variable
specifying the address the cramfs is located.
This works for powerpc and for ARM.
Use CONFIG_CMD_CRAMFS.
Signed-off-by: Andreas Huber <andreas.huber@keymile.com>
Signed-off-by: Heiko Schocher <hs@denx.de>
---
common/Makefile | 1 +
common/cmd_cramfs.c | 216 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 217 insertions(+), 0 deletions(-)
create mode 100644 common/cmd_cramfs.c
diff --git a/common/Makefile b/common/Makefile
index 7784180..038c15c 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -105,6 +105,7 @@ COBJS-$(CONFIG_CMD_IMMAP) += cmd_immap.o
COBJS-$(CONFIG_CMD_IRQ) += cmd_irq.o
COBJS-$(CONFIG_CMD_ITEST) += cmd_itest.o
COBJS-$(CONFIG_CMD_JFFS2) += cmd_jffs2.o
+COBJS-$(CONFIG_CMD_CRAMFS) += cmd_cramfs.o
COBJS-$(CONFIG_CMD_LICENSE) += cmd_license.o
COBJS-y += cmd_load.o
COBJS-$(CONFIG_LOGBUFFER) += cmd_log.o
diff --git a/common/cmd_cramfs.c b/common/cmd_cramfs.c
new file mode 100644
index 0000000..55e2d36
--- /dev/null
+++ b/common/cmd_cramfs.c
@@ -0,0 +1,216 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it 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; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ * based on: cmd_jffs2.c
+ *
+ * Add support for a CRAMFS located in RAM
+ */
+
+
+/*
+ * CRAMFS support
+ */
+#include <common.h>
+#include <command.h>
+#include <malloc.h>
+#include <linux/list.h>
+#include <linux/ctype.h>
+#include <jffs2/jffs2.h>
+#include <jffs2/load_kernel.h>
+#include <cramfs/cramfs_fs.h>
+
+/* enable/disable debugging messages */
+#define DEBUG_CRAMFS
+#undef DEBUG_CRAMFS
+
+#ifdef DEBUG_CRAMFS
+# define DEBUGF(fmt, args...) printf(fmt ,##args)
+#else
+# define DEBUGF(fmt, args...)
+#endif
+
+#ifdef CONFIG_CRAMFS_CMDLINE
+flash_info_t flash_info[1];
+
+#ifndef CONFIG_CMD_JFFS2
+#include <linux/stat.h>
+char *mkmodestr(unsigned long mode, char *str)
+{
+ static const char *l = "xwr";
+ int mask = 1, i;
+ char c;
+
+ switch (mode & S_IFMT) {
+ case S_IFDIR: str[0] = 'd'; break;
+ case S_IFBLK: str[0] = 'b'; break;
+ case S_IFCHR: str[0] = 'c'; break;
+ case S_IFIFO: str[0] = 'f'; break;
+ case S_IFLNK: str[0] = 'l'; break;
+ case S_IFSOCK: str[0] = 's'; break;
+ case S_IFREG: str[0] = '-'; break;
+ default: str[0] = '?';
+ }
+
+ for(i = 0; i < 9; i++) {
+ c = l[i%3];
+ str[9-i] = (mode & mask)?c:'-';
+ mask = mask<<1;
+ }
+
+ if(mode & S_ISUID) str[3] = (mode & S_IXUSR)?'s':'S';
+ if(mode & S_ISGID) str[6] = (mode & S_IXGRP)?'s':'S';
+ if(mode & S_ISVTX) str[9] = (mode & S_IXOTH)?'t':'T';
+ str[10] = '\0';
+ return str;
+}
+#endif /* CONFIG_CMD_JFFS2 */
+
+extern int cramfs_check (struct part_info *info);
+extern int cramfs_load (char *loadoffset, struct part_info *info, char *filename);
+extern int cramfs_ls (struct part_info *info, char *filename);
+extern int cramfs_info (struct part_info *info);
+
+/***************************************************/
+/* U-boot commands */
+/***************************************************/
+
+/**
+ * Routine implementing fsload u-boot command. This routine tries to load
+ * a requested file from cramfs filesystem@location 'cramfsaddr'.
+ * cramfsaddr is an evironment variable.
+ *
+ * @param cmdtp command internal data
+ * @param flag command flag
+ * @param argc number of arguments supplied to the command
+ * @param argv arguments list
+ * @return 0 on success, 1 otherwise
+ */
+int do_cramfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+ char *filename;
+ int size;
+ ulong offset = load_addr;
+
+ struct part_info part;
+ struct mtd_device dev;
+ struct mtdids id;
+
+ ulong addr;
+ addr = simple_strtoul(getenv("cramfsaddr"), NULL, 16);
+
+ /* hack! */
+ /* cramfs_* only supports NOR flash chips */
+ /* fake the device type */
+ id.type = MTD_DEV_TYPE_NOR;
+ id.num = 0;
+ dev.id = &id;
+ part.dev = &dev;
+ /* fake the address offset */
+ part.offset = addr - flash_info[id.num].start[0];
+
+ /* pre-set Boot file name */
+ if ((filename = getenv("bootfile")) == NULL) {
+ filename = "uImage";
+ }
+
+ if (argc == 2) {
+ filename = argv[1];
+ }
+ if (argc == 3) {
+ offset = simple_strtoul(argv[1], NULL, 0);
+ load_addr = offset;
+ filename = argv[2];
+ }
+
+ size = 0;
+ if (cramfs_check(&part))
+ size = cramfs_load ((char *) offset, &part, filename);
+
+ if (size > 0) {
+ char buf[10];
+ printf("### CRAMFS load complete: %d bytes loaded to 0x%lx\n",
+ size, offset);
+ sprintf(buf, "%x", size);
+ setenv("filesize", buf);
+ } else {
+ printf("### CRAMFS LOAD ERROR<%x> for %s!\n", size, filename);
+ }
+
+ return !(size > 0);
+}
+
+/**
+ * Routine implementing u-boot ls command which lists content of a given
+ * directory at location 'cramfsaddr'.
+ * cramfsaddr is an evironment variable.
+ *
+ * @param cmdtp command internal data
+ * @param flag command flag
+ * @param argc number of arguments supplied to the command
+ * @param argv arguments list
+ * @return 0 on success, 1 otherwise
+ */
+int do_cramfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+ char *filename = "/";
+ int ret;
+ struct part_info part;
+ struct mtd_device dev;
+ struct mtdids id;
+
+ ulong addr;
+ addr = simple_strtoul(getenv("cramfsaddr"), NULL, 16);
+
+ /* hack! */
+ /* cramfs_* only supports NOR flash chips */
+ /* fake the device type */
+ id.type = MTD_DEV_TYPE_NOR;
+ id.num = 0;
+ dev.id = &id;
+ part.dev = &dev;
+ /* fake the address offset */
+ part.offset = addr - flash_info[id.num].start[0];
+
+ if (argc == 2)
+ filename = argv[1];
+
+ ret = 0;
+ if (cramfs_check(&part))
+ ret = cramfs_ls (&part, filename);
+
+ return ret ? 0 : 1;
+}
+
+/* command line only */
+
+/***************************************************/
+U_BOOT_CMD(
+ cramfsload, 3, 0, do_cramfs_load,
+ "cramfsload\t- load binary file from a filesystem image",
+ "[ off ] [ filename ]\n"
+ " - load binary file from address 'cramfsaddr'\n"
+ " with offset 'off'\n"
+);
+U_BOOT_CMD(
+ cramfsls, 2, 1, do_cramfs_ls,
+ "cramfsls\t- list files in a directory (default /)",
+ "[ directory ]\n"
+ " - list files in a directory.\n"
+);
+
+#endif /* #ifdef CONFIG_CRAMFS_CMDLINE */
+
+/***************************************************/
--
1.6.2.5
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
next reply other threads:[~2010-01-07 7:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-07 7:55 Heiko Schocher [this message]
2010-01-17 23:44 ` [U-Boot] CRAMFS: support cramfs in RAM Wolfgang Denk
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=4B45938A.3050101@denx.de \
--to=hs@denx.de \
--cc=u-boot@lists.denx.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.