LS1C102是loongarch32架构

LS1C102学习板示意图(正面)


----------------|USB|-------------------------
|
| []                                []
| []  <=拨码(内/外flash)            []  <=拨码(flash/uart)
|
|           [   ch341a   ]
| -                                        -
| -          [][][][] <=4个跳帽            -
| -                                        -
| -          [复位按键]                    -
| -                         [spi flash]    -
|...                                       ...
| -                                        -
| -                                        -
| -           [ LS1C102 ]                  -
| -                                        -
| -  <=排针                                -  <=排针
|
|             [LED1]  <=IO20
|
|                            [用户按键]  <=IO22
|
|           [    JTAG    ]
----------------------------------------------

配套TYPE C数据线一根 烧录是通过ch341a芯片

一.准备工作 开发主机平台 linux/debian minicom 调试串口 flashrom 烧录工具

minicom配置

root@debian:/home/linlin# minicom
root@debian:/home/linlin#

设置波特率115200、数据8位、无校验、停止位1位 保存配置名称为ls1c102

安装flashrom

root@debian:/# apt-get install flashrom

linlin@debian:~$ /usr/sbin/flashrom --help
...
 -r | --read <file>                 read flash and save to <file>
 -w | --write <file>                write <file> to flash
 -v | --verify <file>               verify flash against <file>
 -E | --erase                       erase flash memory
 -V | --verbose                     more verbose output
 -c | --chip <chipname>             probe only for specified flash chip
...
 -L | --list-supported              print supported devices
 -p | --programmer <name>[:<param>] specify the programmer device. One of
    internal, dummy, nic3com, nicrealtek, gfxnvidia, drkaiser, satasii, atavia,
    it8212, ft2232_spi, serprog, buspirate_spi, dediprog, developerbox,
    rayer_spi, pony_spi, nicintel, nicintel_spi, nicintel_eeprom, ogp_spi,
    satamv, linux_mtd, linux_spi, usbblaster_spi, pickit2_spi, ch341a_spi,   <= 支持ch341a芯片
    digilent_spi, stlinkv3_spi.

You can specify one of -h, -R, -L, -E, -r, -w, -v or no operation.
If no operation is specified, flashrom will only probe for flash chips.
linlin@debian:~$ 

可见支持编程器ch341a芯片

TYPE C数据线一端插学习板USB口,另一端插到主机USB口,上电

以下需在root根用户下运行flashrom命令

二.调试串口 原厂程序 四个跳帽全拨掉 拨码(内/外flash) 拨到 外flash 拨码(flash/uart) 拨到 uart

上电,led1灯一闪一闪,应是在运行

店家图片资料标明"uart模式使用flash要拨掉跳线帽",我不清楚要拨掉那个跳帽,所以干脆4个跳帽都拨掉

1.minicom

root@debian:/home/linlin# minicom ls1c102
minicom: 无法打开文件 /dev/modem: 没有那个文件或目录

欢迎使用 minicom 2.9

选项: I18n 
通信端口 /dev/modem /dev/ttyUSB0

按 CTRL-A Z 说明特殊键 

TIMER_WAKE_INT feed WDG!
TIMER_WAKE_INT feed WDG!
TIMER_WAKE_INT feed WDG!
TIMER_WAKE_INT feed WDG!
TIMER_WAKE_INT feed WDG!
按复位按钮
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
||  |||||||||       |||||       ||||   |||||  |||||      |||||       |||||     |
||  ||||||||   ||||  |||   ||||  |||    ||||  ||||  ||||  |||   ||||  |||   ||||
||  ||||||||  |||||| |||  |||||| |||  |  |||  |||  ||||||||||||   |||||||  |||||
||  ||||||||  |||||| |||  |||||| |||  ||  ||  |||  |||    |||||||    ||||  |||||
||  ||||||||  |||||| |||  |||||| |||  |||  |  |||  |||||  ||||||||||  |||  |||||
||  ||||||||   ||||  |||   ||||  |||  ||||    |||   ||||  |||   |||  ||||   ||||
||       ||||       |||||       ||||  |||||   ||||       |||||      ||||||     |
|||||||||||||||||||||||||||||||||||||||[2020 LOONGSON]||||||||||||||||||||||||||
                                                                                
Key reset!                                                                      
                                                                                
spi bootTIMER_WAKE_INT feed WDG!                                                
TIMER_WAKE_INT feed WDG!                                                        
TIMER_WAKE_INT feed WDG!                                                        
root@debian:/home/linlin#

2.读闪存芯片型号

root@debian:/home/linlin# /usr/sbin/flashrom -p ch341a_spi
flashrom unknown on Linux 6.6.15-amd64 (x86_64)
flashrom is free software, get the source code at https://flashrom.org

