-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.c
92 lines (77 loc) · 2.64 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* LICENSE PLACEHOLDER
*
* @file main.c
* @package OpenPST Extras - QFPROM Kernel Module
* @brief This linux kernel module allows you to read/write QFPROM rows
* where permission is granted. Optionally can run as a tcp
* server so you can call to it from outside of kernel space.
* @see client.py for connecting to the server
*
* @author Gassan Idriss <[email protected]>
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include "qfprom.h"
#include "server.h"
#include "debug.h"
typedef struct qfprom_read_operation_entry_s {
char name[75];
uint32_t address;
bool corrected;
} qfprom_read_operation_entry_t;
typedef struct qfprom_write_operation_entry_s {
char name[75];
uint32_t address;
uint32_t lsb;
uint32_t msb;
uint32_t bus_clk_khz;
} qfprom_write_operation_entry_t;
static short int start_tcp = 0;
static qfprom_read_operation_entry_t read_rows_table[] = {
// Enter the rows you wish to add to the read list
// name address corrected
//{ "Name", 0x80000000, 0x00000000 }
};
static qfprom_write_operation_entry_t write_rows_table[] = {
// Enter the rows you wish to add to the write list
// name address lsb msb bus_clk_khz
//{ "Name", 0x80000000, 0x00000000, 0x00000000, 0x00000000 },
//{ "Test", 0xFC4B80B8, 0x00000000, 0x00000000, 0x00000000}
};
static int __init tz_qfprom_init(void)
{
int i;
int read_count = sizeof(read_rows_table)/sizeof(qfprom_read_operation_entry_t);
int write_count = sizeof(write_rows_table)/sizeof(qfprom_write_operation_entry_t);
scm_qfprom_read_row_data_t read_row_data = {};
scm_qfprom_write_row_data_t write_row_data = {};
if (start_tcp > 0) {
tcp_server_start(start_tcp);
}
if (sizeof(read_rows_table) > 0) {
for (i=0; i < read_count; i++) {
log("%s - 0x%08X - %d\n", read_rows_table[i].name, read_rows_table[i].address, read_rows_table[i].corrected);
tz_qfprom_read_row(read_rows_table[i].address, (read_rows_table[i].corrected ? 0x01 : 0x00), &read_row_data);
}
}
if (sizeof(write_rows_table) > 0) {
for (i=0; i < write_count; i++) {
tz_qfprom_write_row(write_rows_table[i].address, write_rows_table[i].lsb, write_rows_table[i].msb, write_rows_table[i].bus_clk_khz, &write_row_data);
}
}
return 0;
}
static void __exit tz_qfprom_exit(void)
{
if (start_tcp > 0) {
tcp_server_shutdown();
}
}
module_init(tz_qfprom_init);
module_exit(tz_qfprom_exit);
MODULE_DESCRIPTION("QFPROM");
MODULE_AUTHOR("Gassan Idriss <[email protected]>");
MODULE_LICENSE("GPL");
module_param(start_tcp, short, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
MODULE_PARM_DESC(start_tcp, "Set to port you wish to enable the tcp server on. By default this is not enabled.");