Machine hangs when writing in battery backed SRAM

From: Fabio Garufi (fgarufi_at_elesia.it)
Date: 03/31/04


Date: Wed, 31 Mar 2004 11:18:55 +0200

Hi all,
    I have a pentium single board computer running a 2.2.12-1 Linux kernel.
It maps a 512 kB battery backed SDRAM into the "memory hole" between 15 and
16 MB. The memroy hole can be "opened" by writing into the register 68 of
82443BX Host to PCI controller.
It happens that, randomly, if I write more than a few tenths of bytes into
this area, through the /dev/mem device, the machine hangs and does not write
anything. Sometimes, instead,all goes smooth. In reading everyting works
perfectly.
Normally the system runs with the hole closed. When I need, I open the hole
raising a bit in the register 68 of 82443BX. When everything goes fine, I
can check that the contents of memory hole are right also after a reboot, as
expected.
I modified the /usr/src/linux/arch/i386/mm/init.c file in order to reserve
the memory from 15 to 16 MB as follows:

--- linux-2.2.12.orig/arch/i386/mm/init.c Fri Mar 29 13:44:24 2002
+++ linux-2.2.12/arch/i386/mm/init.c Fri Mar 29 13:52:49 2002
@@ -413,8 +413,6 @@
        start_low_mem += PAGE_SIZE; /* 32bit
startup
 code */
        start_low_mem = smp_alloc_memory(start_low_mem); /* AP
processor
stacks */
 #endif
- start_mem = PAGE_ALIGN(start_mem);
-
        /*
         * IBM messed up *AGAIN* in their thinkpad: 0xA0000 -> 0x9F000.
         * They seem to have done something stupid with the floppy
@@ -425,10 +423,10 @@
                start_low_mem += PAGE_SIZE;
        }

- while (start_mem < end_mem) {
- clear_bit(PG_reserved, &mem_map[MAP_NR(start_mem)].flags);
- start_mem += PAGE_SIZE;
- }
+ for (tmp = PAGE_ALIGN(start_mem) ; tmp < end_mem ; tmp += PAGE_SIZE)
+ if (tmp < PAGE_OFFSET + (15 << 20) || tmp >= PAGE_OFFSET +
(16 << 20))
+ clear_bit(PG_reserved, &mem_map[MAP_NR(tmp)].flags);
+
        for (tmp = PAGE_OFFSET ; tmp < end_mem ; tmp += PAGE_SIZE) {
                if (tmp >= MAX_DMA_ADDRESS)
                        clear_bit(PG_DMA, &mem_map[MAP_NR(tmp)].flags);

To write into memory I simply:

offs = 0xF00008; //leave a byte for security
fdw = open ("/dev/mem", O_RDWR|O_SYNC);
  if(fdw < 0)
    {
        perror("open write:");
        return -1;
    }
  if(lseek(fdw, (off_t)offs, SEEK_SET) <0)
    {
        perror("lseek 3:");
        close(fdw);
        return -1;
    }
  //write file in memory
    for (i = 0; i< (n/4)+1; i++)
    {
        int j=0;
        fprintf(stderr,"."); fflush(stderr);
        if( (j = write(fdw, &buffer[i], sizeof(u_long))) < sizeof(u_long))
            {
                perror("write in mem\n");
                close(fdw);
                return -1;
            }
        }
   close(fdw);

This program always ends with success, and a check within it ensures that
the what written in memory is correct. Anyway when closing the hole, the
machine often hangs and, in this case, at the next reboot, the Battery
Backed SRAM appears not to be written.

Any help appreciated.

--------------------------
** Dr. Fabio Garufi
** Software Manager
**
** ELE.SI.A. S.r.l.
** ISO 9001 CERTIFIED
** Tel. +39.0774.3653.227 / Fax +39.0774.3653.300
** http://www.elesia.it
------------------------------------------------------------------------



Relevant Pages

  • Machine hangs when writing in battery backed SRAM
    ... It maps a 512 kB battery backed SDRAM into the "memory hole" between 15 and ... can check that the contents of memory hole are right also after a reboot, ...
    (comp.os.linux.embedded)
  • Machine hangs when writing in battery backed SRAM
    ... It maps a 512 kB battery backed SDRAM into the "memory hole" between 15 and ... can check that the contents of memory hole are right also after a reboot, ...
    (comp.os.linux.development.system)
  • Machine hangs when writing in battery backed SRAM
    ... It maps a 512 kB battery backed SDRAM into the "memory hole" between 15 and ... can check that the contents of memory hole are right also after a reboot, ...
    (comp.os.linux.development.apps)
  • Re: Rema patch fun
    ... I wrap the tube around my left forefinger, with the hole directly ... you can look at the glue smear and see its center. ... Note that memory is involved here too- a memory system called ... approximately the diameter of the patch centered on the hole, ...
    (rec.bicycles.tech)
  • Re: Rema patch fun
    ... I wrap the tube around my left forefinger, with the hole directly ... you can look at the glue smear and see its center. ... Note that memory is involved here too- a memory system called ... approximately the diameter of the patch centered on the hole, ...
    (rec.bicycles.tech)