Skip to content

Commit 4649c57

Browse files
New Lantiq tool for reading and writing the EEPROM (#147)
* use vue * update tool for edit the EEPROM for rooted * new tool for read the EEPROM for all lantiq
1 parent f68fb6b commit 4649c57

4 files changed

Lines changed: 1299 additions & 86 deletions

File tree

_ont/ont-huawei-ma5671a-rooted.md

Lines changed: 17 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -12,96 +12,27 @@ layout: default
1212
## Web procedure
1313

1414

15-
1. Get `sfp_a2_info` and paste into the form
16-
17-
<form id="huawei-rooted">
18-
<div class="form-floating mb-3">
19-
<input type="text" class="form-control" placeholder="sfp_a2_info input" name="sfp-a2-info" id="sfp-a2-info" >
20-
<label for="sfp-a2-info">sfp_a2_info input</label>
21-
</div>
22-
<div class="form-floating mb-3">
23-
<input type="text" class="form-control" placeholder="GPON S/N" name="gpon-sn" id="gpon-sn" value="" pattern="([A-Z]{4}[0-9A-Za-z]{8})|([0-9A-F]{8}[0-9A-Za-z]{8})">
24-
<label for="gpon-sn">GPON S/N in format GPON12345678 or 47504F4E12345678, empty for not modify it</label>
25-
</div>
26-
<div class="form-floating mb-3">
27-
<input type="text" class="form-control" placeholder="GPON Ploam Password" name="gpon-password" id="gpon-password" value="" maxlength="22">
28-
<label for="gpon-password">GPON S/N in format 1234567890, 31323334353637383930 or 0x31323334353637383930, empty for not modify it</label>
29-
</div>
30-
<div class="form-floating mb-3">
31-
<input type="text" class="form-control" placeholder="MAC address" name="mac-addr" id="mac-addr" value="" pattern="[0-9A-Fa-f]{2}[:-]?[0-9A-Fa-f]{2}[:-]?[0-9A-Fa-f]{2}[:-]?[0-9A-Fa-f]{2}[:-]?[0-9A-Fa-f]{2}[:-]?[0-9A-Fa-f]{2}">
32-
<label for="mac-addr">MAC Address in format 48:57:02:da:be:ef, 48-57-02-da-be-ef or 485702dabeef, empty for not modify it</label>
33-
</div>
34-
<div class="mb-3">
35-
<input type="submit" class="btn btn-primary" value="Calculate!">
36-
</div>
37-
<div class="form-floating mb-3">
38-
<input readonly class="form-control" type="text" id="result" placeholder="sfp_a2_info result">
39-
<label for="result">sfp_a2_info result</label>
40-
</div>
41-
</form>
42-
<script>
43-
var form = document.getElementById('huawei-rooted');
44-
form.addEventListener('submit',(event) => {
45-
event.preventDefault();
46-
var fomrdata = new FormData(form);
47-
var sfp_a2_info = fomrdata.get('sfp-a2-info');
48-
var sfp_a2_info_arr = sfp_a2_info.split('@');
49-
if(sfp_a2_info_arr.length > 10 && sfp_a2_info_arr[0] === 'begin-base64 644 sfp_a2_info ') {
50-
var gpon_sn = fomrdata.get('gpon-sn');
51-
if(gpon_sn.length == 12) {
52-
var vendor_id = gpon_sn.substring(0, 4);
53-
var progressive = gpon_sn.substring(4);
54-
var vendor_id_hex = ([...vendor_id].map((elem, n) => Number(vendor_id.charCodeAt(n)).toString(16)).join(''));
55-
gpon_sn = vendor_id_hex+progressive;
56-
}
57-
if(gpon_sn.length == 16) {
58-
var hex = base64ToHex(sfp_a2_info_arr[6]);
59-
hex = hex.substring(0,16) + gpon_sn + hex.substring(32);
60-
sfp_a2_info_arr[6] = hexToBase64(hex);
61-
}
62-
var gpon_password = fomrdata.get('gpon-password');
63-
if(gpon_password.length > 0) {
64-
if(gpon_password.length <= 10) {
65-
gpon_password = ([...gpon_password].map((elem, n) => Number(gpon_password.charCodeAt(n)).toString(16)).join(''));
66-
gpon_password += '0'.repeat(20-gpon_password.length);
67-
}
68-
else if(gpon_password.length == 22 && gpon_password.substring(0,2) === '0x') {
69-
gpon_password = gpon_password.substring(3);
70-
}
71-
if(gpon_password.length == 20) {
72-
var hex = base64ToHex(sfp_a2_info_arr[5]);
73-
hex = hex.substring(0,22) + gpon_password + hex.substring(42);
74-
sfp_a2_info_arr[5] = hexToBase64(hex);
75-
}
76-
}
77-
var mac_addr = fomrdata.get('mac-addr');
78-
if(mac_addr.length == 17) {
79-
mac_addr = mac_addr.replace('-','');
80-
mac_addr = mac_addr.replace(':','');
81-
}
82-
if(mac_addr.length == 12) {
83-
var hex = base64ToHex(sfp_a2_info_arr[9]);
84-
hex = hex.substring(0,48) + mac_addr + hex.substring(61);
85-
sfp_a2_info_arr[9] = hexToBase64(hex);
86-
}
87-
document.getElementById('result').value = sfp_a2_info_arr.join('@');
88-
} else {
89-
document.getElementById('result').value = 'sfp_a2_info variable in wrong format!';
90-
}
91-
});
92-
function hexToBase64(hexStr) {
93-
return btoa([...hexStr].reduce((acc, _, i) => acc += !(i - 1 & 1) ? String.fromCharCode(parseInt(hexStr.substring(i - 1, i + 1), 16)) : '', ''));
94-
}
95-
function base64ToHex(base64Value) {
96-
return [...atob(base64Value)].map(c=> c.charCodeAt(0).toString(16).padStart(2,0)).join('');
97-
}
98-
</script>
15+
1. Get `fw_printenv sfp_a2_info` and paste into the form
16+
17+
<div id="app">
18+
<vue-lantiq-eeprom type='eeprom-rooted-edit'></vue-lantiq-eeprom>
19+
</div>
20+
<script src="https://unpkg.com/vue@latest"></script>
21+
<script src="https://cdn.jsdelivr.net/npm/vue3-sfc-loader"></script>
22+
<script src="/assets/js/vue-eeprom.js"></script>
23+
24+
{% include alert.html content="Executing these commands requires a minimum of familiarity with `vim`. If you do not know `vim`, follow the commands precisely." alert="Danger" icon="svg-warning" color="red" %}
9925

10026
{:style="counter-reset:none"}
101-
2. Transfer modified file back into variable `sfp_a2_info`, replace `<output>` with the output of web form.
27+
1. Copy the script's output to the clipboard
28+
1. Run the comman `vim /tmp/sfp_a2.txt` in the stick
29+
1. Press the right mouse button in the terminal or `CTRL`+`V`
30+
1. Press `ESC` command from keyboard
31+
1. Type `:wq`
32+
1. Run:
10233

10334
```shell
104-
fw_setenv sfp_a2_info "<output>"
35+
fw_setenv sfp_a2_info ($cat /tmp/sfp_a2.txt)
10536
```
10637

10738
## Temporary file procedure

_tools/ont-lantiq-print-eeprom.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: Lantiq Print EEPROM
3+
has_children: false
4+
layout: default
5+
---
6+
7+
1. Get `sfp_a0_low_128` or `sfp_a2_info` and paste into the form
8+
9+
10+
<div id="app">
11+
<vue-lantiq-eeprom type='eeprom-print'></vue-lantiq-eeprom>
12+
</div>
13+
<script src="https://unpkg.com/vue@latest"></script>
14+
<script src="https://cdn.jsdelivr.net/npm/vue3-sfc-loader"></script>
15+
<script src="/assets/js/vue-eeprom.js"></script>
16+
17+
{% include alert.html content="For more information, see the SFF-8472 Rev 10.2 specification." alert="Info" icon="svg-info" color="blue" %}

assets/js/vue-eeprom.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const { createApp } = Vue;
2+
const { loadModule } = window['vue3-sfc-loader'];
3+
const options = {
4+
moduleCache: {
5+
vue: Vue,
6+
},
7+
getFile(url) {
8+
return fetch(url).then((resp) =>
9+
resp.ok ? resp.text() : Promise.reject(resp)
10+
);
11+
},
12+
addStyle(styleStr) {
13+
const style = document.createElement('style');
14+
style.textContent = styleStr;
15+
const ref = document.head.getElementsByTagName('style')[0] || null;
16+
document.head.insertBefore(style, ref);
17+
},
18+
log(type, ...args) {
19+
console.log(type, ...args);
20+
},
21+
};
22+
const app = createApp({
23+
components: {
24+
VueLantiqEeprom: Vue.defineAsyncComponent(() =>
25+
loadModule('/assets/js/vue/vue-lantiq-eeprom.vue', options)
26+
),
27+
},
28+
}).mount('#app');

0 commit comments

Comments
 (0)