Tiny210(S5PV210) U-BOOT(一)----启动过程

CPU上电后,此时SP指针指向0x0000_0000,从这个地址取第一条指令。但此时:PLL没有启动,CPU工作频率为外部输入晶振频率,非常低(S5PV210中晶振在CPU旁边,两颗24MHz,一颗27MHz);CPU的工作模式、中断设置等不确定;存储空间的各个BANK(包括内存)都没有驱动,内存不能使用。在这种情况下必须在第一条指令处做一些初始化工作,这段初始化程序与操作系统独立分开,称之为Bootloader。下面以S5PV210用的U-BOOT为例:


友善之臂Tiny210 SDK2用的是三星公司的S5PV210,在开始U-BOOT的移植之前,有必要弄清楚S5PV210的启动过程:


由图上所知,由OM(Operating Mode)pin导入到iROM中,OM是什么?打开Tiny210V2_V1.0_120713_sch.pdf的原理图,搜索OM

查找到一个表格,有上表可知,OM1/OM2/OM3决定的是从SD卡启动还是从Nand Flash启动。

继续往下看,由图可知,OM1/OM2/OM3分别接在XOM1/XOM2/XOM3上面。

再来看旁边XOM的一个信号反相器74LVC1G04的图


查看74LVC1G04原理图,找到pin脚图和逻辑图



由图可知,这是一个反相器,2中输入高电平,则4中输出低电平;2中输入低电平,则4中输出高电平,OK。
当XOM拨到1时,XOM1为NC状态,XOM1 = 0,pin4的输出为1,XOM2=XOM3=1,则为0-1-1,为SDBOOT;
当XOM拨到2时,XOM1为输入状态,XOM1 = 1,pin4的输出为0,XOM2 = XOM3 = 0,为1-0-0,Nand启动模式,至此,OM的输入判断分析结束。

继续看芯片手册,手册上关于iROM/iRAM及Bootloader描述如下:

  • The iROM code is placed in internal 64KB ROM. It initializes basic system functions such as clock, stack, and heap. 
  • The iROM loads the first boot loader image from a specific booting device to internal 96KB SRAM. The booting device is selected by Operating Mode (OM) pins. According to the secure boot key values, the iROM code may do an integrity check on the first boot loader image. 
  • The first boot loader loads the second boot loader then may check the integrity of the second boot loader according the secure boot key values. 
  • The second boot loader initializes system clock, UART, and DRAM controller. After initializing DRAM controller, it loads OS image from the booting device to DRAM. According to the secure boot key values, the second boot loader can do an integrity check on the OS image. 
  • After the booting completes, the second boot loader jumps to the operating system. 

按照芯片手册上的启动分析图及上面的描述,总结启动流程为:
S5PV210上电将iROM(interal ROM)处执行固化的启动代码,它对系统时钟进行初始化,对启动设备进行判断,并从启动设备中复制BL1(最大16KB)到iRAM(0xd002_0000处,其中0xd002_0010之前的16个字节存储的的BL1的校验信息和BL1尺寸)中,并对BL1进行校验,检验OK转入BL1进行执行;BL1执行完成后,开始执行BL2,BL2加载内核,把OS在SDRAM中运行起来。
BL0,BL1,BL2:
(1)BL0:是指S5PV210的iROM中固化的启动代码
作用初始化系统时钟,设置看门狗,初始化堆和栈,加载BL1
(2)BL1:是批在iRAM自动从外扩存储器(nand/sd/usb)中拷贝的uboot.bin二进制文件的头最大16K代码
作用初始化RAM,关闭Cache,设置栈,加载BL2
(3)BL2:是指在代码重定向后在内存中执行的uboot的完整代码
作用初始化其它外设,加载OS内核
(4)三者之间的关系:(Interal ROM固化代码)BL0将BL1(bootloader的前16KB--BL1)加载到iRAM;BL1然后在iRAM中运行将BL2(整个bootloader)加载到SDRAM(DDR);BL2加载内核,把OS在SDRAM中运行起来,最终OS是运行在SDRAM(内存)中的。
在这个过程中,u-boot需要初始化的硬件是CPU和DDR,所以,这两个硬件必须在u-boot阶段就做好初始化的工作。
### 将 YOLO 格式数据集换为 COCO 格式的实现 YOLOCOCO 是两种常见的目标检测数据集格式,它们之间的主要区别在于标注文件的结构和存储方式。以下是将 YOLO 格式数据集换为 COCO 格式的具体方法。 #### 1. 数据准备 在开始换之前,需要准备好以下内容: - **YOLO 格式的标签文件**:这些是以 `.txt` 文件形式存在的标注文件,位于 `labels/` 文件夹下。 - **图像文件路径列表**:用于构建 COCO 的 `images` 字段。 - **类别名称列表**:定义了数据集中包含的目标类别的名称。 #### 2. 换逻辑 COCO 格式的标注文件是一个 JSON 文件,其基本结构如下: ```json { "info": {}, "licenses": [], "categories": [ {"id": 0, "name": "class_1"}, {"id": 1, "name": "class_2"} ], "images": [ {"id": 0, "file_name": "image_1.jpg", "width": 640, "height": 480}, {"id": 1, "file_name": "image_2.jpg", "width": 640, "height": 480} ], "annotations": [ { "id": 0, "image_id": 0, "category_id": 0, "bbox": [x_min, y_min, width, height], "area": area_of_bbox, "iscrowd": 0 } ] } ``` 为了完成换,需执行以下几个操作: - 构建 `categories` 部分,基于类别名称列表生成对应的 ID 映射关系[^1]。 - 解析每张图片的信息并填充到 `images` 列表中。 - 对于每个标注文件解析边界框坐标,并将其从相对位置 (YOLO 格式) 换为绝对像素位置 (COCO 格式),最后填入 `annotations` 中。 #### 3. Python 实现脚本 下面提供了一个完整的 Python 脚本来完成上述任务: ```python import os import json from PIL import Image def convert_yolo_to_coco(yolo_labels_dir, images_dir, output_json_path, class_names): """ Convert YOLO format dataset to COCO format. :param yolo_labels_dir: Path to the directory containing .txt label files in YOLO format. :param images_dir: Path to the directory containing image files. :param output_json_path: Output path for saving the resulting COCO-format JSON file. :param class_names: List of class names corresponding to indices used in labels. """ # Initialize COCO structure coco_data = { "info": {}, "licenses": [], "categories": [{"id": idx, "name": name} for idx, name in enumerate(class_names)], "images": [], "annotations": [] } annotation_id_counter = 0 # Process each image and its associated label file for img_idx, filename in enumerate(os.listdir(images_dir)): if not filename.lower().endswith(('.png', '.jpg', '.jpeg')): continue img_path = os.path.join(images_dir, filename) img = Image.open(img_path) w, h = img.size # Add image entry coco_image_entry = { "id": img_idx, "file_name": filename, "width": w, "height": h } coco_data["images"].append(coco_image_entry) # Load corresponding label file label_filename = f"{os.path.splitext(filename)[0]}.txt" label_filepath = os.path.join(yolo_labels_dir, label_filename) if not os.path.exists(label_filepath): continue with open(label_filepath, 'r') as lbl_f: lines = lbl_f.readlines() for line in lines: parts = list(map(float, line.strip().split())) cls_id, xc_norm, yc_norm, w_norm, h_norm = map(int, parts[:1]) + parts[1:] # Convert normalized coordinates back to absolute values x_center = xc_norm * w y_center = yc_norm * h box_w = w_norm * w box_h = h_norm * h x_min = int(x_center - box_w / 2) y_min = int(y_center - box_h / 2) # Create annotation entry annotation_entry = { "id": annotation_id_counter, "image_id": img_idx, "category_id": cls_id, "bbox": [x_min, y_min, box_w, box_h], "area": box_w * box_h, "iscrowd": 0 } coco_data["annotations"].append(annotation_entry) annotation_id_counter += 1 # Save result to a JSON file with open(output_json_path, 'w') as out_f: json.dump(coco_data, out_f) if __name__ == "__main__": yolo_labels_directory = "/path/to/yolo/labels/" images_directory = "/path/to/images/" output_json_file = "/path/to/output/coco_format.json" classes_list = ["cat", "dog"] # Replace this with your actual class names. convert_yolo_to_coco( yolo_labels_dir=yolo_labels_directory, images_dir=images_directory, output_json_path=output_json_file, class_names=classes_list ) ``` 此代码实现了从 YOLO 格式COCO 格式换过程[^2]。它通过遍历所有的图片及其关联的标注文件来提取必要的信息,并按照 COCO 的标准格式重组数据。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值