Professional CMake: A Practical Guide Part III The Bigger Picture

Chapter 23. Finding Things 中等规模以上的项目除了本身的项目之外, 可能还依赖于其他东西. 比如 a particular library or tool, location of a specific configuration file or a header for a library. 甚至项目可能需要找一个 package, 其中定义了一系列内容, 包括 targets, functions, variables… find_...命令提供了搜索 file、library 或 progaram,甚至 package 的能力. 23.1 Finding Files and Paths find_file(outVar name | NAMES name1 [name2...] [HINTS path1 [path2...] [ENV var]...] [PATHS path1 [path2...] [ENV var]...] [PATH_SUFFIXES suffix1 [suffix2 ...]] [NO_DEFAULT_PATH] [NO_PACKAGE_ROOT_PATH] [NO_CMAKE_PATH] [NO_CMAKE_ENVIRONMENT_PATH] [NO_SYSTEM_ENVIRONMENT_PATH] [NO_CMAKE_SYSTEM_PATH] [CMAKE_FIND_ROOT_PATH_BOTH | ONLY_CMAKE_FIND_ROOT_PATH | NO_CMAKE_FIND_ROOT_PATH] [DOC "description"] ) 搜索顺序按如下表格:...

2024-11-30 · 5 min

Professional CMake: A Practical Guide Part II Builds In Depth

Chapter 13. Build Type 13.1 Build Type Basics cmake 有以下几种 build type, 不同的 tpye 会导致 compiler 和 linker flags 不同: Debug: no optimization and full debug information. Release: typically full optimization and no debug information. RelWithDebInfo: 有优化 + debug info. MinRizeRel: 优化 size. 13.1.1 Single Configuration Generators 像 make, ninja, 每个 build directory 只支持一种 build type, 需要在编译时指定 cache variable CMAKE_BUILD_TYPE: cmake -G Ninja -DCMAKE_BUILD_TYPE:STRING=Debug ../source cmake --build . 一种可能的文件布局方式: 13.1.2 Multiple Configuration Generators 类似 Xcode and Visual Studio, 不关注, 跳过....

2024-11-29 · 13 min

Professional CMake: A Practical Guide Part I Fundamentals

Reference Professional CMake A Practical Guide version 1.0.0 2018 年出版, 基于 cmake 3.12 版本(2018-7-17). 目前该书出到了 19th Edition, 支持到 cmake 3.30, 不断更新中. Chapter 1. Introduction From Wikipedia: CMake is a free, cross-platform, software development tool for building applications via compiler-independent instructions. It also can automate testing, packaging and installation. It runs on a variety of platforms and supports many programming languages. Build 部分由其他不同的 build tool 负责, 比如 make, ninja, Visual Studio, XCode…...

2024-11-20 · 14 min

GNU Linker Script

Reference 官方文档: https://sourceware.org/binutils/docs/ld.pdf 2. Invocation 讲了 command line ld 的各种选项。 3. Linker Script 3.1 Basic Linker Script Concepts loadable section and allocatable section A section may be marked as loadable, which means that the contents should be loaded into memory when the output file is run. A section with no contents may be allocatable, which means that an area in memory should be set aside, but nothing in particular should be loaded there (in some cases this memory must be zeroed out)....

2024-11-12 · 3 min

DRM(12) -- Panel

Panel and Bridge 对于 dpi, mipi dsi connector, DRM core 提供了 struct drm_panel 来简化流程。 情况 1:设备树存在 panel 节点 imx6ull-dhcom-pdk2.dts 中的存在 panel 节点,对应 panel-simple.c: &lcdif { status = "okay"; port { display_out: endpoint { remote-endpoint = <&panel_in>; }; }; }; panel { compatible = "auo,g101evn010"; power-supply = <&ldo4_ext>; backlight = <&lcd_backlight>; port { panel_in: endpoint { remote-endpoint = <&display_out>; }; }; }; 这种情况比较简单,在底层 driver 中调用drm_of_find_panel_or_bridge找到设备树中的 panel 节点,和 panel driver 匹配,找到 panel driver 注册的 drm_panel 结构体。...

2024-10-15 · 3 min

CS61A Project2 Cats

