|
1 | 1 | # Copyright (c) Quectel Wireless Solution, Co., Ltd.All Rights Reserved. |
2 | | -# |
| 2 | +# |
3 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
4 | 4 | # you may not use this file except in compliance with the License. |
5 | 5 | # You may obtain a copy of the License at |
6 | | -# |
| 6 | +# |
7 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
8 | | -# |
| 8 | +# |
9 | 9 | # Unless required by applicable law or agreed to in writing, software |
10 | 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | 15 | import uos |
16 | 16 | import ujson |
17 | 17 |
|
18 | | -''' |
| 18 | +""" |
19 | 19 | Mark.Zhu - 2022/12/02 |
20 | 20 | Added the littlefs2 mount function,it will be called after a failed attempt to mount littlefs1 |
21 | | -''' |
| 21 | +""" |
22 | 22 | # global datacall_flag |
23 | 23 | datacall_flag = 1 |
24 | 24 |
|
| 25 | + |
25 | 26 | def _repl_enable(): |
26 | 27 | global datacall_flag |
27 | 28 | if "system_config.json" in uos.listdir("/"): |
28 | | - with open("/system_config.json", "r", encoding='utf-8') as fd: |
| 29 | + with open("/system_config.json", "r", encoding="utf-8") as fd: |
29 | 30 | try: |
30 | 31 | json_data = ujson.load(fd) |
31 | 32 | datacall_flag = json_data.get("datacallFlag", 1) |
32 | | - |
33 | 33 | except ValueError: |
34 | | - with open("/usr/system_config.json", "w", encoding='utf-8') as fdw: |
| 34 | + with open("/usr/system_config.json", "w", encoding="utf-8") as fdw: |
35 | 35 | new_json_data = ujson.dumps({"replFlag": 0, "datacallFlag": datacall_flag}) |
36 | 36 | fdw.write(new_json_data) |
37 | 37 | else: |
38 | | - with open("/system_config.json", "w+", encoding='utf-8') as fd: |
| 38 | + with open("/system_config.json", "w+", encoding="utf-8") as fd: |
39 | 39 | repl_data = ujson.dumps({"replFlag": 0}) |
40 | 40 | fd.write(repl_data) |
41 | 41 |
|
42 | | -try: |
| 42 | + |
| 43 | +try: |
43 | 44 | udev = None |
44 | 45 | try: |
45 | 46 | from uos import VfsLfs1 as VfsLfs |
46 | 47 | except Exception: |
47 | 48 | from uos import VfsLfs2 as VfsLfs |
48 | 49 |
|
49 | | - udev = uos.FlashDevice('customer_fs', 4096) |
| 50 | + udev = uos.FlashDevice("customer_fs", 4096) |
50 | 51 | try: |
51 | | - uos.mount(udev, '/') |
| 52 | + uos.mount(udev, "/") |
52 | 53 | except Exception as e: |
53 | | - if 'ENODEV' in str(e): |
| 54 | + if "ENODEV" in str(e): |
54 | 55 | VfsLfs.mkfs(udev) |
55 | | - uos.mount(udev, '/') |
56 | | - else: |
57 | | - raise ValueError("LFS usr mount fail".format(e)) |
58 | | - if 'usr' not in uos.listdir(): |
59 | | - uos.mkdir('usr') |
60 | | - if 'bak' not in uos.listdir(): |
61 | | - uos.mkdir('bak') |
62 | | - |
| 56 | + uos.mount(udev, "/") |
| 57 | + if "usr" not in uos.listdir(): |
| 58 | + uos.mkdir("usr") |
| 59 | + if "bak" not in uos.listdir(): |
| 60 | + uos.mkdir("bak") |
63 | 61 |
|
64 | 62 | except Exception: |
65 | | - print('error occurs in boot step.') |
| 63 | + print("error occurs in boot step.") |
66 | 64 |
|
67 | 65 | finally: |
68 | 66 | _repl_enable() |
0 commit comments