ThinkNotes

Simple is not easy | 化繁为简,知易行难

0%

在存储设备的windows系统环境下调试时,因为存储设备本身的问题,有时候coredump不能成功生成到系统目录,本文记录如何修改coredump路径,以及用键盘测试coredump生成符合预期。

使能windows的coredump

Enabling a Kernel-Mode Dump File

修改coredump路径

Windows 的内存转储文件选项概述

可以修改注册表HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\CrashControl的DumpFile键值对,默认路径%SystemRoot%在cmd echo出来是”C:", 修改为指定路径例如”E:\Memory.dmp”。

image-20230724155525547

此操作也可以在控制面板完成,两者等效。

crashcontrol2

使用键盘手动生成coredump

阅读全文 »

前言

最近Debian12发布,尝鲜在移动硬盘装了Debian12+KDE,但不习惯Debian繁琐的包管理和Ubuntu越来越商业化的行为,最终切换到ArchLinux,进入Pacman和AUR的包管理和滚动更新风格。此文记录ArchLinux安装配置过程。

构建多系统的U盘启动盘

使用ventoy/Start to use Ventoy,将各系统镜像放到Ventoy目录即可,不需要用传统的UltraISO那种一个系统ISO要占用整个U盘。
Arch Linux的ISO在此下载

使用archinstall安装ArchLinux

传统的ArchLinux安装方式过于繁琐,现在Arch Linux安装包提供一个类GUI的脚本archinstall,按需求配置即可,可以一键处理包括KDE/GNOME/I3W等桌面在内的全部安装过程。

参考 使用 archinstall 自动化脚本安装 Arch Linux 完整指南使用 archinstall 安装 Arch Linux 和 KDE 桌面环境

我的配置如下。Profile选择安装desktop Kde, Network选择Use NetworkManager后,Kde Plasma被自动安装,不需要按参考文章手动安装桌面:

image-20230712164243209

配置主题

阅读全文 »

安装kernel编译环境

1
sudo apt install build-essential libncurses-dev bison flex libssl-dev libelf-dev

安装bear

1
sudo apt install bear

使用bear编译kernel,生成compile_commands.json,参考:Ubuntu22 直接 make 内核成功,但不能使用 bear 命令

1
bear -- make -j4

在编译Kernel的源代码环境安装clangd服务端:

1
sudo apt install clangd

在查看代码的VSCode环境安装clangd客户端(即VSCode的clangd插件):一般通过windows机器的VSCode SSH连接Linux的clangd服务,因此需要将VSCode的remote SSH登陆到Linux机器(注意不要同时使用Xshell等其他SSH工具,否则VSCode remote SSH连不上)

VSCode remote SSH中打开代码后,clangd自动indexing(完成Kernel index需要相当长时间),CTRL+鼠标左键查看定义,ALT+左键头返回跳转

阅读全文 »

xv6是mit6.828操作系统课程的基于unix v6重新实现的教学操作系统。

本文英文部分是x86版本的xv6(mit6.828 2018及以前的版本)完全注释,github:xv6-annotated

本文中文部分是我学习xv6过程中添加了部分中文注解

DAS BOOT

First things first: in order for a computer to run xv6, we need to load it from
disk into memory and tell the processor to start running it. So how does this
all happen?

The Boot Process

When you press the power button, the hardware gets initialized by a piece of
firmware called the BIOS (Basic Input/Output System) that comes pre-installed on
the motherboard on a ROM chip. Nowadays, your computer probably uses UEFI loaded
from flash memory, but xv6 pretends like it’s 1995 and sticks with BIOS. Since
xv6 runs on x86 hardware, we’re gonna have to satisfy all the janky requirements
that come with that architecture, in addition to the BIOS’s requirements.

Now the BIOS has to load some other code called the boot loader from disk;
then it’s the boot loader’s job to load the OS and get it running. The boot
loader has to act as a middle-man because the BIOS has no idea where on the disk
you decided to put the OS.

The BIOS will look for the boot loader in the very first sector (512 bytes) of
whatever mass storage device you told it to boot from, which we’ll call the boot
disk. The processor will execute the instructions it finds there. This means
you have to make a choice: either your boot loader has to be less than 512 bytes
or you can split it up into smaller parts and have each part load the next one.
xv6 takes the first approach.

The BIOS loads the boot loader into memory at address 0x7C00, then sets the
processor’s %ip register to that address and jumps to it. Remember that %eip
is the instruction pointer on x86? Okay cool. But why did I write %ip instead
of %eip? Well, the BIOS assumes we’re gonna be using 16 bits because of the
hellscape known as backwards-compatibility, so we’ve gotta pretend like it’s
1975 before we can pretend it’s 1995. The irony here is that this initial 16-bit
mode is called “real mode”. So on top of loading the OS, the boot loader will
also have to shepherd the processor from real mode to 32-bit “protected mode”.

阅读全文 »

本文在Ubuntu22.04上搭建xv6(x86版本)的开发环境,用于编译、调试xv6源码。

  • xv6 x86版本参考MIT6.828/2018
  • xv6 riscv版本参考MIT6.S081 ,MIT6.828从2019年以后以RISCV指令集实现,并拆分了课程

两者的课程内容区别:

6.828 and 6.S081 will be offered as two separate classes. 6.S081 (Introduction to Operating Systems) will be taught as a stand-alone AUS subject for undergraduates, and will provide an introduction to operating systems. 6.828 will be offered as a graduate-level seminar-style class focused on research in operating systems. 6.828 will assume you have taken 6.S081 or an equivalent class.

为什么选用x86版本:

x86版本有更完善的资料和更细节的代码讲解,参考:

xv6-annotated

woai3c/MIT6.828

学完x86版本再学riscv版本,只需要关注指令集差异即可

编译工具链

阅读全文 »

PWM简介

先从应用上讲讲PWM:

有一盏日光灯,一般我们只能打开它或者关闭它,不存在中间状态;

有另一个LED灯,支持在一秒以内极快速的速度开关开关,其变化超过人眼识别的24帧率,LED灯看上去就像一直开着,但亮度比常开暗一些;如果控制灯快速开关过程中的打开时间和关闭时间的比例,就可以调节人眼看到的灯亮度。

以上就是PWM的大概应用原理:用高频率的开关信号,控制输出信号的平均强度,使输出信号能在0%到100%强度间任意调节。

用电路语句讲PWM原理:用数字信号的占空比来调制模拟信号的幅度(电压)。

PWM详细介绍参考:What is PWM: Pulse Width Modulation

脉冲宽度(pulse width)是指单位时间的高电平的持续时间,脉冲宽度越大被调制的模拟信号电压越大。

  • 在一定的频率下,通过不同的(高电平)占空比即可得到不同脉冲宽度,进而调节输出的模拟电压信号
  • 在一定的占空比下,通过不同的频率实现不同的调节速度;频率要适配不同设备,不能任意设置,例如电机频率50HZ,MCU外设1000Hz。频率不决定被调制电压的幅度。

PWM的调制信号如下:

阅读全文 »

esp32是乐鑫的SOC,支持Wifi, BLE等IOT功能;官方教程:ESP-IDF编程指南

ESP-IDF环境搭建

按官方教程在Linux ubuntu搭建ESP-IDF开发环境,有clone idf一直失败的问题

本节记录不用翻墙搭建ESP-ID环境的过程,视频参考:Linux 如何安装 ESP-IDF ESP32 开发环境搭建

版本发布、下载

https://github.com/espressif/esp-idf/releases

手动下载release版本的idf压缩包,例如下载esp-idf-v5.0.1.zip

解压到 ~/esp/esp-idf (mv esp-idf-v5.0.1 esp-idf)

安装依赖

1
sudo apt-get install git wget flex bison gperf python3 python3-venv python3-setuptools cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0
阅读全文 »

Ubuntu PC开发环境配置

本文基于Ubuntu 22.04 LTS

系统配置

软件下载源

使用国内软件源下载:

1
software&updates -> Ubuntu Software -> download from -> cn99.com或aliyun.com

中文输入法

安装中文输入法(pinyin)的步骤:

安装中文支持:

1
Settings -> Region&language -> Manage Installed Languages -> Install/Remove Languages -> 安装chinese simplified
阅读全文 »

信号完整性

在讨论ReDriver之前,先说明信号完整性(Signal Integrity, SI)的相关背景。
电子信号在传输过程中(无线或有线)都会受到环境噪声干扰,信号功率也会随着传输距离衰减(signal attenuation)。
通信系统中用信噪比表达的信号的好坏:

1
信噪比(dB)=10*log(信号/噪音)
  • 当信噪比大于设备接收灵敏度时,信号能被正常接收和解析(成逻辑0/1)
  • 当信噪比小于设备接收灵敏度时,信号被错误解析(错误的逻辑0/1)或者是根本解析不出信号(噪声完全淹没信号,接收端恒为0或1,没有信号变化)。

信号完整性(Signal Integrity, SI)一般指PCB电路中的电压信号的信噪比好坏。如果电路中信号能够以要求的时序、持续时间和电压幅度到达接收器,则该电路具有较好的信号完整性。反之当信号不能正常响应时,就出现了信号完整性问题。一般通过眼图观测信号完整性好坏。

信号完整性在高速电路更容易出问题,表现为信号有传输延迟和时序错误、电路串扰(电容性、电感性串扰)等。

高速信号的PCB电路设计和信号完整性密切相关,例如下图是PCB使用FR4材料和Megtron6材料,信号-频率函数显示衰减度不同。

Attenuation versus Frequency as a function of PCB material

ReDriver

Redriver能减弱信号在远距离、高噪声环境的传输中的信号完整性问题对接收端的影响。

阅读全文 »

本文转载自 linked-list-good-taste,添加了个人理解的注释

Linked lists, pointer tricks and good taste

Introduction

In a 2016 TED interview (14:10) Linus Torvalds speaks about what he considers good taste in coding. As an example, he presents two implementations of item removal in singly linked lists (reproduced below). In order to remove the first item from a list, one of the implementations requires a special case, the other one does not. Linus, obviously, prefers the latter.

His comment is:

[…] I don’t want you to understand why it doesn’t have the if statement.
But I want you to understand that sometimes you can see a problem in a
different way and rewrite it so that a special case goes away and becomes the
normal case, and that’s good code. […] – L. Torvalds

The code snippets he presents are C-style pseudocode and are simple enough to follow. However, as Linus mentions in the comment, the snippets lack a conceptual explanation and it is not immediately evident how the more elegant solution actually works.

The next two sections look at the technical approach in detail and demonstrate how and why the indirect addressing approach is so neat. The last section extends the solution from item deletion to insertion.

The code

阅读全文 »