Skip to contentSkip to conversation

: redundand copy of the environment data on 32bit flash chips

U-Boot-Users Bogdan Woldert-Jokisz 1 participant 1 message Apr 3, 2003

lore
Share & tools
lore
#0 lore raw

hi

I use a board with a 32bit flash chip with u-boot-0.2.0. It works fine.

I need the redundant copy of the environment data and there is a problem.

The command saveenv writes correctly the environment data into the defined sector of the flash, but can't deactivate/activate one of the environment sectors if it's not empty.

I find out: the function write_word in board/walnut405/flash.c returns code 2 (Flash not erased) from the following statement:

        ...
        /* Check if Flash is (sufficiently) erased */
        if ((*((volatile FLASH_WORD_SIZE *) dest) &
            (FLASH_WORD_SIZE) data) != (FLASH_WORD_SIZE) data)

                return (2);
        }

        for (i = 0; i < 4 / sizeof (FLASH_WORD_SIZE); i++) {
                int flag;

                /* Disable interrupts which might cause a timeout here */
                flag = disable_interrupts ();
                ...

I thing it should be to:

        ...
        /* Check if Flash is (sufficiently) erased */
/*        if ((*((volatile FLASH_WORD_SIZE *) dest) &
            (FLASH_WORD_SIZE) data) != (FLASH_WORD_SIZE) data)

                return (2);
        } */

        for (i = 0; i < 4 / sizeof (FLASH_WORD_SIZE); i++) {
                int flag;

                /* Check if Flash is (sufficiently) erased */
                if ( ( dest2[i] & data2[i] ) != data2[i] )

                        return (2);
                }

                /* Disable interrupts which might cause a timeout here */
                flag = disable_interrupts ();
                ...

This change works on my board (self-development) fine.

Reason (only in german, sorry):

Mit der If-Anweisung moechte man sicherstellen, dass nicht versucht wird ein 0-Bit mit einem 1-Bit zu ueberschreiben. FLASH_WORD_SIZE ist auf unsigned short definiert. Die Adressierung des Flashes finget 32Bit-weise statt, d.h. dest und data sind 32Bit lang.

Falls beim savenv einer der Sektoren aktiviert oder deaktiviert werden soll, dann unterscheiden sich dest und data lediglich in dem 17-ten Bit (das Flag).

"*((volatile FLASH_WORD_SIZE *) dest)" liefert die zwei Byte aus dem Flash, die ueberschreiben werden sollen; die oberen zwei Bytes der 32Bit. "(FLASH_WORD_SIZE) data" hingegen liefert die unteren zwei Bytes von data. Es muessten aber auch die oberen sein.

Man koennte die If-Anweisung an der Stelle lassen, an der sie stand und nur die Typecasts weglassen, damit die gesammten 32Bit miteinander verglichen werden. Da gibt es noch ein Problem (* auf ulong), dass aber sicherlich loesbar ist. Ich kenne mich damit nicht so gut aus.

Gruesse
Bogdan