ååã¯ãã ãã¶è¦å´ãã¦ãQEMU ãã½ã¼ã¹ãããã«ããã¾ããã
ä»åã¯ãQEMU ã®ã½ã¼ã¹ã³ã¼ããå¤æ´ãã¦ãSTM32 ã®åä½ãå¤ãã¦ã¿ã¾ãã
ããã§ã¯ããã£ã¦ããã¾ãã
åèæç®
ã¯ããã«
ãQEMUãåãããã®è¨äºä¸è¦§ã§ããè¯ãã£ããåèã«ãã¦ãã ããã
QEMUãåããã®è¨äºä¸è¦§
Interface 2022å¹´ 7æå· ã«ãå¿ç¨ä¾ã¨ãã¦ãQEMU ã®ã½ã¼ã¹ã³ã¼ããå¤æ´ãã¦ãSTM32 ã®åä½ãå¤æ´ããå
容ãæ¸ããã¦ãã¾ãã
第2åã®ãSTM32(ARM Cortex-M)をQEMUで動かす(ソースコード確認編) - daisukeの技術ブログãã§è©ä¾¡ãã¼ãã®ãã¿ã³ãæ¼ãã¦ãã«ã¼ã¬ããã²ã¼ã ã®åä½ã確èªãã¾ããããã®ãã¿ã³ã®åä½ãå¤æ´ããå
容ãæ¸ããã¦ãã¾ãã
å
·ä½çã«ã¯ãé常ã®ãã¿ã³ã¯ããã¿ã³ãæ¼ããã¦ãªãç¶æ
âãã¿ã³ãæ¼ãããç¶æ
âãã¿ã³ãæ¼ããã¦ãªãç¶æ
ã¨å¤åãã¦ããã¾ããããã¿ã³ãæ¼ãããç¶æ
ã§ããã¿ã³ã®ç¶æ
ã®æ´æ°å¦çãåé¤ï¼ã³ã¡ã³ãã¢ã¦ãï¼ãã¦ããã¿ã³ãæ¼ãã£ã±ãªãã®ç¶æ
ãä½ãã¨ãããã®ã§ãã
ããã§ã¯ããã£ã¦ããã¾ãã
QEMUã®ã½ã¼ã¹ãå¤æ´ãã
ã¾ããã½ã¼ã¹ã³ã¼ããç¹å®ãã¾ãã
Cortex-M ç¨ã®ãã¼ãã¦ã§ã¢ã®ã½ã¼ã¹ã³ã¼ãã¯ä»¥ä¸ã«ããã¾ãã
~/Work/xpack-dev-tools/qemu-arm-xpack.git/build/linux-x64/sources/qemu-2.8.0-17-legacy.git/hw/cortexm
ãã®ãã£ã¬ã¯ããªã® button-gpio.c
ãå¤æ´å¯¾è±¡ã®ã½ã¼ã¹ã³ã¼ãã«ãªãã¾ãã
é¢æ°ä¸è¦§ã§ããå
é ã®1ã¤ã ããå
¬éé¢æ°ã§ããã以å¤ã¯ãéå
¬éã®é¢æ°ã§ãã
void button_gpio_create_from_info()
static void button_gpio_down_callback()
static void button_gpio_up_callback()
static void button_gpio_instance_init_callback()
static void button_gpio_realize_callback()
static void button_gpio_reset_callback()
static void button_gpio_class_init_callback()
static void button_gpio_type_init()
対象ã®é¢æ°ã¯ãbutton_gpio_up_callback()
ã§ããã¿ã³ãã¢ãããããï¼æ¼ãããç¶æ
ããé¢ãããç¶æ
ã«ãªã£ãï¼ã¨ãã«å¼ã°ããã³ã¼ã«ããã¯é¢æ°ã®ããã§ãã
ãã®é¢æ°ã®å
容ã¯ä»¥ä¸ã§ãã
static void button_gpio_up_callback(ButtonState *button)
{
qemu_log_function_name();
ButtonGPIOState *state = BUTTON_GPIO_STATE(button);
button->value = state->active_low ? 1 : 0;
printf("[%s up=%d]", object_get_canonical_path_component(OBJECT(button)),
button->value);
cm_irq_set(state->irq_out, button->value);
}
Interface 2022å¹´ 7æå· ã®éãã«å¤æ´ãã¾ãã
å¤æ´å¾ã®ã½ã¼ã¹ã§ãã
å¤æ´ç®æã¯2ãæã§ããã¿ã³ã®å¤ãè¨å®ãã¦ãã1è¡ãã³ã¡ã³ãã¢ã¦ãããã®ã¨ãprintf()
ã§åºåããæååã«ã**fault injection**
ã追å ãã¾ããã
ããã«ããããã¿ã³ãé¢ãããã®ã«ããã®ç¶æ
ã«ç§»è¡ããªãã®ã§ããã¿ã³ãæ¼ããã£ã±ãªãã®ç¶æ
ã«ãªãã¨ãããã¨ã®ããã§ãã
static void button_gpio_up_callback(ButtonState *button)
{
qemu_log_function_name();
ButtonGPIOState *state = BUTTON_GPIO_STATE(button);
printf("[%s up=%d] **fault injection**", object_get_canonical_path_component(OBJECT(button)),
button->value);
cm_irq_set(state->irq_out, button->value);
}
QEMUã®ã½ã¼ã¹ããã«ããã
å·®åãã«ãã試ãã¦ã¿ã
ã¾ãã¯ãå·®åã®ãã«ãã§ãå¤æ´ããã½ã¼ã¹ãåæ ããããã確èªãããã¨æãã¾ããåç´ã«ãdeep-clean
ãå®è¡ããã«ããã以éã®å
容ã ããå®è¡ãã¦ã¿ã¾ãã
xpm run docker-prepare --config linux-x64 -C ~/Work/xpack-dev-tools/qemu-arm-xpack.git && \
xpm run docker-link-deps --config linux-x64 -C ~/Work/xpack-dev-tools/qemu-arm-xpack.git && \
xpm run docker-build-develop --config linux-x64 -C ~/Work/xpack-dev-tools/qemu-arm-xpack.git
ãããªãã3åãããã§ãã«ããå®äºãã¾ãã
å®è¡ãã¦ã¿ã¾ããããæ®å¿µãªãããå¤æ´ã¯åæ ããã¦ãã¾ããã§ããã
package.jsonãèªã
ãã«ãæé ã¯ä»¥ä¸ã«å¾ã£ã¦ãã¾ãã
github.com
ãã«ãæé ã¯ä»¥ä¸ã¨ãªã£ã¦ãã¾ãã
å®éã®ãã«ãã¯æå¾ã®4ã¤ã® xpm ã®å®è¡ã§ãã
rm -f ~/Work/xpack-dev-tools/qemu-arm-xpack.git/package-lock.json && \
git -C ~/Work/xpack-dev-tools/qemu-arm-xpack.git pull && \
xpm run install -C ~/Work/xpack-dev-tools/qemu-arm-xpack.git && \
git -C ~/Work/xpack-dev-tools/xbb-helper-xpack.git pull && \
xpm link -C ~/Work/xpack-dev-tools/xbb-helper-xpack.git && \
xpm run link-deps -C ~/Work/xpack-dev-tools/qemu-arm-xpack.git && \
\
xpm run deep-clean --config linux-x64 -C ~/Work/xpack-dev-tools/qemu-arm-xpack.git && \
xpm run docker-prepare --config linux-x64 -C ~/Work/xpack-dev-tools/qemu-arm-xpack.git && \
xpm run docker-link-deps --config linux-x64 -C ~/Work/xpack-dev-tools/qemu-arm-xpack.git && \
xpm run docker-build-develop --config linux-x64 -C ~/Work/xpack-dev-tools/qemu-arm-xpack.git
ãããããä½ããã¦ãããããpackage.json ã詳ããè¦ã¾ãã
deep-clean
~/Work/xpack-dev-tools/qemu-arm-xpack.git
ã®ãã«ãä¸ã«ä½ããã3ã¤ã®ãã£ã¬ã¯ã㪠build
ãxpacks
ãnode_modules
ãå
¨ã¦åé¤ãã¦ããããã§ããbuild
ã«ã¯å
ã»ã©å¤æ´ããã½ã¼ã¹ã³ã¼ããå«ã¾ããã®ã§ãdeep-clean
ãå®è¡ããã¨å¤æ´ã¯åæ ããã¾ããã
2ã¤ç®ã®å®è¡ã¯ããã®ãã£ã¬ã¯ããªã¯åå¨ããªãã®ã§ä½ãããªãã¨æãã¾ãã
"deep-clean": [
"rm -rf build xpacks node_modules package-lock.json",
"rm -rf ${HOME}/Work/xpack-dev-tools-build/{{ properties.appLcName }}-[0-9]*-*"
],
docker-prepare
ãã£ã¬ã¯ããªã®ä½æã¨ãDockerã³ã³ããã®åä½æãã³ã³ããã®ç°å¢æ§ç¯ãxpm install
ã§å¿
è¦ãªã©ã¤ãã©ãªã®ã¤ã³ã¹ãã¼ã«ã¾ã§ãè¡ã£ã¦ãããã§ãã
"docker-prepare": [
"mkdir -pv ${HOME}/Work/xpack-dev-tools/xbb-helper-xpack.git",
"mkdir -pv ${HOME}/.local/xPacks ${HOME}/.cache/xPacks ${HOME}/Work/cache",
"mkdir -pv ${HOME}/.wine",
"docker rm --force {{ properties.containerName }}",
"docker create --name {{ properties.containerName }} --tty --hostname docker --volume $(pwd):$(pwd) --volume ${HOME}/Work/xpack-dev-tools/xbb-helper-xpack.git:${HOME}/Work/xpack-dev-tools/xbb-helper-xpack.git --volume ${HOME}/.cache/xPacks:${HOME}/.cache/xPacks --volume ${HOME}/Work/cache:${HOME}/Work/cache --volume ${HOME}/.wine:${HOME}/.wine --workdir $(pwd) {{ properties.dockerImage }}",
"docker start {{ properties.containerName }}",
"docker exec {{ properties.containerName }} {{ properties.force32 }} npm install --location=global xpm@{{ properties.xpm-version }}",
"docker exec {{ properties.containerName }} {{ properties.force32 }} userdel node",
"docker exec {{ properties.containerName }} {{ properties.force32 }} groupadd --gid $(id -g) --force $(id -gn)",
"docker exec {{ properties.containerName }} {{ properties.force32 }} useradd --home-dir ${HOME} --uid $(id -u) --gid $(id -g) $(id -un) --create-home",
"docker exec {{ properties.containerName }} {{ properties.force32 }} chown --recursive $(id -u):$(id -g) ${HOME}",
"docker exec --user $(id -un) {{ properties.containerName }} {{ properties.force32 }} bash -c 'lsb_release -sd && whoami && pwd && ls -lLA && ls -l ${HOME}'",
"docker exec --user $(id -un) {{ properties.containerName }} {{ properties.force32 }} xpm install",
"docker exec --user $(id -un) {{ properties.containerName }} {{ properties.force32 }} xpm install --config {{ configuration.name }}"
],
docker-link-deps
ãã¾ãæå³ã¯åãã£ã¦ã¾ããããxpm ã®ãªã³ã¯ãå®è¡ãã¦ãããã§ãã
"docker-link-deps": [
"docker exec --user $(id -un) {{ properties.containerName }} {{ properties.force32 }} xpm link -C ${HOME}/Work/xpack-dev-tools/xbb-helper-xpack.git",
"docker exec --user $(id -un) {{ properties.containerName }} {{ properties.force32 }} xpm run link-deps"
],
docker-build-develop
æå¾ã® xpm ã®å®è¡ã§ããããã§ãã½ã¼ã¹ã®ã¯ãã¼ã³ã¨ãã«ãã®ä¸¡æ¹ãå®è¡ãã¦ãããã§ãã
ã½ã¼ã¹ã®ã¯ãã¼ã³ã®å¾ã«ãã½ã¼ã¹ã®å¤æ´ããããã®ã§ãxpm ã³ãã³ãã®ã¬ãã«ã§ã¯å·®åãã«ãã¯åºæ¥ãªããã¨ã«ãªãã¾ãã
Dockerã³ã³ããä¸ã§ãxpm run build-develop
ãå®è¡ãã¦ããã®ã§ãããããããå°ãç´°ããè¦ã¦ããã¾ãã
"docker-build-develop": [
"docker exec --user $(id -un) {{ properties.containerName }} {{ properties.force32 }} xpm run build-develop --config {{ configuration.name }}"
],
build-develop
build-develop
ã¯ã以ä¸ã¨ãªã£ã¦ãã¾ããé¢ä¿ããããããã£ãè²¼ã£ã¦ããã¾ããã
scripts/build.sh
ãå¼æ°ä»ãã§å®è¡ãã¦ããããã§ãã
"build-develop": "{{ properties.commandBashBuild }} --develop",
"commandBashBuild": "bash {{ properties.dbg }} scripts/build.sh --target {{ configuration.name }} --build-folder {{ properties.buildFolderRelativePathPosix }}",
"dbg": ""
"name": "@xpack-dev-tools/qemu-arm",
"buildFolderRelativePathPosix": "{{ 'build' | path_posix_join: configuration.name | downcase }}",
scripts/build.shãèªã
以ä¸ã¯ãscripts/build.sh
ã®éè¦ãªé¨åã§ãã
ä»ã®ãã¡ã¤ã«ããã£ã¨è¦ãã¨ãããæå¾ãã2çªç®ã® build_common_parse_options
ãã³ãã³ãã©ã¤ã³å¼æ°ã®å¦çã§ãbuild_common_run
ãå®éã®ãã«ããå®è¡ãããã¨ããã®ããã§ãããã以å¤ã¯ãå¤æ°ãé¢æ°ãå®ç¾©ãã¦ããã ãã®ããã§ããã
åå²ãã¦å®è¡ã§ããã¨ããããªã¨æã£ã¦ã¾ãããããããªç°¡åã«ã¯åºæ¥ãªãããã§ãã
source "${scripts_folder_path}/application.sh"
source "${helper_folder_path}/scripts/build-common.sh"
source "${scripts_folder_path}/versioning.sh"
if [ ${#XBB_APPLICATION_COMMON_DEPENDENCIES[@]} -ne 0 ]
then
for dependency in ${XBB_APPLICATION_COMMON_DEPENDENCIES[@]}
do
echo "Including ${helper_folder_path}/dependencies/${dependency}.sh..."
source "${helper_folder_path}/dependencies/${dependency}.sh"
done
fi
if [ ${#XBB_APPLICATION_DEPENDENCIES[@]} -ne 0 ]
then
for dependency in ${XBB_APPLICATION_DEPENDENCIES[@]}
do
echo "Including ${scripts_folder_path}/dependencies/${dependency}.sh..."
source "${scripts_folder_path}/dependencies/${dependency}.sh"
done
fi
help_message=" bash $0 [--win] [--debug] [--develop] [--jobs N] [--help]"
build_common_parse_options "${help_message}" "$@"
build_common_run
make
ãå®è¡ãã¦ããªããdocker-build-develop
ãå®è¡ããã¨ãã«ãå¤æ´ããããã¡ã¤ã«ããã«ã対象ã«ãªã£ã¦å·®åãã«ããåºæ¥ãã¯ãã§ããããªããå¤æ´ãåæ ããã¾ããããã®çç±ãæããã«ããæ¹åã§èãã¾ãã
ã·ã§ã«ã¹ã¯ãªãããè¦ã¦ããã¨ã~/Work/xpack-dev-tools/qemu-arm-xpack.git/scripts/dependencies/qemu-arm-legacy.sh
ã¨ããã®ãè¦ã¤ãã¾ãããããã STM32 ãå«ãããã¤ã³ã³ç¨ã® QEMU ã®ãã«ãã®ããã§ãããã¾ãåãã°ãå·®åãã«ããåºæ¥ããã§ãã
ãã®ã·ã§ã«ã¹ã¯ãªããã詳ããè¦ãã¨ãstampãã¡ã¤ã«ã¨ããã®ãä½ããã¦ããããããã¨ä½ãããªããç¡ããã°ããã«ããããã¹ã«å
¥ããã®ãããªæãã«ãªã£ã¦ãã¾ãã
ã»ã»ã»çç¥ã»ã»ã»
local qemu_arm_legacy_stamp_file_path="${XBB_STAMPS_FOLDER_PATH}/stamp-${qemu_arm_legacy_folder_name}-installed"
if [ ! -f "${qemu_arm_legacy_stamp_file_path}" ] || [ "${XBB_IS_DEBUG}" == "y" ]
then
(
ã»ã»ã»çç¥ã»ã»ã»
echo
echo "Running qemu arm legacy make..."
run_verbose make -j ${XBB_JOBS} V=1
run_verbose make install
run_verbose make install-gme
ã»ã»ã»çç¥ã»ã»ã»
å·®åãã«ãããã£ã¦ã¿ã
試ãã«ã~/Work/xpack-dev-tools/qemu-arm-xpack.git/build/linux-x64/x86_64-pc-linux-gnu/stamps/stamp-qemu-legacy-2.8.0-17-installed
ãåé¤ãã¦ããã¿ã³ãæ¼ãã£ã±ãªãã®ç¶æ
ã«ãªãã½ã¼ã¹ã³ã¼ãã®å¤æ´ãè¡ã£ã¦ããã«ããå®è¡ãã¦ã¿ã¾ãã
ããããå¤æ´ããã½ã¼ã¹ã³ã¼ããåä½ã«åæ ããã¾ãããstamps
ãã£ã¬ã¯ããªã®ãã¡ã¤ã«ã®æç¡ã«ãã£ã¦ããã«ããå®è¡ããããã©ãããå¶å¾¡ãã¦ããããã§ãã
ä»åã¯ä»¥ä¸ã«ãªãã¾ãã
ãããã«
ä»åããã ãã¶è¦å´ãã¦ãQEMU ã®ã½ã¼ã¹ã³ã¼ãã®å¤æ´ãåæ ãããã¨ãåºæ¥ã¾ããã
ãã®è¨äºã誰ãã®å½¹ã«ç«ã¦ã°å¬ããã§ãã
æå¾ã«ãªãã¾ããããã¨ã³ã¸ãã¢ã°ã«ã¼ãã®ã©ã³ãã³ã°ã«åå ä¸ã§ãã
æ°æ¥½ã«ãããã¨ãããããé¡ããããã¾ãð
ä»åã¯ä»¥ä¸ã§ãï¼
æå¾ã¾ã§ãèªã¿ããã ãããããã¨ããããã¾ããã