Last active
December 22, 2015 03:49
-
-
Save thotypous/6413327 to your computer and use it in GitHub Desktop.
last_FL_duty query testing for Kobo Aura HD with kernel 2.6.35.3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local ffi = require("ffi") | |
| local C = ffi.C | |
| ffi.cdef[[ | |
| static const int O_RDONLY = 0; | |
| static const int SEEK_SET = 0; | |
| int open(const char *, int, ...); | |
| int close(int); | |
| long int lseek(int, long int, int) __attribute__((__nothrow__, __leaf__)); | |
| int read(int, void *, unsigned int); | |
| ]] | |
| function getLastFLDuty() | |
| local phys_start, value | |
| local var_addr = 0x803b8b58 | |
| local page_offset = 0x80000000 | |
| for line in io.lines("/proc/iomem") do | |
| phys_start = line:match("^(%x+)-%x+ : System RAM") | |
| if phys_start then | |
| phys_start = tonumber(phys_start, 16) | |
| break | |
| end | |
| end | |
| if var_addr and page_offset and phys_start then | |
| local data = ffi.new("int[1]") | |
| local fd = C.open("/dev/mem", C.O_RDONLY) | |
| C.lseek(fd, var_addr + phys_start - page_offset, C.SEEK_SET) | |
| if C.read(fd, data, ffi.sizeof(data)) ~= -1 then | |
| value = data[0] | |
| end | |
| C.close(fd) | |
| end | |
| return value | |
| end | |
| print(bit.tohex(getLastFLDuty())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment