Skip to content

Conversation

messigogogo
Copy link
Contributor

@messigogogo messigogogo commented Sep 28, 2025

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

#10441 修改了 KERNEL_VADDR_START 未定义时的默认值:由原先的 0x1000 改为 ARCH_RAM_OFFSET + ARCH_TEXT_OFFSET。
这一调整在执行 rt_hw_board_init ->rt_hw_mmu_map_init -> rt_aspace_init 时,改变了非 rt-smart 模式下 MMU 虚拟地址与物理地址一一映射的逻辑,我方ARCH_RAM_OFFSET + ARCH_TEXT_OFFSET = 0x80080000,导致 80080000 之前的地址段未被映射,从而引发启动失败。

你的解决方案是什么 (what is your solution)

修改回原来的写法

请提供验证的bsp和config (provide the config and bsp)

  • BSP:
  • .config:
  • action:

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

@messigogogo messigogogo changed the title aarch64 mmu修复 [CPU/AARCH64] 修复 MMU Sep 28, 2025
@github-actions github-actions bot added BSP Arch: ARM/AArch64 BSP related with arm libcpu BSP: Phytium BSP related with Phytium labels Sep 28, 2025
Copy link

👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!

为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).


🛠 操作步骤 | Steps

  1. 前往 Actions 页面 | Go to the Actions page
    点击进入工作流 → | Click to open workflow →

  2. 点击 Run workflow | Click Run workflow

  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  • 将目标分支设置为 \ Set the target branch to:master
  • 设置PR number为 \ Set the PR number to:10757
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将自动推送至你的分支。
    The formatted code will be automatically pushed to your branch.

完成后,提交将自动更新至 master 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the master branch automatically, and the related Pull Request will be updated.

如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!

/* restrict virtual address on usage of RT_NULL */
#ifndef KERNEL_VADDR_START
#define KERNEL_VADDR_START (ARCH_RAM_OFFSET + ARCH_TEXT_OFFSET)
#define KERNEL_VADDR_START 0x1000
Copy link
Member

@supperthomas supperthomas Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个其他平台也是这个值吗?可以kconfig配出这个值吗?
ARCH_RAM_OFFSET 和 ARCH_TEXT_OFFSET

Copy link
Contributor Author

@messigogogo messigogogo Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以前一直都是0x1000,这个值和libcpu\aarch64\link.lds.S 关联,不能随便配,代表内存的起始地址

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image 你可以通过改.config来实现等价这个值,固定某个值估计不太解耦。我估计其他平台这里可能不一样。

@supperthomas
Copy link
Member

@GuEe-GUI @BernardXiong

@GuEe-GUI
Copy link
Contributor

ARCH_RAM_OFFSET 和 ARCH_TEXT_OFFSET配置不出来就再加个配置配置出来,反正不要写死

@messigogogo
Copy link
Contributor Author

messigogogo commented Sep 28, 2025

ARCH_RAM_OFFSET 和 ARCH_TEXT_OFFSET配置不出来就再加个配置配置出来,反正不要写死

我这个值配出来了,加起来是0x8008000,并且需要正确链接到.ld文件里,但是rt_hw_board_init ->rt_hw_mmu_map_init -> rt_aspace_init要用的这个值,范围需要包含我前面的地址,原本的范围是0x1000-0x?现在成了0x80080000-0x?,假设有个串口寄存器0x28000000,如果不走rt_aspace_init流程我这个地址就写不进去。您看有没有更好的方案,不把这两个需求耦合在一起

@GuEe-GUI
Copy link
Contributor

GuEe-GUI commented Sep 28, 2025

考虑使用 rt_ioremap 访问外设么?

如果存在比较大的修改,也可以考虑在 BSP 的配置中强制对 KERNEL_VADDR_START 进行配置:

config KERNEL_VADDR_START
    hex
    default 0x1000

@messigogogo
Copy link
Contributor Author

messigogogo commented Sep 29, 2025

考虑使用 rt_ioremap 访问外设么?

如果存在比较大的修改,也可以考虑在 BSP 的配置中强制对 KERNEL_VADDR_START 进行配置:

config KERNEL_VADDR_START
    hex
    default 0x1000

这种改方法很不方便,因为我也适配了rtsmart,我开启rtsmart配置时,也需要rtsmart的默认值0xffff000000000000,如果在我的bsp里强加这样一个配置就会和libcpu的Kconfig的值冲突,
config KERNEL_VADDR_START
hex
default 0x1000
depends on !RT_USING_SMART,
加载不下来rtsmart的默认值。这个值能否释放出来不和rtsmart强相关?

@GuEe-GUI
Copy link
Contributor

这样可以么?

if RT_USING_SMART
[...]
endif

@messigogogo
Copy link
Contributor Author

这样可以么?

if RT_USING_SMART
[...]
endif
  • 有试过

@GuEe-GUI
Copy link
Contributor

那就再添加一个配置宏,如果没有这个宏就默认为(ARCH_RAM_OFFSET + ARCH_TEXT_OFFSET)

@messigogogo
Copy link
Contributor Author

那就再添加一个配置宏,如果没有这个宏就默认为(ARCH_RAM_OFFSET + ARCH_TEXT_OFFSET)

有没有示例写法,我试一下,KERNEL_VADDR_START,不好被覆盖,我也不好每次开关smart都要手写

@GuEe-GUI
Copy link
Contributor

GuEe-GUI commented Sep 29, 2025

类似这样:

#ifndef KERNEL_VADDR_START
#ifdef  KERNEL_ASPACE_START
#define KERNEL_VADDR_START KERNEL_ASPACE_START
#else
#define KERNEL_VADDR_START (ARCH_RAM_OFFSET + ARCH_TEXT_OFFSET)
#endif
#endif /* KERNEL_VADDR_START */

KERNEL_ASPACE_START 可以由 BSP 自行定义

@messigogogo
Copy link
Contributor Author

类似这样:

#ifndef KERNEL_VADDR_START
#ifdef  KERNEL_ASPACE_START
#define KERNEL_VADDR_START KERNEL_ASPACE_START
#else
#define KERNEL_VADDR_START (ARCH_RAM_OFFSET + ARCH_TEXT_OFFSET)
#endif
#endif /* KERNEL_VADDR_START */

KERNEL_ASPACE_START 可以由 BSP 自行定义

已修改

@Rbb666 Rbb666 added this to the v5.2.2 milestone Oct 5, 2025
@Rbb666
Copy link
Member

Rbb666 commented Oct 9, 2025

@messigogogo 麻烦规范下PR的标题吧,请说明清楚PR修改了什么内容

@messigogogo messigogogo changed the title [CPU/AARCH64] 修复 MMU [CPU/AARCH64] 增加aarch64 KERNEL_ASPACE_START配置 Oct 9, 2025
@messigogogo messigogogo changed the title [CPU/AARCH64] 增加aarch64 KERNEL_ASPACE_START配置 [CPU/AARCH64] 增加libcpu/aarch64 KERNEL_ASPACE_START配置 Oct 9, 2025
@Rbb666 Rbb666 merged commit cc72712 into RT-Thread:master Oct 10, 2025
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: ARM/AArch64 BSP related with arm BSP: Phytium BSP related with Phytium BSP libcpu

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants