传统的操作系统需要一个bootloader,在bootloader加载操作系统之前,需要BIOS/UEFI或者BSP来完成硬件环境的准备。
那么鸿蒙和BIOS/UEFI/BSP以及bootloader之间是什么关系呢?让我们徜徉在代码的美景,让我们找一下这个桃花源的入口。
从原理上推断,这些代码不在鸿蒙本身,而在鸿蒙配套的开发板上。
例如:海思hi3516dv300单板的U-boot文件请在开源包中获取,路径为vendor\\hisi\\hi35xx\\hi3516dv300\\uboot\\out\\boot\\u-boot-hi3516dv300.bin
我们以hi3861为例,分析一下代码。
https://gitee.com/openharmony/vendor_hisi_hi3861_hi3861/tree/master/hi3861/boot/flashboot/startup
我们看这里的几个文件:
按照惯例从main.c入手。
首先是文件头注释,我们看到这个是一个apache的license,非常友好的。
/*
* Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
然后看里面的干货:
#define KERNEL_START_ADDR 0x40D3C0
hi_u32
g_uart_auth
;
#define FLASHBOOT_UART_DEFAULT_PARAM {115200, 8, 1, 0, 0, 0, 2, 1, 4}
hi_void
boot_kernel
(
uintptr_t
kaddr
)
{
__asm__
__volatile__
(
"ecall"
);
/* switch U-MODE -> M-MODE */
hi_void
(
*
entry
)(
hi_void
)
=
(
hi_void
*
)(
kaddr
);
entry
();
}
启动的参数全部展示出来了。
加载鸿蒙操作系统,调用ecall,从U-MODE切换到M-MODE。
入口地址已经在宏定义声明,入口函数就是直接entry()。
本文参与了「解读鸿蒙源码」技术征文,欢迎正在阅读的你也加入。