From: Gaurav Singh <gausinghnsit@gmail.com>
To: Juergen Beisert <jbe@pengutronix.de>,
Sascha Hauer <s.hauer@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: Failing to load Barebox Environment
Date: Fri, 1 Oct 2010 16:40:25 +0530 [thread overview]
Message-ID: <AANLkTikcCPfcaDAdmLajCY-Y9RQn=9gqz28VfZELfTb8@mail.gmail.com> (raw)
In-Reply-To: <AANLkTikrna=mcBoayqbAezJdvuo1oUhs3XEUrf+W3kpA@mail.gmail.com>
Hi all,
Well turns out my character device inode values were being overwritten
by the NAND buffer contents... this was because I have to change
NAND_MAX_PAGESIZE from 2048 to 4096 ! I have a NAND on my board where
Page size is 4096.
It is working fine now - no need for a seperate envfs_nand_load function.
Thanks
Regards
Gaurav
On Thu, Sep 30, 2010 at 12:09 PM, Gaurav Singh <gausinghnsit@gmail.com> wrote:
> Hi Sascha, Juergen,
> I did a rather crude workaround for this. Copied the NAND partition
> containing the environment from NAND on startup into a file using
> run_command.
> run_command("cp /dev/env0 /env_temp",0);
> then
> envfs_load("/env_temp", "/env")
>
> This is working fine.
> I think - overall the enfs_load logic has to be tweaked for NAND devices.
>
> Now I wrote a new enfs_nand_load function - This basically reads a
> Page of NAND (which works fine if my env file is less than 4096 :))
> into the buffer and manipulates it to prepare the Environment
> correctly. So basically we can read the entire environment partition
> from NAND in one go and then manipulate it to prepare the env in RAM.
>
> int envfs_nand_load(char *filename, char *dir)
> {
> struct envfs_super* super;
> void *buf = NULL, *buf_free = NULL;
> int envfd;
> int fd, ret = 0;
> char *str, *tmp;
> int namelen_full;
> unsigned long size;
>
> envfd = open(filename, O_RDONLY);
> if (envfd < 0) {
> printf("Open %s %s\n", filename, errno_str());
> return -1;
> }
> /* Reading a Page into Buf */
> size = ENVFS_32(4096);
> buf = xzalloc(size);
> buf_free = buf;
> printf("1\n");
> ret = read(envfd, buf, size);
> if (ret < size) {
> perror("read");
> ret = errno;
> goto out;
> }
>
> super = (struct envfs_super *)buf;
>
> if ( ENVFS_32(super->magic) != ENVFS_MAGIC) {
> printf("envfs: wrong magic on %s\n", filename);
> ret = -EIO;
> goto out;
> }
>
> if (crc32(0, (unsigned char *)super, sizeof(struct envfs_super) - 4)
> != ENVFS_32(super->sb_crc)) {
> printf("wrong crc on env superblock\n");
> ret = -EIO;
> goto out;
> }
>
> void *buf2;
> size = ENVFS_32(super->size);
> /* Rest on ENV except Superblock to be kept in buf2 */
> buf2 = (void *)((char *)buf + sizeof(struct envfs_super));
>
> if (crc32(0, (unsigned char *)buf2, size)
> != ENVFS_32(super->crc)) {
> printf("wrong crc on env\n");
> ret = -EIO;
> goto out;
> }
>
> while (size) {
> struct envfs_inode *inode;
> uint32_t inode_size, inode_namelen;
>
> inode = (struct envfs_inode *)buf2;
>
> if (ENVFS_32(inode->magic) != ENVFS_INODE_MAGIC) {
> printf("envfs: wrong magic on %s\n", filename);
> ret = -EIO;
> goto out;
> }
> inode_size = ENVFS_32(inode->size);
> inode_namelen = ENVFS_32(inode->namelen);
>
> debug("loading %s size %d namelen %d\n", inode->data,
> inode_size, inode_namelen);
>
> str = concat_path_file(dir, inode->data);
> tmp = strdup(str);
> make_directory(dirname(tmp));
> free(tmp);
>
> fd = open(str, O_WRONLY | O_CREAT | O_TRUNC, 0644);
> free(str);
> if (fd < 0) {
> printf("Open %s\n", errno_str());
> ret = fd;
> goto out;
> }
>
> namelen_full = PAD4(inode_namelen);
> ret = write(fd, buf2 + namelen_full + sizeof(struct
> envfs_inode),
> inode_size);
> if (ret < inode_size) {
> perror("write");
> ret = errno;
> close(fd);
> goto out;
> }
>
> close(fd);
>
> buf2 += PAD4(inode_namelen) + PAD4(inode_size) +
> sizeof(struct envfs_inode);
> size -= PAD4(inode_namelen) + PAD4(inode_size) +
> sizeof(struct envfs_inode);
> }
>
> ret = 0;
> out:
> close(envfd);
> if (buf_free)
> free(buf_free);
> return ret;
> }
>
>
>
>
> On Wed, Sep 29, 2010 at 2:53 PM, Juergen Beisert <jbe@pengutronix.de> wrote:
>> Juergen Beisert wrote:
>>> Just a note:
>>>
>>> You configure:
>>> > >> devfs_add_partition("nand0", 0x00000, 0x200000, PARTITION_FIXED,
>>> > >> "self_raw"); dev_add_bb_dev("self_raw", "self0");
>>> > >> devfs_add_partition("nand0", 0x200000, 0x200000, PARTITION_FIXED,
>>> > >> "env_raw"); dev_add_bb_dev("env_raw", "env0");
>>>
>>> And then:
>>> > EVB2065> addpart /dev/nand0 4M(barebox)ro,2M(kernel)ro,-(root)
>>>
>>> Both must match!
>>>
>>> Try instead:
>>>
>>> EVB2065> addpart /dev/nand0 256k(barebox)ro,256k(env),2M(kernel)ro,-(root)
>>>
>>> jbe
>>
>> Ups, sorry: 0x200000 != 256k (didn't count the '0' right...)
>>
>> EVB2065> addpart /dev/nand0 2M(barebox)ro,2M(env),2M(kernel)ro,-(root)
>>
>> jbe
>>
>> --
>> Pengutronix e.K. | Juergen Beisert |
>> Linux Solutions for Science and Industry | Phone: +49-8766-939 228 |
>> Vertretung Sued/Muenchen, Germany | Fax: +49-5121-206917-5555 |
>> Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de/ |
>>
>
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
prev parent reply other threads:[~2010-10-01 11:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-29 6:50 Gaurav Singh
2010-09-29 7:29 ` Juergen Beisert
2010-09-29 7:48 ` Sascha Hauer
2010-09-29 9:01 ` Gaurav Singh
2010-09-29 9:08 ` Juergen Beisert
2010-09-29 9:14 ` Gaurav Singh
2010-09-29 9:23 ` Juergen Beisert
2010-09-29 10:03 ` Gaurav Singh
2010-09-29 10:08 ` Gaurav Singh
2010-09-30 6:39 ` Gaurav Singh
2010-10-01 11:10 ` Gaurav Singh [this message]
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='AANLkTikcCPfcaDAdmLajCY-Y9RQn=9gqz28VfZELfTb8@mail.gmail.com' \
--to=gausinghnsit@gmail.com \
--cc=barebox@lists.infradead.org \
--cc=jbe@pengutronix.de \
--cc=s.hauer@pengutronix.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox