Community discussions

MikroTik App
 
VFXCode
just joined
Topic Author
Posts: 1
Joined: Tue Jan 27, 2009 3:49 pm

Accessing Hardware info from OpenWRT

Wed May 30, 2012 5:26 pm

Is there any way to access the board information (Specificaly the board serial number) through OpenWRT?
Its obvious RouterOS can get them somehow.


I have found only one way however it is not 100% reliable and doesnt work on board without Serial port.
1) Format flash through the RooterBOOT
2) cat /proc/mtd should have this layout
root@OpenWrt:/tmp# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 0000b000 00001000 "routerboot"
mtd1: 00001000 00001000 "hard_config"
mtd2: 00002000 00001000 "bios"
mtd3: 00001000 00001000 "soft_config"
mtd4: 00040000 00004000 "booter"
mtd5: 005c0000 00004000 "kernel"
mtd6: 03a00000 00004000 "rootfs"
3) Search /dev/mtdblock1 for the serial.
Provided you have the same board and same RooterBOOT version serial should be in the same offset.
 
vldtoma
just joined
Posts: 4
Joined: Fri Sep 23, 2016 3:50 pm

Re: Accessing Hardware info from OpenWRT

Mon Dec 17, 2018 5:26 pm

Did you find a way to get the serial number ?
 
idahorazor
just joined
Posts: 2
Joined: Wed Jan 30, 2013 5:50 am

Re: Accessing Hardware info from OpenWRT

Wed Feb 06, 2019 1:31 am

This is a patch I came up with for OpenWRT

Save the following patch as 951-MIPS-ath79-add-mikrotik-serial.patch
Then copy that file into target/linux/ar71xx/patches-4.14/951-MIPS-ath79-add-mikrotik-serial.patch
Compile OpenWRT
--- a/arch/mips/ath79/mach-rbspi.c
+++ b/arch/mips/ath79/mach-rbspi.c
@@ -690,6 +690,12 @@ static __init const struct rb_info *rbsp
 	if (!info)
 		return NULL;
 
+	/* Set Mikrotik Serial Number */
+	if (info->board_serial) {
+		mips_set_machine_serial(info->board_serial);
+	} else
+		pr_err("Mikrotik serial number not found\n");
+
 	if (info->board_name) {
 		str = "RouterBOARD ";
 		if (strncmp(info->board_name, str, strlen(str))) {
--- a/arch/mips/include/asm/prom.h
+++ b/arch/mips/include/asm/prom.h
@@ -30,5 +30,7 @@ static inline void device_tree_init(void
 
 extern char *mips_get_machine_name(void);
 extern void mips_set_machine_name(const char *name);
+extern char *mips_get_machine_serial(void);
+extern void mips_set_machine_serial(char *serial);
 
 #endif /* __ASM_PROM_H */
--- a/arch/mips/kernel/proc.c
+++ b/arch/mips/kernel/proc.c
@@ -55,6 +55,11 @@ static int show_cpuinfo(struct seq_file
 		if (mips_get_machine_name())
 			seq_printf(m, "machine\t\t\t: %s\n",
 				   mips_get_machine_name());
+
+		/* Show manufacturer serial number */
+		if (mips_get_machine_serial())
+			seq_printf(m, "serial number\t\t: %s\n",
+				mips_get_machine_serial());
 	}
 
 	seq_printf(m, "processor\t\t: %ld\n", n);
--- a/arch/mips/kernel/prom.c
+++ b/arch/mips/kernel/prom.c
@@ -23,6 +23,7 @@
 #include <asm/prom.h>
 
 static char mips_machine_name[64] = "Unknown";
+char *mips_machine_serial = "None";
 
 __init void mips_set_machine_name(const char *name)
 {
@@ -38,6 +39,19 @@ char *mips_get_machine_name(void)
 	return mips_machine_name;
 }
 
+__init void mips_set_machine_serial(char *serial)
+{
+	if (serial == NULL)
+		return;
+
+	mips_machine_serial = serial;
+}
+
+char *mips_get_machine_serial(void)
+{
+	return mips_machine_serial;
+}
+
 #ifdef CONFIG_USE_OF
 void __init early_init_dt_add_memory_arch(u64 base, u64 size)
 {
--- a/arch/mips/ath79/routerboot.h
+++ b/arch/mips/ath79/routerboot.h
@@ -18,6 +18,7 @@ struct rb_info {
 	unsigned int soft_cfg_offs;
 
 	const char *board_name;
+	char *board_serial;
 	u32 hw_options;
 };
 
--- a/arch/mips/ath79/routerboot.c
+++ b/arch/mips/ath79/routerboot.c
@@ -164,6 +164,20 @@ rb_get_board_name(void)
 	return tag;
 }
 
+__init char *
+rb_get_board_serial(void)
+{
+        u16 tag_len;
+        u8 *tag;
+        int err;
+
+        err = rb_find_hard_cfg_tag(RB_ID_SERIAL_NUMBER, &tag, &tag_len);
+        if (err)
+                return NULL;
+
+        return tag;
+}
+
 __init u32
 rb_get_hw_options(void)
 {
@@ -295,6 +309,7 @@ rb_init_info(void *data, unsigned int si
 		return NULL;
 
 	rb_info.board_name = rb_get_board_name();
+	rb_info.board_serial = rb_get_board_serial();
 	rb_info.hw_options = rb_get_hw_options();
 
 	return &rb_info;
This patch will expose the serial number in /proc/cpuinfo
root@OpenWRT:/# cat /proc/cpuinfo
system type             : Qualcomm Atheros QCA9558 ver 1 rev 0
machine                 : MikroTik RouterBOARD 962UiGS-5HacT2HnT
serial number           : 6DEC05469E1F
processor               : 0
cpu model               : MIPS 74Kc V5.0
BogoMIPS                : 358.80
wait instruction        : yes
microsecond timers      : yes
tlb_entries             : 32
extra interrupt vector  : yes
hardware watchpoint     : yes, count: 4, address/irw mask: [0x0ffc, 0x0ffc, 0x0ffb, 0x0ffb]
isa                     : mips1 mips2 mips32r1 mips32r2
ASEs implemented        : mips16 dsp dsp2
Options implemented     : tlb 4kex 4k_cache prefetch mcheck ejtag llsc dc_aliases perf_cntr_intr_bit cdmm nan_legacy nan_2008 contextconfig perf
shadow register sets    : 1
kscratch registers      : 0
package                 : 0
core                    : 0
VCED exceptions         : not available
VCEI exceptions         : not available
Hope this helps!
 
vldtoma
just joined
Posts: 4
Joined: Fri Sep 23, 2016 3:50 pm

Re: Accessing Hardware info from OpenWRT

Wed Feb 06, 2019 2:04 pm

I used your patch but it doesn't work, I have the serial number field in the /proc/cpuinfo file but it shows none :
system type		: Atheros AR9344 rev 3
machine			: MikroTik RouterBOARD 951Ui-2HnD
serial number		: None
processor		: 0
cpu model		: MIPS 74Kc V4.12
BogoMIPS		: 299.82
wait instruction	: yes
microsecond timers	: yes
tlb_entries		: 32
extra interrupt vector	: yes
hardware watchpoint	: yes, count: 4, address/irw mask: [0x0ffc, 0x0ffc, 0x0ffb, 0x0ffb]
isa			: mips1 mips2 mips32r1 mips32r2
ASEs implemented	: mips16 dsp dsp2
shadow register sets	: 1
kscratch registers	: 0
package			: 0
core			: 0
VCED exceptions		: not available
VCEI exceptions		: not available
Any advice? Thank you.
 
idahorazor
just joined
Posts: 2
Joined: Wed Jan 30, 2013 5:50 am

Re: Accessing Hardware info from OpenWRT

Wed Feb 06, 2019 11:50 pm

You are running the Mikrotik RouterBOARD 951 ( mach-rb95x.c ), while I only patched ( mach-rbspi.c )
I'm using the rb-hap series.

You will want to add the following code snippet to mach-rb95x.c inside of the rb95x_setup(void) function:
	/* Set Mikrotik Serial Number */
        if (info->board_serial) {
                mips_set_machine_serial(info->board_serial);
        } else
                pr_err("Mikrotik serial number not found\n");
It should look something like this:
static int __init rb95x_setup(void)
{
        const struct rb_info *info;

        info = rb_init_info((void *)(KSEG1ADDR(AR71XX_SPI_BASE)), 0x10000);
        if (!info)
                return -EINVAL;
                
	/* Set Mikrotik Serial Number */
        if (info->board_serial) {
                mips_set_machine_serial(info->board_serial);
        } else
                pr_err("Mikrotik serial number not found\n");

        rb95x_nand_init();

        return 0;
}
 
vldtoma
just joined
Posts: 4
Joined: Fri Sep 23, 2016 3:50 pm

Re: Accessing Hardware info from OpenWRT

Mon Feb 18, 2019 11:28 am

Thank you for your help, I've edited the patch file that you provided and it works, the serial number is available in cpuinfo.
--- a/arch/mips/ath79/mach-rb95x.c
+++ b/arch/mips/ath79/mach-rb95x.c
@@ -11,7 +11,7 @@
  */

 #define pr_fmt(fmt) "rb95x: " fmt
-
+#include <asm/prom.h>
 #include <linux/version.h>
 #include <linux/phy.h>
 #include <linux/delay.h>
@@ -251,11 +251,17 @@ static int __init rb95x_setup(void)
 {
 	const struct rb_info *info;
 
 	info = rb_init_info((void *)(KSEG1ADDR(AR71XX_SPI_BASE)), 0x10000);
 	if (!info)
 		return -EINVAL;
+	/* Set Mikrotik Serial Number */
+	if (info->board_serial) {
+		mips_set_machine_serial(info->board_serial);
+	} else
+		pr_err("Mikrotik serial number not found\n");
+
 
 	rb95x_nand_init();
 
 	return 0;
 }
--- a/arch/mips/include/asm/prom.h
+++ b/arch/mips/include/asm/prom.h
@@ -30,5 +30,7 @@ static inline void device_tree_init(void
 
 extern char *mips_get_machine_name(void);
 extern void mips_set_machine_name(const char *name);
+extern char *mips_get_machine_serial(void);
+extern void mips_set_machine_serial(char *serial);
 
 #endif /* __ASM_PROM_H */
--- a/arch/mips/kernel/proc.c
+++ b/arch/mips/kernel/proc.c
@@ -55,6 +55,11 @@ static int show_cpuinfo(struct seq_file
 		if (mips_get_machine_name())
 			seq_printf(m, "machine\t\t\t: %s\n",
 				   mips_get_machine_name());
+
+		/* Show manufacturer serial number */
+		if (mips_get_machine_serial())
+			seq_printf(m, "serial number\t\t: %s\n",
+				mips_get_machine_serial());
 	}
 
 	seq_printf(m, "processor\t\t: %ld\n", n);
--- a/arch/mips/kernel/prom.c
+++ b/arch/mips/kernel/prom.c
@@ -23,6 +23,7 @@
 #include <asm/prom.h>
 
 static char mips_machine_name[64] = "Unknown";
+char *mips_machine_serial = "None";
 
 __init void mips_set_machine_name(const char *name)
 {
@@ -38,6 +39,19 @@ char *mips_get_machine_name(void)
 	return mips_machine_name;
 }
 
+__init void mips_set_machine_serial(char *serial)
+{
+	if (serial == NULL)
+		return;
+
+	mips_machine_serial = serial;
+}
+
+char *mips_get_machine_serial(void)
+{
+	return mips_machine_serial;
+}
+
 #ifdef CONFIG_USE_OF
 void __init early_init_dt_add_memory_arch(u64 base, u64 size)
 {
--- a/arch/mips/ath79/routerboot.h
+++ b/arch/mips/ath79/routerboot.h
@@ -18,6 +18,7 @@ struct rb_info {
 	unsigned int soft_cfg_offs;
 
 	const char *board_name;
+	char *board_serial;
 	u32 hw_options;
 };
 
--- a/arch/mips/ath79/routerboot.c
+++ b/arch/mips/ath79/routerboot.c
@@ -164,6 +164,20 @@ rb_get_board_name(void)
 	return tag;
 }
 
+__init char *
+rb_get_board_serial(void)
+{
+        u16 tag_len;
+        u8 *tag;
+        int err;
+
+        err = rb_find_hard_cfg_tag(RB_ID_SERIAL_NUMBER, &tag, &tag_len);
+        if (err)
+                return NULL;
+
+        return tag;
+}
+
 __init u32
 rb_get_hw_options(void)
 {
@@ -295,6 +309,7 @@ rb_init_info(void *data, unsigned int si
 		return NULL;
 
 	rb_info.board_name = rb_get_board_name();
+	rb_info.board_serial = rb_get_board_serial();
 	rb_info.hw_options = rb_get_hw_options();
 
 	return &rb_info;

Who is online

Users browsing this forum: No registered users and 56 guests