Using clock_gettime for delay loops (clk_id: 1, resolution: 1ns).
Couldn't open device 1a86:5512.
Error: Programmer initialization failed.   <= 出错

长按复位按钮也一样Error

在启用USB作uart,读闪存出错

三.备份原厂ROM 四个跳帽全插上 拨码(内/外flash) 拨到 内或外flash 拨码(flash/uart) 拨到 flash

上电,led1一闪一闪

1.读闪存芯片型号

root@debian:/home/linlin# /usr/sbin/flashrom -p ch341a_spi
flashrom unknown on Linux 6.6.15-amd64 (x86_64)
flashrom is free software, get the source code at https://flashrom.org

Using clock_gettime for delay loops (clk_id: 1, resolution: 1ns).
===
SFDP has autodetected a flash chip which is not natively supported by flashrom yet.
All standard operations (read, verify, erase and write) should work, but to support all possible features we need to add them manually.
You can help us by mailing us the output of the following command to flashrom@flashrom.org:
'flashrom -VV [plus the -p/--programmer parameter]'
Thanks for your help!
===
Found Unknown flash chip "SFDP-capable chip" (4096 kB, SPI) on ch341a_spi.
===
This flash part has status UNTESTED for operations: WP
The test status of this chip may have been updated in the latest development
version of flashrom. If you are running the latest development version,
please email a report to flashrom@flashrom.org if any of the above operations
work correctly for you with this flash chip. Please include the flashrom log
file for all operations you tested (see the man page for details), and mention
which mainboard or programmer you tested in the subject line.
Thanks for your help!
No operations were specified.
root@debian:/home/linlin# 

没能识别出闪存厂家,但识别出外flash大小4096 kB 在启用USB作flash,读闪存正常,应该是通过ch341a芯片

学习板spi flash芯片图标很模糊,大概Puya p25Q字样,网上搜索是普冉Puya厂家,查到p25q32h规格(32M bit即32/8=4M)已对应上学习板

2.读ROM 备份ROM原来的程序到ls1c_old.bin

root@debian:/home/linlin# /usr/sbin/flashrom -p ch341a_spi  -r ls1c_old.bin
flashrom unknown on Linux 6.6.15-amd64 (x86_64)
...(略,同上)
Thanks for your help!
Reading flash... done.
root@debian:/home/linlin# 

在没识别闪存型号下还是能读出ROM

3.查看大小

root@debian:/home/linlin# ls ls1c_old.bin -l
-rw-r--r-- 1 root root 4194304  3月19日 21:52 ls1c_old.bin
root@debian:/home/linlin# 

4194304=4096K=4M

四.烧录 四个跳帽全插上 拨码(内/外flash) 拨到 外flash 拨码(flash/uart) 拨到 flsah 上电,led1一闪一闪

1.烧写 ls1c102_old.bin为原厂程序

root@debian:/home/linlin# /usr/sbin/flashrom -p ch341a_spi  -w ls1c102_old.bin
flashrom unknown on Linux 6.6.15-amd64 (x86_64)
...
Thanks for your help!
Reading old flash chip contents... done. <= 读时led1灯已灭
Erasing and writing flash chip... 
Warning: Chip content is identical to the requested image.  <= 这个仅警告
Erase/write done. <= 这应烧写成功吧
root@debian:/home/linlin# 

然后烧写过程led1灯灭 烧写完led1灯又一闪一闪,应是启动运行

因为是用原厂程序烧写,无从知道是否烧写成功还是依旧原来的ROM,所以下面先擦除再烧写

2.擦除flash

root@debian:/home/linlin# /usr/sbin/flashrom -p ch341a_spi  -E
flashrom unknown on Linux 6.6.15-amd64 (x86_64)
...
Thanks for your help!
Erasing and writing flash chip... Erase/write done.
root@debian:/home/linlin# 

擦除完,led1不亮 重新上电,led1不亮,说明应真的擦除了

3.重新烧写原厂程序

root@debian:/home/linlin# /usr/sbin/flashrom -p ch341a_spi  -w ls1c102_old.bin
flashrom unknown on Linux 6.6.15-amd64 (x86_64)
...
Thanks for your help!
Reading old flash chip contents... done.
Erasing and writing flash chip... Erase/write done.
Verifying flash... VERIFIED.
root@debian:/home/linlin# 

烧完led1灯一闪一闪

五.总结 LS1C101实验板读、擦除、写闪存过程要长按住复位键不放(https://blog.51cto.com/u_13752418/2579076) LS1C102学习板读、擦除、写闪存都不用长按住复位键