Overview 使用如下命令对每个 question 检查正确性: python3 ok -q [question number] -i 使用 ok 系统允许的 debug 打印: print("DEBUG:", x) 运行 cats GUI 系统: python3 cats_gui.py Problem 1 实现 pick 函数,其中函数接受的参数: paragraphs: 表示 paragraphs 的字符串 list select: 一个对字符串的判断函数,return True or False k: 第 k 个满足 select 的 paragraphs 返回 paragraphs 中第 k 个满足 select 的字符串,没有满足的返回空字符串。 def pick(paragraphs, select, k): """Return the Kth paragraph from PARAGRAPHS for which the SELECT returns True. If there are fewer than K such paragraphs, return an empty string....

2024-09-29 · 4 min

Debug DRM driver in QEMU with Buildroot support

Buildroot 编译 kernel 和 rootfs 我们想在 QEMU 中进行 debug,那么首先需要准备好 kernel image 和 rootfs。这边我们采用的是 buildroot 的方式来创建我们需要的 kernel 和 rootfs。 下载 buildroot 2024: wget https://buildroot.org/downloads/buildroot-2024.02.6.tar.gz 接着进入 buildroot 目录,执行 make qemu_x86_64_defconfig,使用 qemu 的配置: cd buildroot-2024.02.6/ make qemu_x86_64_defconfig 对该 config 文件作如下改动: # support custom linux source code BR2_PACKAGE_OVERRIDE_FILE="board/qemu/x86_64/custom_override.mk" BR2_LINUX_KERNEL_CUSTOM_VERSION=y BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="linux-6.10" BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/x86_64/custom_linux.config" # GDB support BR2_PACKAGE_HOST_GDB=y # cross gdb for host machine BR2_PACKAGE_GDB=y BR2_PACKAGE_GDB_SERVER=y BR2_TOOLCHAIN_BUILDROOT_CXX=y BR2_DEBUG_3=y BR2_ENABLE_DEBUG=y # enable debug symbol in packages BR2_OPTIMIZE_0=y BR2_PACKAGE_LIBDRM=y BR2_PACKAGE_DRMTEST=y # custom drm test package 改动目的主要是:...

2024-09-26 · 2 min

DRM(8) -- Encoder

encoder 从 CRTC 拿到 pixel data,并将其转化为 connector 需要的 format。 encoder 通过 drm_encoder_init() 初始化,drm_encoder_cleanup() 清除。 struct drm_encoder_funcs { void (*reset)(struct drm_encoder *encoder); void (*destroy)(struct drm_encoder *encoder); int (*late_register)(struct drm_encoder *encoder); void (*early_unregister)(struct drm_encoder *encoder); void (*debugfs_init)(struct drm_encoder *encoder, struct dentry *root); }; reset: reset encoder。 destroy: drm_encoder_cleanup。如果用 drmm_encoder_init() 初始化的则不需要实现.destroy. late_register: 和 crtc 相关接口类似。 early_unregister: 同上。 debugfs_init: 注册 debugfs_init。 struct drm_encoder { struct drm_device *dev; struct list_head head; struct drm_mode_object base; char *name; int encoder_type; unsigned index; uint32_t possible_crtcs; uint32_t possible_clones; struct list_head bridge_chain; const struct drm_encoder_funcs *funcs; const struct drm_encoder_helper_funcs *helper_private; struct dentry *debugfs_entry; }; encoder_type: DRM_MODE_ENCODER_<foo>...

2024-09-18 · 1 min

DRM(7) -- Connector

DRM connector 是对显示接收器 (display sink) 的抽象,包括固定的 panels, 或者其他任何可以显示像素的东西。 通过 drm_connector_init() 和 drm_connector_register() 初始化和注册。 connector 使用前必须 attach 到 encoder 上,对于 encoder 和 connector 1:1 的情况,在初始化流程中调用 drm_connector_attach_encoder(). Data Structure struct drm_connector { struct drm_device *dev; struct device *kdev; struct device_attribute *attr; struct fwnode_handle *fwnode; struct list_head head; struct list_head global_connector_list_entry; struct drm_mode_object base; char *name; struct mutex mutex; unsigned index; int connector_type; int connector_type_id; bool interlace_allowed; bool doublescan_allowed; bool stereo_allowed; bool ycbcr_420_allowed; enum drm_connector_registration_state registration_state; struct list_head modes; enum drm_connector_status status; struct list_head probed_modes; struct drm_display_info display_info; const struct drm_connector_funcs *funcs; struct drm_property_blob *edid_blob_ptr; struct drm_object_properties properties; uint8_t polled; const struct drm_connector_helper_funcs *helper_private; struct drm_cmdline_mode cmdline_mode; enum drm_connector_force force; u64 epoch_counter; u32 possible_encoders; struct drm_encoder *encoder; struct i2c_adapter *ddc; struct dentry *debugfs_entry; struct drm_connector_state *state; }; connector_type: DRM_MODE_CONNECTOR_XXX。...

2024-09-18 · 4 min

DRM(4) -- CRTC

Overview CRTC 代表整个 display pipeline。它接收来自 drm_plane 的像素数据并将它们混合在一起。drm_display_mode 也附加在 CRTC 上,用于指定显示时序。在输出端,数据被送入一个或多个 drm_encoder,然后每个 encoder 都连接到一个 drm_connector 上。 crtc 使用drm_crtc_init_with_planes() 来初始化。 数据结构 drm_crtc struct drm_crtc { struct drm_device *dev; struct device_node *port; struct list_head head; char *name; struct drm_modeset_lock mutex; struct drm_mode_object base; unsigned index; const struct drm_crtc_funcs *funcs; const struct drm_crtc_helper_funcs *helper_private; struct drm_object_properties properties; struct drm_property *scaling_filter_property; struct drm_crtc_state *state; struct list_head commit_list; spinlock_t commit_lock; struct dentry *debugfs_entry; struct drm_crtc_crc crc; unsigned int fence_context; spinlock_t fence_lock; unsigned long fence_seqno; char timeline_name[32]; struct drm_self_refresh_data *self_refresh_data; }; drm_crtc_state struct drm_crtc_state { struct drm_crtc *crtc; bool enable; bool active; bool planes_changed : 1; bool mode_changed : 1; bool active_changed : 1; bool connectors_changed : 1; bool zpos_changed : 1; bool color_mgmt_changed : 1; bool no_vblank : 1; u32 plane_mask; u32 connector_mask; u32 encoder_mask; struct drm_display_mode adjusted_mode; struct drm_display_mode mode; struct drm_property_blob *mode_blob; struct drm_property_blob *degamma_lut; struct drm_property_blob *ctm; struct drm_property_blob *gamma_lut; u32 target_vblank; bool async_flip; bool vrr_enabled; bool self_refresh_active; enum drm_scaling_filter scaling_filter; struct drm_pending_vblank_event *event; struct drm_crtc_commit *commit; struct drm_atomic_state *state; }; enable: userspace set CRTC MODE_ID property, 进入 drm_atomic_set_mode_prop_for_crtc() 函数中设置 crtc 的 enable 状态。...

2024-09-04 · 4 min