mirror of
https://github.com/riptidewave93/UNVR-NAS.git
synced 2025-03-09 15:40:13 +00:00
fix: additional fixups for UNVR/UNVRPro
* Fixup fan control so it works on UNVR * Add LED integration work for UNVR * Rename our mtd-ro kernel module dir * Fixup shortnames in ubnteeprom
This commit is contained in:
parent
5962f1ea30
commit
58ce1fb99f
10 changed files with 35 additions and 32 deletions
1
tools/ubnt-mtd-lock/Kbuild
Normal file
1
tools/ubnt-mtd-lock/Kbuild
Normal file
|
@ -0,0 +1 @@
|
|||
obj-m := ubnt-mtd-lock.o
|
11
tools/ubnt-mtd-lock/README.md
Normal file
11
tools/ubnt-mtd-lock/README.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
# ubnt-mtd-lock
|
||||
|
||||
A stupid basic kernel module to ensure we set /dev/mtd* as RO (fully) in our firmware. This is done to prevent users/bad actors from wiping your bootloader/Unifi EEPROM, which are required for your device to function!
|
||||
|
||||
## Building
|
||||
|
||||
make -C ${kernel_source_dir} M=$PWD
|
||||
|
||||
## License
|
||||
|
||||
This code is licensed under the GNU General Public License, version 2. A copy of said license can be found at [https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html#SEC1](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html#SEC1)
|
78
tools/ubnt-mtd-lock/ubnt-mtd-lock.c
Normal file
78
tools/ubnt-mtd-lock/ubnt-mtd-lock.c
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (C) 2024 Chris Blake <chrisrblake93@gmail.com>
|
||||
*
|
||||
* Inspired by mtd-rw: https://github.com/jclehner/mtd-rw/tree/master
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; version 2 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/mtd/mtd.h>
|
||||
#include <linux/err.h>
|
||||
|
||||
#ifndef MODULE
|
||||
#error "uvnt-mtd-lock must be compiled as a module."
|
||||
#endif
|
||||
|
||||
#define MOD_INFO KERN_INFO "ubnt-mtd-lock: "
|
||||
#define MOD_ERR KERN_ERR "ubnt-mtd-lock: "
|
||||
|
||||
static int set_readonly(unsigned n)
|
||||
{
|
||||
struct mtd_info *mtd = get_mtd_device(NULL, n);
|
||||
int err;
|
||||
|
||||
if (IS_ERR(mtd)) {
|
||||
if (PTR_ERR(mtd) != -ENODEV) {
|
||||
printk(MOD_ERR "error probing mtd%d %ld\n", n, PTR_ERR(mtd));
|
||||
}
|
||||
return PTR_ERR(mtd);
|
||||
}
|
||||
|
||||
err = -EEXIST;
|
||||
|
||||
if (mtd->flags & MTD_WRITEABLE) {
|
||||
printk(MOD_INFO "setting mtd%d \"%s\" readonly\n", n, mtd->name);
|
||||
mtd->flags &= ~MTD_WRITEABLE;
|
||||
err = 0;
|
||||
}
|
||||
|
||||
put_mtd_device(mtd);
|
||||
return err;
|
||||
}
|
||||
|
||||
int ubnt_mtd_lock_init(void)
|
||||
{
|
||||
int i, err;
|
||||
|
||||
/* For all MTD partitions, go RO. Assume <15 for UNVR/UNVRPRO, as UNVR OG has 10 */
|
||||
for (i = 0; i < 15; ++i) {
|
||||
err = set_readonly(i);
|
||||
if (err == -ENODEV) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ubnt_mtd_lock_exit(void)
|
||||
{
|
||||
/* Do nothing, we wanna keep mtd locked!!! */
|
||||
}
|
||||
|
||||
module_init(ubnt_mtd_lock_init);
|
||||
module_exit(ubnt_mtd_lock_exit);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("Chris Blake <chrisrblake93@gmail.com>");
|
||||
MODULE_DESCRIPTION("Unifi UNVR/UNVRPRO driver to force MTD partitions RO");
|
||||
MODULE_VERSION("1");
|
Loading…
Add table
Add a link
Reference in a new issue