Package: powerpc-utils
Version: 1.1.3-16
Tags: patch

Hi,

nvsetenv and nvsetvol can write to the nvram. The current generic_nvram
driver (2.6.12) has no special close function. The pmac_nvram driver can
only read or write whole nvram banks, so it allocates a ram buffer for
them.

This leads to the effect that the updated values can get lost, as
the changes are not written back to the physical nvram (happens e.g. on
an iBook G4)

The enclosed patch works around this problem from userspace by calling
the available ioctl for syncing the nvram explicitly.

Bye,

Joerg


--- nvsetenv.c.orig     2005-08-06 19:20:54.000000000 +0200
+++ nvsetenv.c  2005-08-06 19:31:54.000000000 +0200
@@ -14,6 +14,12 @@
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <sys/ioctl.h>
+#include <asm/nvram.h>
+#ifndef IOC_NVRAM_SYNC
+#warning IOC_NVRAM_SYNC undefined -- update your headers
+#define IOC_NVRAM_SYNC _IO('p', 0x43)
+#endif
 
 #define NVSTART                0x1800  // Start of the NVRam OF partition
 #define NVSIZE         0x800   // Size of of the NVRam
@@ -325,6 +331,7 @@
     else
        nvOld(ac, av, i, nvfd);
     
+    (void) ioctl(nvfd, IOC_NVRAM_SYNC);
     (void) close(nvfd);
     exit(EXIT_SUCCESS);
 }
--- nvsetvol.c.orig     2005-08-06 19:21:09.000000000 +0200
+++ nvsetvol.c  2005-08-06 19:33:23.000000000 +0200
@@ -15,6 +15,12 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <sys/ioctl.h>
+#include <asm/nvram.h>
+#ifndef IOC_NVRAM_SYNC
+#warning IOC_NVRAM_SYNC undefined -- update your headers
+#define IOC_NVRAM_SYNC _IO('p', 0x43)
+#endif
 
 typedef struct {
      unsigned char sig;
@@ -99,6 +105,7 @@
               die("error writing /dev/nvram");
          printf("new volume is %d\n", buf[VOLADDR]);
      }
+     ioctl(fd, IOC_NVRAM_SYNC);
      close(fd);
      return 0;
 }
--- nvvideo.c.orig      2005-08-06 19:21:46.000000000 +0200
+++ nvvideo.c   2005-08-06 19:38:25.000000000 +0200
@@ -3,6 +3,12 @@
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <sys/ioctl.h>
+#include <asm/nvram.h>
+#ifndef IOC_NVRAM_SYNC
+#warning IOC_NVRAM_SYNC undefined -- update your headers
+#define IOC_NVRAM_SYNC _IO('p', 0x43)
+#endif
 
 #define NVSTART        0x140f
 #define NVSIZE 0x2
@@ -96,6 +102,7 @@
        break;
     }
 
+    (void) ioctl(nvfd, IOC_NVRAM_SYNC);
     (void) close(nvfd);
     exit(EXIT_SUCCESS);
 }

Attachment: signature.asc
Description: Digital signature

Reply via email to